diff options
author | ByteHamster <info@bytehamster.com> | 2022-05-07 10:52:45 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2022-05-08 11:18:50 +0200 |
commit | 1fa0c32142c0c288adf8784c6c032ae3fa4a6611 (patch) | |
tree | c87d5cdf10bc0afe3a10e9137608cc8ea5521e78 /app | |
parent | 77ced35dff5b9d398575913e7b751ce2d53f7c6e (diff) | |
download | AntennaPod-1fa0c32142c0c288adf8784c6c032ae3fa4a6611.zip |
Multi-Select on 'All episodes' screen
Diffstat (limited to 'app')
3 files changed, 78 insertions, 23 deletions
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 b658e5f08..d47544e6f 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java @@ -22,12 +22,15 @@ import android.widget.ProgressBar; import android.widget.TextView; import android.widget.Toast; +import com.google.android.material.snackbar.Snackbar; +import com.leinardi.android.speeddial.SpeedDialView; import de.danoeh.antennapod.adapter.EpisodeItemListAdapter; import de.danoeh.antennapod.event.FeedListUpdateEvent; import de.danoeh.antennapod.event.playback.PlaybackPositionEvent; import de.danoeh.antennapod.event.PlayerStatusEvent; import de.danoeh.antennapod.event.UnreadItemsUpdateEvent; import de.danoeh.antennapod.core.menuhandler.MenuItemUtils; +import de.danoeh.antennapod.fragment.actions.EpisodeMultiSelectActionHandler; import de.danoeh.antennapod.ui.common.PagedToolbarFragment; import de.danoeh.antennapod.view.EpisodeItemListRecyclerView; import de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder; @@ -59,7 +62,7 @@ import io.reactivex.schedulers.Schedulers; /** * Shows unread or recently published episodes */ -public abstract class EpisodesListFragment extends Fragment { +public abstract class EpisodesListFragment extends Fragment implements EpisodeItemListAdapter.OnSelectModeListener { public static final String TAG = "EpisodesListFragment"; protected static final int EPISODES_PER_PAGE = 150; @@ -72,6 +75,7 @@ public abstract class EpisodesListFragment extends Fragment { ProgressBar progLoading; View loadingMoreView; EmptyViewHandler emptyView; + SpeedDialView speedDialView; @NonNull List<FeedItem> episodes = new ArrayList<>(); @@ -174,17 +178,13 @@ public abstract class EpisodesListFragment extends Fragment { // The method is called on all fragments in a ViewPager, so this needs to be ignored in invisible ones. // Apparently, none of the visibility check method works reliably on its own, so we just use all. return false; - } - if (item.getItemId() == R.id.share_item) { - return true; // avoids that the position is reset when we need it in the submenu - } - - if (listAdapter.getLongPressedItem() == null) { + } else if (listAdapter.getLongPressedItem() == null) { Log.i(TAG, "Selected item or listAdapter was null, ignoring selection"); return super.onContextItemSelected(item); + } else if (listAdapter.onContextItemSelected(item)) { + return true; } FeedItem selectedItem = listAdapter.getLongPressedItem(); - return FeedItemMenuHandler.onMenuItemClicked(this, item.getItemId(), selectedItem); } @@ -225,6 +225,31 @@ public abstract class EpisodesListFragment extends Fragment { createRecycleAdapter(recyclerView, emptyView); emptyView.hide(); + speedDialView = root.findViewById(R.id.fabSD); + speedDialView.setOverlayLayout(root.findViewById(R.id.fabSDOverlay)); + speedDialView.inflate(R.menu.episodes_apply_action_speeddial); + speedDialView.setOnChangeListener(new SpeedDialView.OnChangeListener() { + @Override + public boolean onMainActionSelected() { + return false; + } + + @Override + public void onToggleChanged(boolean open) { + if (open && listAdapter.getSelectedCount() == 0) { + ((MainActivity) getActivity()).showSnackbarAbovePlayer(R.string.no_items_selected, + Snackbar.LENGTH_SHORT); + speedDialView.close(); + } + } + }); + speedDialView.setOnActionSelectedListener(actionItem -> { + new EpisodeMultiSelectActionHandler(((MainActivity) getActivity()), listAdapter.getSelectedItems()) + .handleAction(actionItem.getId()); + listAdapter.endSelectMode(); + return true; + }); + return root; } @@ -292,14 +317,38 @@ public abstract class EpisodesListFragment extends Fragment { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); + if (!inActionMode()) { + menu.findItem(R.id.multi_select).setVisible(true); + } MenuItemUtils.setOnClickListeners(menu, EpisodesListFragment.this::onContextItemSelected); } }; + listAdapter.setOnSelectModeListener(this); listAdapter.updateItems(episodes); recyclerView.setAdapter(listAdapter); emptyViewHandler.updateAdapter(listAdapter); } + @Override + public void onDestroyView() { + super.onDestroyView(); + if (listAdapter != null) { + listAdapter.endSelectMode(); + } + listAdapter = null; + } + + @Override + public void onStartSelectMode() { + speedDialView.setVisibility(View.VISIBLE); + } + + @Override + public void onEndSelectMode() { + speedDialView.close(); + speedDialView.setVisibility(View.GONE); + } + @Subscribe(threadMode = ThreadMode.MAIN) public void onEventMainThread(FeedItemEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/InboxFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/InboxFragment.java index abb04b2f3..5063da9a4 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/InboxFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/InboxFragment.java @@ -67,6 +67,9 @@ public class InboxFragment extends EpisodesListFragment implements Toolbar.OnMen SwipeActions swipeActions = new SwipeActions(this, TAG).attachTo(recyclerView); swipeActions.setFilter(new FeedItemFilter(FeedItemFilter.NEW)); + speedDialView.removeActionItemById(R.id.mark_unread_batch); + speedDialView.removeActionItemById(R.id.remove_from_queue_batch); + speedDialView.removeActionItemById(R.id.delete_batch); return inboxContainer; } diff --git a/app/src/main/res/layout/all_episodes_fragment.xml b/app/src/main/res/layout/all_episodes_fragment.xml index 3b560967c..c1e7e6434 100644 --- a/app/src/main/res/layout/all_episodes_fragment.xml +++ b/app/src/main/res/layout/all_episodes_fragment.xml @@ -2,9 +2,9 @@ <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" - android:orientation="vertical" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + android:orientation="vertical"> <TextView android:id="@+id/txtvInformation" @@ -23,17 +23,17 @@ android:layout_below="@+id/txtvInformation" android:layout_above="@id/loadingMore"> - <de.danoeh.antennapod.view.EpisodeItemListRecyclerView - android:id="@android:id/list" - android:layout_width="match_parent" - android:layout_height="match_parent" - android:layout_marginTop="0dp" - android:layout_marginBottom="0dp" - android:paddingTop="@dimen/list_vertical_padding" - android:paddingBottom="@dimen/list_vertical_padding" - android:paddingHorizontal="@dimen/additional_horizontal_spacing" - tools:itemCount="13" - tools:listitem="@layout/feeditemlist_item" /> + <de.danoeh.antennapod.view.EpisodeItemListRecyclerView + android:id="@android:id/list" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_marginTop="0dp" + android:layout_marginBottom="0dp" + android:paddingTop="@dimen/list_vertical_padding" + android:paddingBottom="@dimen/list_vertical_padding" + android:paddingHorizontal="@dimen/additional_horizontal_spacing" + tools:itemCount="13" + tools:listitem="@layout/feeditemlist_item" /> </androidx.swiperefreshlayout.widget.SwipeRefreshLayout> @@ -45,7 +45,7 @@ android:indeterminateOnly="true" android:visibility="gone" android:layout_centerInParent="true" - tools:background="@android:color/holo_red_light"/> + tools:background="@android:color/holo_red_light" /> <LinearLayout android:id="@+id/loadingMore" @@ -76,4 +76,7 @@ </LinearLayout> -</RelativeLayout>
\ No newline at end of file + <include + layout="@layout/multi_select_speed_dial" /> + +</RelativeLayout> |