Various stable improvements

This commit is contained in:
Phillip Thelen 2020-07-28 12:31:36 +02:00
parent 941f8b6a9d
commit eae77cfad5
23 changed files with 199 additions and 83 deletions

View file

@ -162,7 +162,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 2491
versionCode 2497
versionName "2.8"
}

View file

@ -4,6 +4,8 @@
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="55dp"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:gravity="bottom">
<TextView
android:id="@+id/label"

View file

@ -1,6 +1,7 @@
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -11,22 +12,41 @@
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>
<RelativeLayout
android:layout_width="60dp"
android:layout_height="80dp">
<FrameLayout
android:id="@+id/egg_frame_view"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/layout_rounded_bg_gray_700"
android:layout_centerVertical="true"
android:layout_alignParentStart="true">
<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>
<TextView
android:id="@+id/egg_count_view"
android:layout_width="24dp"
android:layout_height="24dp"
style="@style/Pill"
android:padding="0dp"
android:gravity="center"
tools:text="12"
android:layout_alignEnd="@id/egg_frame_view"
android:layout_alignTop="@id/egg_frame_view"
android:layout_marginEnd="-8dp"
android:layout_marginTop="-8dp"/>
</RelativeLayout>
<FrameLayout
android:layout_width="80dp"
android:layout_height="80dp"
android:background="@drawable/layout_rounded_bg_gray_700"
android:layout_marginEnd="@dimen/spacing_large">
android:layout_marginEnd="10dp"
android:layout_marginStart="@dimen/spacing_small">
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/pet_view"
android:layout_width="@dimen/gear_image_size"
@ -34,16 +54,35 @@
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>
<RelativeLayout
android:layout_width="60dp"
android:layout_height="80dp">
<FrameLayout
android:id="@+id/potion_frame_view"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/layout_rounded_bg_gray_700"
android:layout_centerVertical="true"
android:layout_alignParentStart="true">
<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>
<TextView
android:id="@+id/potion_count_view"
android:layout_width="24dp"
android:layout_height="24dp"
android:padding="0dp"
android:gravity="center"
style="@style/Pill"
tools:text="12"
android:layout_alignEnd="@id/potion_frame_view"
android:layout_alignTop="@id/potion_frame_view"
android:layout_marginEnd="-8dp"
android:layout_marginTop="-8dp" />
</RelativeLayout>
</LinearLayout>
<TextView
android:id="@+id/pet_title_view"

View file

@ -12,8 +12,6 @@
android:scrollbarThumbVertical="@color/scrollbarThumb"
android:scrollbars="vertical"
android:clipToPadding="false"
android:paddingStart="@dimen/spacing_medium"
android:paddingEnd="@dimen/spacing_medium"
android:background="@color/white"/>
<TextView

View file

@ -20,10 +20,10 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceMedium"
style="@style/Overline"
tools:text="Section Header"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp" />
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp" />
<Spinner
android:id="@+id/classSelectionSpinner"
android:layout_width="wrap_content"

View file

@ -304,8 +304,7 @@
</activity>
<fragment
android:id="@+id/petDetailRecyclerFragment"
android:name="com.habitrpg.android.habitica.ui.fragments.inventory.stable.PetDetailRecyclerFragment"
android:label="@string/pets">
android:name="com.habitrpg.android.habitica.ui.fragments.inventory.stable.PetDetailRecyclerFragment">
<argument
android:name="type"
app:argType="string" />
@ -319,8 +318,7 @@
</fragment>
<fragment
android:id="@+id/mountDetailRecyclerFragment"
android:name="com.habitrpg.android.habitica.ui.fragments.inventory.stable.MountDetailRecyclerFragment"
android:label="@string/mounts" >
android:name="com.habitrpg.android.habitica.ui.fragments.inventory.stable.MountDetailRecyclerFragment">
<argument
android:name="type"
app:argType="string" />

View file

@ -10,6 +10,7 @@
<attr name="textColorPrimaryDark" format="color" />
<attr name="barColor" format="color" />
<attr name="toolbarContentColor" format="color" />
<attr name="colorPrimaryText" format="color" />
<attr name="taskFormTint" format="color" />
<attr name="textColorSecondaryDark" format="color" />
<attr name="statsColor" format="color" />

View file

@ -49,12 +49,13 @@
<item name="searchViewStyle">@style/SearchViewStyle</item>
<item name="toolbarContentColor">@color/white</item>
<item name="colorPrimaryText">@color/brand_50</item>
</style>
<style name="MainAppTheme.Red">
<item name="colorPrimary">@color/red_5</item>
<item name="colorPrimaryDark">@color/red_1</item>
<item name="colorPrimary">@color/red_10</item>
<item name="colorPrimaryDark">@color/red_5</item>
<item name="colorAccent">@color/red_100</item>
<item name="android:colorPrimary">@color/red_5</item>
<item name="android:colorPrimaryDark">@color/red_1</item>
@ -68,11 +69,12 @@
<item name="barColor">@color/red_5</item>
<item name="taskFormTint">@color/red_50</item>
<item name="toolbarContentColor">@color/red_1</item>
<item name="colorPrimaryText">@color/red_1</item>
</style>
<style name="MainAppTheme.Maroon">
<item name="colorPrimary">@color/red_1</item>
<item name="colorPrimaryDark">@color/maroon_1</item>
<item name="colorPrimary">@color/red_10</item>
<item name="colorPrimaryDark">@color/maroon_5</item>
<item name="colorAccent">@color/maroon_100</item>
<item name="android:colorPrimary">@color/red_1</item>
<item name="android:colorPrimaryDark">@color/maroon_1</item>
@ -85,11 +87,12 @@
<item name="textColorPrimaryDark">@color/red_500</item>
<item name="barColor">@color/red_1</item>
<item name="taskFormTint">@color/maroon_50</item>
<item name="colorPrimaryText">@color/maroon_1</item>
</style>
<style name="MainAppTheme.Orange">
<item name="colorPrimary">@color/orange_10</item>
<item name="colorPrimaryDark">@color/orange_5</item>
<item name="colorPrimary">@color/orange_50</item>
<item name="colorPrimaryDark">@color/orange_10</item>
<item name="colorAccent">@color/orange_100</item>
<item name="android:colorPrimary">@color/orange_10</item>
<item name="android:colorPrimaryDark">@color/orange_5</item>
@ -103,11 +106,12 @@
<item name="barColor">@color/orange_10</item>
<item name="taskFormTint">@color/orange_50</item>
<item name="toolbarContentColor">@color/orange_1</item>
<item name="colorPrimaryText">@color/orange_1</item>
</style>
<style name="MainAppTheme.Yellow">
<item name="colorPrimary">@color/yellow_10</item>
<item name="colorPrimaryDark">@color/yellow_5</item>
<item name="colorPrimary">@color/yellow_50</item>
<item name="colorPrimaryDark">@color/yellow_10</item>
<item name="colorAccent">@color/yellow_100</item>
<item name="android:colorPrimary">@color/yellow_10</item>
<item name="android:colorPrimaryDark">@color/yellow_5</item>
@ -121,6 +125,7 @@
<item name="barColor">@color/yellow_10</item>
<item name="taskFormTint">@color/yellow_10</item>
<item name="toolbarContentColor">@color/yellow_1</item>
<item name="colorPrimaryText">@color/yellow_1</item>
</style>
<style name="MainAppTheme.Green">
@ -139,6 +144,7 @@
<item name="barColor">@color/green_10</item>
<item name="taskFormTint">@color/green_50</item>
<item name="toolbarContentColor">@color/green_1</item>
<item name="colorPrimaryText">@color/green_1</item>
</style>
<style name="MainAppTheme.Teal">
@ -157,6 +163,7 @@
<item name="barColor">@color/teal_10</item>
<item name="taskFormTint">@color/teal_50</item>
<item name="toolbarContentColor">@color/teal_1</item>
<item name="colorPrimaryText">@color/teal_1</item>
</style>
<style name="MainAppTheme.Blue">
@ -175,6 +182,7 @@
<item name="barColor">@color/blue_10</item>
<item name="taskFormTint">@color/blue_50</item>
<item name="toolbarContentColor">@color/blue_1</item>
<item name="colorPrimaryText">@color/blue_1</item>
</style>
<style name="BottomSheetTheme" parent="Theme.AppCompat.NoActionBar">
@ -624,14 +632,14 @@
<style name="TaskFormTextInputLayoutAppearance" parent="Widget.MaterialComponents.TextInputLayout.FilledBox">
<!-- reference our hint & error styles -->
<item name="boxBackgroundColor">@color/white_75_alpha</item>
<item name="android:textColor">@color/textColorLight</item>
<item name="android:textColor">?attr/colorPrimaryText</item>
<item name="android:textColorHint">@color/textColorLight</item>
<item name="colorControlNormal">@color/white</item>
<item name="hintTextAppearance">@style/TaskFormHintTextAppearance</item>
</style>
<style name="TaskFormHintTextAppearance">
<item name="colorPrimary">?attr/toolbarContentColor</item>
<item name="colorPrimary">?attr/colorPrimaryText</item>
<item name="android:textSize">12sp</item>
<item name="android:fontFamily">@string/font_family_medium</item>
<item name="fontFamily">@string/font_family_medium</item>
@ -639,7 +647,7 @@
<style name="TextInputLayoutAppearanceTheme">
<item name="boxBackgroundColor">@color/taskform_gray</item>
<item name="android:textColor">@color/textColorLight</item>
<item name="android:textColor">?attr/colorPrimaryText</item>
<item name="android:textColorHint">@color/gray_300</item>
<item name="android:colorControlNormal">@color/gray_400</item>
<item name="android:colorControlActivated">@color/brand_400</item>

View file

@ -75,6 +75,8 @@ interface InventoryRepository : BaseRepository {
fun purchaseItem(purchaseType: String, key: String, purchaseQuantity: Int): Flowable<Any>
fun togglePinnedItem(item: ShopItem): Flowable<List<ShopItem>>
fun getItems(itemClass: Class<out Item>, keys: Array<String>, user: User?): Flowable<out RealmResults<out Item>>
fun getItems(itemClass: Class<out Item>, keys: Array<String>): Flowable<out RealmResults<out Item>>
fun getItems(itemClass: Class<out Item>): Flowable<out RealmResults<out Item>>
fun getLatestMysteryItem(): Flowable<Equipment>
fun getItem(type: String, key: String): Flowable<Item>
}

View file

@ -58,8 +58,12 @@ class InventoryRepositoryImpl(localRepository: InventoryLocalRepository, apiClie
return localRepository.getOwnedItems(userID, includeZero)
}
override fun getItems(itemClass: Class<out Item>, keys: Array<String>, user: User?): Flowable<out RealmResults<out Item>> {
return localRepository.getItems(itemClass, keys, user)
override fun getItems(itemClass: Class<out Item>, keys: Array<String>): Flowable<out RealmResults<out Item>> {
return localRepository.getItems(itemClass, keys)
}
override fun getItems(itemClass: Class<out Item>): Flowable<out RealmResults<out Item>> {
return localRepository.getItems(itemClass)
}
override fun getEquipment(key: String): Flowable<Equipment> {
@ -124,6 +128,10 @@ class InventoryRepositoryImpl(localRepository: InventoryLocalRepository, apiClie
return localRepository.getLatestMysteryItem()
}
override fun getItem(type: String, key: String): Flowable<Item> {
return localRepository.getItem(type, key)
}
private fun sellItem(user: User?, item: Item, ownedItem: OwnedItem): Flowable<User> {
if (user != null && appConfigManager.enableLocalChanges()) {
localRepository.executeTransaction {

View file

@ -30,7 +30,8 @@ interface InventoryLocalRepository : ContentLocalRepository {
fun getOwnedEquipment(type: String): Flowable<RealmResults<Equipment>>
fun getItems(itemClass: Class<out Item>, keys: Array<String>, user: User?): Flowable<out RealmResults<out Item>>
fun getItems(itemClass: Class<out Item>, keys: Array<String>): Flowable<out RealmResults<out Item>>
fun getItems(itemClass: Class<out Item>): Flowable<out RealmResults<out Item>>
fun getOwnedItems(itemType: String, userID: String, includeZero: Boolean): Flowable<RealmResults<OwnedItem>>
fun getOwnedItems(userID: String, includeZero: Boolean): Flowable<Map<String, OwnedItem>>
fun getEquipmentType(type: String, set: String): Flowable<RealmResults<Equipment>>

View file

@ -92,11 +92,16 @@ class RealmInventoryLocalRepository(realm: Realm, private val context: Context)
.filter { it.isLoaded }
}
override fun getItems(itemClass: Class<out Item>, keys: Array<String>, user: User?): Flowable<out RealmResults<out Item>> {
override fun getItems(itemClass: Class<out Item>, keys: Array<String>): Flowable<out RealmResults<out Item>> {
return realm.where(itemClass).`in`("key", keys).findAll().asFlowable()
.filter { it.isLoaded }
}
override fun getItems(itemClass: Class<out Item>): Flowable<out RealmResults<out Item>> {
return realm.where(itemClass).findAll().asFlowable()
.filter { it.isLoaded }
}
override fun getOwnedItems(userID: String, includeZero: Boolean): Flowable<Map<String, OwnedItem>> {
var query = realm.where(OwnedItem::class.java)
if (!includeZero) {

View file

@ -22,6 +22,8 @@ import androidx.appcompat.app.ActionBarDrawerToggle
import androidx.core.content.FileProvider
import androidx.core.content.edit
import androidx.lifecycle.ViewModelProviders
import androidx.navigation.NavController
import androidx.navigation.NavDestination
import androidx.navigation.findNavController
import com.facebook.drawee.view.SimpleDraweeView
import com.google.firebase.analytics.FirebaseAnalytics
@ -211,13 +213,8 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
supportActionBar?.setHomeButtonEnabled(true)
val navigationController = findNavController(R.id.nav_host_fragment)
navigationController.addOnDestinationChangedListener { _, destination, _ ->
if (destination.label.isNullOrEmpty() && user?.isValid == true) {
binding.toolbarTitle.text = user?.profile?.name
} else if (user?.isValid == true && user?.profile != null) {
binding.toolbarTitle.text = destination.label
}
drawerFragment?.setSelection(destination.id, null, false)
navigationController.addOnDestinationChangedListener { _, destination, arguments ->
updateToolbarTitle(destination, arguments)
}
MainNavigationController.setup(navigationController)
@ -231,6 +228,24 @@ open class MainActivity : BaseActivity(), TutorialView.OnTutorialReaction {
}
}
private fun updateToolbarTitle(destination: NavDestination, arguments: Bundle?) {
binding.toolbarTitle.text = if (destination.id == R.id.petDetailRecyclerFragment || destination.id == R.id.mountDetailRecyclerFragment) {
arguments?.getString("type")
} else if (destination.label.isNullOrEmpty() && user?.isValid == true) {
user?.profile?.name
} else if (user?.isValid == true && user?.profile != null) {
destination.label
} else {
""
}
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
}, RxErrorHandler.handleEmptyError()))
}
drawerFragment?.setSelection(destination.id, null, false)
}
override fun onSupportNavigateUp(): Boolean {
onBackPressed()
return true

View file

@ -44,11 +44,11 @@ class PetDetailRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapt
return false
}
private fun hasEgg(pet: Pet): Boolean {
return ownedItems?.get(pet.animal + "-eggs")?.numberOwned ?: 0 > 0
private fun eggCount(pet: Pet): Int {
return ownedItems?.get(pet.animal + "-eggs")?.numberOwned ?: 0
}
private fun hasPotion(pet: Pet): Boolean {
return ownedItems?.get(pet.color + "-hatchingPotions")?.numberOwned ?: 0 > 0
private fun potionCount(pet: Pet): Int {
return ownedItems?.get(pet.color + "-hatchingPotions")?.numberOwned ?: 0
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): androidx.recyclerview.widget.RecyclerView.ViewHolder =
@ -65,8 +65,8 @@ class PetDetailRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapt
is Pet -> {
(holder as? PetViewHolder)?.bind(obj,
ownedPets?.get(obj.key ?: "")?.trained ?: 0,
hasEgg(obj),
hasPotion(obj),
eggCount(obj),
potionCount(obj),
canRaiseToMount(obj),
ownsSaddles,
ownedItems?.get(obj.animal + "-eggs") != null,

View file

@ -85,7 +85,7 @@ class ShopRecyclerAdapter(private val configManager: AppConfigManager) : android
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): androidx.recyclerview.widget.RecyclerView.ViewHolder =
when (viewType) {
0 -> ShopHeaderViewHolder(parent)
1 -> SectionViewHolder(parent)
1 -> SectionViewHolder(parent.inflate(R.layout.shop_section_header))
2 -> EmptyStateViewHolder(parent.inflate(emptyViewResource))
else -> {
val view = parent.inflate(R.layout.row_shopitem)

View file

@ -24,6 +24,7 @@ import io.reactivex.subjects.PublishSubject
class StableRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private var eggs: Map<String, Egg> = mapOf()
var animalIngredientsRetriever: ((Animal) -> Pair<Egg?, HatchingPotion?>)? = null
var itemType: String? = null
private val equipEvents = PublishSubject.create<String>()
@ -60,8 +61,8 @@ class StableRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
(holder as? PetViewHolder)?.bind(item,
item.numberOwned,
canRaiseToMount = false,
hasEgg = false,
hasPotion = false,
eggCount = 0,
potionCount = 0,
ownsSaddles = false,
hasUnlockedEgg = false,
hasUnlockedPotion = false,
@ -103,6 +104,10 @@ class StableRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
}
override fun getItemCount(): Int = itemList.size
fun setEggs(eggs: Map<String, Egg>) {
this.eggs = eggs
notifyDataSetChanged()
}
internal class StableHeaderViewHolder(parent: ViewGroup) : RecyclerView.ViewHolder(parent.inflate(R.layout.shop_header)) {
@ -130,7 +135,7 @@ class StableRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
fun bind(item: Animal) {
this.animal = item
val context = itemView.context
titleView.text = item.animal
titleView.text = eggs[item.animal]?.mountText ?: item.animal
ownedTextView.visibility = View.VISIBLE
val imageName = if (itemType == "pets") {

View file

@ -81,8 +81,6 @@ abstract class BaseMainFragment : BaseFragment() {
activity?.supportActionBar?.setDisplayHomeAsUpEnabled(true)
}
private fun updateTabLayoutVisibility() {
if (this.usesTabLayout) {
tabLayout?.removeAllTabs()

View file

@ -229,7 +229,7 @@ class ItemRecyclerFragment : BaseFragment(), androidx.swiperefreshlayout.widget.
}
}
.map { items -> items.mapNotNull { it.key } }
.flatMap { inventoryRepository.getItems(itemClass, it.toTypedArray(), user) }
.flatMap { inventoryRepository.getItems(itemClass, it.toTypedArray()) }
.map {
val itemMap = mutableMapOf<String, Item>()
for (item in it) {

View file

@ -71,6 +71,7 @@ class PetDetailRecyclerFragment : BaseMainFragment() {
animalColor = args.color
}
resetViews()
layoutManager = androidx.recyclerview.widget.GridLayoutManager(getActivity(), 2)
@ -86,8 +87,8 @@ class PetDetailRecyclerFragment : BaseMainFragment() {
recyclerView.layoutManager = layoutManager
recyclerView.addItemDecoration(MarginDecoration(getActivity()))
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()
val egg = inventoryRepository.getItems(Egg::class.java, arrayOf(it.animal)).firstElement().blockingGet().firstOrNull()
val potion = inventoryRepository.getItems(HatchingPotion::class.java, arrayOf(it.color)).firstElement().blockingGet().firstOrNull()
Pair(egg as? Egg, potion as? HatchingPotion)
}
recyclerView.adapter = adapter
@ -102,6 +103,11 @@ class PetDetailRecyclerFragment : BaseMainFragment() {
view.post { setGridSpanCount(view.width) }
}
override fun onResume() {
super.onResume()
activity?.title = animalType
}
override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putString(ANIMAL_TYPE_KEY, this.animalType)

View file

@ -87,8 +87,8 @@ class StableRecyclerFragment : BaseFragment() {
if (adapter == null) {
adapter = StableRecyclerAdapter()
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()
val egg = inventoryRepository.getItems(Egg::class.java, arrayOf(it.animal)).firstElement().blockingGet().firstOrNull()
val potion = inventoryRepository.getItems(HatchingPotion::class.java, arrayOf(it.color)).firstElement().blockingGet().firstOrNull()
Pair(egg as? Egg, potion as? HatchingPotion)
}
adapter?.itemType = this.itemType
@ -145,6 +145,17 @@ class StableRecyclerFragment : BaseFragment() {
animalMap
}
compositeSubscription.add(inventoryRepository.getItems(Egg::class.java)
.map {
val eggMap = mutableMapOf<String, Egg>()
it.forEach { egg ->
eggMap[egg.key] = egg as Egg
}
eggMap
}
.subscribe(Consumer {
adapter?.setEggs(it)
}, RxErrorHandler.handleEmptyError()))
compositeSubscription.add(observable.zipWith(ownedObservable, BiFunction<RealmResults<out Animal>, Map<String, OwnedObject>, ArrayList<Any>> { unsortedAnimals, ownedAnimals ->
mapAnimals(unsortedAnimals, ownedAnimals)
}).subscribe(Consumer { items -> adapter?.setItemList(items) }, RxErrorHandler.handleEmptyError()))

View file

@ -144,7 +144,9 @@ class ChallengeDetailFragment: BaseMainFragment() {
}, RxErrorHandler.handleEmptyError()))
}
joinButton?.setOnClickListener { challenge?.let { challenge -> challengeRepository.joinChallenge(challenge).subscribe(Consumer {}, RxErrorHandler.handleEmptyError()) } }
joinButton?.setOnClickListener { challenge?.let { challenge -> challengeRepository.joinChallenge(challenge)
.flatMap { userRepository.retrieveUser(true) }
.subscribe(Consumer {}, RxErrorHandler.handleEmptyError()) } }
leaveButton?.setOnClickListener { showChallengeLeaveDialog() }
refresh()

View file

@ -24,8 +24,8 @@ class PetViewHolder(parent: ViewGroup, private val equipEvents: PublishSubject<S
private var hasMount: Boolean = false
private var hasUnlockedPotion: Boolean = false
private var hasUnlockedEgg: Boolean = false
private var hasEgg: Boolean = false
private var hasPotion: Boolean = false
private var eggCount: Int = 0
private var potionCount: Int = 0
private var ownsSaddles = false
private var animal: Pet? = null
@ -36,7 +36,7 @@ class PetViewHolder(parent: ViewGroup, private val equipEvents: PublishSubject<S
private var canRaiseToMount: Boolean = false
private val canHatch: Boolean
get() = hasEgg && hasPotion
get() = eggCount > 0 && potionCount > 0
init {
itemView.setOnClickListener(this)
@ -44,9 +44,9 @@ class PetViewHolder(parent: ViewGroup, private val equipEvents: PublishSubject<S
fun bind(item: Pet,
trained: Int,
eggCount: Int,
potionCount: Int,
canRaiseToMount: Boolean,
hasEgg: Boolean,
hasPotion: Boolean,
ownsSaddles: Boolean,
hasUnlockedEgg: Boolean,
hasUnlockedPotion: Boolean,
@ -55,8 +55,8 @@ class PetViewHolder(parent: ViewGroup, private val equipEvents: PublishSubject<S
isOwned = trained > 0
binding.imageView.alpha = 1.0f
this.canRaiseToMount = canRaiseToMount
this.hasEgg = hasEgg
this.hasPotion = hasPotion
this.eggCount = eggCount
this.potionCount = potionCount
this.ownsSaddles = ownsSaddles
this.hasUnlockedEgg = hasUnlockedEgg
this.hasUnlockedPotion = hasUnlockedPotion
@ -157,8 +157,8 @@ class PetViewHolder(parent: ViewGroup, private val equipEvents: PublishSubject<S
dialog.configure(it,
ingredients?.first,
ingredients?.second,
hasEgg,
hasPotion,
eggCount,
potionCount,
hasUnlockedEgg,
hasUnlockedPotion,
hasMount)

View file

@ -3,6 +3,7 @@ package com.habitrpg.android.habitica.ui.views.dialogs
import android.content.Context
import android.graphics.drawable.BitmapDrawable
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.TextView
@ -35,17 +36,33 @@ class PetSuggestHatchDialog(context: Context) : HabiticaAlertDialog(context) {
setAdditionalContentView(binding.root)
}
fun configure(pet: Animal, egg: Egg?, potion: HatchingPotion?, hasEgg: Boolean, hasPotion: Boolean, hasUnlockedEgg: Boolean, hasUnlockedPotion: Boolean, hasMount: Boolean) {
fun configure(pet: Animal, egg: Egg?, potion: HatchingPotion?, eggCount: Int, potionCount: Int, hasUnlockedEgg: Boolean, hasUnlockedPotion: Boolean, hasMount: Boolean) {
DataBindingUtils.loadImage(binding.eggView, "Pet_Egg_${pet.animal}")
DataBindingUtils.loadImage(binding.hatchingPotionView, "Pet_HatchingPotion_${pet.color}")
binding.petTitleView.text = pet.text
val hasEgg = eggCount > 0
val hasPotion = potionCount > 0
binding.eggView.alpha = if (hasEgg) 1.0f else 0.5f
binding.hatchingPotionView.alpha = if (hasPotion) 1.0f else 0.5f
val eggName = egg?.text ?: pet.animal.capitalize()
val potionName = potion?.text ?: pet.color.capitalize()
if (hasEgg) {
binding.eggCountView.visibility = View.VISIBLE
binding.eggCountView.text = eggCount.toString()
} else {
binding.eggCountView.visibility = View.GONE
}
if (hasPotion) {
binding.potionCountView.visibility = View.VISIBLE
binding.potionCountView.text = potionCount.toString()
} else {
binding.potionCountView.visibility = View.GONE
}
if (hasEgg && hasPotion) {
binding.descriptionView.text = context.getString(R.string.can_hatch_pet,
eggName,