mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-18 19:59:00 +00:00
implement fixing character values
This commit is contained in:
parent
591fff8aa9
commit
fe01f892bb
12 changed files with 325 additions and 4 deletions
|
|
@ -46,6 +46,13 @@
|
|||
android:screenOrientation="portrait"
|
||||
tools:ignore="UnusedAttribute">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.activities.FixCharacterValuesActivity"
|
||||
android:parentActivityName=".ui.activities.PrefsActivity"
|
||||
android:label="@string/PS_settings_title"
|
||||
android:screenOrientation="portrait"
|
||||
tools:ignore="UnusedAttribute">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.activities.LoginActivity"
|
||||
android:label="@string/LoginActivityName"
|
||||
|
|
|
|||
181
Habitica/res/layout/activity_fixcharacter.xml
Normal file
181
Habitica/res/layout/activity_fixcharacter.xml
Normal file
|
|
@ -0,0 +1,181 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context="com.habitrpg.android.habitica.ui.activities.FixCharacterValuesActivity">
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
android:theme="@style/Toolbar"
|
||||
app:layout_scrollFlags="scroll|enterAlways"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark"/>
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
<ScrollView android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:id="@+id/textView5"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/outer_inset"
|
||||
android:text="@string/fix_character_description" />
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginLeft="@dimen/outer_inset"
|
||||
android:layout_marginRight="@dimen/outer_inset">
|
||||
<TableRow>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/stats"
|
||||
style="@style/TableHeader"
|
||||
/>
|
||||
</TableRow>
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/HP_default"
|
||||
android:labelFor="@+id/healthEditText"/>
|
||||
|
||||
<EditText
|
||||
android:id="@id/healthEditText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:inputType="number" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/XP_default"
|
||||
android:labelFor="@+id/experienceEditText" />
|
||||
|
||||
<EditText
|
||||
android:id="@id/experienceEditText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:inputType="number" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/gold_singular"
|
||||
android:labelFor="@+id/goldEditText"/>
|
||||
|
||||
<EditText
|
||||
android:id="@id/goldEditText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:inputType="number" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/MP_default"
|
||||
android:labelFor="@+id/manaEditText"/>
|
||||
|
||||
<EditText
|
||||
android:id="@id/manaEditText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:inputType="number" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/level"
|
||||
android:labelFor="@+id/levelEditText"/>
|
||||
|
||||
<EditText
|
||||
android:id="@id/levelEditText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:inputType="number" />
|
||||
</TableRow>
|
||||
|
||||
<TableRow>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/profile_achievements"
|
||||
style="@style/TableHeader"
|
||||
/>
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/streak_label"
|
||||
android:labelFor="@+id/streakEditText"/>
|
||||
|
||||
<EditText
|
||||
android:id="@id/streakEditText"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:ems="10"
|
||||
android:inputType="number" />
|
||||
</TableRow>
|
||||
|
||||
</TableLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
||||
|
|
@ -665,4 +665,10 @@
|
|||
<string name="want_to_subscribe">I want to Subscribe</string>
|
||||
<string name="seasonal_closed_description">The Grand Galas happen close to the solstices and equinoxes, so check back then to find a fun assortment of special seasonal items!</string>
|
||||
<string name="come_back_soon">Come back soon!</string>
|
||||
<string name="level">Level</string>
|
||||
<string name="streak_label">21-Day Streaks</string>
|
||||
<string name="stats">Stats</string>
|
||||
<string name="fix_character_description">If you\'ve encountered a bug or made a mistake that unfairly changed your character (damage you shouldn\'t have taken, Gold you didn\'t really earn, etc.), you can manually correct your numbers here. Yes, this makes it possible to cheat: use this feature wisely, or you\'ll sabotage your own habit-building!</string>
|
||||
<string name="fix_character_values">Fix Character Values</string>
|
||||
<string name="saving">Saving</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -405,4 +405,8 @@
|
|||
<item name="android:minHeight">12dip</item>
|
||||
<item name="android:maxHeight">12dip</item>
|
||||
</style>
|
||||
|
||||
<style name="TableHeader" parent="Title1">
|
||||
<item name="android:layout_marginTop">@dimen/content_section_spacing</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:title="@string/PS_contact_title" >
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/PS_contact_title">
|
||||
|
||||
<PreferenceCategory
|
||||
android:title="@string/pref_account_header"
|
||||
|
|
@ -95,6 +96,9 @@
|
|||
android:order="6"
|
||||
android:summary="@string/dailyDueDefaultViewDescription"
|
||||
/>
|
||||
<Preference android:title="@string/fix_character_values"
|
||||
app:key="fixCharacterValues"
|
||||
android:order="7"/>
|
||||
<Preference android:title="@string/logout"
|
||||
android:key="logout"
|
||||
android:summary="@string/logout_description"
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import com.habitrpg.android.habitica.ui.activities.AboutActivity;
|
|||
import com.habitrpg.android.habitica.ui.activities.ChallengeDetailActivity;
|
||||
import com.habitrpg.android.habitica.ui.activities.ClassSelectionActivity;
|
||||
import com.habitrpg.android.habitica.ui.activities.CreateChallengeActivity;
|
||||
import com.habitrpg.android.habitica.ui.activities.FixCharacterValuesActivity;
|
||||
import com.habitrpg.android.habitica.ui.activities.FullProfileActivity;
|
||||
import com.habitrpg.android.habitica.ui.activities.GemPurchaseActivity;
|
||||
import com.habitrpg.android.habitica.ui.activities.GroupFormActivity;
|
||||
|
|
@ -93,6 +94,8 @@ import com.habitrpg.android.habitica.widget.HabitButtonWidgetService;
|
|||
import com.habitrpg.android.habitica.widget.TaskListFactory;
|
||||
import com.habitrpg.android.habitica.widget.TaskListWidgetProvider;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Component;
|
||||
|
|
@ -277,4 +280,6 @@ public interface AppComponent {
|
|||
void inject(QuestDetailFragment questDetailFragment);
|
||||
|
||||
void inject(PurchaseDialog purchaseDialog);
|
||||
|
||||
void inject(@NotNull FixCharacterValuesActivity fixCharacterValuesActivity);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ public class User extends RealmObject implements Avatar {
|
|||
private Date lastCron;
|
||||
private Boolean needsCron;
|
||||
private int loginIncentives;
|
||||
private int streakCount;
|
||||
|
||||
public Preferences getPreferences() {
|
||||
return preferences;
|
||||
|
|
@ -364,4 +365,12 @@ public class User extends RealmObject implements Avatar {
|
|||
}
|
||||
return android.R.color.black;
|
||||
}
|
||||
|
||||
public void setStreakCount(int streakCount) {
|
||||
this.streakCount = streakCount;
|
||||
}
|
||||
|
||||
public int getStreakCount() {
|
||||
return streakCount;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,94 @@
|
|||
package com.habitrpg.android.habitica.ui.activities
|
||||
|
||||
import android.app.ProgressDialog
|
||||
import android.os.Bundle
|
||||
import android.os.PersistableBundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.widget.EditText
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.components.AppComponent
|
||||
import com.habitrpg.android.habitica.data.UserRepository
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.user.User
|
||||
import com.habitrpg.android.habitica.modules.AppModule
|
||||
import kotlinx.android.synthetic.main.activity_fixcharacter.*
|
||||
import rx.functions.Action0
|
||||
import rx.functions.Action1
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Named
|
||||
|
||||
class FixCharacterValuesActivity: BaseActivity() {
|
||||
|
||||
@Inject
|
||||
public lateinit var repository: UserRepository
|
||||
|
||||
@field:[Inject Named(AppModule.NAMED_USER_ID)]
|
||||
lateinit var userId: String
|
||||
|
||||
override fun getLayoutResId(): Int = R.layout.activity_fixcharacter
|
||||
|
||||
override fun injectActivity(component: AppComponent?) {
|
||||
component?.inject(this)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setTitle(R.string.fix_character_values)
|
||||
setupToolbar(toolbar)
|
||||
|
||||
repository.getUser(userId).first().subscribe(Action1 {
|
||||
user = it
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_save, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
|
||||
val id = item?.itemId
|
||||
|
||||
if (id == R.id.action_save_changes) {
|
||||
val progressDialog = ProgressDialog.show(this, getString(R.string.saving), "")
|
||||
val userInfo = HashMap<String, Any>()
|
||||
userInfo["stats.hp"] = healthEditText.getDoubleValue()
|
||||
userInfo["stats.exp"] = experienceEditText.getDoubleValue()
|
||||
userInfo["stats.gp"] = goldEditText.getDoubleValue()
|
||||
userInfo["stats.mp"] = manaEditText.getDoubleValue()
|
||||
userInfo["stats.lvl"] = levelEditText.getDoubleValue().toInt()
|
||||
userInfo["achievements.streak"] = streakEditText.getDoubleValue().toInt()
|
||||
repository.updateUser(user, userInfo).subscribe(Action1 {}, RxErrorHandler.handleEmptyError(), Action0 {
|
||||
progressDialog.dismiss()
|
||||
finish()
|
||||
})
|
||||
return true
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
private var user: User? = null
|
||||
set(value) {
|
||||
if (value != null) {
|
||||
updateFields(value)
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateFields(user: User) {
|
||||
healthEditText.setText(user.stats?.hp.toString())
|
||||
experienceEditText.setText(user.stats?.exp.toString())
|
||||
goldEditText.setText(user.stats?.gp.toString())
|
||||
manaEditText.setText(user.stats?.mp.toString())
|
||||
levelEditText.setText(user.stats?.lvl.toString())
|
||||
streakEditText.setText(user.streakCount.toString())
|
||||
}
|
||||
|
||||
fun EditText.getDoubleValue(): Double {
|
||||
val stringValue = this.text.toString()
|
||||
return stringValue.toDouble()
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -137,7 +137,7 @@ public class GroupFormActivity extends BaseActivity {
|
|||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_task_form, menu);
|
||||
getMenuInflater().inflate(R.menu.menu_save, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@ import com.habitrpg.android.habitica.modules.AppModule;
|
|||
import com.habitrpg.android.habitica.ui.WrapContentRecyclerViewLayoutManager;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.CheckListAdapter;
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.RemindersAdapter;
|
||||
import com.habitrpg.android.habitica.ui.fragments.social.party.PartyDetailFragment;
|
||||
import com.habitrpg.android.habitica.ui.helpers.MarkdownParser;
|
||||
import com.habitrpg.android.habitica.ui.helpers.SimpleItemTouchHelperCallback;
|
||||
import com.habitrpg.android.habitica.ui.helpers.ViewHelper;
|
||||
|
|
@ -958,7 +957,7 @@ public class TaskFormActivity extends BaseActivity implements AdapterView.OnItem
|
|||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_task_form, menu);
|
||||
getMenuInflater().inflate(R.menu.menu_save, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import com.habitrpg.android.habitica.helpers.notifications.PushNotificationManag
|
|||
import com.habitrpg.android.habitica.models.user.User;
|
||||
import com.habitrpg.android.habitica.prefs.TimePreference;
|
||||
import com.habitrpg.android.habitica.ui.activities.ClassSelectionActivity;
|
||||
import com.habitrpg.android.habitica.ui.activities.FixCharacterValuesActivity;
|
||||
import com.habitrpg.android.habitica.ui.activities.MainActivity;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
@ -34,6 +35,8 @@ import javax.inject.Inject;
|
|||
|
||||
import rx.Subscription;
|
||||
|
||||
import static com.habitrpg.android.habitica.ui.activities.MainActivity.SELECT_CLASS_RESULT;
|
||||
|
||||
public class PreferencesFragment extends BasePreferencesFragment implements
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
|
|
@ -150,6 +153,9 @@ public class PreferencesFragment extends BasePreferencesFragment implements
|
|||
}
|
||||
RxErrorHandler.reportError(throwable);
|
||||
});
|
||||
} else if (preference.getKey().equals("fixCharacterValues")) {
|
||||
Intent intent = new Intent(getActivity(), FixCharacterValuesActivity.class);
|
||||
getActivity().startActivity(intent);
|
||||
}
|
||||
return super.onPreferenceTreeClick(preference);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -129,6 +129,12 @@ public class UserDeserializer implements JsonDeserializer<User> {
|
|||
user.setNeedsCron(obj.get("needsCron").getAsBoolean());
|
||||
}
|
||||
|
||||
if (obj.has("achievements")) {
|
||||
if (obj.getAsJsonObject("achievements").has("streak")) {
|
||||
user.setStreakCount(obj.getAsJsonObject("achievements").get("streak").getAsInt());
|
||||
}
|
||||
}
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue