This commit is contained in:
Phillip Thelen 2020-04-22 14:52:36 +02:00
parent e72cc072f1
commit dc803b52f8
4 changed files with 281 additions and 61 deletions

View file

@ -35,72 +35,266 @@
android:background="@color/gray_700"
android:layout_marginBottom="16dp"
/>
<com.habitrpg.android.habitica.ui.views.settings.FixValuesEditText
android:id="@+id/healthEditText"
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="@string/HP_default"
app:fixIconName="health"
app:hintStyle="@style/RedTextLabel"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="12dp"
app:iconBgColor="@color/red_500"/>
<com.habitrpg.android.habitica.ui.views.settings.FixValuesEditText
android:id="@+id/experienceEditText"
android:layout_marginBottom="12dp" >
<View
android:id="@+id/healthIconBackgroundView"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/red_500"/>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<com.google.android.material.textfield.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"
android:paddingTop="8dp"
android:hint="@string/health"
android:paddingStart="16dp">
<EditText
android:id="@+id/healthEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="numberDecimal"
android:background="@android:color/transparent"/>
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="@+id/healthIconView"
android:layout_width="56dp"
android:layout_height="56dp"
android:scaleType="center"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:background="@color/gray_500"
android:layout_marginEnd="56dp"/>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="@string/XP_default"
app:fixIconName="experience"
app:hintStyle="@style/YellowTextLabel"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="12dp"
app:iconBgColor="@color/yellow_500"/>
<com.habitrpg.android.habitica.ui.views.settings.FixValuesEditText
android:id="@+id/manaEditText"
android:layout_marginBottom="12dp" >
<View
android:id="@+id/experienceIconBackgroundView"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/yellow_500"/>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<com.google.android.material.textfield.TextInputLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/layout_rounded_bg_gray_700"
android:paddingTop="8dp"
android:hint="@string/experience_points"
android:paddingStart="16dp">
<EditText
android:id="@+id/experienceEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="numberDecimal"
android:background="@android:color/transparent"/>
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="@+id/experienceIconView"
android:layout_width="56dp"
android:layout_height="56dp"
android:scaleType="center"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:background="@color/gray_500"
android:layout_marginEnd="56dp"/>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="@string/MP_default"
app:fixIconName="mana"
app:hintStyle="@style/BlueTextLabel"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="12dp"
app:iconBgColor="@color/blue_500"/>
<com.habitrpg.android.habitica.ui.views.settings.FixValuesEditText
android:id="@+id/goldEditText"
android:layout_marginBottom="12dp" >
<View
android:id="@+id/manaIconBackgroundView"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/blue_500"/>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<com.google.android.material.textfield.TextInputLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/layout_rounded_bg_gray_700"
android:paddingTop="8dp"
android:hint="@string/mana_points"
android:paddingStart="16dp">
<EditText
android:id="@+id/manaEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="numberDecimal"
android:background="@android:color/transparent"/>
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="@+id/manaIconView"
android:layout_width="56dp"
android:layout_height="56dp"
android:scaleType="center"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:background="@color/gray_500"
android:layout_marginEnd="56dp"/>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="@string/gold_plural"
app:fixIconName="gold"
app:hintStyle="@style/YellowTextLabel"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="12dp"
app:iconBgColor="@color/yellow_500"/>
<com.habitrpg.android.habitica.ui.views.settings.FixValuesEditText
android:id="@+id/levelEditText"
android:layout_marginBottom="12dp" >
<View
android:id="@+id/goldIconBackgroundView"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/yellow_500"/>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<com.google.android.material.textfield.TextInputLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/layout_rounded_bg_gray_700"
android:paddingTop="8dp"
android:hint="@string/gold_capitalilzed"
android:paddingStart="16dp">
<EditText
android:id="@+id/goldEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="numberDecimal"
android:background="@android:color/transparent"/>
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="@+id/goldIconView"
android:layout_width="56dp"
android:layout_height="56dp"
android:scaleType="center"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:background="@color/gray_500"
android:layout_marginEnd="56dp"/>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="@string/character_level"
app:fixIconName="level"
app:hintStyle="@style/PurpleTextLabel"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="12dp"
app:iconBgColor="@color/brand_300"/>
<com.habitrpg.android.habitica.ui.views.settings.FixValuesEditText
android:id="@+id/streakEditText"
android:layout_marginBottom="12dp" >
<View
android:id="@+id/levelIconBackgroundView"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/red_500"/>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<com.google.android.material.textfield.TextInputLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/layout_rounded_bg_gray_700"
android:paddingTop="8dp"
android:hint="@string/character_level"
android:paddingStart="16dp">
<EditText
android:id="@+id/levelEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="number"
android:background="@android:color/transparent"/>
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="@+id/levelIconView"
android:layout_width="56dp"
android:layout_height="56dp"
android:scaleType="center"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:background="@color/gray_500"
android:layout_marginEnd="56dp"/>
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="@string/streak_label"
app:fixIconName="streak"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="12dp"
app:iconBgColor="@color/gray_400"/>
android:layout_marginBottom="12dp" >
<View
android:id="@+id/streakIconBackgroundView"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="@color/gray_400"/>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/streakEditTextWrapper"
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@drawable/layout_rounded_bg_gray_700"
android:paddingTop="8dp"
android:hint="@string/streak_label"
android:paddingStart="16dp">
<EditText
android:id="@+id/streakEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="number"
android:background="@android:color/transparent"/>
</com.google.android.material.textfield.TextInputLayout>
<ImageView
android:id="@+id/streakIconView"
android:layout_width="56dp"
android:layout_height="56dp"
android:scaleType="center"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_gravity="bottom"
android:background="@color/gray_500"
android:layout_marginEnd="56dp"/>
</FrameLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>

View file

@ -24,7 +24,7 @@
android:background="@drawable/layout_rounded_bg_gray_700"
android:paddingTop="8dp"
android:paddingStart="16dp">
<EditText
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="match_parent"

View file

@ -1,10 +1,12 @@
package com.habitrpg.android.habitica.ui.activities
import android.app.ProgressDialog
import android.graphics.PorterDuff
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.EditText
import androidx.core.content.ContextCompat
import com.habitrpg.android.habitica.R
import com.habitrpg.android.habitica.components.UserComponent
@ -15,9 +17,9 @@ import com.habitrpg.android.habitica.models.user.Stats
import com.habitrpg.android.habitica.models.user.User
import com.habitrpg.android.habitica.modules.AppModule
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
import com.habitrpg.android.habitica.ui.views.settings.FixValuesEditText
import io.reactivex.functions.Action
import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.activity_fixcharacter.*
import javax.inject.Inject
import javax.inject.Named
@ -50,6 +52,19 @@ class FixCharacterValuesActivity: BaseActivity() {
compositeSubscription.add(repository.getUser(userId).firstElement().subscribe(Consumer {
user = it
}, RxErrorHandler.handleEmptyError()))
setIconBackground(binding.healthIconBackgroundView, ContextCompat.getColor(this, R.color.red_500))
setIconBackground(binding.experienceIconBackgroundView, ContextCompat.getColor(this, R.color.yellow_500))
setIconBackground(binding.manaIconBackgroundView, ContextCompat.getColor(this, R.color.blue_500))
setIconBackground(binding.goldIconBackgroundView, ContextCompat.getColor(this, R.color.yellow_500))
setIconBackground(binding.streakIconBackgroundView, ContextCompat.getColor(this, R.color.gray_400))
binding.healthIconView.setImageBitmap(HabiticaIconsHelper.imageOfHeartLightBg())
binding.experienceIconView.setImageBitmap(HabiticaIconsHelper.imageOfExperience())
binding.manaIconView.setImageBitmap(HabiticaIconsHelper.imageOfMagic())
binding.goldIconView.setImageBitmap(HabiticaIconsHelper.imageOfGold())
binding.levelIconView.setImageBitmap(HabiticaIconsHelper.imageOfRogueLightBg())
binding.streakIconView.setImageResource(R.drawable.achievement_thermometer)
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
@ -90,35 +105,42 @@ class FixCharacterValuesActivity: BaseActivity() {
private fun updateFields(user: User) {
val stats = user.stats ?: return
binding.healthEditText.text = stats.hp.toString()
binding.experienceEditText.text = stats.exp.toString()
binding.goldEditText.text = stats.gp.toString()
binding.manaEditText.text = stats.mp.toString()
binding.levelEditText.text = stats.lvl.toString()
binding.streakEditText.text = user.streakCount.toString()
binding.healthEditText.setText(stats.hp.toString())
binding.experienceEditText.setText(stats.exp.toString())
binding.goldEditText.setText(stats.gp.toString())
binding.manaEditText.setText(stats.mp.toString())
binding.levelEditText.setText(stats.lvl.toString())
binding.streakEditText.setText(user.streakCount.toString())
when (stats.habitClass) {
Stats.WARRIOR -> {
binding.levelEditText.iconBackgroundColor = ContextCompat.getColor(this, R.color.red_500)
binding.levelEditText.setIconBitmap(HabiticaIconsHelper.imageOfWarriorLightBg())
setIconBackground(levelIconBackgroundView, ContextCompat.getColor(this, R.color.red_500))
binding.levelIconView.setImageBitmap(HabiticaIconsHelper.imageOfWarriorLightBg())
}
Stats.MAGE -> {
binding.levelEditText.iconBackgroundColor = ContextCompat.getColor(this, R.color.blue_500)
binding.levelEditText.setIconBitmap(HabiticaIconsHelper.imageOfMageLightBg())
setIconBackground(levelIconBackgroundView, ContextCompat.getColor(this, R.color.blue_500))
binding.levelIconView.setImageBitmap(HabiticaIconsHelper.imageOfMageLightBg())
}
Stats.HEALER -> {
binding.levelEditText.iconBackgroundColor = ContextCompat.getColor(this, R.color.yellow_500)
binding.levelEditText.setIconBitmap(HabiticaIconsHelper.imageOfHealerLightBg())
setIconBackground(levelIconBackgroundView, ContextCompat.getColor(this, R.color.yellow_500))
binding.levelIconView.setImageBitmap(HabiticaIconsHelper.imageOfHealerLightBg())
}
Stats.ROGUE -> {
binding.levelEditText.iconBackgroundColor = ContextCompat.getColor(this, R.color.brand_500)
binding.levelEditText.setIconBitmap(HabiticaIconsHelper.imageOfRogueLightBg())
setIconBackground(levelIconBackgroundView, ContextCompat.getColor(this, R.color.brand_500))
binding.levelIconView.setImageBitmap(HabiticaIconsHelper.imageOfRogueLightBg())
}
}
}
private fun FixValuesEditText.getDoubleValue(): Double {
val stringValue = this.text
private fun setIconBackground(view: View, color: Int) {
val backgroundDrawable = ContextCompat.getDrawable(this, R.drawable.layout_rounded_bg)
backgroundDrawable?.setColorFilter(color, PorterDuff.Mode.MULTIPLY)
backgroundDrawable?.alpha = 50
view.background = backgroundDrawable
}
private fun EditText.getDoubleValue(): Double {
val stringValue = this.text.toString()
return try {
stringValue.toDouble()
} catch (_: NumberFormatException) {

View file

@ -14,11 +14,12 @@ import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
class FixValuesEditText(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) {
private val binding: FixvaluesEdittextBinding = FixvaluesEdittextBinding.inflate(context.layoutInflater, this)
private var binding: FixvaluesEdittextBinding
var text: String
get() = binding.editText.text.toString()
set(value) {
binding.editText.setText(value)
binding.editText.hint = value
}
@ColorRes
@ -37,6 +38,9 @@ class FixValuesEditText(context: Context, attrs: AttributeSet) : FrameLayout(con
R.styleable.FixValuesEditText,
0, 0)
val view = context.layoutInflater.inflate(R.layout.fixvalues_edittext, this, true)
binding = FixvaluesEdittextBinding.bind(view)
binding.editText.hint = attributes.getString(R.styleable.FixValuesEditText_title)
binding.editTextWrapper.hint = binding.editText.hint
binding.editTextWrapper.setHintTextAppearance(attributes.getResourceId(R.styleable.FixValuesEditText_hintStyle, R.style.PurpleTextLabel))