mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-19 20:29:02 +00:00
Improve stable overview and add new dialog for unhatched
This commit is contained in:
parent
2dbbac0b41
commit
96682e106f
8 changed files with 230 additions and 19 deletions
64
Habitica/res/layout/dialog_pet_suggest_hatch.xml
Normal file
64
Habitica/res/layout/dialog_pet_suggest_hatch.xml
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal">
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="@dimen/spacing_small"
|
||||
android:layout_marginBottom="@dimen/spacing_large">
|
||||
<FrameLayout
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:background="@drawable/layout_rounded_bg_gray_700"
|
||||
android:layout_marginEnd="@dimen/spacing_large">
|
||||
<com.facebook.drawee.view.SimpleDraweeView
|
||||
android:id="@+id/egg_view"
|
||||
android:layout_width="@dimen/gear_image_size"
|
||||
android:layout_height="@dimen/gear_image_size"
|
||||
android:layout_gravity="center"/>
|
||||
</FrameLayout>
|
||||
<FrameLayout
|
||||
android:layout_width="80dp"
|
||||
android:layout_height="80dp"
|
||||
android:background="@drawable/layout_rounded_bg_gray_700"
|
||||
android:layout_marginEnd="@dimen/spacing_large">
|
||||
<com.facebook.drawee.view.SimpleDraweeView
|
||||
android:id="@+id/pet_view"
|
||||
android:layout_width="@dimen/gear_image_size"
|
||||
android:layout_height="@dimen/gear_image_size"
|
||||
android:alpha="0.1"
|
||||
android:layout_gravity="center" />
|
||||
</FrameLayout>
|
||||
<FrameLayout
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="50dp"
|
||||
android:background="@drawable/layout_rounded_bg_gray_700">
|
||||
<com.facebook.drawee.view.SimpleDraweeView
|
||||
android:id="@+id/hatchingPotion_view"
|
||||
android:layout_width="@dimen/gear_image_size"
|
||||
android:layout_height="@dimen/gear_image_size"
|
||||
android:layout_gravity="center" />
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
||||
<TextView
|
||||
android:id="@+id/pet_title_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/Subheader2"
|
||||
android:textColor="@color/gray_100"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_marginBottom="@dimen/spacing_medium"/>
|
||||
<TextView
|
||||
android:id="@+id/description_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/Body2"
|
||||
android:textColor="@color/gray_200"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_marginBottom="@dimen/spacing_medium"/>
|
||||
</LinearLayout>
|
||||
|
|
@ -1027,8 +1027,8 @@
|
|||
<string name="percent_completed">%d%% Complete</string>
|
||||
<string name="create_task_title">Create a Task</string>
|
||||
<string name="complete_task_title">Complete a Task</string>
|
||||
<string name="hatch_pet_title">Hatch a Pet</string>
|
||||
<string name="feedPet_title">Feed a Pet</string>
|
||||
<string name="hatch_pet_title">Hatch a new pet</string>
|
||||
<string name="feedPet_title">Feed a pet</string>
|
||||
<string name="purchase_equipment_title">Purchase Equipment</string>
|
||||
<string name="create_task_description">Add a task for something you would like to accomplish this week</string>
|
||||
<string name="complete_task_description">Check off any of your tasks to earn rewards</string>
|
||||
|
|
@ -1058,4 +1058,10 @@
|
|||
<string name="excessItemsNoneLeft">You already have everything you need for all %s pets. Are you sure you want to purchase %d %ss?</string>
|
||||
<string name="equip">Equip</string>
|
||||
<string name="view_onboarding_tasks">View Onboarding Tasks</string>
|
||||
<string name="suggest_pet_hatch">You\'ll need a %s Egg and %s Potion to hatch this pet</string>
|
||||
<string name="can_hatch_pet">You can use a %s Egg and a %s Potion to hatch this pet</string>
|
||||
<string name="hatch_pet">Hatch Pet</string>
|
||||
<string name="unhatched_pet">Unhatched Pet</string>
|
||||
<string name="magic_potions">Magic Potions</string>
|
||||
<string name="magic_potion">Magic Potion</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ fun Animal.getTranslatedType(c: Context?): String {
|
|||
"quest" -> c?.getString(R.string.quest).toString()
|
||||
"wacky" -> c?.getString(R.string.wacky).toString()
|
||||
"special" -> c?.getString(R.string.special).toString()
|
||||
"premium" -> c?.getString(R.string.magic_potion).toString()
|
||||
else -> {
|
||||
type
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,16 +10,19 @@ import android.widget.TextView
|
|||
import com.facebook.drawee.view.SimpleDraweeView
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.events.commands.FeedCommand
|
||||
import com.habitrpg.android.habitica.extensions.addCloseButton
|
||||
import com.habitrpg.android.habitica.extensions.inflate
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.inventory.Mount
|
||||
import com.habitrpg.android.habitica.models.inventory.Pet
|
||||
import com.habitrpg.android.habitica.models.inventory.*
|
||||
import com.habitrpg.android.habitica.models.user.OwnedItem
|
||||
import com.habitrpg.android.habitica.models.user.OwnedMount
|
||||
import com.habitrpg.android.habitica.models.user.OwnedPet
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
||||
import com.habitrpg.android.habitica.ui.menu.BottomSheetMenu
|
||||
import com.habitrpg.android.habitica.ui.menu.BottomSheetMenuItem
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.PetSuggestHatchDialog
|
||||
import io.reactivex.BackpressureStrategy
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.Observable
|
||||
|
|
@ -38,12 +41,15 @@ class PetDetailRecyclerAdapter(data: OrderedRealmCollection<Pet>?, autoUpdate: B
|
|||
private var existingMounts: RealmResults<Mount>? = null
|
||||
private var ownedPets: Map<String, OwnedPet>? = null
|
||||
private var ownedMounts: Map<String, OwnedMount>? = null
|
||||
private var ownedItems: Map<String, OwnedItem>? = null
|
||||
private val equipEvents = PublishSubject.create<String>()
|
||||
|
||||
fun getEquipFlowable(): Flowable<String> {
|
||||
return equipEvents.toFlowable(BackpressureStrategy.DROP)
|
||||
}
|
||||
|
||||
var animalIngredientsRetriever: ((Animal) -> Pair<Egg?, HatchingPotion?>)? = null
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PetViewHolder {
|
||||
return PetViewHolder(parent.inflate(R.layout.pet_detail_item))
|
||||
}
|
||||
|
|
@ -68,6 +74,12 @@ class PetDetailRecyclerAdapter(data: OrderedRealmCollection<Pet>?, autoUpdate: B
|
|||
this.ownedPets = ownedPets
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
fun setOwnedItems(ownedItems: Map<String, OwnedItem>) {
|
||||
this.ownedItems = ownedItems
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
inner class PetViewHolder(itemView: View) : androidx.recyclerview.widget.RecyclerView.ViewHolder(itemView), View.OnClickListener {
|
||||
var animal: Pet? = null
|
||||
var ownedPet: OwnedPet? = null
|
||||
|
|
@ -88,6 +100,11 @@ class PetDetailRecyclerAdapter(data: OrderedRealmCollection<Pet>?, autoUpdate: B
|
|||
return false
|
||||
}
|
||||
|
||||
private val canHatch: Boolean
|
||||
get() {
|
||||
return ownedItems?.get(animal?.animal + "-eggs") != null && ownedItems?.get(animal?.color + "-hatchingPotions") != null
|
||||
}
|
||||
|
||||
init {
|
||||
itemView.setOnClickListener(this)
|
||||
}
|
||||
|
|
@ -126,6 +143,7 @@ class PetDetailRecyclerAdapter(data: OrderedRealmCollection<Pet>?, autoUpdate: B
|
|||
|
||||
override fun onClick(v: View) {
|
||||
if (!this.isOwned) {
|
||||
showRequirementsDialog()
|
||||
return
|
||||
}
|
||||
val context = context ?: return
|
||||
|
|
@ -148,5 +166,15 @@ class PetDetailRecyclerAdapter(data: OrderedRealmCollection<Pet>?, autoUpdate: B
|
|||
}
|
||||
menu.show()
|
||||
}
|
||||
|
||||
private fun showRequirementsDialog() {
|
||||
val context = context ?: return
|
||||
val dialog = PetSuggestHatchDialog(context)
|
||||
animal?.let {
|
||||
val ingredients = animalIngredientsRetriever?.invoke(it)
|
||||
dialog.configure(it, ingredients?.first, ingredients?.second, canHatch)
|
||||
}
|
||||
dialog.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import androidx.core.content.ContextCompat
|
|||
import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.facebook.drawee.view.SimpleDraweeView
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.events.commands.FeedCommand
|
||||
import com.habitrpg.android.habitica.extensions.inflate
|
||||
import com.habitrpg.android.habitica.helpers.MainNavigationController
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
|
|
@ -18,11 +19,17 @@ import com.habitrpg.android.habitica.ui.activities.MainActivity
|
|||
import com.habitrpg.android.habitica.ui.fragments.inventory.stable.StableFragmentDirections
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
|
||||
import com.habitrpg.android.habitica.ui.helpers.bindView
|
||||
import com.habitrpg.android.habitica.ui.menu.BottomSheetMenu
|
||||
import com.habitrpg.android.habitica.ui.menu.BottomSheetMenuItem
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.SectionViewHolder
|
||||
import com.habitrpg.android.habitica.ui.views.NPCBannerView
|
||||
import io.reactivex.BackpressureStrategy
|
||||
import io.reactivex.Flowable
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.functions.Consumer
|
||||
import io.reactivex.subjects.PublishSubject
|
||||
import org.greenrobot.eventbus.EventBus
|
||||
|
||||
|
||||
class StableRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<androidx.recyclerview.widget.RecyclerView.ViewHolder>() {
|
||||
|
|
@ -30,6 +37,11 @@ class StableRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<
|
|||
var itemType: String? = null
|
||||
var context: Context? = null
|
||||
var activity: MainActivity? = null
|
||||
private val equipEvents = PublishSubject.create<String>()
|
||||
|
||||
fun getEquipFlowable(): Flowable<String> {
|
||||
return equipEvents.toFlowable(BackpressureStrategy.DROP)
|
||||
}
|
||||
|
||||
private var itemList: List<Any> = ArrayList()
|
||||
|
||||
|
|
@ -120,7 +132,8 @@ class StableRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<
|
|||
|
||||
fun bind(item: Animal) {
|
||||
this.animal = item
|
||||
titleView.text = if (item.type == "special") {
|
||||
val isIndividualAnimal = item.type == "special" || animal?.type == "wacky"
|
||||
titleView.text = if (isIndividualAnimal) {
|
||||
item.text
|
||||
} else {
|
||||
item.animal
|
||||
|
|
@ -131,27 +144,33 @@ class StableRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<
|
|||
this.ownedTextView.alpha = 1.0f
|
||||
|
||||
val imageName = if (itemType == "pets") {
|
||||
"Pet_Egg_" + item.animal
|
||||
if (isIndividualAnimal) {
|
||||
"social_Pet-" + animal?.key
|
||||
} else {
|
||||
"Pet_Egg_" + item.animal
|
||||
}
|
||||
} else {
|
||||
"Mount_Icon_" + item.key
|
||||
}
|
||||
|
||||
context?.let {
|
||||
|
||||
var owned = item.numberOwned
|
||||
var totalNum = item.totalNumber
|
||||
|
||||
val owned = item.numberOwned
|
||||
val totalNum = item.totalNumber
|
||||
|
||||
this.ownedTextView.text = context?.getString(R.string.pet_ownership_fraction, owned, totalNum)
|
||||
this.ownedTextView.background = context?.getDrawable(R.drawable.layout_rounded_bg_shopitem_price)
|
||||
|
||||
this.ownedTextView.setTextColor(ContextCompat.getColor(it, R.color.black) )
|
||||
|
||||
ownedTextView.visibility = if (animal?.type == "special") View.GONE else View.VISIBLE
|
||||
ownedTextView.visibility = if (isIndividualAnimal) View.GONE else View.VISIBLE
|
||||
imageView.background = null
|
||||
|
||||
DataBindingUtils.loadImage(imageName) {
|
||||
val drawable = BitmapDrawable(context?.resources, it)
|
||||
val numberOwned = item.numberOwned == 0
|
||||
DataBindingUtils.loadImage(imageName) {bitmap ->
|
||||
val drawable = if (isIndividualAnimal) {
|
||||
BitmapDrawable(context?.resources, if (numberOwned) bitmap.extractAlpha() else bitmap)
|
||||
} else {
|
||||
BitmapDrawable(context?.resources, bitmap)
|
||||
}
|
||||
Observable.just(drawable)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(Consumer {
|
||||
|
|
@ -175,6 +194,20 @@ class StableRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<
|
|||
override fun onClick(v: View) {
|
||||
val animal = this.animal
|
||||
if (animal != null) {
|
||||
if (animal.type == "special" || animal.type == "wacky") {
|
||||
if (animal.numberOwned == 0) return
|
||||
val context = context ?: return
|
||||
val menu = BottomSheetMenu(context)
|
||||
menu.setTitle(animal.text)
|
||||
menu.addMenuItem(BottomSheetMenuItem(itemView.resources.getString(R.string.equip)))
|
||||
menu.setSelectionRunnable {
|
||||
animal.let {
|
||||
equipEvents.onNext(it.key)
|
||||
}
|
||||
}
|
||||
menu.show()
|
||||
return
|
||||
}
|
||||
val color = if (animal.type == "special") animal.color else null
|
||||
if (animal.numberOwned > 0) {
|
||||
if (itemType == "pets") {
|
||||
|
|
|
|||
|
|
@ -9,9 +9,12 @@ import com.habitrpg.android.habitica.components.UserComponent
|
|||
import com.habitrpg.android.habitica.data.InventoryRepository
|
||||
import com.habitrpg.android.habitica.events.commands.FeedCommand
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.inventory.Egg
|
||||
import com.habitrpg.android.habitica.models.inventory.HatchingPotion
|
||||
import com.habitrpg.android.habitica.models.inventory.Mount
|
||||
import com.habitrpg.android.habitica.models.inventory.Pet
|
||||
import com.habitrpg.android.habitica.models.user.Items
|
||||
import com.habitrpg.android.habitica.models.user.OwnedItem
|
||||
import com.habitrpg.android.habitica.models.user.OwnedMount
|
||||
import com.habitrpg.android.habitica.models.user.OwnedPet
|
||||
import com.habitrpg.android.habitica.ui.adapter.inventory.PetDetailRecyclerAdapter
|
||||
|
|
@ -83,6 +86,11 @@ class PetDetailRecyclerFragment : BaseMainFragment() {
|
|||
compositeSubscription.add(adapter.getEquipFlowable()
|
||||
.flatMap<Items> { key -> inventoryRepository.equip(user, "pet", key) }
|
||||
.subscribe(Consumer { }, RxErrorHandler.handleEmptyError()))
|
||||
adapter.animalIngredientsRetriever = {
|
||||
val egg = inventoryRepository.getItems(Egg::class.java, arrayOf(it.animal), null).firstElement().blockingGet().firstOrNull()
|
||||
val potion = inventoryRepository.getItems(HatchingPotion::class.java, arrayOf(it.color), null).firstElement().blockingGet().firstOrNull()
|
||||
Pair(egg as? Egg, potion as? HatchingPotion)
|
||||
}
|
||||
|
||||
view.post { setGridSpanCount(view.width) }
|
||||
}
|
||||
|
|
@ -122,6 +130,7 @@ class PetDetailRecyclerFragment : BaseMainFragment() {
|
|||
return@map mountMap
|
||||
}
|
||||
.subscribe(Consumer { adapter.setOwnedMounts(it) }, RxErrorHandler.handleEmptyError()))
|
||||
compositeSubscription.add(inventoryRepository.getOwnedItems().subscribe(Consumer { adapter.setOwnedItems(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()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,10 +12,7 @@ import com.habitrpg.android.habitica.extensions.getTranslatedType
|
|||
import com.habitrpg.android.habitica.extensions.inflate
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.inventory.Animal
|
||||
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.models.user.User
|
||||
import com.habitrpg.android.habitica.models.user.*
|
||||
import com.habitrpg.android.habitica.ui.activities.MainActivity
|
||||
import com.habitrpg.android.habitica.ui.adapter.inventory.StableRecyclerAdapter
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment
|
||||
|
|
@ -91,6 +88,12 @@ class StableRecyclerFragment : BaseFragment() {
|
|||
adapter?.context = context
|
||||
recyclerView?.adapter = adapter
|
||||
recyclerView?.itemAnimator = SafeDefaultItemAnimator()
|
||||
|
||||
adapter?.let {
|
||||
compositeSubscription.add(it.getEquipFlowable()
|
||||
.flatMap<Items> { key -> inventoryRepository.equip(user, if (itemType == "pets") "pet" else "mount", key) }
|
||||
.subscribe(Consumer { }, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
}
|
||||
|
||||
this.loadItems()
|
||||
|
|
@ -146,7 +149,7 @@ class StableRecyclerFragment : BaseFragment() {
|
|||
var lastAnimal: Animal = unsortedAnimals[0] ?: return items
|
||||
var lastSectionTitle = ""
|
||||
for (animal in unsortedAnimals) {
|
||||
val identifier = if (animal.animal.isNotEmpty() && animal.type != "special") animal.animal else animal.key
|
||||
val identifier = if (animal.animal.isNotEmpty() && (animal.type != "special" && animal.type != "wacky")) animal.animal else animal.key
|
||||
val lastIdentifier = if (lastAnimal.animal.isNotEmpty()) lastAnimal.animal else lastAnimal.key
|
||||
if (identifier != lastIdentifier || animal === unsortedAnimals[unsortedAnimals.size - 1]) {
|
||||
if (!((lastAnimal.type == "premium" || lastAnimal.type == "special") && lastAnimal.numberOwned == 0)) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,67 @@
|
|||
package com.habitrpg.android.habitica.ui.views.dialogs
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.view.LayoutInflater
|
||||
import com.facebook.drawee.view.SimpleDraweeView
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.databinding.DialogPetSuggestHatchBinding
|
||||
import com.habitrpg.android.habitica.helpers.MainNavigationController
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.inventory.Animal
|
||||
import com.habitrpg.android.habitica.models.inventory.Egg
|
||||
import com.habitrpg.android.habitica.models.inventory.HatchingPotion
|
||||
import com.habitrpg.android.habitica.ui.activities.MainActivity
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
|
||||
import io.reactivex.Observable
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.functions.Consumer
|
||||
|
||||
class PetSuggestHatchDialog(context: Context) : HabiticaAlertDialog(context) {
|
||||
|
||||
|
||||
private lateinit var binding: DialogPetSuggestHatchBinding
|
||||
|
||||
init {
|
||||
val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as? LayoutInflater
|
||||
inflater?.let { binding = DialogPetSuggestHatchBinding.inflate(it) }
|
||||
setAdditionalContentView(binding.root)
|
||||
}
|
||||
|
||||
fun configure(pet: Animal, egg: Egg?, potion: HatchingPotion?, canHatch: Boolean) {
|
||||
DataBindingUtils.loadImage(binding.eggView, "Pet_Egg_${pet.animal}")
|
||||
DataBindingUtils.loadImage(binding.hatchingPotionView, "Pet_HatchingPotion_${pet.color}")
|
||||
binding.petTitleView.text = pet.text
|
||||
|
||||
|
||||
if (canHatch) {
|
||||
binding.descriptionView.text = context.getString(R.string.can_hatch_pet,
|
||||
egg?.text ?: pet.animal.capitalize(),
|
||||
potion?.text ?: pet.color.capitalize())
|
||||
addButton(R.string.hatch_pet, true, false) { _, _ ->
|
||||
val thisPotion = potion ?: return@addButton
|
||||
val thisEgg = egg ?: return@addButton
|
||||
(getActivity() as? MainActivity)?.hatchPet(thisPotion, thisEgg)
|
||||
}
|
||||
setTitle(R.string.hatch_pet_title)
|
||||
} else {
|
||||
binding.descriptionView.text = context.getString(R.string.suggest_pet_hatch,
|
||||
egg?.text ?: pet.animal.capitalize(),
|
||||
potion?.text ?: pet.color.capitalize())
|
||||
setTitle(R.string.unhatched_pet)
|
||||
}
|
||||
|
||||
addButton(R.string.close, !canHatch)
|
||||
|
||||
val imageName = "social_Pet-${pet.animal}-${pet.color}"
|
||||
DataBindingUtils.loadImage(imageName) {
|
||||
val resources = context.resources ?: return@loadImage
|
||||
val drawable = BitmapDrawable(resources, it.extractAlpha())
|
||||
Observable.just(drawable)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(Consumer {
|
||||
binding.petView.background = drawable
|
||||
}, RxErrorHandler.handleEmptyError())
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue