mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-07-13 17:51:57 +00:00
Fix stable section header
This commit is contained in:
parent
ae992accfe
commit
a371ee4410
4 changed files with 51 additions and 22 deletions
|
|
@ -240,7 +240,11 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
|
|||
}
|
||||
if (destination.id == R.id.petDetailRecyclerFragment || destination.id == R.id.mountDetailRecyclerFragment) {
|
||||
compositeSubscription.add(inventoryRepository.getItem("egg", arguments?.getString("type") ?: "").firstElement().subscribe(Consumer {
|
||||
binding.toolbarTitle.text = (it as? Egg)?.mountText
|
||||
binding.toolbarTitle.text = if (destination.id == R.id.petDetailRecyclerFragment) {
|
||||
(it as? Egg)?.text
|
||||
} else {
|
||||
(it as? Egg)?.mountText
|
||||
}
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
drawerFragment?.setSelection(destination.id, null, false)
|
||||
|
|
|
|||
|
|
@ -135,7 +135,10 @@ class StableRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
|||
fun bind(item: Animal) {
|
||||
this.animal = item
|
||||
val context = itemView.context
|
||||
titleView.text = eggs[item.animal]?.mountText ?: item.animal
|
||||
val egg = eggs[item.animal]
|
||||
if (egg != null) {
|
||||
titleView.text = if (item.type == "drop" || itemType == "mounts") egg.mountText else egg.text
|
||||
} else item.animal
|
||||
ownedTextView.visibility = View.VISIBLE
|
||||
|
||||
val imageName = if (itemType == "pets") {
|
||||
|
|
|
|||
|
|
@ -14,12 +14,16 @@ import com.habitrpg.android.habitica.models.inventory.Mount
|
|||
import com.habitrpg.android.habitica.models.inventory.Pet
|
||||
import com.habitrpg.android.habitica.models.inventory.StableSection
|
||||
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.adapter.inventory.MountDetailRecyclerAdapter
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment
|
||||
import com.habitrpg.android.habitica.ui.helpers.MarginDecoration
|
||||
import com.habitrpg.android.habitica.ui.helpers.SafeDefaultItemAnimator
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
||||
import io.reactivex.functions.BiFunction
|
||||
import io.reactivex.functions.Consumer
|
||||
import io.realm.RealmResults
|
||||
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -116,27 +120,35 @@ class MountDetailRecyclerFragment : BaseMainFragment() {
|
|||
|
||||
private fun loadItems() {
|
||||
if (animalType != null || animalGroup != null) {
|
||||
compositeSubscription.add(inventoryRepository.getOwnedMounts().firstElement()
|
||||
compositeSubscription.add(inventoryRepository.getMounts(animalType, animalGroup, animalColor)
|
||||
.zipWith(inventoryRepository.getOwnedMounts()
|
||||
.map { ownedMounts ->
|
||||
val mountMap = mutableMapOf<String, OwnedMount>()
|
||||
ownedMounts.forEach { mountMap[it.key ?: ""] = it }
|
||||
return@map mountMap
|
||||
}
|
||||
.subscribe(Consumer { adapter?.setOwnedMounts(it) }, RxErrorHandler.handleEmptyError()))
|
||||
compositeSubscription.add(inventoryRepository.getMounts(animalType, animalGroup, animalColor)
|
||||
.map {
|
||||
}.doOnNext {
|
||||
adapter?.setOwnedMounts(it)
|
||||
}, BiFunction<RealmResults<out Mount>, Map<String, OwnedObject>, List<Any>> { unsortedAnimals, ownedAnimals ->
|
||||
val items = mutableListOf<Any>()
|
||||
var lastMount: Mount? = null
|
||||
for (mount in it) {
|
||||
var currentSection: StableSection? = null
|
||||
for (mount in unsortedAnimals) {
|
||||
if (mount.type == "wacky" || mount.type == "special") continue
|
||||
if (mount.type != lastMount?.type) {
|
||||
items.add(StableSection(mount.type, mount.getTranslatedType(context)))
|
||||
currentSection = StableSection(mount.type, mount.getTranslatedType(context))
|
||||
items.add(currentSection)
|
||||
}
|
||||
currentSection?.let {
|
||||
it.totalCount += 1
|
||||
if (ownedAnimals.containsKey(mount.key)) {
|
||||
it.ownedCount += 1
|
||||
}
|
||||
}
|
||||
items.add(mount)
|
||||
lastMount = mount
|
||||
}
|
||||
items
|
||||
}
|
||||
})
|
||||
.subscribe(Consumer { adapter?.setItemList(it) }, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
|||
import com.habitrpg.android.habitica.models.inventory.*
|
||||
import com.habitrpg.android.habitica.models.user.Items
|
||||
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.adapter.inventory.PetDetailRecyclerAdapter
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment
|
||||
|
|
@ -21,9 +22,11 @@ import com.habitrpg.android.habitica.ui.helpers.MarginDecoration
|
|||
import com.habitrpg.android.habitica.ui.helpers.SafeDefaultItemAnimator
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
||||
import com.habitrpg.android.habitica.ui.helpers.resetViews
|
||||
import io.reactivex.functions.BiFunction
|
||||
import io.reactivex.functions.Consumer
|
||||
import io.realm.RealmResults
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import java.util.ArrayList
|
||||
import javax.inject.Inject
|
||||
|
||||
class PetDetailRecyclerFragment : BaseMainFragment() {
|
||||
|
|
@ -129,13 +132,6 @@ class PetDetailRecyclerFragment : BaseMainFragment() {
|
|||
|
||||
private fun loadItems() {
|
||||
if (animalType?.isNotEmpty() == true || animalGroup?.isNotEmpty() == true) {
|
||||
compositeSubscription.add(inventoryRepository.getOwnedPets()
|
||||
.map { ownedMounts ->
|
||||
val mountMap = mutableMapOf<String, OwnedPet>()
|
||||
ownedMounts.forEach { mountMap[it.key ?: ""] = it }
|
||||
return@map mountMap
|
||||
}
|
||||
.subscribe(Consumer { adapter.setOwnedPets(it) }, RxErrorHandler.handleEmptyError()))
|
||||
compositeSubscription.add(inventoryRepository.getOwnedMounts()
|
||||
.map { ownedMounts ->
|
||||
val mountMap = mutableMapOf<String, OwnedMount>()
|
||||
|
|
@ -144,20 +140,34 @@ class PetDetailRecyclerFragment : BaseMainFragment() {
|
|||
}
|
||||
.subscribe(Consumer { adapter.setOwnedMounts(it) }, RxErrorHandler.handleEmptyError()))
|
||||
compositeSubscription.add(inventoryRepository.getOwnedItems(true).subscribe(Consumer { adapter.setOwnedItems(it) }, RxErrorHandler.handleEmptyError()))
|
||||
compositeSubscription.add(inventoryRepository.getPets(animalType, animalGroup, animalColor)
|
||||
.map {
|
||||
compositeSubscription.add(inventoryRepository.getPets(animalType, animalGroup, animalColor).zipWith(inventoryRepository.getOwnedPets()
|
||||
.map { ownedPets ->
|
||||
val petMap = mutableMapOf<String, OwnedPet>()
|
||||
ownedPets.forEach { petMap[it.key ?: ""] = it }
|
||||
return@map petMap
|
||||
}.doOnNext {
|
||||
adapter.setOwnedPets(it)
|
||||
}, BiFunction<RealmResults<out Pet>, Map<String, OwnedObject>, List<Any>> { unsortedAnimals, ownedAnimals ->
|
||||
val items = mutableListOf<Any>()
|
||||
var lastPet: Pet? = null
|
||||
for (pet in it) {
|
||||
var currentSection: StableSection? = null
|
||||
for (pet in unsortedAnimals) {
|
||||
if (pet.type == "wacky" || pet.type == "special") continue
|
||||
if (pet.type != lastPet?.type) {
|
||||
items.add(StableSection(pet.type, pet.getTranslatedType(context)))
|
||||
currentSection = StableSection(pet.type, pet.getTranslatedType(context))
|
||||
items.add(currentSection)
|
||||
}
|
||||
currentSection?.let {
|
||||
it.totalCount += 1
|
||||
if (ownedAnimals.containsKey(pet.key)) {
|
||||
it.ownedCount += 1
|
||||
}
|
||||
}
|
||||
items.add(pet)
|
||||
lastPet = pet
|
||||
}
|
||||
items
|
||||
}
|
||||
})
|
||||
.subscribe(Consumer { adapter.setItemList(it) }, RxErrorHandler.handleEmptyError()))
|
||||
compositeSubscription.add(inventoryRepository.getMounts(animalType, animalGroup, animalColor).subscribe(Consumer<RealmResults<Mount>> { adapter.setExistingMounts(it) }, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue