redesign fix character values screen

This commit is contained in:
Phillip Thelen 2017-10-16 11:40:24 +02:00
parent bd4ce296e5
commit ffbbed6d9e
8 changed files with 202 additions and 157 deletions

View file

@ -5,7 +5,8 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
tools:context="com.habitrpg.android.habitica.ui.activities.FixCharacterValuesActivity"> tools:context="com.habitrpg.android.habitica.ui.activities.FixCharacterValuesActivity"
android:background="@color/white">
<android.support.design.widget.AppBarLayout <android.support.design.widget.AppBarLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
@ -30,152 +31,77 @@
android:id="@+id/textView5" android:id="@+id/textView5"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="@dimen/outer_inset" android:padding="@dimen/outer_inset"
android:text="@string/fix_character_description" /> android:text="@string/fix_character_description"
android:background="@color/gray_700"
android:layout_marginBottom="16dp"
/>
<TableLayout <com.habitrpg.android.habitica.ui.views.settings.FixValuesEditText
android:id="@+id/healthEditText"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/outer_inset" app:title="@string/HP_default"
android:layout_marginRight="@dimen/outer_inset"> app:fixIconName="health"
<TableRow> app:hintStyle="@style/RedTextLabel"
<TextView android:layout_marginLeft="16dp"
android:layout_width="match_parent" android:layout_marginRight="16dp"
android:layout_height="wrap_content" android:layout_marginBottom="12dp"
android:text="@string/stats" app:iconBgColor="@color/red_500"/>
style="@style/TableHeader" <com.habitrpg.android.habitica.ui.views.settings.FixValuesEditText
/> android:id="@+id/experienceEditText"
</TableRow> android:layout_width="match_parent"
<TableRow android:layout_height="wrap_content"
android:layout_width="match_parent" app:title="@string/XP_default"
android:layout_height="match_parent"> app:fixIconName="experience"
app:hintStyle="@style/YellowTextLabel"
<TextView android:layout_marginLeft="16dp"
android:layout_width="0dp" android:layout_marginRight="16dp"
android:layout_height="wrap_content" android:layout_marginBottom="12dp"
android:layout_weight="1" app:iconBgColor="@color/yellow_500"/>
android:text="@string/HP_default" <com.habitrpg.android.habitica.ui.views.settings.FixValuesEditText
android:labelFor="@+id/healthEditText"/> android:id="@+id/manaEditText"
android:layout_width="match_parent"
<EditText android:layout_height="wrap_content"
android:id="@+id/healthEditText" app:title="@string/MP_default"
android:layout_width="0dp" app:fixIconName="mana"
android:layout_height="wrap_content" app:hintStyle="@style/BlueTextLabel"
android:layout_weight="1" android:layout_marginLeft="16dp"
android:ems="10" android:layout_marginRight="16dp"
android:inputType="number" /> android:layout_marginBottom="12dp"
</TableRow> app:iconBgColor="@color/blue_500"/>
<com.habitrpg.android.habitica.ui.views.settings.FixValuesEditText
<TableRow android:id="@+id/goldEditText"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="wrap_content"
app:title="@string/gold_plural"
<TextView app:fixIconName="gold"
android:layout_width="0dp" app:hintStyle="@style/YellowTextLabel"
android:layout_height="wrap_content" android:layout_marginLeft="16dp"
android:layout_weight="1" android:layout_marginRight="16dp"
android:text="@string/XP_default" android:layout_marginBottom="12dp"
android:labelFor="@+id/experienceEditText" /> app:iconBgColor="@color/yellow_500"/>
<com.habitrpg.android.habitica.ui.views.settings.FixValuesEditText
<EditText android:id="@+id/levelEditText"
android:id="@+id/experienceEditText" android:layout_width="match_parent"
android:layout_width="0dp" android:layout_height="wrap_content"
android:layout_height="wrap_content" app:title="@string/character_level"
android:layout_weight="1" app:fixIconName="level"
android:ems="10" app:hintStyle="@style/PurpleTextLabel"
android:inputType="number" /> android:layout_marginLeft="16dp"
</TableRow> android:layout_marginRight="16dp"
android:layout_marginBottom="12dp"
<TableRow app:iconBgColor="@color/brand_300"/>
android:layout_width="match_parent" <com.habitrpg.android.habitica.ui.views.settings.FixValuesEditText
android:layout_height="match_parent"> android:id="@+id/streakEditText"
android:layout_width="match_parent"
<TextView android:layout_height="wrap_content"
android:layout_width="0dp" app:title="@string/streak_label"
android:layout_height="wrap_content" app:fixIconName="streak"
android:layout_weight="1" android:layout_marginLeft="16dp"
android:text="@string/gold_singular" android:layout_marginRight="16dp"
android:labelFor="@+id/goldEditText"/> android:layout_marginBottom="12dp"
app:iconBgColor="@color/gray_400"/>
<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> </LinearLayout>
</ScrollView> </ScrollView>
</LinearLayout> </LinearLayout>

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<merge 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:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_margin="6dp"
android:background="@drawable/layout_rounded_bg"
tools:parentTag="FrameLayout">
<View
android:id="@+id/iconBackgroundView"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="@color/red_500"/>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<android.support.design.widget.TextInputLayout
android:id="@+id/editTextWrapper"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/layout_rounded_bg_gray_700">
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="number" />
</android.support.design.widget.TextInputLayout>
<ImageView
android:id="@+id/iconView"
android:layout_width="56dp"
android:layout_height="56dp"
android:scaleType="center"/>
</LinearLayout>
</merge>

View file

@ -42,4 +42,10 @@
<declare-styleable name="CurrencyViews"> <declare-styleable name="CurrencyViews">
<attr name="hasLightBackground" format="boolean" /> <attr name="hasLightBackground" format="boolean" />
</declare-styleable> </declare-styleable>
<declare-styleable name="FixValuesEditText">
<attr name="fixIconName" format="string" />
<attr name="title" format="string" />
<attr name="iconBgColor" format="color" />
<attr name="hintStyle" format="integer" />
</declare-styleable>
</resources> </resources>

View file

@ -668,7 +668,7 @@
<string name="level">Level</string> <string name="level">Level</string>
<string name="streak_label">21-Day Streaks</string> <string name="streak_label">21-Day Streaks</string>
<string name="stats">Stats</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_description">If youve encountered a bug or made a mistake that unfairly changed your character, you can manually correct those values here.</string>
<string name="fix_character_values">Fix Character Values</string> <string name="fix_character_values">Fix Character Values</string>
<string name="saving">Saving</string> <string name="saving">Saving</string>
<string name="forgot_password_title">Email a Password Reset Link</string> <string name="forgot_password_title">Email a Password Reset Link</string>
@ -688,4 +688,5 @@
<string name="change_email">Change Email Address</string> <string name="change_email">Change Email Address</string>
<string name="change_login_name">Change Login Name</string> <string name="change_login_name">Change Login Name</string>
<string name="change">Change</string> <string name="change">Change</string>
<string name="character_level">Character Level</string>
</resources> </resources>

View file

@ -409,4 +409,18 @@
<style name="TableHeader" parent="Title1"> <style name="TableHeader" parent="Title1">
<item name="android:layout_marginTop">@dimen/content_section_spacing</item> <item name="android:layout_marginTop">@dimen/content_section_spacing</item>
</style> </style>
<style name="RedTextLabel" parent="TextAppearance.AppCompat">
<item name="android:textColor">@color/red_10</item>
</style>
<style name="YellowTextLabel" parent="TextAppearance.AppCompat">
<item name="android:textColor">@color/yellow_10</item>
</style>
<style name="BlueTextLabel" parent="TextAppearance.AppCompat">
<item name="android:textColor">@color/blue_10</item>
</style>
<style name="PurpleTextLabel" parent="TextAppearance.AppCompat">
<item name="android:textColor">@color/brand_300</item>
</style>
</resources> </resources>

View file

@ -12,6 +12,7 @@ import com.habitrpg.android.habitica.data.UserRepository
import com.habitrpg.android.habitica.helpers.RxErrorHandler import com.habitrpg.android.habitica.helpers.RxErrorHandler
import com.habitrpg.android.habitica.models.user.User import com.habitrpg.android.habitica.models.user.User
import com.habitrpg.android.habitica.modules.AppModule import com.habitrpg.android.habitica.modules.AppModule
import com.habitrpg.android.habitica.ui.views.settings.FixValuesEditText
import kotlinx.android.synthetic.main.activity_fixcharacter.* import kotlinx.android.synthetic.main.activity_fixcharacter.*
import rx.functions.Action0 import rx.functions.Action0
import rx.functions.Action1 import rx.functions.Action1
@ -78,16 +79,16 @@ class FixCharacterValuesActivity: BaseActivity() {
} }
private fun updateFields(user: User) { private fun updateFields(user: User) {
healthEditText.setText(user.stats?.hp.toString()) healthEditText.text = user.stats?.hp.toString()
experienceEditText.setText(user.stats?.exp.toString()) experienceEditText.text = user.stats?.exp.toString()
goldEditText.setText(user.stats?.gp.toString()) goldEditText.text = user.stats?.gp.toString()
manaEditText.setText(user.stats?.mp.toString()) manaEditText.text = user.stats?.mp.toString()
levelEditText.setText(user.stats?.lvl.toString()) levelEditText.text = user.stats?.lvl.toString()
streakEditText.setText(user.streakCount.toString()) streakEditText.text = user.streakCount.toString()
} }
fun EditText.getDoubleValue(): Double { fun FixValuesEditText.getDoubleValue(): Double {
val stringValue = this.text.toString() val stringValue = this.text
return stringValue.toDouble() return stringValue.toDouble()
} }

View file

@ -14,12 +14,10 @@ import butterknife.BindView
import com.habitrpg.android.habitica.ui.fragments.preferences.APIPreferenceFragment import com.habitrpg.android.habitica.ui.fragments.preferences.APIPreferenceFragment
import com.habitrpg.android.habitica.ui.fragments.preferences.AuthenticationPreferenceFragment import com.habitrpg.android.habitica.ui.fragments.preferences.AuthenticationPreferenceFragment
import com.habitrpg.android.habitica.ui.fragments.preferences.ProfilePreferencesFragment import com.habitrpg.android.habitica.ui.fragments.preferences.ProfilePreferencesFragment
import kotlinx.android.synthetic.main.activity_prefs.*
class PrefsActivity : BaseActivity(), PreferenceFragmentCompat.OnPreferenceStartScreenCallback { class PrefsActivity : BaseActivity(), PreferenceFragmentCompat.OnPreferenceStartScreenCallback {
@BindView(R.id.toolbar)
lateinit var toolbar: Toolbar
override fun getLayoutResId(): Int = R.layout.activity_prefs override fun getLayoutResId(): Int = R.layout.activity_prefs
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {

View file

@ -0,0 +1,61 @@
package com.habitrpg.android.habitica.ui.views.settings
import android.content.Context
import android.content.res.TypedArray
import android.graphics.PorterDuff
import android.support.v4.content.ContextCompat
import android.util.AttributeSet
import android.view.View
import android.widget.EditText
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import com.habitrpg.android.habitica.R
import butterknife.BindView
import butterknife.ButterKnife
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
import kotlinx.android.synthetic.main.fixvalues_edittext.view.*
class FixValuesEditText(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) {
var text: String
get() = editText?.text.toString()
set(value) {
editText?.setText(value)
}
init {
View.inflate(context, R.layout.fixvalues_edittext, this)
ButterKnife.bind(this)
val attributes = context.theme.obtainStyledAttributes(
attrs,
R.styleable.FixValuesEditText,
0, 0)
editText.hint = attributes.getString(R.styleable.FixValuesEditText_title)
editTextWrapper.hint = editText.hint
editTextWrapper.setHintTextAppearance(attributes.getInteger(R.styleable.FixValuesEditText_hintStyle, R.style.PurpleTextLabel))
val backgroundDrawable = ContextCompat.getDrawable(context, R.drawable.layout_rounded_bg)
backgroundDrawable.setColorFilter(attributes.getColor(R.styleable.FixValuesEditText_iconBgColor, 0), PorterDuff.Mode.MULTIPLY)
backgroundDrawable.alpha = 50
iconBackgroundView.background = backgroundDrawable
val iconName = attributes.getString(R.styleable.FixValuesEditText_fixIconName)
if (iconName == "health") {
iconView.setImageBitmap(HabiticaIconsHelper.imageOfHeartLightBg())
} else if (iconName == "experience") {
iconView.setImageBitmap(HabiticaIconsHelper.imageOfExperience())
} else if (iconName == "mana") {
iconView.setImageBitmap(HabiticaIconsHelper.imageOfMagic())
} else if (iconName == "gold") {
iconView.setImageBitmap(HabiticaIconsHelper.imageOfGold())
} else if (iconName == "level") {
iconView.setImageBitmap(HabiticaIconsHelper.imageOfRogueLightBg())
} else if (iconName == "streak") {
}
}
}