Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull to Refresh Feed #4893

Merged
merged 3 commits into from
Nov 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ dependencies {
implementation "androidx.room:room-rxjava2:${androidxRoomVersion}"
kapt "androidx.room:room-compiler:${androidxRoomVersion}"

implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"

implementation "com.xwray:groupie:${groupieVersion}"
implementation "com.xwray:groupie-kotlin-android-extensions:${groupieVersion}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import androidx.core.view.isVisible
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.preference.PreferenceManager
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import icepick.State
import java.util.Calendar
import kotlinx.android.synthetic.main.error_retry.error_button_retry
Expand All @@ -56,6 +57,7 @@ import org.schabi.newpipe.util.Localization

class FeedFragment : BaseListFragment<FeedState, Unit>() {
private lateinit var viewModel: FeedViewModel
private lateinit var swipeRefreshLayout: SwipeRefreshLayout
@State
@JvmField
var listState: Parcelable? = null
Expand Down Expand Up @@ -83,7 +85,8 @@ class FeedFragment : BaseListFragment<FeedState, Unit>() {

override fun onViewCreated(rootView: View, savedInstanceState: Bundle?) {
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.stateLiveData.observe(viewLifecycleOwner, Observer { it?.let(::handleResult) })
}
Expand Down Expand Up @@ -189,6 +192,7 @@ class FeedFragment : BaseListFragment<FeedState, Unit>() {

empty_state_view?.let { animateView(it, false, 0) }
animateView(error_panel, false, 0)
swipeRefreshLayout.isRefreshing = false
}

override fun showEmptyState() {
Expand Down
21 changes: 14 additions & 7 deletions app/src/main/res/layout/fragment_feed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,22 @@
android:background="?attr/separator_color" />
</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_height="match_parent"
android:layout_below="@+id/refresh_root_view"
android:scrollbars="vertical"
android:visibility="gone"
tools:listitem="@layout/list_stream_item"
tools:visibility="visible" />
android:layout_below="@+id/refresh_root_view">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/items_list"
android:layout_width="match_parent"
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
android:id="@+id/loading_panel_root"
Expand Down