mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-15 10:41:58 +00:00
allow to change class in settings.
This commit is contained in:
parent
0046e43609
commit
ebe09f0301
4 changed files with 121 additions and 10 deletions
|
|
@ -40,13 +40,9 @@
|
|||
<string name="confirmpassword">Confirm password</string>
|
||||
|
||||
<string name="logout">Logout</string>
|
||||
<string name="logout_description">Log out of your account</string>
|
||||
<string name="account_details">Account Details</string>
|
||||
<string name="LoginActivityName">Welcome</string>
|
||||
<string name="user_dead_title">You\'re dead!</string>
|
||||
<string name="user_dead_mess">You weren\'t vigilant enough, and get lost between some bad habits and some difficult dailies.
|
||||
You are going to revive, but will loose a level, your gold and a random piece of equipment.
|
||||
Try to be more careful with your dailies, and manage those bad habits!
|
||||
</string>
|
||||
|
||||
<string name="string_revive">Revive</string>
|
||||
<string name="please_connect">Please connect through the application before using a widget</string>
|
||||
|
|
@ -329,5 +325,8 @@ To start, which parts of your life do you want to improve?</string>
|
|||
<string name="choose_class">Choose Class</string>
|
||||
<string name="dialog_go_back">Go Back</string>
|
||||
<string name="opt_out_confirmation">Are you sure you want to Opt Out?</string>
|
||||
<string name="change_class">Change your class</string>
|
||||
<string name="change_class_description">Change your class and refund your attribute points for 3 gems. </string>
|
||||
<string name="enable_class">Enable Class System</string>
|
||||
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -3,12 +3,14 @@
|
|||
android:title="@string/PS_contact_title" >
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/pref_account_header">
|
||||
android:title="@string/pref_account_header"
|
||||
android:key="account_prefs">
|
||||
|
||||
<PreferenceScreen
|
||||
android:key="accountDetails"
|
||||
android:title="@string/account_details"
|
||||
android:summary="Check your account details">
|
||||
android:summary="Check your account details"
|
||||
android:order="1">
|
||||
|
||||
<PreferenceCategory android:title="Account Details">
|
||||
|
||||
|
|
@ -48,10 +50,14 @@
|
|||
|
||||
</PreferenceScreen>
|
||||
|
||||
<Preference
|
||||
android:key="choose_class"
|
||||
android:order="2"/>
|
||||
|
||||
<Preference android:title="@string/logout"
|
||||
android:key="logout"
|
||||
android:summary="Log out of your account"/>
|
||||
android:summary="@string/logout_description"
|
||||
android:order="99"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
|
|
|
|||
|
|
@ -167,7 +167,6 @@ public class APIHelper implements ErrorHandler, Profiler {
|
|||
.setLogLevel(BuildConfig.DEBUG ? RestAdapter.LogLevel.FULL : RestAdapter.LogLevel.NONE)
|
||||
.setRequestInterceptor(requestInterceptor)
|
||||
.setConverter(new GsonConverter(gson))
|
||||
|
||||
.build();
|
||||
this.apiService = adapter.create(ApiService.class);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,24 +7,55 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
|
||||
import com.habitrpg.android.habitica.APIHelper;
|
||||
import com.habitrpg.android.habitica.HabiticaApplication;
|
||||
import com.habitrpg.android.habitica.HostConfig;
|
||||
import com.habitrpg.android.habitica.NotificationPublisher;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
|
||||
import com.habitrpg.android.habitica.callbacks.MergeUserCallback;
|
||||
import com.habitrpg.android.habitica.prefs.TimePreference;
|
||||
import com.habitrpg.android.habitica.ui.activities.ClassSelectionActivity;
|
||||
import com.habitrpg.android.habitica.ui.activities.MainActivity;
|
||||
import com.habitrpg.android.habitica.ui.activities.PrefsActivity;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.BaseTransaction;
|
||||
import com.raizlabs.android.dbflow.runtime.transaction.TransactionListener;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import retrofit.Callback;
|
||||
import retrofit.RetrofitError;
|
||||
import retrofit.client.Response;
|
||||
|
||||
public class PreferencesFragment extends BasePreferencesFragment implements
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
SharedPreferences.OnSharedPreferenceChangeListener, Callback<HabitRPGUser> {
|
||||
|
||||
private Context context;
|
||||
private TimePreference timePreference;
|
||||
private Preference classSelectionPreference;
|
||||
private HabitRPGUser user;
|
||||
private APIHelper apiHelper;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
apiHelper = HabiticaApplication.ApiHelper;
|
||||
|
||||
context = getActivity();
|
||||
|
||||
String userID = getPreferenceManager().getSharedPreferences().getString(context.getString(R.string.SP_userID), null);
|
||||
if (userID != null) {
|
||||
new Select().from(HabitRPGUser.class).where(Condition.column("id").eq(userID)).async().querySingle(userTransactionListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -32,6 +63,9 @@ public class PreferencesFragment extends BasePreferencesFragment implements
|
|||
timePreference = (TimePreference) findPreference("reminder_time");
|
||||
boolean useReminder = getPreferenceManager().getSharedPreferences().getBoolean("use_reminder", false);
|
||||
timePreference.setEnabled(useReminder);
|
||||
|
||||
classSelectionPreference = findPreference("choose_class");
|
||||
classSelectionPreference.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -47,11 +81,62 @@ public class PreferencesFragment extends BasePreferencesFragment implements
|
|||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == MainActivity.SELECT_CLASS_RESULT) {
|
||||
if (data.getBooleanExtra("optedOut", false)) {
|
||||
Map<String, Object> updateData = new HashMap<>();
|
||||
updateData.put("preferences.disableClasses", true);
|
||||
updateData.put("flags.classSelected", true);
|
||||
apiHelper.apiService.updateUser(updateData, this);
|
||||
} else {
|
||||
String selectedClass = data.getStringExtra("selectedClass");
|
||||
if (selectedClass != null) {
|
||||
apiHelper.apiService.changeClass(selectedClass, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private TransactionListener<HabitRPGUser> userTransactionListener = new TransactionListener<HabitRPGUser>() {
|
||||
@Override
|
||||
public void onResultReceived(HabitRPGUser habitRPGUser) {
|
||||
PreferencesFragment.this.setUser(habitRPGUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onReady(BaseTransaction<HabitRPGUser> baseTransaction) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasResult(BaseTransaction<HabitRPGUser> baseTransaction, HabitRPGUser habitRPGUser) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(Preference preference) {
|
||||
if (preference.getKey().equals("logout")) {
|
||||
HabiticaApplication.logout(context);
|
||||
getActivity().finish();
|
||||
} else if (preference.getKey().equals("choose_class")) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("size", user.getPreferences().getSize());
|
||||
bundle.putString("skin", user.getPreferences().getSkin());
|
||||
bundle.putString("shirt", user.getPreferences().getShirt());
|
||||
bundle.putInt("hairBangs", user.getPreferences().getHair().getBangs());
|
||||
bundle.putInt("hairBase", user.getPreferences().getHair().getBase());
|
||||
bundle.putString("hairColor", user.getPreferences().getHair().getColor());
|
||||
bundle.putInt("hairMustache", user.getPreferences().getHair().getMustache());
|
||||
bundle.putInt("hairBeard", user.getPreferences().getHair().getBeard());
|
||||
bundle.putBoolean("isInitialSelection", false);
|
||||
|
||||
Intent intent = new Intent(getActivity(), ClassSelectionActivity.class);
|
||||
intent.putExtras(bundle);
|
||||
startActivityForResult(intent, MainActivity.SELECT_CLASS_RESULT);
|
||||
return true;
|
||||
}
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
|
|
@ -115,4 +200,26 @@ public class PreferencesFragment extends BasePreferencesFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
public void setUser(HabitRPGUser user) {
|
||||
this.user = user;
|
||||
if (user.getFlags().getClassSelected()) {
|
||||
if (user.getPreferences().getDisableClasses()) {
|
||||
classSelectionPreference.setTitle(getString(R.string.enable_class));
|
||||
} else {
|
||||
classSelectionPreference.setTitle(getString(R.string.change_class));
|
||||
classSelectionPreference.setSummary(getString(R.string.change_class_description));
|
||||
}
|
||||
classSelectionPreference.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void success(HabitRPGUser habitRPGUser, Response response) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(RetrofitError error) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue