diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedPreferences.java index 5ffee0d62..dbbd2b1a4 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/feed/FeedPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/feed/FeedPreferences.java @@ -15,6 +15,7 @@ import de.danoeh.antennapod.core.storage.PodDBAdapter; public class FeedPreferences { public static final float SPEED_USE_GLOBAL = -1; + public static final String TAG_ROOT = "#root"; @NonNull private FeedFilter filter; @@ -36,6 +37,7 @@ public class FeedPreferences { private float feedPlaybackSpeed; private int feedSkipIntro; private int feedSkipEnding; + private String[] tags = {TAG_ROOT, "Test 1", "Test 2"}; public FeedPreferences(long feedID, boolean autoDownload, AutoDeleteAction auto_delete_action, VolumeAdaptionSetting volumeAdaptionSetting, String username, String password) { this(feedID, autoDownload, true, auto_delete_action, volumeAdaptionSetting, @@ -240,4 +242,12 @@ public class FeedPreferences { public int getFeedSkipEnding() { return feedSkipEnding; } + + public String[] getTags() { + return tags; + } + + public void setTags(String[] tags) { + this.tags = tags; + } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java index e285d82ff..74e8e23cb 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java @@ -11,6 +11,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -867,24 +868,27 @@ public final class DBReader { int numDownloadedItems = adapter.getNumberOfDownloadedEpisodes(); List items = new ArrayList<>(); - for (int i = 0, feedsSize = feeds.size(); i < feedsSize; i++) { - items.add(new NavDrawerData.FeedDrawerItem(feeds.get(i), i, feedCounters.get(feeds.get(i).getId()))); + Map folders = new HashMap<>(); + for (Feed feed : feeds) { + for (String tag : feed.getPreferences().getTags()) { + NavDrawerData.FeedDrawerItem drawerItem = new NavDrawerData.FeedDrawerItem(feed, feed.getId(), + feedCounters.get(feed.getId())); + if (FeedPreferences.TAG_ROOT.equals(tag)) { + items.add(drawerItem); + continue; + } + NavDrawerData.FolderDrawerItem folder; + if (folders.containsKey(tag)) { + folder = folders.get(tag); + } else { + folder = new NavDrawerData.FolderDrawerItem(tag); + folders.put(tag, folder); + items.add(folder); + } + drawerItem.id |= folder.id; + folder.children.add(drawerItem); + } } - - List folderItems = new ArrayList<>(); - for (int i = 0, feedsSize = feeds.size(); i < feedsSize; i++) { - folderItems.add(new NavDrawerData.FeedDrawerItem(feeds.get(i), 10001 + i, - feedCounters.get(feeds.get(i).getId()))); - } - items.add(new NavDrawerData.FolderDrawerItem("Folder 1", folderItems, 10000)); - - List folderItems2 = new ArrayList<>(); - for (int i = 0, feedsSize = feeds.size(); i < feedsSize; i++) { - folderItems2.add(new NavDrawerData.FeedDrawerItem(feeds.get(i), 20001 + i, - feedCounters.get(feeds.get(i).getId()))); - } - items.add(new NavDrawerData.FolderDrawerItem("Folder 2", folderItems2, 20000)); - NavDrawerData result = new NavDrawerData(items, queueSize, numNewItems, numDownloadedItems, feedCounters, UserPreferences.getEpisodeCleanupAlgorithm().getReclaimableItems()); adapter.close(); diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/NavDrawerData.java b/core/src/main/java/de/danoeh/antennapod/core/storage/NavDrawerData.java index 66d3f7940..ce497834d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/NavDrawerData.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/NavDrawerData.java @@ -3,6 +3,7 @@ package de.danoeh.antennapod.core.storage; import de.danoeh.antennapod.core.feed.Feed; import de.danoeh.antennapod.core.util.LongIntMap; +import java.util.ArrayList; import java.util.List; public class NavDrawerData { @@ -34,7 +35,7 @@ public class NavDrawerData { public final Type type; private int layer; - public final long id; + public long id; public DrawerItem(Type type, long id) { this.type = type; @@ -55,13 +56,12 @@ public class NavDrawerData { } public static class FolderDrawerItem extends DrawerItem { - public final List children; + public final List children = new ArrayList<>(); public final String name; public boolean isOpen; - public FolderDrawerItem(String name, List children, long id) { - super(DrawerItem.Type.FOLDER, id); - this.children = children; + public FolderDrawerItem(String name) { + super(DrawerItem.Type.FOLDER, name.hashCode() & ~0xFFF); // Drop lower 12 bits for item ids this.name = name; }