diff options
author | ByteHamster <info@bytehamster.com> | 2021-03-05 13:40:14 +0100 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2021-03-05 13:40:14 +0100 |
commit | 8586c7672053e45d2bfce29909a6a99cd68c4b8f (patch) | |
tree | 165e9bcca3d4cf0292d28fab4f5eb0222c05cf3b /app/src | |
parent | 4b7f7880a5394603340d81b8a286a78b100df052 (diff) | |
download | AntennaPod-8586c7672053e45d2bfce29909a6a99cd68c4b8f.zip |
Make folders work on subscriptions page
Diffstat (limited to 'app/src')
3 files changed, 41 insertions, 14 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java index 660302d56..fc97cace5 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/SubscriptionsAdapter.java @@ -23,6 +23,7 @@ import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.feed.LocalFeedUpdater; import de.danoeh.antennapod.core.storage.NavDrawerData; import de.danoeh.antennapod.fragment.FeedItemlistFragment; +import de.danoeh.antennapod.fragment.SubscriptionFragment; import de.danoeh.antennapod.ui.common.ThemeUtils; import jp.shts.android.library.TriangleLabelView; @@ -132,6 +133,9 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI Feed feed = ((NavDrawerData.FeedDrawerItem) drawerItem).feed; Fragment fragment = FeedItemlistFragment.newInstance(feed.getId()); mainActivityRef.get().loadChildFragment(fragment); + } else if (drawerItem.type == NavDrawerData.DrawerItem.Type.FOLDER) { + Fragment fragment = SubscriptionFragment.newInstance(drawerItem.getTitle()); + mainActivityRef.get().loadChildFragment(fragment); } } @@ -145,7 +149,5 @@ public class SubscriptionsAdapter extends BaseAdapter implements AdapterView.OnI int getCount(); NavDrawerData.DrawerItem getItem(int position); - - int getFeedCounter(long feedId); } } 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 c9f85b22e..58cfece14 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/SubscriptionFragment.java @@ -28,6 +28,7 @@ import android.widget.TextView; import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.joanzapata.iconify.Iconify; +import java.util.List; import java.util.Locale; import java.util.concurrent.Callable; @@ -69,6 +70,7 @@ public class SubscriptionFragment extends Fragment implements Toolbar.OnMenuItem private static final String PREFS = "SubscriptionFragment"; private static final String PREF_NUM_COLUMNS = "columns"; private static final String KEY_UP_ARROW = "up_arrow"; + private static final String ARGUMENT_FOLDER = "folder"; private static final int MIN_NUM_COLUMNS = 2; private static final int[] COLUMN_CHECKBOX_IDS = { @@ -78,13 +80,14 @@ public class SubscriptionFragment extends Fragment implements Toolbar.OnMenuItem R.id.subscription_num_columns_5}; private GridView subscriptionGridLayout; - private NavDrawerData navDrawerData; + private List<NavDrawerData.DrawerItem> listItems; private SubscriptionsAdapter subscriptionAdapter; private FloatingActionButton subscriptionAddButton; private ProgressBar progressBar; private EmptyViewHandler emptyView; private TextView feedsFilteredMsg; private Toolbar toolbar; + private String displayedFolder = null; private Feed selectedFeed = null; private boolean isUpdatingFeeds = false; @@ -93,6 +96,14 @@ public class SubscriptionFragment extends Fragment implements Toolbar.OnMenuItem private Disposable disposable; private SharedPreferences prefs; + public static SubscriptionFragment newInstance(String folderTitle) { + SubscriptionFragment fragment = new SubscriptionFragment(); + Bundle args = new Bundle(); + args.putString(ARGUMENT_FOLDER, folderTitle); + fragment.setArguments(args); + return fragment; + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -120,6 +131,13 @@ public class SubscriptionFragment extends Fragment implements Toolbar.OnMenuItem } refreshToolbarState(); + if (getArguments() != null) { + displayedFolder = getArguments().getString(ARGUMENT_FOLDER, null); + if (displayedFolder != null) { + toolbar.setTitle(displayedFolder); + } + } + subscriptionGridLayout = root.findViewById(R.id.subscriptions_grid); subscriptionGridLayout.setNumColumns(prefs.getInt(PREF_NUM_COLUMNS, getDefaultNumOfColumns())); registerForContextMenu(subscriptionGridLayout); @@ -232,12 +250,23 @@ public class SubscriptionFragment extends Fragment implements Toolbar.OnMenuItem disposable.dispose(); } emptyView.hide(); - disposable = Observable.fromCallable(DBReader::getNavDrawerData) + disposable = Observable.fromCallable( + () -> { + NavDrawerData data = DBReader.getNavDrawerData(); + List<NavDrawerData.DrawerItem> items = data.items; + for (NavDrawerData.DrawerItem item : items) { + if (item.type == NavDrawerData.DrawerItem.Type.FOLDER + && item.getTitle().equals(displayedFolder)) { + return ((NavDrawerData.FolderDrawerItem) item).children; + } + } + return items; + }) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe( result -> { - navDrawerData = result; + listItems = result; subscriptionAdapter.notifyDataSetChanged(); emptyView.updateVisibility(); progressBar.setVisibility(View.GONE); // Keep hidden to avoid flickering while refreshing @@ -347,8 +376,8 @@ public class SubscriptionFragment extends Fragment implements Toolbar.OnMenuItem private final SubscriptionsAdapter.ItemAccess itemAccess = new SubscriptionsAdapter.ItemAccess() { @Override public int getCount() { - if (navDrawerData != null) { - return navDrawerData.items.size(); + if (listItems != null) { + return listItems.size(); } else { return 0; } @@ -356,16 +385,11 @@ public class SubscriptionFragment extends Fragment implements Toolbar.OnMenuItem @Override public NavDrawerData.DrawerItem getItem(int position) { - if (navDrawerData != null && 0 <= position && position < navDrawerData.items.size()) { - return navDrawerData.items.get(position); + if (listItems != null && 0 <= position && position < listItems.size()) { + return listItems.get(position); } else { return null; } } - - @Override - public int getFeedCounter(long feedId) { - return navDrawerData != null ? navDrawerData.feedCounters.get(feedId) : 0; - } }; } diff --git a/app/src/main/res/layout/fragment_subscriptions.xml b/app/src/main/res/layout/fragment_subscriptions.xml index d08e0c501..c738300c5 100644 --- a/app/src/main/res/layout/fragment_subscriptions.xml +++ b/app/src/main/res/layout/fragment_subscriptions.xml @@ -12,6 +12,7 @@ android:theme="?attr/actionBarTheme" android:layout_alignParentTop="true" app:title="@string/subscriptions_label" + app:navigationIcon="?homeAsUpIndicator" android:id="@+id/toolbar"/> <TextView |