diff options
author | ByteHamster <info@bytehamster.com> | 2022-11-27 17:46:28 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2022-11-27 17:46:28 +0100 |
commit | 6e9325b5491f9922049aa80c447e5d51bf03551c (patch) | |
tree | 7c2ca08ceca2a2caf52f6976950b6c77b0083cbe | |
parent | 3973f450bed152a10aa46de23791f9028da33f8b (diff) | |
download | AntennaPod-6e9325b5491f9922049aa80c447e5d51bf03551c.zip |
Add swipe-to-refresh to home screen
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/ui/home/HomeFragment.java | 10 | ||||
-rw-r--r-- | app/src/main/res/layout/home_fragment.xml | 25 |
2 files changed, 26 insertions, 9 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/ui/home/HomeFragment.java b/app/src/main/java/de/danoeh/antennapod/ui/home/HomeFragment.java index f03c6a3fd..da3fd7b05 100644 --- a/app/src/main/java/de/danoeh/antennapod/ui/home/HomeFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/ui/home/HomeFragment.java @@ -3,6 +3,8 @@ package de.danoeh.antennapod.ui.home; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; import android.text.TextUtils; import android.util.Log; import android.view.LayoutInflater; @@ -70,6 +72,14 @@ public class HomeFragment extends Fragment implements Toolbar.OnMenuItemClickLis refreshToolbarState(); populateSectionList(); updateWelcomeScreenVisibility(); + + viewBinding.swipeRefresh.setDistanceToTriggerSync(getResources().getInteger(R.integer.swipe_refresh_distance)); + viewBinding.swipeRefresh.setOnRefreshListener(() -> { + AutoUpdateManager.runImmediate(requireContext()); + new Handler(Looper.getMainLooper()).postDelayed(() -> viewBinding.swipeRefresh.setRefreshing(false), + getResources().getInteger(R.integer.swipe_to_refresh_duration_in_ms)); + }); + return viewBinding.getRoot(); } diff --git a/app/src/main/res/layout/home_fragment.xml b/app/src/main/res/layout/home_fragment.xml index 0c5d872b3..fca9406a8 100644 --- a/app/src/main/res/layout/home_fragment.xml +++ b/app/src/main/res/layout/home_fragment.xml @@ -65,18 +65,25 @@ </LinearLayout> - <androidx.core.widget.NestedScrollView - android:id="@+id/homeScrollView" + <androidx.swiperefreshlayout.widget.SwipeRefreshLayout + android:id="@+id/swipeRefresh" android:layout_width="match_parent" - android:layout_height="wrap_content"> + android:layout_height="match_parent"> - <LinearLayout - android:id="@+id/homeContainer" + <androidx.core.widget.NestedScrollView + android:id="@+id/homeScrollView" android:layout_width="match_parent" - android:layout_height="wrap_content" - android:orientation="vertical" - android:paddingBottom="12dp" /> + android:layout_height="wrap_content"> + + <LinearLayout + android:id="@+id/homeContainer" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:paddingBottom="12dp" /> + + </androidx.core.widget.NestedScrollView> - </androidx.core.widget.NestedScrollView> + </androidx.swiperefreshlayout.widget.SwipeRefreshLayout> </LinearLayout> |