Do not animate dummy views (#6231)

This commit is contained in:
ByteHamster 2022-12-11 17:56:07 +01:00 committed by GitHub
parent effe70a412
commit b670cf6111
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 32 additions and 9 deletions

View File

@ -39,6 +39,7 @@ public class EpisodeItemListAdapter extends SelectableAdapter<EpisodeItemViewHol
private FeedItem longPressedItem;
int longPressedPosition = 0; // used to init actionMode
private int dummyViews = 0;
private boolean wasEverUpdated = false;
public EpisodeItemListAdapter(MainActivity mainActivity) {
super(mainActivity);
@ -48,10 +49,18 @@ public class EpisodeItemListAdapter extends SelectableAdapter<EpisodeItemViewHol
public void setDummyViews(int dummyViews) {
this.dummyViews = dummyViews;
notifyDataSetChanged();
}
public void showDummyViewsIfNeverUpdated(int dummyViews) {
if (!wasEverUpdated) {
setDummyViews(dummyViews);
}
}
public void updateItems(List<FeedItem> items) {
episodes = items;
wasEverUpdated = true;
notifyDataSetChanged();
updateTitle();
}

View File

@ -53,6 +53,7 @@ public class SubscriptionsRecyclerAdapter extends SelectableAdapter<Subscription
private NavDrawerData.DrawerItem selectedItem = null;
int longPressedPosition = 0; // used to init actionMode
private int dummyViews = 0;
private boolean wasEverUpdated = false;
public SubscriptionsRecyclerAdapter(MainActivity mainActivity) {
super(mainActivity);
@ -213,10 +214,19 @@ public class SubscriptionsRecyclerAdapter extends SelectableAdapter<Subscription
public void setDummyViews(int dummyViews) {
this.dummyViews = dummyViews;
notifyDataSetChanged();
}
public void showDummyViewsIfNeverUpdated(int dummyViews) {
if (!wasEverUpdated) {
setDummyViews(dummyViews);
}
}
public void setItems(List<NavDrawerData.DrawerItem> listItems) {
this.listItems = listItems;
wasEverUpdated = true;
notifyDataSetChanged();
}
@Override

View File

@ -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);

View File

@ -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());

View File

@ -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);

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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();
}