Merge pull request from ByteHamster/home-pull-refresh

Add pull-to-refresh to home screen
This commit is contained in:
ByteHamster 2022-11-30 19:54:28 +01:00 committed by GitHub
commit 1ee85b5bb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 9 deletions
app/src/main
java/de/danoeh/antennapod/ui/home
res/layout

@ -3,6 +3,8 @@ package de.danoeh.antennapod.ui.home;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -70,6 +72,14 @@ public class HomeFragment extends Fragment implements Toolbar.OnMenuItemClickLis
refreshToolbarState(); refreshToolbarState();
populateSectionList(); populateSectionList();
updateWelcomeScreenVisibility(); 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(); return viewBinding.getRoot();
} }

@ -65,18 +65,25 @@
</LinearLayout> </LinearLayout>
<androidx.core.widget.NestedScrollView <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/homeScrollView" android:id="@+id/swipeRefresh"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="match_parent">
<LinearLayout <androidx.core.widget.NestedScrollView
android:id="@+id/homeContainer" android:id="@+id/homeScrollView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
android:orientation="vertical"
android:paddingBottom="12dp" />
</androidx.core.widget.NestedScrollView> <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.swiperefreshlayout.widget.SwipeRefreshLayout>
</LinearLayout> </LinearLayout>