Build tags based on feed properties

This commit is contained in:
ByteHamster 2021-01-02 20:39:04 +01:00
parent 3104232e5d
commit 1eb47a2d6b
3 changed files with 36 additions and 22 deletions

View File

@ -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;
}
}

View File

@ -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<NavDrawerData.DrawerItem> 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<String, NavDrawerData.FolderDrawerItem> 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;
}
List<NavDrawerData.DrawerItem> 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())));
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);
}
items.add(new NavDrawerData.FolderDrawerItem("Folder 1", folderItems, 10000));
List<NavDrawerData.DrawerItem> 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();

View File

@ -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<DrawerItem> children;
public final List<DrawerItem> children = new ArrayList<>();
public final String name;
public boolean isOpen;
public FolderDrawerItem(String name, List<DrawerItem> 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;
}