mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-19 12:18:59 +00:00
add pull to refresh to item list
This commit is contained in:
parent
0f05045d2d
commit
2afef8b2f9
2 changed files with 29 additions and 10 deletions
|
|
@ -1,9 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<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"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -12,14 +12,22 @@
|
|||
android:id="@+id/titleTextView"
|
||||
android:background="?colorPrimary"
|
||||
android:textColor="@android:color/white" />
|
||||
<com.habitrpg.android.habitica.ui.helpers.RecyclerViewEmptySupport
|
||||
android:id="@+id/recyclerView"
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/refreshLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:scrollbarSize="3dp"
|
||||
android:scrollbarThumbVertical="@color/scrollbarThumb"
|
||||
android:scrollbars="vertical" />
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/gray_700"
|
||||
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:scrollbarSize="3dp"
|
||||
android:scrollbarThumbVertical="@color/scrollbarThumb"
|
||||
android:scrollbars="vertical" />
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import android.view.ViewGroup
|
|||
import android.view.Window
|
||||
import android.widget.Button
|
||||
import android.widget.TextView
|
||||
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
|
||||
|
|
@ -27,12 +28,13 @@ import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar.Companion.showSna
|
|||
import io.reactivex.functions.Consumer
|
||||
import javax.inject.Inject
|
||||
|
||||
class ItemRecyclerFragment : BaseFragment() {
|
||||
class ItemRecyclerFragment : BaseFragment(), androidx.swiperefreshlayout.widget.SwipeRefreshLayout.OnRefreshListener {
|
||||
|
||||
@Inject
|
||||
lateinit var inventoryRepository: InventoryRepository
|
||||
@Inject
|
||||
lateinit var userRepository: UserRepository
|
||||
val refreshLayout: SwipeRefreshLayout? by bindView(R.id.refreshLayout)
|
||||
val recyclerView: RecyclerViewEmptySupport? by bindView(R.id.recyclerView)
|
||||
val emptyView: View? by bindView(R.id.emptyView)
|
||||
private val emptyTextView: TextView? by bindView(R.id.empty_text_view)
|
||||
|
|
@ -70,6 +72,7 @@ class ItemRecyclerFragment : BaseFragment() {
|
|||
resetViews()
|
||||
|
||||
recyclerView?.setEmptyView(emptyView)
|
||||
refreshLayout?.setOnRefreshListener(this)
|
||||
emptyTextView?.text = getString(R.string.empty_items, itemTypeText)
|
||||
|
||||
val context = activity
|
||||
|
|
@ -191,6 +194,14 @@ class ItemRecyclerFragment : BaseFragment() {
|
|||
outState.putString(ITEM_TYPE_KEY, this.itemType)
|
||||
}
|
||||
|
||||
override fun onRefresh() {
|
||||
refreshLayout?.isRefreshing = true
|
||||
compositeSubscription.add(userRepository.retrieveUser(true, true)
|
||||
.doOnTerminate {
|
||||
refreshLayout?.isRefreshing = false
|
||||
}.subscribe(Consumer { }, RxErrorHandler.handleEmptyError()))
|
||||
}
|
||||
|
||||
private fun hatchPet(potion: HatchingPotion, egg: Egg) {
|
||||
dismiss()
|
||||
(activity as? MainActivity)?.hatchPet(potion, egg)
|
||||
|
|
|
|||
Loading…
Reference in a new issue