finish selecting a class after levelup

This commit is contained in:
Phillip Thelen 2016-04-14 17:15:05 +02:00
parent a444dfd3a9
commit 0046e43609
6 changed files with 55 additions and 10 deletions

View file

@ -322,7 +322,7 @@ To start, which parts of your life do you want to improve?</string>
<string name="mage_description">Mages learn swiftly, gaining Experience and Levels faster than other classes. They also get a great deal of Mana for using special abilities. Play a Mage if you enjoy the tactical game aspects of Habit, or if you are strongly motivated by leveling up and unlocking advanced features!</string>
<string name="rogue_description">Rogues love to accumulate wealth, gaining more Gold than anyone else, and are adept at finding random items. Their iconic Stealth ability lets them duck the consequences of missed Dailies. Play a Rogue if you find strong motivation from Rewards and Achievements, striving for loot and badges!</string>
<string name="healer_description">Healers stand impervious against harm, and extend that protection to others. Missed Dailies and bad Habits don\'t faze them much, and they have ways to recover Health from failure. Play a Healer if you enjoy assisting others in your Party, or if the idea of cheating Death through hard work inspires you!</string>
<string name="select_class">Select String</string>
<string name="select_class">Select Class</string>
<string name="opt_out_class">Opt Out</string>
<string name="opt_out_description">Can\'t be bothered with classes? Want to choose later? Opt out - you\'ll be a warrior with no special abilities. You can read about the class system later on the wiki and enable classes at any time.</string>
<string name="class_confirmation" formatted="false">Are you sure you want to be a %s?</string>

View file

@ -0,0 +1,46 @@
package com.habitrpg.android.habitica.callbacks;
import com.habitrpg.android.habitica.ui.activities.MainActivity;
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
import com.magicmicky.habitrpgwrapper.lib.models.Items;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
public class MergeUserCallback implements Callback<HabitRPGUser> {
private final HabitRPGUserCallback.OnUserReceived mCallback;
private HabitRPGUser user;
public MergeUserCallback(HabitRPGUserCallback.OnUserReceived callback, HabitRPGUser user) {
this.mCallback = callback;
this.user = user;
}
@Override
public void success(HabitRPGUser user, Response response) {
if (user.getItems() != null) {
this.user.setItems(user.getItems());
}
if (user.getPreferences() != null) {
this.user.setPreferences(user.getPreferences());
}
if (user.getFlags() != null) {
this.user.setFlags(user.getFlags());
}
if (user.getStats() != null) {
this.user.setStats(user.getStats());
}
this.user.async().save();
mCallback.onUserReceived(this.user);
}
@Override
public void failure(RetrofitError error) {
mCallback.onUserFail();
}
}

View file

@ -92,7 +92,7 @@ public class AvatarWithBarsViewModel implements View.OnClickListener {
mpBar.valueBarLayout.setVisibility((stats.get_class() == null || stats.getLvl() < 10 || user.getPreferences().getDisableClasses()) ? View.GONE : View.VISIBLE);
if (user.getPreferences().getDisableClasses()) {
if (user.getPreferences().getDisableClasses() || !user.getFlags().getClassSelected()) {
lvlText.setText(context.getString(R.string.user_level, user.getStats().getLvl()));
lvlText.setCompoundDrawables(null, null, null, null);
} else {

View file

@ -137,7 +137,7 @@ public class ClassSelectionActivity extends BaseActivity {
.setPositiveButton(getString(R.string.opt_out_class), (dialog, which) -> {
Intent intent = new Intent();
intent.putExtra("optedOut", true);
setResult(RESULT_OK, intent);
setResult(MainActivity.SELECT_CLASS_RESULT, intent);
finish();
}).create();
alert.show();
@ -153,7 +153,7 @@ public class ClassSelectionActivity extends BaseActivity {
Intent intent = new Intent();
intent.putExtra("selectedClass", classIdentifier);
setResult(RESULT_OK, intent);
setResult(MainActivity.SELECT_CLASS_RESULT, intent);
finish();
});
AlertDialog alert = builder.create();

View file

@ -32,6 +32,7 @@ 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.ItemsCallback;
import com.habitrpg.android.habitica.callbacks.MergeUserCallback;
import com.habitrpg.android.habitica.callbacks.TaskScoringCallback;
import com.habitrpg.android.habitica.callbacks.UnlockCallback;
import com.habitrpg.android.habitica.databinding.ValueBarBinding;
@ -127,7 +128,7 @@ public class MainActivity extends BaseActivity implements HabitRPGUserCallback.O
GemsPurchaseFragment.Listener, TutorialView.OnTutorialReaction {
private static final int MIN_LEVEL_FOR_SKILLS = 11;
private static final int SELECT_CLASS_RESULT = 11;
public static final int SELECT_CLASS_RESULT = 11;
@Bind(R.id.floating_menu_wrapper)
FrameLayout floatingMenuWrapper;
@ -637,7 +638,7 @@ public class MainActivity extends BaseActivity implements HabitRPGUserCallback.O
super.onActivityResult(requestCode, resultCode, data);
checkout.onActivityResult(requestCode, resultCode, data);
if (resultCode == SELECT_CLASS_RESULT) {
if (data.getBooleanExtra("optingOut", false)) {
if (data.getBooleanExtra("optedOut", false)) {
Map<String, Object> updateData = new HashMap<>();
updateData.put("preferences.disableClasses", true);
updateData.put("flags.classSelected", true);
@ -645,9 +646,7 @@ public class MainActivity extends BaseActivity implements HabitRPGUserCallback.O
} else {
String selectedClass = data.getStringExtra("selectedClass");
if (selectedClass != null) {
Map<String, Object> updateData = new HashMap<>();
updateData.put("class", selectedClass);
mAPIHelper.apiService.changeClass(updateData, new HabitRPGUserCallback(this));
mAPIHelper.apiService.changeClass(selectedClass, new MergeUserCallback(this, this.user));
}
}
}

View file

@ -122,7 +122,7 @@ public interface ApiService {
void useSkill(@Path("skill") String skillName, @Query("targetType") String targetType, Callback<HabitRPGUser> habitRPGUserCallback);
@POST("/user/class/change")
void changeClass(@Body Map<String, Object> updateDictionary, Callback<HabitRPGUser> cb);
void changeClass(@Query("class") String className, Callback<HabitRPGUser> cb);
/* Group API */