swipe to refresh added
This commit is contained in:
parent
81c24510a8
commit
745773b207
3 changed files with 31 additions and 8 deletions
|
@ -167,6 +167,7 @@ dependencies {
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.13.1'
|
testImplementation 'junit:junit:4.13.1'
|
||||||
testImplementation 'org.mockito:mockito-core:3.3.3'
|
testImplementation 'org.mockito:mockito-core:3.3.3'
|
||||||
|
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
|
||||||
|
|
||||||
androidTestImplementation "androidx.test.ext:junit:1.1.1"
|
androidTestImplementation "androidx.test.ext:junit:1.1.1"
|
||||||
androidTestImplementation "androidx.room:room-testing:${androidxRoomVersion}"
|
androidTestImplementation "androidx.room:room-testing:${androidxRoomVersion}"
|
||||||
|
|
|
@ -34,6 +34,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
|
||||||
|
@ -56,6 +57,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
|
||||||
|
@ -78,11 +80,16 @@ class FeedFragment : BaseListFragment<FeedState, Unit>() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||||
|
|
||||||
return inflater.inflate(R.layout.fragment_feed, container, false)
|
return inflater.inflate(R.layout.fragment_feed, container, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
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) })
|
||||||
|
@ -189,6 +196,9 @@ 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)
|
||||||
|
if (swipeRefreshLayout.isRefreshing){
|
||||||
|
swipeRefreshLayout.isRefreshing = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun showEmptyState() {
|
override fun showEmptyState() {
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<RelativeLayout
|
||||||
|
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:id="@+id/refresh_root_view"
|
android:id="@+id/refresh_root_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -70,15 +74,23 @@
|
||||||
android:background="?attr/separator_color" />
|
android:background="?attr/separator_color" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/items_list"
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
android:id="@+id/swiperefresh"
|
||||||
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:layout_below="@+id/refresh_root_view">
|
||||||
android:scrollbars="vertical"
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:visibility="gone"
|
android:id="@+id/items_list"
|
||||||
tools:listitem="@layout/list_stream_item"
|
android:layout_width="match_parent"
|
||||||
tools:visibility="visible" />
|
android:layout_height="match_parent"
|
||||||
|
|
||||||
|
android:scrollbars="vertical"
|
||||||
|
android:visibility="gone"
|
||||||
|
tools:listitem="@layout/list_stream_item"
|
||||||
|
tools:visibility="visible" />
|
||||||
|
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/loading_panel_root"
|
android:id="@+id/loading_panel_root"
|
||||||
|
|
Loading…
Reference in a new issue