mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
Improve all kind of list handling. Fixes #1578
This commit is contained in:
parent
734674d5d8
commit
658ee56f25
28 changed files with 359 additions and 245 deletions
|
|
@ -146,7 +146,7 @@ android {
|
|||
buildConfigField "String", "TESTING_LEVEL", "\"production\""
|
||||
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 2991
|
||||
versionCode 2994
|
||||
versionName "3.3"
|
||||
}
|
||||
|
||||
|
|
|
|||
BIN
Habitica/res/drawable-hdpi/baseline_error_outline_black_36dp.png
Normal file
BIN
Habitica/res/drawable-hdpi/baseline_error_outline_black_36dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 746 B |
BIN
Habitica/res/drawable-mdpi/baseline_error_outline_black_36dp.png
Normal file
BIN
Habitica/res/drawable-mdpi/baseline_error_outline_black_36dp.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 499 B |
Binary file not shown.
|
After Width: | Height: | Size: 954 B |
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
43
Habitica/res/layout/empty_item.xml
Normal file
43
Habitica/res/layout/empty_item.xml
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/emptyView"
|
||||
style="@style/EmptyView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/empty_icon_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="4dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/emptyViewTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/text_ternary"
|
||||
android:textSize="@dimen/card_medium_text"
|
||||
tools:text="No Items" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/emptyViewDescription"
|
||||
style="@style/Body2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/text_ternary"
|
||||
tools:text="No Items" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/HabiticaButton.Primary"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"
|
||||
android:layout_marginTop="@dimen/spacing_large"/>
|
||||
</LinearLayout>
|
||||
25
Habitica/res/layout/failed_item.xml
Normal file
25
Habitica/res/layout/failed_item.xml
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
<androidx.constraintlayout.utils.widget.ImageFilterView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/baseline_error_outline_black_36dp"
|
||||
android:tint="@color/text_quad"/>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/failed"
|
||||
style="@style/Headline"
|
||||
android:textColor="@color/text_primary"/>
|
||||
<Button
|
||||
android:id="@+id/refresh_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/HabiticaButton.Primary"
|
||||
android:text="@string/retry"
|
||||
android:layout_marginTop="@dimen/spacing_large" />
|
||||
</LinearLayout>
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/refreshLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior">
|
||||
<com.habitrpg.android.habitica.ui.helpers.RecyclerViewEmptySupport
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:divider="@null"
|
||||
android:scrollbars="vertical"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:id="@+id/emptyView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="48dp"
|
||||
android:layout_marginEnd="48dp"
|
||||
android:layout_marginTop="32dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
style="@style/Headline"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:maxLines="2"
|
||||
android:text="@string/not_part_of_a_challenge"
|
||||
android:textAlignment="center"
|
||||
android:textColor="#8a000000" />
|
||||
|
||||
<TextView
|
||||
style="@style/Body2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="22dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/join_a_challenge"
|
||||
android:textAlignment="center"
|
||||
android:textColor="#66000000" />
|
||||
|
||||
<TextView
|
||||
style="@style/Body2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="22dp"
|
||||
android:gravity="center"
|
||||
android:text="@string/check_the_public_challenge_tab"
|
||||
android:textAlignment="center"
|
||||
android:textColor="#66000000" />
|
||||
|
||||
</LinearLayout>
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
|
@ -41,23 +41,4 @@
|
|||
android:text="@string/open_market"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/emptyView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/empty_text_view"
|
||||
style="@style/EmptyView"
|
||||
android:gravity="center" />
|
||||
<Button
|
||||
android:id="@+id/openEmptyMarketButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/open_market"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
|||
|
|
@ -1,23 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
<com.habitrpg.android.habitica.ui.helpers.RecyclerViewEmptySupport
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.habitrpg.android.habitica.ui.helpers.RecyclerViewEmptySupport
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbarSize="3dp"
|
||||
android:scrollbarThumbVertical="@color/scrollbarThumb"
|
||||
android:scrollbars="vertical"
|
||||
android:clipToPadding="false"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/emptyView"
|
||||
style="@style/EmptyView"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbarSize="3dp"
|
||||
android:scrollbarThumbVertical="@color/scrollbarThumb"
|
||||
android:scrollbars="vertical"
|
||||
android:clipToPadding="false"/>
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.habitrpg.android.habitica.ui.helpers.RecyclerViewEmptySupport
|
||||
android:id="@+id/recyclerView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbarSize="3dp"
|
||||
android:scrollbarThumbVertical="@color/scrollbarThumb"
|
||||
android:scrollbars="vertical"
|
||||
android:clipToPadding="false"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/emptyView"
|
||||
style="@style/EmptyView"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
|
|
@ -19,40 +18,4 @@
|
|||
android:scrollbarThumbVertical="@color/scrollbarThumb"
|
||||
android:scrollbars="vertical" />
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/emptyView"
|
||||
style="@style/EmptyView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="60dp"
|
||||
android:orientation="vertical"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/empty_icon_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="4dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/emptyViewTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="6dp"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/text_ternary"
|
||||
android:textSize="@dimen/card_medium_text"
|
||||
tools:text="No Items" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/emptyViewDescription"
|
||||
style="@style/Body2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:textColor="@color/text_ternary"
|
||||
tools:text="No Items" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
|||
11
Habitica/res/layout/loading_item.xml
Normal file
11
Habitica/res/layout/loading_item.xml
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<ProgressBar
|
||||
android:id="@+id/loading_indicator"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
/>
|
||||
</FrameLayout>
|
||||
|
|
@ -1166,6 +1166,10 @@
|
|||
<string name="locked_equipment_shop_dialog">You must purchase the previous items in this sequence to unlock</string>
|
||||
<string name="caused_damage">You caused damage to the boss</string>
|
||||
<string name="avatar_style">Style</string>
|
||||
<string name="failed">Failed to load</string>
|
||||
<string name="daily_item_checkbox">Daily Checkbox</string>
|
||||
<string name="retry">Retry</string>
|
||||
<string name="empty_title">Nothing here yet</string>
|
||||
<string name="empty_equipment_description">You don\'t have any equipment of this type yet. You can purchase equipment from the market using the gold you earned.</string>
|
||||
<string name="todo_item_checkbox">Todo Checkbox</string>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -87,6 +87,7 @@ class RealmInventoryLocalRepository(realm: Realm) : RealmContentLocalRepository(
|
|||
"hatchingPotions" -> it.items?.hatchingPotions
|
||||
"food" -> it.items?.food
|
||||
"quests" -> it.items?.quests
|
||||
"special" -> it.items?.special?.ownedItems
|
||||
else -> emptyList()
|
||||
} ?: emptyList()
|
||||
if (includeZero) {
|
||||
|
|
|
|||
|
|
@ -30,13 +30,17 @@ class ShopRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<an
|
|||
var shopSpriteSuffix: String = ""
|
||||
set(value) {
|
||||
field = value
|
||||
notifyItemChanged(0)
|
||||
if (items.size > 0) {
|
||||
notifyItemChanged(0)
|
||||
}
|
||||
}
|
||||
var context: Context? = null
|
||||
var user: User? = null
|
||||
set(value) {
|
||||
field = value
|
||||
this.notifyDataSetChanged()
|
||||
if (items.size > 0) {
|
||||
this.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
private var pinnedItemKeys: List<String> = ArrayList()
|
||||
|
||||
|
|
@ -49,7 +53,7 @@ class ShopRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<an
|
|||
internal var selectedGearCategory: String = ""
|
||||
set(value) {
|
||||
field = value
|
||||
if (field != "") {
|
||||
if (field != "" && items.size > 0) {
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
|
@ -200,12 +204,16 @@ class ShopRecyclerAdapter : androidx.recyclerview.widget.RecyclerView.Adapter<an
|
|||
|
||||
fun setOwnedItems(ownedItems: Map<String, OwnedItem>) {
|
||||
this.ownedItems = ownedItems
|
||||
this.notifyDataSetChanged()
|
||||
if (items.size > 0) {
|
||||
this.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
fun setPinnedItemKeys(pinnedItemKeys: List<String>) {
|
||||
this.pinnedItemKeys = pinnedItemKeys
|
||||
this.notifyDataSetChanged()
|
||||
if (items.size > 0) {
|
||||
this.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
internal class ShopHeaderViewHolder(parent: ViewGroup) : androidx.recyclerview.widget.RecyclerView.ViewHolder(parent.inflate(R.layout.shop_header)) {
|
||||
|
|
|
|||
|
|
@ -135,6 +135,7 @@ class StableRecyclerAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
|||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
if (itemList.size <= position) { return 0 }
|
||||
val item = itemList[position]
|
||||
return if (item == "header") {
|
||||
0
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@ import io.reactivex.rxjava3.subjects.PublishSubject
|
|||
class RewardsRecyclerViewAdapter(private var customRewards: List<Task>?, private val layoutResource: Int) : BaseRecyclerViewAdapter<Task, RecyclerView.ViewHolder>(), TaskRecyclerViewAdapter {
|
||||
var user: User? = null
|
||||
set(value) {
|
||||
if (field?.versionNumber == value?.versionNumber) {
|
||||
return
|
||||
}
|
||||
field = value
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,12 +7,15 @@ import android.view.ViewGroup
|
|||
import androidx.recyclerview.widget.DividerItemDecoration
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.components.UserComponent
|
||||
import com.habitrpg.android.habitica.data.InventoryRepository
|
||||
import com.habitrpg.android.habitica.databinding.FragmentRefreshRecyclerviewBinding
|
||||
import com.habitrpg.android.habitica.helpers.MainNavigationController
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.ui.adapter.inventory.EquipmentRecyclerViewAdapter
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment
|
||||
import com.habitrpg.android.habitica.ui.helpers.EmptyItem
|
||||
import com.habitrpg.android.habitica.ui.helpers.SafeDefaultItemAnimator
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -29,6 +32,7 @@ class EquipmentDetailFragment : BaseMainFragment<FragmentRefreshRecyclerviewBind
|
|||
}
|
||||
|
||||
var type: String? = null
|
||||
var typeText: String? = null
|
||||
var equippedGear: String? = null
|
||||
var isCostume: Boolean? = null
|
||||
|
||||
|
|
@ -52,6 +56,15 @@ class EquipmentDetailFragment : BaseMainFragment<FragmentRefreshRecyclerviewBind
|
|||
equippedGear = args.equippedGear
|
||||
}
|
||||
binding?.refreshLayout?.setOnRefreshListener(this)
|
||||
binding?.recyclerView?.onRefresh = { onRefresh() }
|
||||
binding?.recyclerView?.emptyItem = EmptyItem(
|
||||
getString(R.string.empty_title),
|
||||
getString(R.string.empty_equipment_description),
|
||||
null,
|
||||
getString(R.string.open_market)
|
||||
) {
|
||||
MainNavigationController.navigate(R.id.marketFragment)
|
||||
}
|
||||
|
||||
this.adapter.equippedGear = this.equippedGear
|
||||
this.adapter.isCostume = this.isCostume
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ import com.habitrpg.android.habitica.models.user.User
|
|||
import com.habitrpg.android.habitica.ui.activities.MainActivity
|
||||
import com.habitrpg.android.habitica.ui.adapter.inventory.ItemRecyclerAdapter
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseDialogFragment
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment
|
||||
import com.habitrpg.android.habitica.ui.helpers.EmptyItem
|
||||
import com.habitrpg.android.habitica.ui.helpers.SafeDefaultItemAnimator
|
||||
import com.habitrpg.android.habitica.ui.helpers.loadImage
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.OpenedMysteryitemDialog
|
||||
|
|
@ -78,9 +78,13 @@ class ItemDialogFragment : BaseDialogFragment<FragmentItemsBinding>(), SwipeRefr
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding?.recyclerView?.setEmptyView(binding?.emptyView)
|
||||
binding?.refreshLayout?.setOnRefreshListener(this)
|
||||
binding?.emptyTextView?.text = getString(R.string.empty_items, itemTypeText)
|
||||
binding?.recyclerView?.emptyItem = EmptyItem(
|
||||
getString(R.string.empty_items, itemTypeText),
|
||||
getString(R.string.open_market)
|
||||
) {
|
||||
openMarket()
|
||||
}
|
||||
|
||||
val context = activity
|
||||
|
||||
|
|
@ -176,7 +180,7 @@ class ItemDialogFragment : BaseDialogFragment<FragmentItemsBinding>(), SwipeRefr
|
|||
openMarket()
|
||||
}
|
||||
|
||||
binding?.openEmptyMarketButton?.setOnClickListener { openMarket() }
|
||||
//binding?.openEmptyMarketButton?.setOnClickListener { openMarket() }
|
||||
|
||||
this.loadItems()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments.inventory.items
|
||||
|
||||
import android.graphics.drawable.BitmapDrawable
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.Window
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.components.UserComponent
|
||||
|
|
@ -23,10 +21,9 @@ import com.habitrpg.android.habitica.models.user.User
|
|||
import com.habitrpg.android.habitica.ui.activities.MainActivity
|
||||
import com.habitrpg.android.habitica.ui.adapter.inventory.ItemRecyclerAdapter
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment
|
||||
import com.habitrpg.android.habitica.ui.helpers.DataBindingUtils
|
||||
import com.habitrpg.android.habitica.ui.helpers.EmptyItem
|
||||
import com.habitrpg.android.habitica.ui.helpers.SafeDefaultItemAnimator
|
||||
import com.habitrpg.android.habitica.ui.helpers.loadImage
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.HabiticaAlertDialog
|
||||
import com.habitrpg.android.habitica.ui.views.dialogs.OpenedMysteryitemDialog
|
||||
import javax.inject.Inject
|
||||
|
||||
|
|
@ -62,9 +59,15 @@ class ItemRecyclerFragment : BaseFragment<FragmentItemsBinding>(), SwipeRefreshL
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding?.recyclerView?.setEmptyView(binding?.emptyView)
|
||||
binding?.refreshLayout?.setOnRefreshListener(this)
|
||||
binding?.emptyTextView?.text = getString(R.string.empty_items, itemTypeText)
|
||||
binding?.recyclerView?.emptyItem = EmptyItem(
|
||||
getString(R.string.empty_items, itemTypeText ?: itemType),
|
||||
null,
|
||||
null,
|
||||
getString(R.string.open_market)
|
||||
) {
|
||||
openMarket()
|
||||
}
|
||||
|
||||
val context = activity
|
||||
|
||||
|
|
@ -129,8 +132,6 @@ class ItemRecyclerFragment : BaseFragment<FragmentItemsBinding>(), SwipeRefreshL
|
|||
openMarket()
|
||||
}
|
||||
|
||||
binding?.openEmptyMarketButton?.setOnClickListener { openMarket() }
|
||||
|
||||
this.loadItems()
|
||||
}
|
||||
|
||||
|
|
@ -176,20 +177,21 @@ class ItemRecyclerFragment : BaseFragment<FragmentItemsBinding>(), SwipeRefreshL
|
|||
}
|
||||
itemType?.let { type ->
|
||||
compositeSubscription.add(inventoryRepository.getOwnedItems(type)
|
||||
.doOnNext { items ->
|
||||
adapter?.data = items
|
||||
.map { it.distinctBy { it.key } }
|
||||
.doOnNext { items ->
|
||||
adapter?.data = items
|
||||
}
|
||||
.map { items -> items.mapNotNull { it.key } }
|
||||
.flatMap { inventoryRepository.getItems(itemClass, it.toTypedArray()) }
|
||||
.map {
|
||||
val itemMap = mutableMapOf<String, Item>()
|
||||
for (item in it) {
|
||||
itemMap[item.key] = item
|
||||
}
|
||||
.map { items -> items.mapNotNull { it.key } }
|
||||
.flatMap { inventoryRepository.getItems(itemClass, it.toTypedArray()) }
|
||||
.map {
|
||||
val itemMap = mutableMapOf<String, Item>()
|
||||
for (item in it) {
|
||||
itemMap[item.key] = item
|
||||
}
|
||||
itemMap
|
||||
}
|
||||
.subscribe({ items ->
|
||||
adapter?.items = items
|
||||
itemMap
|
||||
}
|
||||
.subscribe({ items ->
|
||||
adapter?.items = items
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import com.habitrpg.android.habitica.components.UserComponent
|
|||
import com.habitrpg.android.habitica.data.InventoryRepository
|
||||
import com.habitrpg.android.habitica.data.SocialRepository
|
||||
import com.habitrpg.android.habitica.databinding.FragmentRecyclerviewBinding
|
||||
import com.habitrpg.android.habitica.databinding.FragmentRefreshRecyclerviewBinding
|
||||
import com.habitrpg.android.habitica.events.GearPurchasedEvent
|
||||
import com.habitrpg.android.habitica.helpers.AppConfigManager
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
|
|
@ -22,12 +23,13 @@ import com.habitrpg.android.habitica.models.social.Group
|
|||
import com.habitrpg.android.habitica.models.user.User
|
||||
import com.habitrpg.android.habitica.ui.adapter.inventory.ShopRecyclerAdapter
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseMainFragment
|
||||
import com.habitrpg.android.habitica.ui.helpers.RecyclerViewState
|
||||
import com.habitrpg.android.habitica.ui.helpers.SafeDefaultItemAnimator
|
||||
import com.habitrpg.android.habitica.ui.views.CurrencyViews
|
||||
import org.greenrobot.eventbus.Subscribe
|
||||
import javax.inject.Inject
|
||||
|
||||
open class ShopFragment : BaseMainFragment<FragmentRecyclerviewBinding>() {
|
||||
open class ShopFragment : BaseMainFragment<FragmentRefreshRecyclerviewBinding>() {
|
||||
|
||||
internal val currencyView: CurrencyViews by lazy {
|
||||
val view = CurrencyViews(context)
|
||||
|
|
@ -48,10 +50,10 @@ open class ShopFragment : BaseMainFragment<FragmentRecyclerviewBinding>() {
|
|||
|
||||
private var gearCategories: MutableList<ShopCategory>? = null
|
||||
|
||||
override var binding: FragmentRecyclerviewBinding? = null
|
||||
override var binding: FragmentRefreshRecyclerviewBinding? = null
|
||||
|
||||
override fun createBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentRecyclerviewBinding {
|
||||
return FragmentRecyclerviewBinding.inflate(inflater, container, false)
|
||||
override fun createBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentRefreshRecyclerviewBinding {
|
||||
return FragmentRefreshRecyclerviewBinding.inflate(inflater, container, false)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
|
|
@ -70,7 +72,12 @@ open class ShopFragment : BaseMainFragment<FragmentRecyclerviewBinding>() {
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
toolbarAccessoryContainer?.addView(currencyView)
|
||||
binding?.recyclerView?.setBackgroundResource(R.color.content_background)
|
||||
|
||||
binding?.recyclerView?.onRefresh = {
|
||||
loadShopInventory()
|
||||
}
|
||||
binding?.refreshLayout?.setOnRefreshListener {
|
||||
loadShopInventory()
|
||||
}
|
||||
adapter = binding?.recyclerView?.adapter as? ShopRecyclerAdapter
|
||||
if (adapter == null) {
|
||||
adapter = ShopRecyclerAdapter()
|
||||
|
|
@ -178,7 +185,12 @@ open class ShopFragment : BaseMainFragment<FragmentRecyclerviewBinding>() {
|
|||
.subscribe({
|
||||
this.shop = it
|
||||
this.adapter?.setShop(it)
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
}, {
|
||||
binding?.recyclerView?.state = RecyclerViewState.FAILED
|
||||
RxErrorHandler.reportError(it)
|
||||
}, {
|
||||
binding?.refreshLayout?.isRefreshing = false
|
||||
}))
|
||||
|
||||
compositeSubscription.add(this.inventoryRepository.getOwnedItems()
|
||||
.subscribe({ adapter?.setOwnedItems(it) }, RxErrorHandler.handleEmptyError()))
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import com.habitrpg.android.habitica.models.inventory.StableSection
|
|||
import com.habitrpg.android.habitica.models.user.*
|
||||
import com.habitrpg.android.habitica.ui.adapter.inventory.StableRecyclerAdapter
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment
|
||||
import com.habitrpg.android.habitica.ui.helpers.EmptyItem
|
||||
import com.habitrpg.android.habitica.ui.helpers.MarginDecoration
|
||||
import com.habitrpg.android.habitica.ui.helpers.SafeDefaultItemAnimator
|
||||
import io.reactivex.rxjava3.core.Flowable
|
||||
|
|
@ -70,8 +71,8 @@ class StableRecyclerFragment : BaseFragment<FragmentRefreshRecyclerviewBinding>(
|
|||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding?.recyclerView?.setEmptyView(binding?.emptyView)
|
||||
binding?.emptyViewTitle?.text = getString(R.string.empty_items, itemTypeText)
|
||||
binding?.recyclerView?.emptyItem = EmptyItem(
|
||||
getString(R.string.empty_items, itemTypeText))
|
||||
binding?.refreshLayout?.setOnRefreshListener(this)
|
||||
|
||||
layoutManager = androidx.recyclerview.widget.GridLayoutManager(activity, 2)
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import com.habitrpg.android.habitica.components.UserComponent
|
|||
import com.habitrpg.android.habitica.data.ChallengeRepository
|
||||
import com.habitrpg.android.habitica.data.SocialRepository
|
||||
import com.habitrpg.android.habitica.data.UserRepository
|
||||
import com.habitrpg.android.habitica.databinding.FragmentChallengeslistBinding
|
||||
import com.habitrpg.android.habitica.databinding.FragmentRefreshRecyclerviewBinding
|
||||
import com.habitrpg.android.habitica.helpers.MainNavigationController
|
||||
import com.habitrpg.android.habitica.helpers.RxErrorHandler
|
||||
import com.habitrpg.android.habitica.models.social.Challenge
|
||||
|
|
@ -26,7 +26,7 @@ import javax.inject.Inject
|
|||
import javax.inject.Named
|
||||
|
||||
|
||||
class ChallengeListFragment : BaseFragment<FragmentChallengeslistBinding>(), androidx.swiperefreshlayout.widget.SwipeRefreshLayout.OnRefreshListener {
|
||||
class ChallengeListFragment : BaseFragment<FragmentRefreshRecyclerviewBinding>(), androidx.swiperefreshlayout.widget.SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
@Inject
|
||||
lateinit var challengeRepository: ChallengeRepository
|
||||
|
|
@ -37,10 +37,10 @@ class ChallengeListFragment : BaseFragment<FragmentChallengeslistBinding>(), and
|
|||
@field:[Inject Named(AppModule.NAMED_USER_ID)]
|
||||
lateinit var userId: String
|
||||
|
||||
override var binding: FragmentChallengeslistBinding? = null
|
||||
override var binding: FragmentRefreshRecyclerviewBinding? = null
|
||||
|
||||
override fun createBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentChallengeslistBinding {
|
||||
return FragmentChallengeslistBinding.inflate(inflater, container, false)
|
||||
override fun createBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentRefreshRecyclerviewBinding {
|
||||
return FragmentRefreshRecyclerviewBinding.inflate(inflater, container, false)
|
||||
}
|
||||
|
||||
private var challengeAdapter: ChallengesListViewAdapter? = null
|
||||
|
|
@ -84,7 +84,6 @@ class ChallengeListFragment : BaseFragment<FragmentChallengeslistBinding>(), and
|
|||
filterGroups?.addAll(it.second)
|
||||
}, RxErrorHandler.handleEmptyError()))
|
||||
|
||||
binding?.recyclerView?.setEmptyView(binding?.emptyView)
|
||||
binding?.recyclerView?.itemAnimator = SafeDefaultItemAnimator()
|
||||
|
||||
challengeAdapter?.updateUnfilteredData(challenges)
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import com.habitrpg.android.habitica.ui.activities.TaskFormActivity
|
|||
import com.habitrpg.android.habitica.ui.adapter.BaseRecyclerViewAdapter
|
||||
import com.habitrpg.android.habitica.ui.adapter.tasks.*
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment
|
||||
import com.habitrpg.android.habitica.ui.helpers.EmptyItem
|
||||
import com.habitrpg.android.habitica.ui.helpers.SafeDefaultItemAnimator
|
||||
import com.habitrpg.android.habitica.ui.viewHolders.tasks.BaseTaskViewHolder
|
||||
import com.habitrpg.android.habitica.ui.views.HabiticaIconsHelper
|
||||
|
|
@ -288,51 +289,61 @@ open class TaskRecyclerViewFragment : BaseFragment<FragmentRefreshRecyclerviewBi
|
|||
}
|
||||
|
||||
private fun setEmptyLabels() {
|
||||
binding?.recyclerView?.setEmptyView(binding?.emptyView)
|
||||
context?.let { binding?.emptyIconView?.setColorFilter(ContextCompat.getColor(it, R.color.text_dimmed), android.graphics.PorterDuff.Mode.MULTIPLY) }
|
||||
if (taskFilterHelper.howMany(taskType) > 0) {
|
||||
binding?.recyclerView?.emptyItem = if (taskFilterHelper.howMany(taskType) > 0) {
|
||||
when (this.taskType) {
|
||||
Task.TYPE_HABIT -> {
|
||||
binding?.emptyIconView?.setImageResource(R.drawable.icon_habits)
|
||||
binding?.emptyViewTitle?.setText(R.string.empty_title_habits_filtered)
|
||||
binding?.emptyViewDescription?.setText(R.string.empty_description_habits_filtered)
|
||||
EmptyItem(
|
||||
getString(R.string.empty_title_habits_filtered),
|
||||
getString(R.string.empty_description_habits_filtered),
|
||||
R.drawable.icon_habits)
|
||||
}
|
||||
Task.TYPE_DAILY -> {
|
||||
binding?.emptyIconView?.setImageResource(R.drawable.icon_dailies)
|
||||
binding?.emptyViewTitle?.setText(R.string.empty_title_dailies_filtered)
|
||||
binding?.emptyViewDescription?.setText(R.string.empty_description_dailies_filtered)
|
||||
EmptyItem(
|
||||
getString(R.string.empty_title_dailies_filtered),
|
||||
getString(R.string.empty_description_dailies_filtered),
|
||||
R.drawable.icon_dailies)
|
||||
}
|
||||
Task.TYPE_TODO -> {
|
||||
binding?.emptyIconView?.setImageResource(R.drawable.icon_todos)
|
||||
binding?.emptyViewTitle?.setText(R.string.empty_title_todos_filtered)
|
||||
binding?.emptyViewDescription?.setText(R.string.empty_description_todos_filtered)
|
||||
EmptyItem(
|
||||
getString(R.string.empty_title_todos_filtered),
|
||||
getString(R.string.empty_description_todos_filtered),
|
||||
R.drawable.icon_todos)
|
||||
}
|
||||
Task.TYPE_REWARD -> {
|
||||
binding?.emptyIconView?.setImageResource(R.drawable.icon_rewards)
|
||||
binding?.emptyViewTitle?.setText(R.string.empty_title_rewards)
|
||||
EmptyItem(
|
||||
getString(R.string.empty_title_rewards_filtered),
|
||||
null,
|
||||
R.drawable.icon_rewards)
|
||||
}
|
||||
else -> EmptyItem("")
|
||||
}
|
||||
} else {
|
||||
when (this.taskType) {
|
||||
Task.TYPE_HABIT -> {
|
||||
binding?.emptyIconView?.setImageResource(R.drawable.icon_habits)
|
||||
binding?.emptyViewTitle?.setText(R.string.empty_title_habits)
|
||||
binding?.emptyViewDescription?.setText(R.string.empty_description_habits)
|
||||
EmptyItem(
|
||||
getString(R.string.empty_title_habits),
|
||||
getString(R.string.empty_description_habits),
|
||||
R.drawable.icon_habits)
|
||||
}
|
||||
Task.TYPE_DAILY -> {
|
||||
binding?.emptyIconView?.setImageResource(R.drawable.icon_dailies)
|
||||
binding?.emptyViewTitle?.setText(R.string.empty_title_dailies)
|
||||
binding?.emptyViewDescription?.setText(R.string.empty_description_dailies)
|
||||
EmptyItem(
|
||||
getString(R.string.empty_title_dailies),
|
||||
getString(R.string.empty_description_dailies),
|
||||
R.drawable.icon_dailies)
|
||||
}
|
||||
Task.TYPE_TODO -> {
|
||||
binding?.emptyIconView?.setImageResource(R.drawable.icon_todos)
|
||||
binding?.emptyViewTitle?.setText(R.string.empty_title_todos)
|
||||
binding?.emptyViewDescription?.setText(R.string.empty_description_todos)
|
||||
EmptyItem(
|
||||
getString(R.string.empty_title_todos),
|
||||
getString(R.string.empty_description_todos),
|
||||
R.drawable.icon_todos)
|
||||
}
|
||||
Task.TYPE_REWARD -> {
|
||||
binding?.emptyIconView?.setImageResource(R.drawable.icon_rewards)
|
||||
binding?.emptyViewTitle?.setText(R.string.empty_title_rewards)
|
||||
EmptyItem(
|
||||
getString(R.string.empty_title_rewards),
|
||||
null,
|
||||
R.drawable.icon_rewards)
|
||||
}
|
||||
else -> EmptyItem("")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,22 +3,108 @@ package com.habitrpg.android.habitica.ui.helpers
|
|||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.animation.AlphaAnimation
|
||||
import android.widget.ProgressBar
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.databinding.EmptyItemBinding
|
||||
import com.habitrpg.android.habitica.databinding.FailedItemBinding
|
||||
import com.habitrpg.android.habitica.extensions.inflate
|
||||
|
||||
data class EmptyItem(
|
||||
var title: String,
|
||||
var text: String? = null,
|
||||
var iconResource: Int? = null,
|
||||
var buttonLabel: String? = null,
|
||||
var onButtonTap: (() -> Unit)? = null
|
||||
)
|
||||
|
||||
enum class RecyclerViewState {
|
||||
LOADING,
|
||||
EMPTY,
|
||||
DISPLAYING_DATA,
|
||||
FAILED
|
||||
}
|
||||
|
||||
//http://stackoverflow.com/a/27801394/1315039
|
||||
class RecyclerViewEmptySupport : RecyclerView {
|
||||
private var emptyView: View? = null
|
||||
var onRefresh: (() -> Unit)? = null
|
||||
var state: RecyclerViewState = RecyclerViewState.LOADING
|
||||
set(value) {
|
||||
field = value
|
||||
when (field) {
|
||||
RecyclerViewState.DISPLAYING_DATA -> updateAdapter(actualAdapter)
|
||||
else -> {
|
||||
updateAdapter(emptyAdapter)
|
||||
emptyAdapter.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateAdapter(newAdapter: Adapter<*>?) {
|
||||
if (adapter != newAdapter) {
|
||||
super.setAdapter(newAdapter)
|
||||
}
|
||||
}
|
||||
|
||||
var emptyItem: EmptyItem? = null
|
||||
set(value) {
|
||||
field = value
|
||||
emptyAdapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
private var actualAdapter: Adapter<*>? = null
|
||||
private val emptyAdapter: Adapter<ViewHolder> = object : Adapter<ViewHolder>() {
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||
return when (viewType) {
|
||||
0 -> {
|
||||
val view = parent.inflate(R.layout.loading_item)
|
||||
val animation1 = AlphaAnimation(0.0f, 1.0f)
|
||||
animation1.duration = 300
|
||||
animation1.startOffset = 500
|
||||
animation1.fillAfter = true
|
||||
view.findViewById<ProgressBar>(R.id.loading_indicator).startAnimation(animation1)
|
||||
object : ViewHolder(view) {}
|
||||
}
|
||||
1 -> FailedViewHolder(parent.inflate(R.layout.failed_item))
|
||||
else -> EmptyViewHolder(parent.inflate(R.layout.empty_item))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
if (holder is EmptyViewHolder) {
|
||||
holder.bind(emptyItem)
|
||||
} else if (holder is FailedViewHolder) {
|
||||
holder.bind(onRefresh)
|
||||
}
|
||||
(holder as? EmptyViewHolder)?.bind(emptyItem)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return 1
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
return when (state) {
|
||||
RecyclerViewState.LOADING -> 0
|
||||
RecyclerViewState.FAILED -> 1
|
||||
else -> 2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val observer = object : RecyclerView.AdapterDataObserver() {
|
||||
override fun onChanged() {
|
||||
checkIfEmpty()
|
||||
updateState()
|
||||
}
|
||||
|
||||
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
|
||||
checkIfEmpty()
|
||||
updateState()
|
||||
}
|
||||
|
||||
override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) {
|
||||
checkIfEmpty()
|
||||
updateState()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -28,25 +114,59 @@ class RecyclerViewEmptySupport : RecyclerView {
|
|||
|
||||
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle)
|
||||
|
||||
internal fun checkIfEmpty() {
|
||||
if (emptyView != null && adapter != null) {
|
||||
val emptyViewVisible = adapter?.itemCount == 0
|
||||
emptyView?.visibility = if (emptyViewVisible) View.VISIBLE else View.GONE
|
||||
visibility = if (emptyViewVisible) View.GONE else View.VISIBLE
|
||||
internal fun updateState(isInitial: Boolean = false) {
|
||||
if (actualAdapter != null && !isInitial) {
|
||||
val emptyViewVisible = actualAdapter?.itemCount == 0
|
||||
if (emptyViewVisible) {
|
||||
state = RecyclerViewState.EMPTY
|
||||
} else {
|
||||
state = RecyclerViewState.DISPLAYING_DATA
|
||||
}
|
||||
} else {
|
||||
state = RecyclerViewState.LOADING
|
||||
}
|
||||
}
|
||||
|
||||
override fun setAdapter(adapter: Adapter<*>?) {
|
||||
val oldAdapter = getAdapter()
|
||||
val oldAdapter = actualAdapter
|
||||
oldAdapter?.unregisterAdapterDataObserver(observer)
|
||||
super.setAdapter(adapter)
|
||||
adapter?.registerAdapterDataObserver(observer)
|
||||
|
||||
checkIfEmpty()
|
||||
}
|
||||
|
||||
fun setEmptyView(emptyView: View?) {
|
||||
this.emptyView = emptyView
|
||||
checkIfEmpty()
|
||||
actualAdapter = adapter
|
||||
updateState(true)
|
||||
}
|
||||
}
|
||||
|
||||
class FailedViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
private val binding = FailedItemBinding.bind(itemView)
|
||||
|
||||
fun bind(onRefresh: (() -> Unit)?) {
|
||||
if (onRefresh != null) {
|
||||
binding.refreshButton.visibility = View.VISIBLE
|
||||
binding.refreshButton.setOnClickListener { onRefresh() }
|
||||
} else {
|
||||
binding.refreshButton.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class EmptyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
|
||||
private val binding = EmptyItemBinding.bind(itemView)
|
||||
|
||||
fun bind(emptyItem: EmptyItem?) {
|
||||
binding.emptyIconView.setColorFilter(ContextCompat.getColor(itemView.context, R.color.text_dimmed), android.graphics.PorterDuff.Mode.MULTIPLY)
|
||||
emptyItem?.iconResource?.let { binding.emptyIconView.setImageResource(it) }
|
||||
binding.emptyViewTitle.text = emptyItem?.title
|
||||
binding.emptyViewDescription.text = emptyItem?.text
|
||||
|
||||
val buttonLabel =emptyItem?.buttonLabel
|
||||
if (buttonLabel != null) {
|
||||
binding.button.visibility = View.VISIBLE
|
||||
binding.button.text = buttonLabel
|
||||
binding.button.setOnClickListener { emptyItem.onButtonTap?.invoke() }
|
||||
} else {
|
||||
binding.button.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,10 +9,12 @@ import android.widget.*
|
|||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.children
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.habitrpg.android.habitica.R
|
||||
import com.habitrpg.android.habitica.extensions.dpToPx
|
||||
import com.habitrpg.android.habitica.extensions.inflate
|
||||
import com.habitrpg.android.habitica.extensions.layoutInflater
|
||||
import com.habitrpg.android.habitica.ui.activities.BaseActivity
|
||||
import com.habitrpg.android.habitica.ui.views.login.LockableScrollView
|
||||
import com.plattysoft.leonids.ParticleSystem
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
|
@ -289,10 +291,11 @@ open class HabiticaAlertDialog(context: Context) : AlertDialog(context, R.style.
|
|||
dialogQueue.removeAt(0)
|
||||
}
|
||||
if (dialogQueue.size > 0) {
|
||||
if ((dialogQueue[0].context as? Activity)?.isFinishing != true) {
|
||||
GlobalScope.launch(context = Dispatchers.Main) {
|
||||
if ((dialogQueue[0].context as? BaseActivity)?.isFinishing != true) {
|
||||
(dialogQueue[0].context as? BaseActivity)?.lifecycleScope?.launch(context = Dispatchers.Main) {
|
||||
delay(500L)
|
||||
if (dialogQueue.size > 0 && (dialogQueue[0].context as? Activity)?.isFinishing == false) {
|
||||
if (dialogQueue.size > 0 && ((dialogQueue[0].context as? Activity)?.isFinishing == false ||
|
||||
((dialogQueue[0].context as? ContextThemeWrapper)?.baseContext as? Activity)?.isFinishing == false)) {
|
||||
dialogQueue[0].show()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue