From b670cf6111a0c04dee0bac1687c6fa3320bba89c Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sun, 11 Dec 2022 17:56:07 +0100 Subject: [PATCH] Do not animate dummy views (#6231) --- .../antennapod/adapter/EpisodeItemListAdapter.java | 9 +++++++++ .../adapter/SubscriptionsRecyclerAdapter.java | 10 ++++++++++ .../fragment/CompletedDownloadsFragment.java | 2 +- .../antennapod/fragment/EpisodesListFragment.java | 2 +- .../antennapod/fragment/FeedItemlistFragment.java | 2 +- .../de/danoeh/antennapod/fragment/QueueFragment.java | 5 +++-- .../antennapod/fragment/SubscriptionFragment.java | 6 ++---- .../java/de/danoeh/antennapod/ui/home/HomeSection.java | 5 +++++ 8 files changed, 32 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/EpisodeItemListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/EpisodeItemListAdapter.java index 644d99e0e..8b591c1af 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/EpisodeItemListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/EpisodeItemListAdapter.java @@ -39,6 +39,7 @@ public class EpisodeItemListAdapter extends SelectableAdapter items) { episodes = items; + wasEverUpdated = true; notifyDataSetChanged(); updateTitle(); } diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsRecyclerAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsRecyclerAdapter.java index a853f100f..fb98d6db3 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsRecyclerAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsRecyclerAdapter.java @@ -53,6 +53,7 @@ public class SubscriptionsRecyclerAdapter extends SelectableAdapter listItems) { this.listItems = listItems; + wasEverUpdated = true; + notifyDataSetChanged(); } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java index c7fe3597b..e91b5ad96 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java @@ -95,7 +95,7 @@ public class CompletedDownloadsFragment extends Fragment adapter.setOnSelectModeListener(this); int previousEpisodesCount = getContext().getSharedPreferences(TAG, Context.MODE_PRIVATE) .getInt(PREF_PREVIOUS_EPISODE_COUNT, 5); - adapter.setDummyViews(Math.max(1, previousEpisodesCount)); + recyclerView.postDelayed(() -> adapter.showDummyViewsIfNeverUpdated(previousEpisodesCount), 250); recyclerView.setAdapter(adapter); recyclerView.addOnScrollListener(new LiftOnScrollListener(root.findViewById(R.id.appbar))); swipeActions = new SwipeActions(this, TAG).attachTo(recyclerView); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java index 2d3343abf..afde124ba 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java @@ -206,7 +206,7 @@ public abstract class EpisodesListFragment extends Fragment listAdapter.setOnSelectModeListener(this); int previousEpisodesCount = getContext().getSharedPreferences(getPrefName(), Context.MODE_PRIVATE) .getInt(PREF_PREVIOUS_EPISODE_COUNT, 5); - listAdapter.setDummyViews(Math.max(1, previousEpisodesCount)); + recyclerView.postDelayed(() -> listAdapter.showDummyViewsIfNeverUpdated(previousEpisodesCount), 250); recyclerView.setAdapter(listAdapter); emptyView = new EmptyViewHandler(getContext()); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java index 318546c83..775c683c7 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java @@ -144,7 +144,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem viewBinding.recyclerView.setRecycledViewPool(((MainActivity) getActivity()).getRecycledViewPool()); adapter = new FeedItemListAdapter((MainActivity) getActivity()); adapter.setOnSelectModeListener(this); - adapter.setDummyViews(10); + viewBinding.recyclerView.postDelayed(() -> adapter.showDummyViewsIfNeverUpdated(10), 250); viewBinding.recyclerView.setAdapter(adapter); swipeActions = new SwipeActions(this, TAG).attachTo(viewBinding.recyclerView); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index 2bb98dc33..94727e4b1 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -124,7 +124,7 @@ public class QueueFragment extends Fragment implements MaterialToolbar.OnMenuIte if (disposable != null) { disposable.dispose(); } - prefs.edit().putInt(PREF_PREVIOUS_EPISODE_COUNT, queue.size()).apply(); + prefs.edit().putInt(PREF_PREVIOUS_EPISODE_COUNT, queue == null ? 0 : queue.size()).apply(); } @Subscribe(threadMode = ThreadMode.MAIN) @@ -468,7 +468,8 @@ public class QueueFragment extends Fragment implements MaterialToolbar.OnMenuIte } }; recyclerAdapter.setOnSelectModeListener(this); - recyclerAdapter.setDummyViews(Math.max(1, prefs.getInt(PREF_PREVIOUS_EPISODE_COUNT, 5))); + int previousEpisodes = Math.max(1, prefs.getInt(PREF_PREVIOUS_EPISODE_COUNT, 5)); + recyclerView.postDelayed(() -> recyclerAdapter.showDummyViewsIfNeverUpdated(previousEpisodes), 250); recyclerView.setAdapter(recyclerAdapter); SwipeRefreshLayout swipeRefreshLayout = root.findViewById(R.id.swipeRefresh); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java index 9cf1b7713..843ef6e49 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java @@ -161,7 +161,8 @@ public class SubscriptionFragment extends Fragment } }; subscriptionAdapter.setOnSelectModeListener(this); - subscriptionAdapter.setDummyViews(Math.max(1, prefs.getInt(PREF_PREVIOUS_EPISODE_COUNT, 5))); + int previousEpisodes = Math.max(1, prefs.getInt(PREF_PREVIOUS_EPISODE_COUNT, 5)); + subscriptionRecycler.postDelayed(() -> subscriptionAdapter.showDummyViewsIfNeverUpdated(previousEpisodes), 250); subscriptionRecycler.setAdapter(subscriptionAdapter); setupEmptyView(); @@ -318,7 +319,6 @@ public class SubscriptionFragment extends Fragment listItems = result; subscriptionAdapter.setDummyViews(0); subscriptionAdapter.setItems(result); - subscriptionAdapter.notifyDataSetChanged(); emptyView.updateVisibility(); }, error -> { Log.e(TAG, Log.getStackTraceString(error)); @@ -410,7 +410,6 @@ public class SubscriptionFragment extends Fragment speedDialView.close(); speedDialView.setVisibility(View.GONE); subscriptionAdapter.setItems(listItems); - subscriptionAdapter.notifyDataSetChanged(); } @Override @@ -422,6 +421,5 @@ public class SubscriptionFragment extends Fragment } } subscriptionAdapter.setItems(feedsOnly); - subscriptionAdapter.notifyDataSetChanged(); } } diff --git a/app/src/main/java/de/danoeh/antennapod/ui/home/HomeSection.java b/app/src/main/java/de/danoeh/antennapod/ui/home/HomeSection.java index 30513c198..7b7d999ad 100644 --- a/app/src/main/java/de/danoeh/antennapod/ui/home/HomeSection.java +++ b/app/src/main/java/de/danoeh/antennapod/ui/home/HomeSection.java @@ -12,6 +12,7 @@ import androidx.annotation.Nullable; import androidx.core.text.TextUtilsCompat; import androidx.core.view.ViewCompat; import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.DefaultItemAnimator; import de.danoeh.antennapod.adapter.EpisodeItemListAdapter; import de.danoeh.antennapod.adapter.HorizontalItemListAdapter; import de.danoeh.antennapod.databinding.HomeSectionBinding; @@ -43,6 +44,10 @@ public abstract class HomeSection extends Fragment implements View.OnCreateConte if (TextUtils.isEmpty(getMoreLinkTitle())) { viewBinding.moreButton.setVisibility(View.INVISIBLE); } + // Dummies are necessary to ensure height, but do not animate them + viewBinding.recyclerView.setItemAnimator(null); + viewBinding.recyclerView.postDelayed( + () -> viewBinding.recyclerView.setItemAnimator(new DefaultItemAnimator()), 500); return viewBinding.getRoot(); }