Remove favorites tab
This commit is contained in:
parent
938df7b7fa
commit
5887a86cec
|
@ -8,7 +8,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.fragment.EpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.AllEpisodesFragment;
|
||||
import de.test.antennapod.EspressoTestUtils;
|
||||
import de.test.antennapod.ui.UITestUtils;
|
||||
import org.hamcrest.Matcher;
|
||||
|
@ -48,7 +48,7 @@ public class ShareDialogTest {
|
|||
context = InstrumentationRegistry.getInstrumentation().getTargetContext();
|
||||
EspressoTestUtils.clearPreferences();
|
||||
EspressoTestUtils.clearDatabase();
|
||||
EspressoTestUtils.setLastNavFragment(EpisodesFragment.TAG);
|
||||
EspressoTestUtils.setLastNavFragment(AllEpisodesFragment.TAG);
|
||||
UITestUtils uiTestUtils = new UITestUtils(context);
|
||||
uiTestUtils.setup();
|
||||
uiTestUtils.addLocalFeedData(true);
|
||||
|
@ -57,8 +57,6 @@ public class ShareDialogTest {
|
|||
|
||||
openNavDrawer();
|
||||
onDrawerItem(withText(R.string.episodes_label)).perform(click());
|
||||
onView(isRoot()).perform(waitForView(withText(R.string.all_episodes_short_label), 1000));
|
||||
onView(withText(R.string.all_episodes_short_label)).perform(click());
|
||||
|
||||
Matcher<View> allEpisodesMatcher;
|
||||
allEpisodesMatcher = Matchers.allOf(withId(android.R.id.list), isDisplayed(), hasMinimumChildCount(2));
|
||||
|
|
|
@ -251,11 +251,9 @@ public class PlaybackTest {
|
|||
protected void startLocalPlayback() {
|
||||
openNavDrawer();
|
||||
onDrawerItem(withText(R.string.episodes_label)).perform(click());
|
||||
onView(isRoot()).perform(waitForView(withText(R.string.all_episodes_short_label), 1000));
|
||||
onView(withText(R.string.all_episodes_short_label)).perform(click());
|
||||
|
||||
final List<FeedItem> episodes = DBReader.getRecentlyPublishedEpisodes(0, 10, FeedItemFilter.unfiltered());
|
||||
Matcher<View> allEpisodesMatcher = allOf(withId(android.R.id.list), isDisplayed(), hasMinimumChildCount(2));
|
||||
Matcher<View> allEpisodesMatcher = allOf(withId(R.id.recyclerView), isDisplayed(), hasMinimumChildCount(2));
|
||||
onView(isRoot()).perform(waitForView(allEpisodesMatcher, 1000));
|
||||
onView(allEpisodesMatcher).perform(actionOnItemAtPosition(0, clickChildViewWithId(R.id.secondaryActionButton)));
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ import de.danoeh.antennapod.activity.PreferenceActivity;
|
|||
import de.danoeh.antennapod.fragment.CompletedDownloadsFragment;
|
||||
import de.danoeh.antennapod.model.feed.Feed;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.fragment.EpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.AllEpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.NavDrawerFragment;
|
||||
import de.danoeh.antennapod.fragment.PlaybackHistoryFragment;
|
||||
import de.danoeh.antennapod.fragment.QueueFragment;
|
||||
|
@ -148,7 +148,7 @@ public class NavigationDrawerTest {
|
|||
|
||||
List<String> hidden = UserPreferences.getHiddenDrawerItems();
|
||||
assertEquals(2, hidden.size());
|
||||
assertTrue(hidden.contains(EpisodesFragment.TAG));
|
||||
assertTrue(hidden.contains(AllEpisodesFragment.TAG));
|
||||
assertTrue(hidden.contains(PlaybackHistoryFragment.TAG));
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ import de.danoeh.antennapod.core.storage.APNullCleanupAlgorithm;
|
|||
import de.danoeh.antennapod.core.storage.APQueueCleanupAlgorithm;
|
||||
import de.danoeh.antennapod.core.storage.EpisodeCleanupAlgorithm;
|
||||
import de.danoeh.antennapod.core.storage.ExceptFavoriteCleanupAlgorithm;
|
||||
import de.danoeh.antennapod.fragment.EpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.AllEpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.QueueFragment;
|
||||
import de.danoeh.antennapod.fragment.SubscriptionFragment;
|
||||
import de.test.antennapod.EspressoTestUtils;
|
||||
|
@ -521,7 +521,7 @@ public class PreferencesTest {
|
|||
Awaitility.await().atMost(1000, MILLISECONDS)
|
||||
.until(() -> UserPreferences.getBackButtonBehavior() == UserPreferences.BackButtonBehavior.GO_TO_PAGE);
|
||||
Awaitility.await().atMost(1000, MILLISECONDS)
|
||||
.until(() -> UserPreferences.getBackButtonGoToPage().equals(EpisodesFragment.TAG));
|
||||
.until(() -> UserPreferences.getBackButtonGoToPage().equals(AllEpisodesFragment.TAG));
|
||||
clickPreference(R.string.pref_back_button_behavior_title);
|
||||
onView(withText(R.string.back_button_go_to_page)).perform(click());
|
||||
onView(withText(R.string.subscriptions_label)).perform(click());
|
||||
|
|
|
@ -37,6 +37,7 @@ import com.bumptech.glide.Glide;
|
|||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import de.danoeh.antennapod.fragment.AllEpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.CompletedDownloadsFragment;
|
||||
import de.danoeh.antennapod.playback.cast.CastEnabledActivity;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
@ -54,7 +55,6 @@ import de.danoeh.antennapod.core.util.download.AutoUpdateManager;
|
|||
import de.danoeh.antennapod.dialog.RatingDialog;
|
||||
import de.danoeh.antennapod.fragment.AddFeedFragment;
|
||||
import de.danoeh.antennapod.fragment.AudioPlayerFragment;
|
||||
import de.danoeh.antennapod.fragment.EpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.InboxFragment;
|
||||
import de.danoeh.antennapod.fragment.FeedItemlistFragment;
|
||||
import de.danoeh.antennapod.fragment.NavDrawerFragment;
|
||||
|
@ -270,8 +270,8 @@ public class MainActivity extends CastEnabledActivity {
|
|||
case InboxFragment.TAG:
|
||||
fragment = new InboxFragment();
|
||||
break;
|
||||
case EpisodesFragment.TAG:
|
||||
fragment = new EpisodesFragment();
|
||||
case AllEpisodesFragment.TAG:
|
||||
fragment = new AllEpisodesFragment();
|
||||
break;
|
||||
case CompletedDownloadsFragment.TAG:
|
||||
fragment = new CompletedDownloadsFragment();
|
||||
|
@ -606,7 +606,7 @@ public class MainActivity extends CastEnabledActivity {
|
|||
loadFragment(PlaybackHistoryFragment.TAG, null);
|
||||
break;
|
||||
case "EPISODES":
|
||||
loadFragment(EpisodesFragment.TAG, null);
|
||||
loadFragment(AllEpisodesFragment.TAG, null);
|
||||
break;
|
||||
case "QUEUE":
|
||||
loadFragment(QueueFragment.TAG, null);
|
||||
|
|
|
@ -25,6 +25,7 @@ import com.joanzapata.iconify.Iconify;
|
|||
import com.joanzapata.iconify.widget.IconTextView;
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.PreferenceActivity;
|
||||
import de.danoeh.antennapod.fragment.AllEpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.CompletedDownloadsFragment;
|
||||
import de.danoeh.antennapod.fragment.InboxFragment;
|
||||
import de.danoeh.antennapod.model.feed.Feed;
|
||||
|
@ -32,7 +33,6 @@ import de.danoeh.antennapod.core.glide.ApGlideSettings;
|
|||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.storage.NavDrawerData;
|
||||
import de.danoeh.antennapod.fragment.AddFeedFragment;
|
||||
import de.danoeh.antennapod.fragment.EpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.NavDrawerFragment;
|
||||
import de.danoeh.antennapod.fragment.PlaybackHistoryFragment;
|
||||
import de.danoeh.antennapod.fragment.QueueFragment;
|
||||
|
@ -117,7 +117,7 @@ public class NavListAdapter extends RecyclerView.Adapter<NavListAdapter.Holder>
|
|||
return R.drawable.ic_playlist_play;
|
||||
case InboxFragment.TAG:
|
||||
return R.drawable.ic_inbox;
|
||||
case EpisodesFragment.TAG:
|
||||
case AllEpisodesFragment.TAG:
|
||||
return R.drawable.ic_feed;
|
||||
case CompletedDownloadsFragment.TAG:
|
||||
return R.drawable.ic_download;
|
||||
|
|
|
@ -22,8 +22,8 @@ import de.danoeh.antennapod.databinding.SwipeactionsDialogBinding;
|
|||
import de.danoeh.antennapod.databinding.SwipeactionsPickerBinding;
|
||||
import de.danoeh.antennapod.databinding.SwipeactionsPickerItemBinding;
|
||||
import de.danoeh.antennapod.databinding.SwipeactionsRowBinding;
|
||||
import de.danoeh.antennapod.fragment.AllEpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.CompletedDownloadsFragment;
|
||||
import de.danoeh.antennapod.fragment.EpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.FeedItemlistFragment;
|
||||
import de.danoeh.antennapod.fragment.InboxFragment;
|
||||
import de.danoeh.antennapod.fragment.QueueFragment;
|
||||
|
@ -62,7 +62,7 @@ public class SwipeActionsDialog {
|
|||
forFragment = context.getString(R.string.inbox_label);
|
||||
keys = Stream.of(keys).filter(a -> !a.getId().equals(SwipeAction.TOGGLE_PLAYED)).toList();
|
||||
break;
|
||||
case EpisodesFragment.TAG:
|
||||
case AllEpisodesFragment.TAG:
|
||||
forFragment = context.getString(R.string.episodes_label);
|
||||
break;
|
||||
case CompletedDownloadsFragment.TAG:
|
||||
|
|
|
@ -3,29 +3,44 @@ package de.danoeh.antennapod.fragment;
|
|||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import com.joanzapata.iconify.Iconify;
|
||||
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.core.storage.DBReader;
|
||||
import de.danoeh.antennapod.dialog.AllEpisodesFilterDialog;
|
||||
import de.danoeh.antennapod.fragment.swipeactions.SwipeActions;
|
||||
import de.danoeh.antennapod.model.feed.FeedItem;
|
||||
import de.danoeh.antennapod.model.feed.FeedItemFilter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Like 'EpisodesFragment' except that it only shows new episodes and
|
||||
* supports swiping to mark as read.
|
||||
* Shows all episodes (possibly filtered by user).
|
||||
*/
|
||||
public class AllEpisodesFragment extends EpisodesListFragment {
|
||||
public class AllEpisodesFragment extends EpisodesListFragment implements Toolbar.OnMenuItemClickListener {
|
||||
public static final String TAG = "EpisodesFragment";
|
||||
private static final String PREF_NAME = "PrefAllEpisodesFragment";
|
||||
private static final String PREF_FILTER = "filter";
|
||||
private static final String KEY_UP_ARROW = "up_arrow";
|
||||
private Toolbar toolbar;
|
||||
private boolean displayUpArrow;
|
||||
private volatile boolean isUpdatingFeeds;
|
||||
private SwipeActions swipeActions;
|
||||
|
||||
private FeedItemFilter feedItemFilter = new FeedItemFilter("");
|
||||
|
||||
|
@ -36,19 +51,55 @@ public class AllEpisodesFragment extends EpisodesListFragment {
|
|||
feedItemFilter = new FeedItemFilter(prefs.getString(PREF_FILTER, ""));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View appEpisodesContainer = View.inflate(getContext(), R.layout.list_container_fragment, null);
|
||||
View root = super.onCreateView(inflater, container, savedInstanceState);
|
||||
((FrameLayout) appEpisodesContainer.findViewById(R.id.listContent)).addView(root);
|
||||
|
||||
toolbar = appEpisodesContainer.findViewById(R.id.toolbar);
|
||||
toolbar.setOnMenuItemClickListener(this);
|
||||
toolbar.inflateMenu(R.menu.episodes);
|
||||
toolbar.setTitle(R.string.episodes_label);
|
||||
toolbar.setOnLongClickListener(v -> {
|
||||
recyclerView.scrollToPosition(5);
|
||||
recyclerView.post(() -> recyclerView.smoothScrollToPosition(0));
|
||||
return false;
|
||||
});
|
||||
updateToolbar();
|
||||
displayUpArrow = getParentFragmentManager().getBackStackEntryCount() != 0;
|
||||
if (savedInstanceState != null) {
|
||||
displayUpArrow = savedInstanceState.getBoolean(KEY_UP_ARROW);
|
||||
}
|
||||
((MainActivity) getActivity()).setupToolbarToggle(toolbar, displayUpArrow);
|
||||
|
||||
swipeActions = new SwipeActions(this, TAG).attachTo(recyclerView);
|
||||
swipeActions.setFilter(feedItemFilter);
|
||||
|
||||
speedDialView.removeActionItemById(R.id.mark_unread_batch);
|
||||
speedDialView.removeActionItemById(R.id.remove_from_queue_batch);
|
||||
speedDialView.removeActionItemById(R.id.delete_batch);
|
||||
return appEpisodesContainer;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getPrefName() {
|
||||
return PREF_NAME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
if (super.onOptionsItemSelected(item)) {
|
||||
return true;
|
||||
}
|
||||
if (item.getItemId() == R.id.filter_items) {
|
||||
AllEpisodesFilterDialog.newInstance(feedItemFilter).show(getChildFragmentManager(), null);
|
||||
return true;
|
||||
} else if (item.getItemId() == R.id.action_favorites) {
|
||||
onFilterChanged(new AllEpisodesFilterDialog.AllEpisodesFilterChangedEvent(feedItemFilter.showIsFavorite
|
||||
? Collections.emptySet() : Collections.singleton(FeedItemFilter.IS_FAVORITE)));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -59,15 +110,10 @@ public class AllEpisodesFragment extends EpisodesListFragment {
|
|||
SharedPreferences prefs = getActivity().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
|
||||
prefs.edit().putString(PREF_FILTER, StringUtils.join(event.filterValues, ",")).apply();
|
||||
page = 1;
|
||||
swipeActions.setFilter(feedItemFilter);
|
||||
loadItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(@NonNull Menu menu) {
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
menu.findItem(R.id.filter_items).setVisible(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onFragmentLoaded(List<FeedItem> episodes) {
|
||||
super.onFragmentLoaded(episodes);
|
||||
|
@ -81,16 +127,40 @@ public class AllEpisodesFragment extends EpisodesListFragment {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean shouldUpdatedItemRemainInList(FeedItem item) {
|
||||
SharedPreferences prefs = getActivity().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
|
||||
FeedItemFilter feedItemFilter = new FeedItemFilter(prefs.getString(PREF_FILTER, ""));
|
||||
private final MenuItemUtils.UpdateRefreshMenuItemChecker updateRefreshMenuItemChecker =
|
||||
() -> DownloadService.isRunning && DownloadService.isDownloadingFeeds();
|
||||
|
||||
if (feedItemFilter.isShowDownloaded() && (!item.hasMedia() || !item.getMedia().isDownloaded())) {
|
||||
return false;
|
||||
private void updateToolbar() {
|
||||
isUpdatingFeeds = MenuItemUtils.updateRefreshMenuItem(toolbar.getMenu(),
|
||||
R.id.refresh_item, updateRefreshMenuItemChecker);
|
||||
toolbar.getMenu().findItem(R.id.filter_items).setVisible(true);
|
||||
}
|
||||
|
||||
return true;
|
||||
@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
|
||||
protected boolean shouldUpdatedItemRemainInList(FeedItem item) {
|
||||
return feedItemFilter.matches(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
outState.putBoolean(KEY_UP_ARROW, displayUpArrow);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
|
@ -1,121 +0,0 @@
|
|||
package de.danoeh.antennapod.fragment;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.google.android.material.tabs.TabLayout;
|
||||
import com.google.android.material.tabs.TabLayoutMediator;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.ui.common.PagedToolbarFragment;
|
||||
|
||||
public class EpisodesFragment extends PagedToolbarFragment {
|
||||
|
||||
public static final String TAG = "EpisodesFragment";
|
||||
private static final String PREF_LAST_TAB_POSITION = "tab_position";
|
||||
private static final String KEY_UP_ARROW = "up_arrow";
|
||||
|
||||
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;
|
||||
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setRetainInstance(true);
|
||||
}
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
View rootView = inflater.inflate(R.layout.pager_fragment, container, false);
|
||||
Toolbar toolbar = rootView.findViewById(R.id.toolbar);
|
||||
toolbar.setTitle(R.string.episodes_label);
|
||||
toolbar.inflateMenu(R.menu.episodes);
|
||||
displayUpArrow = getParentFragmentManager().getBackStackEntryCount() != 0;
|
||||
if (savedInstanceState != null) {
|
||||
displayUpArrow = savedInstanceState.getBoolean(KEY_UP_ARROW);
|
||||
}
|
||||
((MainActivity) getActivity()).setupToolbarToggle(toolbar, displayUpArrow);
|
||||
|
||||
ViewPager2 viewPager = rootView.findViewById(R.id.viewpager);
|
||||
viewPager.setAdapter(new EpisodesPagerAdapter(this));
|
||||
viewPager.setOffscreenPageLimit(2);
|
||||
super.setupPagedToolbar(toolbar, viewPager);
|
||||
|
||||
// Give the TabLayout the ViewPager
|
||||
tabLayout = rootView.findViewById(R.id.sliding_tabs);
|
||||
|
||||
new TabLayoutMediator(tabLayout, viewPager, (tab, position) -> {
|
||||
switch (position) {
|
||||
case POS_ALL_EPISODES:
|
||||
tab.setText(R.string.all_episodes_short_label);
|
||||
break;
|
||||
case POS_FAV_EPISODES:
|
||||
tab.setText(R.string.favorite_episodes_label);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}).attach();
|
||||
|
||||
// restore our last position
|
||||
SharedPreferences prefs = getActivity().getSharedPreferences(TAG, Context.MODE_PRIVATE);
|
||||
int lastPosition = prefs.getInt(PREF_LAST_TAB_POSITION, 0);
|
||||
viewPager.setCurrentItem(lastPosition, false);
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
// save our tab selection
|
||||
SharedPreferences prefs = getActivity().getSharedPreferences(TAG, Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putInt(PREF_LAST_TAB_POSITION, tabLayout.getSelectedTabPosition());
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
outState.putBoolean(KEY_UP_ARROW, displayUpArrow);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
static class EpisodesPagerAdapter extends FragmentStateAdapter {
|
||||
|
||||
EpisodesPagerAdapter(@NonNull Fragment fragment) {
|
||||
super(fragment);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment createFragment(int position) {
|
||||
switch (position) {
|
||||
case POS_ALL_EPISODES:
|
||||
return new AllEpisodesFragment();
|
||||
default:
|
||||
case POS_FAV_EPISODES:
|
||||
return new FavoriteEpisodesFragment();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return TOTAL_COUNT;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
package de.danoeh.antennapod.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.recyclerview.widget.ItemTouchHelper;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import de.danoeh.antennapod.activity.MainActivity;
|
||||
import de.danoeh.antennapod.model.feed.FeedItemFilter;
|
||||
import de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.event.FavoritesEvent;
|
||||
import de.danoeh.antennapod.model.feed.FeedItem;
|
||||
import de.danoeh.antennapod.core.storage.DBReader;
|
||||
import de.danoeh.antennapod.core.storage.DBWriter;
|
||||
|
||||
/**
|
||||
* Like 'EpisodesFragment' except that it only shows favorite episodes and
|
||||
* supports swiping to remove from favorites.
|
||||
*/
|
||||
public class FavoriteEpisodesFragment extends EpisodesListFragment {
|
||||
|
||||
private static final String TAG = "FavoriteEpisodesFrag";
|
||||
private static final String PREF_NAME = "PrefFavoriteEpisodesFragment";
|
||||
|
||||
@Override
|
||||
protected String getPrefName() {
|
||||
return PREF_NAME;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onEvent(FavoritesEvent event) {
|
||||
Log.d(TAG, String.format("onEvent() called with: event = [%s]", event));
|
||||
loadItems();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(@NonNull Menu menu) {
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
menu.findItem(R.id.filter_items).setVisible(false);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View root = super.onCreateView(inflater, container, savedInstanceState);
|
||||
emptyView.setIcon(R.drawable.ic_star);
|
||||
emptyView.setTitle(R.string.no_fav_episodes_head_label);
|
||||
emptyView.setMessage(R.string.no_fav_episodes_label);
|
||||
|
||||
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0,
|
||||
ItemTouchHelper.LEFT) {
|
||||
@Override
|
||||
public boolean onMove(@NonNull RecyclerView recyclerView,
|
||||
@NonNull RecyclerView.ViewHolder viewHolder,
|
||||
@NonNull RecyclerView.ViewHolder target) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int swipeDir) {
|
||||
EpisodeItemViewHolder holder = (EpisodeItemViewHolder) viewHolder;
|
||||
Log.d(TAG, String.format("remove(%s)", holder.getFeedItem().getId()));
|
||||
|
||||
if (disposable != null) {
|
||||
disposable.dispose();
|
||||
}
|
||||
FeedItem item = holder.getFeedItem();
|
||||
if (item != null) {
|
||||
DBWriter.removeFavoriteItem(item);
|
||||
|
||||
((MainActivity) getActivity()).showSnackbarAbovePlayer(R.string.removed_item, Snackbar.LENGTH_LONG)
|
||||
.setAction(getString(R.string.undo), v -> DBWriter.addFavoriteItem(item));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
|
||||
itemTouchHelper.attachToRecyclerView(recyclerView);
|
||||
return root;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected List<FeedItem> loadData() {
|
||||
return DBReader.getFavoriteItemsList(0, page * EPISODES_PER_PAGE);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected List<FeedItem> loadMoreData(int page) {
|
||||
return DBReader.getFavoriteItemsList((page - 1) * EPISODES_PER_PAGE, EPISODES_PER_PAGE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int loadTotalItemCount() {
|
||||
return DBReader.getTotalEpisodeCount(new FeedItemFilter(FeedItemFilter.IS_FAVORITE));
|
||||
}
|
||||
}
|
|
@ -273,7 +273,7 @@ public class FeedItemlistFragment extends Fragment implements AdapterView.OnItem
|
|||
new RenameItemDialog(getActivity(), feed).show();
|
||||
return true;
|
||||
} else if (itemId == R.id.remove_feed) {
|
||||
((MainActivity) getActivity()).loadFragment(EpisodesFragment.TAG, null);
|
||||
((MainActivity) getActivity()).loadFragment(AllEpisodesFragment.TAG, null);
|
||||
RemoveFeedDialog.show(getContext(), feed);
|
||||
return true;
|
||||
} else if (itemId == R.id.action_search) {
|
||||
|
|
|
@ -67,7 +67,7 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS
|
|||
public static final String[] NAV_DRAWER_TAGS = {
|
||||
QueueFragment.TAG,
|
||||
InboxFragment.TAG,
|
||||
EpisodesFragment.TAG,
|
||||
AllEpisodesFragment.TAG,
|
||||
SubscriptionFragment.TAG,
|
||||
CompletedDownloadsFragment.TAG,
|
||||
PlaybackHistoryFragment.TAG,
|
||||
|
@ -173,7 +173,7 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS
|
|||
new RenameItemDialog(getActivity(), feed).show();
|
||||
return true;
|
||||
} else if (itemId == R.id.remove_feed) {
|
||||
((MainActivity) getActivity()).loadFragment(EpisodesFragment.TAG, null);
|
||||
((MainActivity) getActivity()).loadFragment(AllEpisodesFragment.TAG, null);
|
||||
RemoveFeedDialog.show(getContext(), feed);
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@ import java.util.List;
|
|||
|
||||
import de.danoeh.antennapod.R;
|
||||
import de.danoeh.antennapod.dialog.SwipeActionsDialog;
|
||||
import de.danoeh.antennapod.fragment.AllEpisodesFragment;
|
||||
import de.danoeh.antennapod.fragment.CompletedDownloadsFragment;
|
||||
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;
|
||||
|
@ -106,7 +106,7 @@ public class SwipeActions extends ItemTouchHelper.SimpleCallback implements Life
|
|||
defaultActions = SwipeAction.DELETE + "," + SwipeAction.DELETE;
|
||||
break;
|
||||
default:
|
||||
case EpisodesFragment.TAG:
|
||||
case AllEpisodesFragment.TAG:
|
||||
defaultActions = SwipeAction.MARK_FAV + "," + SwipeAction.START_DOWNLOAD;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,13 @@
|
|||
android:menuCategory="container"
|
||||
android:title="@string/filter"
|
||||
android:visible="false"
|
||||
custom:showAsAction="ifRoom"/>
|
||||
custom:showAsAction="always"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_favorites"
|
||||
android:icon="@drawable/ic_star_border"
|
||||
android:menuCategory="container"
|
||||
android:title="@string/favorite_episodes_label"
|
||||
custom:showAsAction="always"/>
|
||||
|
||||
</menu>
|
||||
|
|
|
@ -75,4 +75,37 @@ public class FeedItemFilter implements Serializable {
|
|||
public boolean isShowDownloaded() {
|
||||
return showDownloaded;
|
||||
}
|
||||
|
||||
public boolean matches(FeedItem item) {
|
||||
if (showNew && !item.isNew()) {
|
||||
return false;
|
||||
} else if (showPlayed && !item.isPlayed()) {
|
||||
return false;
|
||||
} else if (showUnplayed && item.isPlayed()) {
|
||||
return false;
|
||||
} else if (showPaused && !item.isInProgress()) {
|
||||
return false;
|
||||
} else if (showNotPaused && item.isInProgress()) {
|
||||
return false;
|
||||
} else if (showNew && !item.isNew()) {
|
||||
return false;
|
||||
} else if (showQueued && !item.isTagged(FeedItem.TAG_QUEUE)) {
|
||||
return false;
|
||||
} else if (showNotQueued && item.isTagged(FeedItem.TAG_QUEUE)) {
|
||||
return false;
|
||||
} else if (showDownloaded && !item.isDownloaded()) {
|
||||
return false;
|
||||
} else if (showNotDownloaded && item.isDownloaded()) {
|
||||
return false;
|
||||
} else if (showHasMedia && !item.hasMedia()) {
|
||||
return false;
|
||||
} else if (showNoMedia && item.hasMedia()) {
|
||||
return false;
|
||||
} else if (showIsFavorite && !item.isTagged(FeedItem.TAG_FAVORITE)) {
|
||||
return false;
|
||||
} else if (showNotFavorite && item.isTagged(FeedItem.TAG_FAVORITE)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
<string name="add_feed_label">Add Podcast</string>
|
||||
<string name="episodes_label">Episodes</string>
|
||||
<string name="queue_label">Queue</string>
|
||||
<string name="all_episodes_short_label">All</string>
|
||||
<string name="inbox_label">Inbox</string>
|
||||
<string name="favorite_episodes_label">Favorites</string>
|
||||
<string name="settings_label">Settings</string>
|
||||
|
|
Loading…
Reference in New Issue