mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
Fix stable issues
This commit is contained in:
parent
c7fc3d70aa
commit
2a4a30da3b
13 changed files with 52 additions and 56 deletions
|
|
@ -4,7 +4,8 @@
|
|||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/brand_50012">
|
||||
android:clipToPadding="false"
|
||||
android:clipChildren="false">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/confetti_container"
|
||||
|
|
@ -15,12 +16,12 @@
|
|||
android:orientation="vertical"
|
||||
android:layout_width="360dp"
|
||||
android:layout_height="wrap_content"
|
||||
tools:background="@android:color/black"
|
||||
android:minWidth="300dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:paddingTop="@dimen/spacing_medium"
|
||||
android:paddingBottom="@dimen/spacing_medium"
|
||||
android:clipChildren="false"
|
||||
android:clipToPadding="false"
|
||||
android:padding="@dimen/spacing_large"
|
||||
android:layout_centerInParent="true">
|
||||
<LinearLayout
|
||||
android:id="@+id/dialog_container"
|
||||
|
|
@ -31,7 +32,8 @@
|
|||
android:background="@drawable/alert_dialog_background"
|
||||
android:paddingBottom="24dp"
|
||||
android:paddingTop="40dp"
|
||||
android:gravity="center_horizontal">
|
||||
android:gravity="center_horizontal"
|
||||
android:elevation="12dp">
|
||||
<TextView
|
||||
android:id="@+id/titleTextView"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
@ -121,6 +123,7 @@
|
|||
android:textSize="16sp"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="?colorAccent"
|
||||
android:elevation="12dp"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
||||
|
|
|
|||
|
|
@ -79,12 +79,13 @@
|
|||
<FrameLayout
|
||||
android:layout_width="59dp"
|
||||
android:layout_height="73dp"
|
||||
android:background="@color/offset_background">
|
||||
android:background="@color/offset_background_30">
|
||||
<com.habitrpg.android.habitica.ui.views.CurrencyView
|
||||
android:id="@+id/change_class_currency_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
style="@style/Body1"
|
||||
app:currency="gems"/>
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@
|
|||
<item name="actionOverflowMenuStyle">@style/PopupTheme</item>
|
||||
<item name="android:popupMenuStyle">@style/PopupTheme</item>
|
||||
<item name="android:textColorLink">@color/brand_400</item>
|
||||
<item name="alertDialogTheme">@style/HabiticaAlertDialogTheme</item>
|
||||
<item name="alertDialogTheme">@style/AlertDialogTheme</item>
|
||||
<item name="android:windowTranslucentStatus">false</item>
|
||||
|
||||
<item name="android:statusBarColor">@color/system_bars</item>
|
||||
|
|
@ -482,6 +482,15 @@
|
|||
<item name="android:textColor">@color/dialog_button_text_color</item>
|
||||
</style>
|
||||
|
||||
<style name="AlertDialogTheme" parent="Theme.AppCompat.DayNight.Dialog.Alert">
|
||||
<item name="colorPrimary">@color/text_brand_neon</item>
|
||||
<item name="colorAccent">@color/color_accent</item>
|
||||
<item name="buttonBarNegativeButtonStyle">@style/NegativeButtonStyle</item>
|
||||
<item name="buttonBarNeutralButtonStyle">@style/PositiveButtonStyle</item>
|
||||
<item name="buttonBarPositiveButtonStyle">@style/PositiveButtonStyle</item>
|
||||
<item name="backgroundTint">@color/dialog_background</item>
|
||||
</style>
|
||||
|
||||
<style name="HabiticaAlertDialogTheme" parent="Theme.Material3.DayNight.Dialog.Alert">
|
||||
<item name="colorAccent">@color/brand_400</item>
|
||||
<item name="android:windowFrame">@null</item>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,10 @@ import com.habitrpg.android.habitica.R
|
|||
import com.habitrpg.android.habitica.models.inventory.Animal
|
||||
|
||||
fun Animal.getTranslatedType(c: Context?): String? {
|
||||
return getTranslatedAnimalType(c, type)
|
||||
}
|
||||
|
||||
fun getTranslatedAnimalType(c: Context?, type: String?): String? {
|
||||
if (c == null) {
|
||||
return type
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package com.habitrpg.android.habitica.models.inventory
|
||||
|
||||
class StableSection(val key: Any?, val text: String) {
|
||||
|
||||
class StableSection(val key: String?, val type: String) {
|
||||
var ownedCount = 0
|
||||
var totalCount = 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ class ShopRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<Vi
|
|||
}
|
||||
sectionHolder.switchClassButton?.visibility = View.VISIBLE
|
||||
sectionHolder.switchClassLabel?.text = context.getString(R.string.change_class_to_x, getTranslatedClassName(context.resources, selectedGearCategory))
|
||||
sectionHolder.switchClassCurrency.value = 3.0
|
||||
sectionHolder.switchClassCurrency?.value = 3.0
|
||||
} else {
|
||||
sectionHolder.switchClassButton?.visibility = View.GONE
|
||||
}
|
||||
|
|
|
|||
|
|
@ -171,7 +171,6 @@ class StableRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
|||
}
|
||||
|
||||
internal inner class StableHeaderViewHolder(parent: ViewGroup) : RecyclerView.ViewHolder(parent.inflate(R.layout.shop_header)) {
|
||||
|
||||
private var binding: ShopHeaderBinding = ShopHeaderBinding.bind(itemView)
|
||||
|
||||
fun bind() {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
|||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.data.InventoryRepository
|
||||
import com.habitrpg.android.habitica.databinding.FragmentRefreshRecyclerviewBinding
|
||||
import com.habitrpg.android.habitica.extensions.getTranslatedType
|
||||
import com.habitrpg.android.habitica.models.inventory.Mount
|
||||
import com.habitrpg.android.habitica.models.inventory.StableSection
|
||||
import com.habitrpg.android.habitica.models.user.OwnedMount
|
||||
|
|
@ -19,12 +18,12 @@ import com.habitrpg.android.habitica.ui.helpers.SafeDefaultItemAnimator
|
|||
import com.habitrpg.android.habitica.ui.viewmodels.MainUserViewModel
|
||||
import com.habitrpg.common.habitica.helpers.ExceptionHandler
|
||||
import com.habitrpg.common.habitica.helpers.launchCatching
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
class MountDetailRecyclerFragment :
|
||||
|
|
@ -148,7 +147,7 @@ class MountDetailRecyclerFragment :
|
|||
for (mount in mounts) {
|
||||
if (mount.type == "wacky" || mount.type == "special") continue
|
||||
if (mount.type != lastMount?.type) {
|
||||
currentSection = StableSection(mount.type, mount.getTranslatedType(context) ?: "")
|
||||
currentSection = StableSection(mount.type, "mounts")
|
||||
items.add(currentSection)
|
||||
}
|
||||
currentSection?.let {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
|||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.data.InventoryRepository
|
||||
import com.habitrpg.android.habitica.databinding.FragmentRefreshRecyclerviewBinding
|
||||
import com.habitrpg.android.habitica.extensions.getTranslatedType
|
||||
import com.habitrpg.android.habitica.interactors.FeedPetUseCase
|
||||
import com.habitrpg.android.habitica.models.inventory.Egg
|
||||
import com.habitrpg.android.habitica.models.inventory.Food
|
||||
|
|
@ -25,12 +24,12 @@ import com.habitrpg.android.habitica.ui.helpers.SafeDefaultItemAnimator
|
|||
import com.habitrpg.android.habitica.ui.viewmodels.MainUserViewModel
|
||||
import com.habitrpg.common.habitica.helpers.ExceptionHandler
|
||||
import com.habitrpg.common.habitica.helpers.launchCatching
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
|
||||
@AndroidEntryPoint
|
||||
class PetDetailRecyclerFragment :
|
||||
|
|
@ -201,8 +200,8 @@ class PetDetailRecyclerFragment :
|
|||
currentSection =
|
||||
StableSection(
|
||||
pet.type,
|
||||
pet.getTranslatedType(context) ?: ""
|
||||
)
|
||||
"pets"
|
||||
)
|
||||
items.add(currentSection)
|
||||
}
|
||||
currentSection?.let { section ->
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import android.os.Bundle
|
|||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.fragment.app.viewModels
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
|
|
@ -49,15 +50,7 @@ class StableFragment : BaseMainFragment<FragmentViewpagerBinding>() {
|
|||
|
||||
override fun createFragment(position: Int): androidx.fragment.app.Fragment {
|
||||
val fragment = StableRecyclerFragment()
|
||||
|
||||
when (position) {
|
||||
0 -> {
|
||||
fragment.itemType = "pets"
|
||||
}
|
||||
1 -> {
|
||||
fragment.itemType = "mounts"
|
||||
}
|
||||
}
|
||||
fragment.arguments = bundleOf(StableRecyclerFragment.ITEM_TYPE_KEY to "pets")
|
||||
fragment.itemTypeText = getPageTitle(position)
|
||||
|
||||
return fragment
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ class StableRecyclerFragment :
|
|||
lateinit var userViewModel: MainUserViewModel
|
||||
|
||||
var adapter: StableRecyclerAdapter? = null
|
||||
var itemType: String? = null
|
||||
var itemTypeText: String? = null
|
||||
internal var layoutManager: androidx.recyclerview.widget.GridLayoutManager? = null
|
||||
|
||||
|
|
@ -55,18 +54,6 @@ class StableRecyclerFragment :
|
|||
return FragmentRefreshRecyclerviewBinding.inflate(inflater, container, false)
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
if (savedInstanceState != null) {
|
||||
this.itemType = savedInstanceState.getString(ITEM_TYPE_KEY, "")
|
||||
}
|
||||
|
||||
return super.onCreateView(inflater, container, savedInstanceState)
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
inventoryRepository.close()
|
||||
super.onDestroy()
|
||||
|
|
@ -77,7 +64,7 @@ class StableRecyclerFragment :
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding?.recyclerView?.emptyItem = EmptyItem(
|
||||
getString(R.string.empty_items, itemTypeText ?: itemType)
|
||||
getString(R.string.empty_items, itemTypeText ?: viewModel.itemType)
|
||||
)
|
||||
binding?.refreshLayout?.setOnRefreshListener(this)
|
||||
|
||||
|
|
@ -107,7 +94,7 @@ class StableRecyclerFragment :
|
|||
callback(Pair(egg, potion))
|
||||
}
|
||||
}
|
||||
adapter?.itemType = this.itemType
|
||||
adapter?.itemType = viewModel.itemType
|
||||
adapter?.shopSpriteSuffix = configManager.shopSpriteSuffix()
|
||||
binding?.recyclerView?.adapter = adapter
|
||||
binding?.recyclerView?.itemAnimator = SafeDefaultItemAnimator()
|
||||
|
|
@ -115,7 +102,7 @@ class StableRecyclerFragment :
|
|||
adapter?.let {
|
||||
it.onEquip = {
|
||||
lifecycleScope.launchCatching {
|
||||
inventoryRepository.equip(if (itemType == "pets") "pet" else "mount", it)
|
||||
inventoryRepository.equip(if (viewModel.itemType == "pets") "pet" else "mount", it)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -131,13 +118,13 @@ class StableRecyclerFragment :
|
|||
|
||||
override fun onSaveInstanceState(outState: Bundle) {
|
||||
super.onSaveInstanceState(outState)
|
||||
outState.putString(ITEM_TYPE_KEY, this.itemType)
|
||||
outState.putString(ITEM_TYPE_KEY, viewModel.itemType)
|
||||
}
|
||||
|
||||
private fun setGridSpanCount(width: Int) {
|
||||
var spanCount = 0
|
||||
if (context != null && context?.resources != null) {
|
||||
val animalWidth = if (itemType == "pets") R.dimen.pet_width else R.dimen.mount_width
|
||||
val animalWidth = if (viewModel.itemType == "pets") R.dimen.pet_width else R.dimen.mount_width
|
||||
val itemWidth: Float = context?.resources?.getDimension(animalWidth) ?: 0.toFloat()
|
||||
|
||||
spanCount = (width / itemWidth).toInt()
|
||||
|
|
@ -167,7 +154,7 @@ class StableRecyclerFragment :
|
|||
}
|
||||
|
||||
companion object {
|
||||
private const val ITEM_TYPE_KEY = "CLASS_TYPE_KEY"
|
||||
internal const val ITEM_TYPE_KEY = "CLASS_TYPE_KEY"
|
||||
private const val HEADER_VIEW_TYPE = 0
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import android.widget.Spinner
|
|||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.extensions.getTranslatedAnimalType
|
||||
import com.habitrpg.android.habitica.extensions.inflate
|
||||
import com.habitrpg.android.habitica.models.inventory.StableSection
|
||||
import com.habitrpg.android.habitica.ui.views.CurrencyView
|
||||
|
|
@ -21,7 +22,7 @@ class SectionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
|||
private val selectionSpinner: Spinner? = itemView.findViewById(R.id.classSelectionSpinner)
|
||||
val switchClassButton: LinearLayout? = itemView.findViewById(R.id.change_class_button)
|
||||
val switchClassLabel: TextView? = itemView.findViewById(R.id.change_class_label)
|
||||
val switchClassCurrency: CurrencyView = itemView.findViewById(R.id.change_class_currency_view)
|
||||
val switchClassCurrency: CurrencyView? = itemView.findViewById(R.id.change_class_currency_view)
|
||||
internal val notesView: TextView? = itemView.findViewById(R.id.headerNotesView)
|
||||
private val countPill: TextView? = itemView.findViewById(R.id.count_pill)
|
||||
var context: Context = itemView.context
|
||||
|
|
@ -57,7 +58,11 @@ class SectionViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
|||
}
|
||||
|
||||
fun bind(section: StableSection) {
|
||||
label.text = section.text
|
||||
label.text = if (section.type == "pets") {
|
||||
context.getString(R.string.pet_category, getTranslatedAnimalType(context, section.key))
|
||||
} else {
|
||||
context.getString(R.string.mount_category, getTranslatedAnimalType(context, section.key))
|
||||
}
|
||||
if (section.key == "special") {
|
||||
countPill?.visibility = View.GONE
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package com.habitrpg.android.habitica.ui.viewmodels
|
|||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.SavedStateHandle
|
||||
import androidx.lifecycle.asLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import com.habitrpg.android.habitica.data.InventoryRepository
|
||||
|
|
@ -14,6 +15,7 @@ import com.habitrpg.android.habitica.models.user.OwnedItem
|
|||
import com.habitrpg.android.habitica.models.user.OwnedMount
|
||||
import com.habitrpg.android.habitica.models.user.OwnedObject
|
||||
import com.habitrpg.android.habitica.models.user.OwnedPet
|
||||
import com.habitrpg.android.habitica.ui.fragments.inventory.stable.StableRecyclerFragment
|
||||
import com.habitrpg.common.habitica.helpers.ExceptionHandler
|
||||
import com.habitrpg.common.habitica.helpers.launchCatching
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
|
|
@ -24,12 +26,13 @@ import javax.inject.Inject
|
|||
|
||||
@HiltViewModel
|
||||
class StableViewModel @Inject constructor(
|
||||
savedStateHandle : SavedStateHandle,
|
||||
userRepository : UserRepository,
|
||||
userViewModel : MainUserViewModel,
|
||||
val inventoryRepository : InventoryRepository
|
||||
) : BaseViewModel(userRepository, userViewModel) {
|
||||
|
||||
private val itemType = ""
|
||||
internal val itemType: String? = savedStateHandle.get(StableRecyclerFragment.ITEM_TYPE_KEY)
|
||||
|
||||
private val _items: MutableLiveData<List<Any>> = MutableLiveData()
|
||||
val items: LiveData<List<Any>> = _items
|
||||
|
|
@ -115,14 +118,9 @@ class StableViewModel @Inject constructor(
|
|||
if (items.size > 0 && items[items.size - 1].javaClass == StableSection::class.java) {
|
||||
items.removeAt(items.size - 1)
|
||||
}
|
||||
/*val title = if (itemType == "pets") {
|
||||
application?.getString(R.string.pet_category, animal.getTranslatedType(application))
|
||||
} else {
|
||||
application?.getString(R.string.mount_category, animal.getTranslatedType(application))
|
||||
}
|
||||
val section = StableSection(animal.type, title ?: "")
|
||||
val section = StableSection(animal.type, itemType ?: "")
|
||||
items.add(section)
|
||||
lastSection = section*/
|
||||
lastSection = section
|
||||
}
|
||||
val isOwned = when (itemType) {
|
||||
"pets" -> {
|
||||
|
|
|
|||
Loading…
Reference in a new issue