diff options
author | ByteHamster <ByteHamster@users.noreply.github.com> | 2022-05-03 22:10:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-03 22:10:39 +0200 |
commit | dfcc342c57e263754bf145501cd237c7570debd2 (patch) | |
tree | 1861894339adfac5bceb40805d40de67933996ed /app/src/main/java/de/danoeh/antennapod/fragment | |
parent | 8eedb82f310dda9f7773b0af2fcf313244f65f1c (diff) | |
download | AntennaPod-dfcc342c57e263754bf145501cd237c7570debd2.zip |
Rename 'new' screen to inbox (#5460)
Diffstat (limited to 'app/src/main/java/de/danoeh/antennapod/fragment')
11 files changed, 152 insertions, 115 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java index cbae077cb..853e7d6f7 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/AllEpisodesFragment.java @@ -67,7 +67,6 @@ public class AllEpisodesFragment extends EpisodesListFragment { super.onPrepareOptionsMenu(menu); menu.findItem(R.id.filter_items).setVisible(true); menu.findItem(R.id.mark_all_read_item).setVisible(true); - menu.findItem(R.id.remove_all_new_flags_item).setVisible(false); } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java index bb987666e..951d42d73 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesFragment.java @@ -26,10 +26,9 @@ public class EpisodesFragment extends PagedToolbarFragment { private static final String PREF_LAST_TAB_POSITION = "tab_position"; private static final String KEY_UP_ARROW = "up_arrow"; - private static final int POS_NEW_EPISODES = 0; - private static final int POS_ALL_EPISODES = 1; - private static final int POS_FAV_EPISODES = 2; - private static final int TOTAL_COUNT = 3; + private static final int POS_ALL_EPISODES = 0; + private static final int POS_FAV_EPISODES = 1; + private static final int TOTAL_COUNT = 2; private TabLayout tabLayout; private boolean displayUpArrow; @@ -61,9 +60,6 @@ public class EpisodesFragment extends PagedToolbarFragment { new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> { switch (position) { - case POS_NEW_EPISODES: - tab.setText(R.string.new_episodes_label); - break; case POS_ALL_EPISODES: tab.setText(R.string.all_episodes_short_label); break; @@ -109,8 +105,6 @@ public class EpisodesFragment extends PagedToolbarFragment { @Override public Fragment createFragment(int position) { switch (position) { - case POS_NEW_EPISODES: - return new NewEpisodesFragment(); case POS_ALL_EPISODES: return new AllEpisodesFragment(); default: 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 b78b777f9..b658e5f08 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/EpisodesListFragment.java @@ -145,17 +145,17 @@ public abstract class EpisodesListFragment extends Fragment { }; markAllReadConfirmationDialog.createNewDialog().show(); return true; - } else if (itemId == R.id.remove_all_new_flags_item) { + } else if (itemId == R.id.remove_all_inbox_item) { ConfirmationDialog removeAllNewFlagsConfirmationDialog = new ConfirmationDialog(getActivity(), - R.string.remove_all_new_flags_label, - R.string.remove_all_new_flags_confirmation_msg) { + R.string.remove_all_inbox_label, + R.string.remove_all_inbox_confirmation_msg) { @Override public void onConfirmButtonPressed(DialogInterface dialog) { dialog.dismiss(); DBWriter.removeAllNewFlags(); ((MainActivity) getActivity()).showSnackbarAbovePlayer( - R.string.removed_all_new_flags_msg, Toast.LENGTH_SHORT); + R.string.removed_all_inbox_msg, Toast.LENGTH_SHORT); } }; removeAllNewFlagsConfirmationDialog.createNewDialog().show(); @@ -276,7 +276,8 @@ public abstract class EpisodesListFragment extends Fragment { if (restoreScrollPosition) { recyclerView.restoreScrollPosition(getPrefName()); } - if (isUpdatingFeeds != updateRefreshMenuItemChecker.isRefreshing()) { + if (isUpdatingFeeds != updateRefreshMenuItemChecker.isRefreshing() + && getParentFragment() instanceof PagedToolbarFragment) { ((PagedToolbarFragment) getParentFragment()).invalidateOptionsMenuIfActive(this); } } @@ -354,7 +355,7 @@ public abstract class EpisodesListFragment extends Fragment { public void onEventMainThread(DownloadEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); DownloaderUpdate update = event.update; - if (event.hasChangedFeedUpdateStatus(isUpdatingFeeds)) { + if (event.hasChangedFeedUpdateStatus(isUpdatingFeeds) && getParentFragment() instanceof PagedToolbarFragment) { ((PagedToolbarFragment) getParentFragment()).invalidateOptionsMenuIfActive(this); } if (update.mediaIds.length > 0) { @@ -369,7 +370,8 @@ public abstract class EpisodesListFragment extends Fragment { private void updateUi() { loadItems(); - if (isUpdatingFeeds != updateRefreshMenuItemChecker.isRefreshing()) { + if (isUpdatingFeeds != updateRefreshMenuItemChecker.isRefreshing() + && getParentFragment() instanceof PagedToolbarFragment) { ((PagedToolbarFragment) getParentFragment()).invalidateOptionsMenuIfActive(this); } } @@ -402,7 +404,9 @@ public abstract class EpisodesListFragment extends Fragment { hasMoreItems = true; episodes = data; onFragmentLoaded(episodes); - ((PagedToolbarFragment) getParentFragment()).invalidateOptionsMenuIfActive(this); + if (getParentFragment() instanceof PagedToolbarFragment) { + ((PagedToolbarFragment) getParentFragment()).invalidateOptionsMenuIfActive(this); + } }, error -> Log.e(TAG, Log.getStackTraceString(error))); } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java index d7bfd404d..33aba3b54 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FavoriteEpisodesFragment.java @@ -48,7 +48,6 @@ public class FavoriteEpisodesFragment extends EpisodesListFragment { super.onPrepareOptionsMenu(menu); menu.findItem(R.id.filter_items).setVisible(false); menu.findItem(R.id.mark_all_read_item).setVisible(false); - menu.findItem(R.id.remove_all_new_flags_item).setVisible(false); } @NonNull diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/InboxFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/InboxFragment.java new file mode 100644 index 000000000..abb04b2f3 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/fragment/InboxFragment.java @@ -0,0 +1,119 @@ +package de.danoeh.antennapod.fragment; + +import android.os.Bundle; +import android.view.MenuItem; +import android.widget.FrameLayout; +import androidx.annotation.NonNull; +import androidx.appcompat.widget.Toolbar; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import java.util.List; + +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.core.event.DownloadEvent; +import de.danoeh.antennapod.core.menuhandler.MenuItemUtils; +import de.danoeh.antennapod.core.service.download.DownloadService; +import de.danoeh.antennapod.fragment.swipeactions.SwipeActions; +import de.danoeh.antennapod.model.feed.FeedItem; +import de.danoeh.antennapod.core.storage.DBReader; +import de.danoeh.antennapod.model.feed.FeedItemFilter; +import org.greenrobot.eventbus.Subscribe; +import org.greenrobot.eventbus.ThreadMode; + +/** + * Like 'EpisodesFragment' except that it only shows new episodes and + * supports swiping to mark as read. + */ +public class InboxFragment extends EpisodesListFragment implements Toolbar.OnMenuItemClickListener { + public static final String TAG = "NewEpisodesFragment"; + private static final String PREF_NAME = "PrefNewEpisodesFragment"; + private static final String KEY_UP_ARROW = "up_arrow"; + + private Toolbar toolbar; + private boolean displayUpArrow; + private volatile boolean isUpdatingFeeds; + + @Override + protected String getPrefName() { + return PREF_NAME; + } + + @Override + protected boolean shouldUpdatedItemRemainInList(FeedItem item) { + return item.isNew(); + } + + @NonNull + @Override + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + View inboxContainer = View.inflate(getContext(), R.layout.inbox_fragment, null); + View root = super.onCreateView(inflater, container, savedInstanceState); + ((FrameLayout) inboxContainer.findViewById(R.id.inboxContent)).addView(root); + emptyView.setTitle(R.string.no_inbox_head_label); + emptyView.setMessage(R.string.no_inbox_label); + + toolbar = inboxContainer.findViewById(R.id.toolbar); + toolbar.setOnMenuItemClickListener(this); + toolbar.inflateMenu(R.menu.inbox); + displayUpArrow = getParentFragmentManager().getBackStackEntryCount() != 0; + if (savedInstanceState != null) { + displayUpArrow = savedInstanceState.getBoolean(KEY_UP_ARROW); + } + ((MainActivity) getActivity()).setupToolbarToggle(toolbar, displayUpArrow); + + SwipeActions swipeActions = new SwipeActions(this, TAG).attachTo(recyclerView); + swipeActions.setFilter(new FeedItemFilter(FeedItemFilter.NEW)); + + return inboxContainer; + } + + private final MenuItemUtils.UpdateRefreshMenuItemChecker updateRefreshMenuItemChecker = + () -> DownloadService.isRunning && DownloadService.isDownloadingFeeds(); + + private void updateToolbar() { + isUpdatingFeeds = MenuItemUtils.updateRefreshMenuItem(toolbar.getMenu(), + R.id.refresh_item, updateRefreshMenuItemChecker); + } + + @Override + public void onStart() { + super.onStart(); + if (isUpdatingFeeds != updateRefreshMenuItemChecker.isRefreshing()) { + updateToolbar(); + } + } + + @Subscribe(sticky = true, threadMode = ThreadMode.MAIN) + public void onEventMainThread(DownloadEvent event) { + super.onEventMainThread(event); + if (event.hasChangedFeedUpdateStatus(isUpdatingFeeds)) { + updateToolbar(); + } + } + + @Override + public boolean onMenuItemClick(MenuItem item) { + return super.onOptionsItemSelected(item); + } + + @Override + public void onSaveInstanceState(@NonNull Bundle outState) { + outState.putBoolean(KEY_UP_ARROW, displayUpArrow); + super.onSaveInstanceState(outState); + } + + @NonNull + @Override + protected List<FeedItem> loadData() { + return DBReader.getNewItemsList(0, page * EPISODES_PER_PAGE); + } + + @NonNull + @Override + protected List<FeedItem> loadMoreData() { + return DBReader.getNewItemsList((page - 1) * EPISODES_PER_PAGE, EPISODES_PER_PAGE); + } +} diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java index bd4f3dd21..5f9276c04 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java @@ -66,6 +66,7 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS public static final String[] NAV_DRAWER_TAGS = { QueueFragment.TAG, + InboxFragment.TAG, EpisodesFragment.TAG, SubscriptionFragment.TAG, DownloadsFragment.TAG, @@ -152,10 +153,10 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS private boolean onFeedContextMenuClicked(Feed feed, MenuItem item) { final int itemId = item.getItemId(); - if (itemId == R.id.remove_all_new_flags_item) { + if (itemId == R.id.remove_all_inbox_item) { ConfirmationDialog removeAllNewFlagsConfirmationDialog = new ConfirmationDialog(getContext(), - R.string.remove_all_new_flags_label, - R.string.remove_all_new_flags_confirmation_msg) { + R.string.remove_all_inbox_label, + R.string.remove_all_inbox_confirmation_msg) { @Override public void onConfirmButtonPressed(DialogInterface dialog) { dialog.dismiss(); diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java deleted file mode 100644 index 44b82ee19..000000000 --- a/app/src/main/java/de/danoeh/antennapod/fragment/NewEpisodesFragment.java +++ /dev/null @@ -1,86 +0,0 @@ -package de.danoeh.antennapod.fragment; - -import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; -import androidx.recyclerview.widget.ItemTouchHelper; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.View; -import android.view.ViewGroup; - -import java.util.List; - -import de.danoeh.antennapod.R; -import de.danoeh.antennapod.model.feed.FeedItem; -import de.danoeh.antennapod.core.storage.DBReader; -import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; -import de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder; - -/** - * Like 'EpisodesFragment' except that it only shows new episodes and - * supports swiping to mark as read. - */ -public class NewEpisodesFragment extends EpisodesListFragment { - - public static final String TAG = "NewEpisodesFragment"; - private static final String PREF_NAME = "PrefNewEpisodesFragment"; - - @Override - protected String getPrefName() { - return PREF_NAME; - } - - @Override - protected boolean shouldUpdatedItemRemainInList(FeedItem item) { - return item.isNew(); - } - - @Override - public void onPrepareOptionsMenu(@NonNull Menu menu) { - super.onPrepareOptionsMenu(menu); - menu.findItem(R.id.filter_items).setVisible(false); - menu.findItem(R.id.mark_all_read_item).setVisible(false); - menu.findItem(R.id.remove_all_new_flags_item).setVisible(true); - } - - @NonNull - @Override - public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - View root = super.onCreateView(inflater, container, savedInstanceState); - emptyView.setTitle(R.string.no_new_episodes_head_label); - emptyView.setMessage(R.string.no_new_episodes_label); - - ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, - ItemTouchHelper.RIGHT) { - @Override - public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, - RecyclerView.ViewHolder target) { - return false; - } - - @Override - public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) { - EpisodeItemViewHolder holder = (EpisodeItemViewHolder) viewHolder; - FeedItemMenuHandler.removeNewFlagWithUndo(NewEpisodesFragment.this, holder.getFeedItem()); - } - }; - - ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback); - itemTouchHelper.attachToRecyclerView(recyclerView); - - return root; - } - - @NonNull - @Override - protected List<FeedItem> loadData() { - return DBReader.getNewItemsList(0, page * EPISODES_PER_PAGE); - } - - @NonNull - @Override - protected List<FeedItem> loadMoreData() { - return DBReader.getNewItemsList((page - 1) * EPISODES_PER_PAGE, EPISODES_PER_PAGE); - } -} 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 ec3240496..94c0b0a41 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java @@ -355,10 +355,10 @@ public class SubscriptionFragment extends Fragment } Feed feed = ((NavDrawerData.FeedDrawerItem) drawerItem).feed; - if (itemId == R.id.remove_all_new_flags_item) { + if (itemId == R.id.remove_all_inbox_item) { displayConfirmationDialog( - R.string.remove_all_new_flags_label, - R.string.remove_all_new_flags_confirmation_msg, + R.string.remove_all_inbox_label, + R.string.remove_all_inbox_confirmation_msg, () -> DBWriter.removeFeedNewFlag(feed.getId())); return true; } else if (itemId == R.id.edit_tags) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/SwipePreferencesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/SwipePreferencesFragment.java index 19099a380..1786fe0bf 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/SwipePreferencesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/SwipePreferencesFragment.java @@ -6,11 +6,13 @@ import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.PreferenceActivity; import de.danoeh.antennapod.dialog.SwipeActionsDialog; import de.danoeh.antennapod.fragment.FeedItemlistFragment; +import de.danoeh.antennapod.fragment.InboxFragment; import de.danoeh.antennapod.fragment.QueueFragment; public class SwipePreferencesFragment extends PreferenceFragmentCompat { private static final String PREF_SWIPE_FEED = "prefSwipeFeed"; private static final String PREF_SWIPE_QUEUE = "prefSwipeQueue"; + private static final String PREF_SWIPE_INBOX = "prefSwipeInbox"; @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { @@ -24,6 +26,10 @@ public class SwipePreferencesFragment extends PreferenceFragmentCompat { new SwipeActionsDialog(requireContext(), QueueFragment.TAG).show(() -> { }); return true; }); + findPreference(PREF_SWIPE_INBOX).setOnPreferenceClickListener(preference -> { + new SwipeActionsDialog(requireContext(), InboxFragment.TAG).show(() -> { }); + return true; + }); } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/RemoveFromInboxSwipeAction.java b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/RemoveFromInboxSwipeAction.java index 4344e4d85..df1ef42c1 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/RemoveFromInboxSwipeAction.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/RemoveFromInboxSwipeAction.java @@ -28,7 +28,7 @@ public class RemoveFromInboxSwipeAction implements SwipeAction { @Override public String getTitle(Context context) { - return context.getString(R.string.remove_new_flag_label); + return context.getString(R.string.remove_inbox_label); } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/SwipeActions.java b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/SwipeActions.java index adf133856..5262592aa 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/SwipeActions.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/swipeactions/SwipeActions.java @@ -22,6 +22,7 @@ import java.util.List; import de.danoeh.antennapod.R; import de.danoeh.antennapod.dialog.SwipeActionsDialog; import de.danoeh.antennapod.fragment.EpisodesFragment; +import de.danoeh.antennapod.fragment.InboxFragment; import de.danoeh.antennapod.fragment.QueueFragment; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedItemFilter; @@ -93,9 +94,9 @@ public class SwipeActions extends ItemTouchHelper.SimpleCallback implements Life public static Actions getPrefsWithDefaults(Context context, String tag) { String defaultActions; switch (tag) { - /*case InboxFragment.TAG: - defaultActions = new int[] {ADD_TO_QUEUE, MARK_UNPLAYED}; - break;*/ + case InboxFragment.TAG: + defaultActions = SwipeAction.ADD_TO_QUEUE + "," + SwipeAction.REMOVE_FROM_INBOX; + break; case QueueFragment.TAG: defaultActions = SwipeAction.REMOVE_FROM_QUEUE + "," + SwipeAction.REMOVE_FROM_QUEUE; break; |