diff --git a/app/build.gradle b/app/build.gradle index e78d5b144..035f6f89f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -167,6 +167,7 @@ dependencies { testImplementation 'junit:junit:4.13.1' 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.room:room-testing:${androidxRoomVersion}" diff --git a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt index e4d10fb61..91f3acb53 100644 --- a/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt +++ b/app/src/main/java/org/schabi/newpipe/local/feed/FeedFragment.kt @@ -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 @@ -56,6 +57,7 @@ import org.schabi.newpipe.util.Localization class FeedFragment : BaseListFragment() { private lateinit var viewModel: FeedViewModel + private lateinit var swipeRefreshLayout: SwipeRefreshLayout @State @JvmField var listState: Parcelable? = null @@ -78,11 +80,16 @@ class FeedFragment : BaseListFragment() { } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return inflater.inflate(R.layout.fragment_feed, container, false) } 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) }) @@ -189,6 +196,9 @@ class FeedFragment : BaseListFragment() { empty_state_view?.let { animateView(it, false, 0) } animateView(error_panel, false, 0) + if (swipeRefreshLayout.isRefreshing){ + swipeRefreshLayout.isRefreshing = false + } } override fun showEmptyState() { diff --git a/app/src/main/res/layout/fragment_feed.xml b/app/src/main/res/layout/fragment_feed.xml index 8d5c64f8d..19cc34106 100644 --- a/app/src/main/res/layout/fragment_feed.xml +++ b/app/src/main/res/layout/fragment_feed.xml @@ -1,10 +1,14 @@ - + + - + android:layout_below="@+id/refresh_root_view"> + + +