Apply action to items that are not loaded yet

This commit is contained in:
ByteHamster 2022-05-08 11:18:11 +02:00
parent 072e172996
commit 2e999aef62
5 changed files with 34 additions and 14 deletions

View File

@ -102,7 +102,7 @@ public class AllEpisodesFragment extends EpisodesListFragment {
@NonNull @NonNull
@Override @Override
protected List<FeedItem> loadMoreData() { protected List<FeedItem> loadMoreData(int page) {
return DBReader.getRecentlyPublishedEpisodes((page - 1) * EPISODES_PER_PAGE, EPISODES_PER_PAGE, feedItemFilter); return DBReader.getRecentlyPublishedEpisodes((page - 1) * EPISODES_PER_PAGE, EPISODES_PER_PAGE, feedItemFilter);
} }

View File

@ -36,6 +36,7 @@ import de.danoeh.antennapod.fragment.actions.EpisodeMultiSelectActionHandler;
import de.danoeh.antennapod.ui.common.PagedToolbarFragment; import de.danoeh.antennapod.ui.common.PagedToolbarFragment;
import de.danoeh.antennapod.view.EpisodeItemListRecyclerView; import de.danoeh.antennapod.view.EpisodeItemListRecyclerView;
import de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder; import de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder;
import io.reactivex.Completable;
import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode; import org.greenrobot.eventbus.ThreadMode;
@ -246,9 +247,25 @@ public abstract class EpisodesListFragment extends Fragment implements EpisodeIt
} }
}); });
speedDialView.setOnActionSelectedListener(actionItem -> { speedDialView.setOnActionSelectedListener(actionItem -> {
new EpisodeMultiSelectActionHandler(((MainActivity) getActivity()), actionItem.getId()) EpisodeMultiSelectActionHandler handler =
.handleAction(listAdapter.getSelectedItems()); new EpisodeMultiSelectActionHandler(((MainActivity) getActivity()), actionItem.getId());
listAdapter.endSelectMode(); Completable.fromAction(
() -> {
handler.handleAction(listAdapter.getSelectedItems());
if (listAdapter.shouldSelectLazyLoadedItems()) {
int applyPage = page + 1;
List<FeedItem> nextPage;
do {
nextPage = loadMoreData(applyPage);
handler.handleAction(nextPage);
applyPage++;
} while (nextPage.size() == EPISODES_PER_PAGE);
}
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(() -> listAdapter.endSelectMode(),
error -> Log.e(TAG, Log.getStackTraceString(error)));
return true; return true;
}); });
@ -276,7 +293,7 @@ public abstract class EpisodesListFragment extends Fragment implements EpisodeIt
} }
isLoadingMore = true; isLoadingMore = true;
loadingMoreView.setVisibility(View.VISIBLE); loadingMoreView.setVisibility(View.VISIBLE);
disposable = Observable.fromCallable(this::loadMoreData) disposable = Observable.fromCallable(() -> loadMoreData(page))
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(data -> { .subscribe(data -> {
@ -477,7 +494,7 @@ public abstract class EpisodesListFragment extends Fragment implements EpisodeIt
* @return The items from the next page of data * @return The items from the next page of data
*/ */
@NonNull @NonNull
protected abstract List<FeedItem> loadMoreData(); protected abstract List<FeedItem> loadMoreData(int page);
/** /**
* Returns the total number of items that would be returned if {@link #loadMoreData} was called often enough. * Returns the total number of items that would be returned if {@link #loadMoreData} was called often enough.

View File

@ -99,7 +99,7 @@ public class FavoriteEpisodesFragment extends EpisodesListFragment {
@NonNull @NonNull
@Override @Override
protected List<FeedItem> loadMoreData() { protected List<FeedItem> loadMoreData(int page) {
return DBReader.getFavoriteItemsList((page - 1) * EPISODES_PER_PAGE, EPISODES_PER_PAGE); return DBReader.getFavoriteItemsList((page - 1) * EPISODES_PER_PAGE, EPISODES_PER_PAGE);
} }

View File

@ -116,7 +116,7 @@ public class InboxFragment extends EpisodesListFragment implements Toolbar.OnMen
@NonNull @NonNull
@Override @Override
protected List<FeedItem> loadMoreData() { protected List<FeedItem> loadMoreData(int page) {
return DBReader.getNewItemsList((page - 1) * EPISODES_PER_PAGE, EPISODES_PER_PAGE); return DBReader.getNewItemsList((page - 1) * EPISODES_PER_PAGE, EPISODES_PER_PAGE);
} }

View File

@ -103,12 +103,15 @@ public class EpisodeMultiSelectActionHandler {
private void showMessage(@PluralsRes int msgId, int numItems) { private void showMessage(@PluralsRes int msgId, int numItems) {
totalNumItems += numItems; totalNumItems += numItems;
String text = activity.getResources().getQuantityString(msgId, totalNumItems, totalNumItems); activity.runOnUiThread(() -> {
if (snackbar != null) { String text = activity.getResources().getQuantityString(msgId, totalNumItems, totalNumItems);
snackbar.setText(text); if (snackbar != null) {
} else { snackbar.setText(text);
snackbar = activity.showSnackbarAbovePlayer(text, Snackbar.LENGTH_LONG); snackbar.show(); // Resets the timeout
} } else {
snackbar = activity.showSnackbarAbovePlayer(text, Snackbar.LENGTH_LONG);
}
});
} }
private long[] getSelectedIds(List<FeedItem> items) { private long[] getSelectedIds(List<FeedItem> items) {