Fix pet and mount display

This commit is contained in:
Phillip Thelen 2019-10-01 19:36:15 +02:00
parent a98d022a47
commit 56eebf0d51
10 changed files with 45 additions and 26 deletions

View file

@ -149,7 +149,7 @@ android {
multiDexEnabled true
resConfigs "en", "bg", "de", "en-rGB", "es", "fr", "hr-rHR", "in", "it", "iw", "ja", "ko", "lt", "nl", "pl", "pt-rBR", "pt-rPT", "ru", "tr", "zh", "zh-rTW"
versionCode 2248
versionCode 2250
versionName "2.1.1"
}

View file

@ -40,8 +40,8 @@ interface InventoryRepository : BaseRepository {
fun openMysteryItem(user: User?): Flowable<Equipment>
fun saveEquipment(equipment: Equipment)
fun getMounts(type: String, group: String): Flowable<RealmResults<Mount>>
fun getPets(type: String, group: String): Flowable<RealmResults<Pet>>
fun getMounts(type: String, group: String, color: String?): Flowable<RealmResults<Mount>>
fun getPets(type: String, group: String, color: String?): Flowable<RealmResults<Pet>>
fun updateOwnedEquipment(user: User)

View file

@ -78,8 +78,8 @@ class InventoryRepositoryImpl(localRepository: InventoryLocalRepository, apiClie
return localRepository.getMounts()
}
override fun getMounts(type: String, group: String): Flowable<RealmResults<Mount>> {
return localRepository.getMounts(type, group)
override fun getMounts(type: String, group: String, color: String?): Flowable<RealmResults<Mount>> {
return localRepository.getMounts(type, group, color)
}
override fun getOwnedMounts(): Flowable<RealmResults<OwnedMount>> {
@ -90,8 +90,8 @@ class InventoryRepositoryImpl(localRepository: InventoryLocalRepository, apiClie
return localRepository.getPets()
}
override fun getPets(type: String, group: String): Flowable<RealmResults<Pet>> {
return localRepository.getPets(type, group)
override fun getPets(type: String, group: String, color: String?): Flowable<RealmResults<Pet>> {
return localRepository.getPets(type, group, color)
}
override fun getOwnedPets(): Flowable<RealmResults<OwnedPet>> {

View file

@ -35,8 +35,8 @@ interface InventoryLocalRepository : ContentLocalRepository {
fun getOwnedItems(userID: String): Flowable<Map<String, OwnedItem>>
fun getEquipment(key: String): Flowable<Equipment>
fun getMounts(type: String, group: String): Flowable<RealmResults<Mount>>
fun getPets(type: String, group: String): Flowable<RealmResults<Pet>>
fun getMounts(type: String, group: String, color: String?): Flowable<RealmResults<Mount>>
fun getPets(type: String, group: String, color: String?): Flowable<RealmResults<Pet>>
fun updateOwnedEquipment(user: User)

View file

@ -119,12 +119,15 @@ class RealmInventoryLocalRepository(realm: Realm, private val context: Context)
.filter { it.isLoaded }
}
override fun getMounts(type: String, group: String): Flowable<RealmResults<Mount>> {
return realm.where(Mount::class.java)
override fun getMounts(type: String, group: String, color: String?): Flowable<RealmResults<Mount>> {
var query = realm.where(Mount::class.java)
.sort("color", Sort.ASCENDING)
.equalTo("type", group)
.equalTo("animal", type)
.findAll()
if (color != null) {
query = query.equalTo("color", color)
}
return query.findAll()
.asFlowable()
.filter { it.isLoaded }
}
@ -146,12 +149,15 @@ class RealmInventoryLocalRepository(realm: Realm, private val context: Context)
.filter { it.isLoaded }
}
override fun getPets(type: String, group: String): Flowable<RealmResults<Pet>> {
return realm.where(Pet::class.java)
override fun getPets(type: String, group: String, color: String?): Flowable<RealmResults<Pet>> {
var query = realm.where(Pet::class.java)
.sort("color", Sort.ASCENDING)
.equalTo("type", group)
.equalTo("animal", type)
.findAll()
if (color != null) {
query = query.equalTo("color", color)
}
return query.findAll()
.asFlowable()
.filter { it.isLoaded }
}

View file

@ -68,7 +68,11 @@ class MountDetailRecyclerAdapter(data: OrderedRealmCollection<Mount>?, autoUpdat
fun bind(item: Mount, ownedMount: OwnedMount?) {
animal = item
this.ownedMount = ownedMount
titleView.text = item.color
titleView.text = when {
item.color == "Veggie" -> context?.getString(R.string.garden)
item.type == "special" ->item.text
else -> item.color
}
ownedTextView.visibility = View.GONE
val imageName = "Mount_Icon_" + itemType + "-" + item.color
this.imageView.alpha = 1.0f

View file

@ -95,10 +95,10 @@ class PetDetailRecyclerAdapter(data: OrderedRealmCollection<Pet>?, autoUpdate: B
fun bind(item: Pet, ownedPet: OwnedPet?) {
this.animal = item
this.ownedPet = ownedPet
if (item.color == "Veggie") {
this.titleView.text = context?.getString(R.string.garden)
} else {
this.titleView.text = item.color
titleView.text = when {
item.color == "Veggie" -> context?.getString(R.string.garden)
item.type == "special" ->item.text
else -> item.color
}
this.imageView.alpha = 1.0f
val imageName = "Pet-$itemType-${item.color}"

View file

@ -77,7 +77,11 @@ class StableRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<
fun bind(item: Animal) {
this.animal = item
titleView.text = item.animal
titleView.text = if (item.type == "special") {
item.text
} else {
item.animal
}
ownedTextView.visibility = View.VISIBLE
this.imageView.alpha = 1.0f
val imageName = if (itemType == "pets") {
@ -104,11 +108,12 @@ class StableRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<
override fun onClick(v: View) {
val animal = this.animal
if (animal != null) {
val color = if (animal.type == "special") animal.color else null
if (animal.numberOwned > 0) {
if (itemType == "pets") {
MainNavigationController.navigate(StableFragmentDirections.openPetDetail(animal.animal, animal.type))
MainNavigationController.navigate(StableFragmentDirections.openPetDetail(animal.animal, animal.type, color))
} else {
MainNavigationController.navigate(StableFragmentDirections.openMountDetail(animal.animal, animal.type))
MainNavigationController.navigate(StableFragmentDirections.openMountDetail(animal.animal, animal.type, color))
}
}
}

View file

@ -28,6 +28,7 @@ class MountDetailRecyclerFragment : BaseMainFragment() {
var adapter: MountDetailRecyclerAdapter? = null
var animalType: String? = null
var animalGroup: String? = null
var animalColor: String? = null
internal var layoutManager: androidx.recyclerview.widget.GridLayoutManager? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
@ -52,6 +53,7 @@ class MountDetailRecyclerFragment : BaseMainFragment() {
val args = MountDetailRecyclerFragmentArgs.fromBundle(it)
animalGroup = args.group
animalType = args.type
animalColor = args.color
}
layoutManager = androidx.recyclerview.widget.GridLayoutManager(activity, 2)
@ -107,7 +109,7 @@ class MountDetailRecyclerFragment : BaseMainFragment() {
return@map mountMap
}
.subscribe(Consumer { adapter?.setOwnedMounts(it) }, RxErrorHandler.handleEmptyError()))
compositeSubscription.add(inventoryRepository.getMounts(animalType!!, animalGroup!!).firstElement().subscribe(Consumer { adapter?.updateData(it) }, RxErrorHandler.handleEmptyError()))
compositeSubscription.add(inventoryRepository.getMounts(animalType!!, animalGroup!!, animalColor).firstElement().subscribe(Consumer { adapter?.updateData(it) }, RxErrorHandler.handleEmptyError()))
}
}

View file

@ -36,6 +36,7 @@ class PetDetailRecyclerFragment : BaseMainFragment() {
var adapter: PetDetailRecyclerAdapter = PetDetailRecyclerAdapter(null, true)
var animalType: String = ""
var animalGroup: String = ""
var animalColor: String? = null
internal var layoutManager: androidx.recyclerview.widget.GridLayoutManager? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
@ -64,6 +65,7 @@ class PetDetailRecyclerFragment : BaseMainFragment() {
val args = MountDetailRecyclerFragmentArgs.fromBundle(it)
animalGroup = args.group
animalType = args.type
animalColor = args.color
}
resetViews()
@ -120,8 +122,8 @@ class PetDetailRecyclerFragment : BaseMainFragment() {
return@map mountMap
}
.subscribe(Consumer { adapter.setOwnedMounts(it) }, RxErrorHandler.handleEmptyError()))
compositeSubscription.add(inventoryRepository.getPets(animalType, animalGroup).firstElement().subscribe(Consumer<RealmResults<Pet>> { adapter.updateData(it) }, RxErrorHandler.handleEmptyError()))
compositeSubscription.add(inventoryRepository.getMounts(animalType, animalGroup).subscribe(Consumer<RealmResults<Mount>> { adapter.setExistingMounts(it) }, RxErrorHandler.handleEmptyError()))
compositeSubscription.add(inventoryRepository.getPets(animalType, animalGroup, animalColor).firstElement().subscribe(Consumer<RealmResults<Pet>> { adapter.updateData(it) }, RxErrorHandler.handleEmptyError()))
compositeSubscription.add(inventoryRepository.getMounts(animalType, animalGroup, animalColor).subscribe(Consumer<RealmResults<Mount>> { adapter.setExistingMounts(it) }, RxErrorHandler.handleEmptyError()))
}
}