Merge pull request #4893 from okan35/whatsNewSwipeRefresh
Pull to Refresh Feed
This commit is contained in:
commit
66d15ea635
3 changed files with 21 additions and 8 deletions
|
@ -205,6 +205,8 @@ dependencies {
|
||||||
implementation "androidx.room:room-rxjava2:${androidxRoomVersion}"
|
implementation "androidx.room:room-rxjava2:${androidxRoomVersion}"
|
||||||
kapt "androidx.room:room-compiler:${androidxRoomVersion}"
|
kapt "androidx.room:room-compiler:${androidxRoomVersion}"
|
||||||
|
|
||||||
|
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
|
||||||
|
|
||||||
implementation "com.xwray:groupie:${groupieVersion}"
|
implementation "com.xwray:groupie:${groupieVersion}"
|
||||||
implementation "com.xwray:groupie-kotlin-android-extensions:${groupieVersion}"
|
implementation "com.xwray:groupie-kotlin-android-extensions:${groupieVersion}"
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ import androidx.core.view.isVisible
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
import icepick.State
|
import icepick.State
|
||||||
import java.util.Calendar
|
import java.util.Calendar
|
||||||
import kotlinx.android.synthetic.main.error_retry.error_button_retry
|
import kotlinx.android.synthetic.main.error_retry.error_button_retry
|
||||||
|
@ -57,6 +58,7 @@ import org.schabi.newpipe.util.Localization
|
||||||
|
|
||||||
class FeedFragment : BaseListFragment<FeedState, Unit>() {
|
class FeedFragment : BaseListFragment<FeedState, Unit>() {
|
||||||
private lateinit var viewModel: FeedViewModel
|
private lateinit var viewModel: FeedViewModel
|
||||||
|
private lateinit var swipeRefreshLayout: SwipeRefreshLayout
|
||||||
@State
|
@State
|
||||||
@JvmField
|
@JvmField
|
||||||
var listState: Parcelable? = null
|
var listState: Parcelable? = null
|
||||||
|
@ -84,7 +86,8 @@ class FeedFragment : BaseListFragment<FeedState, Unit>() {
|
||||||
|
|
||||||
override fun onViewCreated(rootView: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(rootView: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(rootView, savedInstanceState)
|
super.onViewCreated(rootView, savedInstanceState)
|
||||||
|
swipeRefreshLayout = requireView().findViewById(R.id.swiperefresh)
|
||||||
|
swipeRefreshLayout.setOnRefreshListener { reloadContent() }
|
||||||
viewModel = ViewModelProvider(this, FeedViewModel.Factory(requireContext(), groupId)).get(FeedViewModel::class.java)
|
viewModel = ViewModelProvider(this, FeedViewModel.Factory(requireContext(), groupId)).get(FeedViewModel::class.java)
|
||||||
viewModel.stateLiveData.observe(viewLifecycleOwner, Observer { it?.let(::handleResult) })
|
viewModel.stateLiveData.observe(viewLifecycleOwner, Observer { it?.let(::handleResult) })
|
||||||
}
|
}
|
||||||
|
@ -190,6 +193,7 @@ class FeedFragment : BaseListFragment<FeedState, Unit>() {
|
||||||
|
|
||||||
empty_state_view?.let { animateView(it, false, 0) }
|
empty_state_view?.let { animateView(it, false, 0) }
|
||||||
animateView(error_panel, false, 0)
|
animateView(error_panel, false, 0)
|
||||||
|
swipeRefreshLayout.isRefreshing = false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showEmptyState() {
|
override fun showEmptyState() {
|
||||||
|
|
|
@ -70,16 +70,23 @@
|
||||||
android:background="?attr/separator_color" />
|
android:background="?attr/separator_color" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
android:id="@+id/swiperefresh"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_below="@+id/refresh_root_view">
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/items_list"
|
android:id="@+id/items_list"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_below="@+id/refresh_root_view"
|
|
||||||
android:scrollbars="vertical"
|
android:scrollbars="vertical"
|
||||||
android:visibility="gone"
|
android:visibility="gone"
|
||||||
tools:listitem="@layout/list_stream_item"
|
tools:listitem="@layout/list_stream_item"
|
||||||
tools:visibility="visible" />
|
tools:visibility="visible" />
|
||||||
|
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/loading_panel_root"
|
android:id="@+id/loading_panel_root"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
Loading…
Reference in a new issue