Use a null key for feeds without folders

This commit is contained in:
Shinokuni 2020-08-10 22:01:51 +02:00
parent ab86bcbcc2
commit 74447b1671
5 changed files with 11 additions and 5 deletions

View File

@ -39,6 +39,8 @@ android {
}
}
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
@ -56,6 +58,8 @@ dependencies {
implementation project(':api')
implementation project(':db')
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10'
implementation 'com.google.android.material:material:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.palette:palette:1.0.0'

View File

@ -19,6 +19,7 @@ import com.readrops.db.entities.account.AccountType;
import com.readrops.api.services.SyncResult;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@ -132,7 +133,7 @@ public abstract class ARepository<T> {
public Single<Map<Folder, List<Feed>>> getFoldersWithFeeds() {
return Single.create(emitter -> {
List<Folder> folders = database.folderDao().getFolders(account.getId());
Map<Folder, List<Feed>> foldersWithFeeds = new TreeMap<>(Folder::compareTo);
Map<Folder, List<Feed>> foldersWithFeeds = new TreeMap<>(Comparator.nullsLast(Folder::compareTo));
for (Folder folder : folders) {
List<Feed> feeds = database.feedDao().getFeedsByFolder(folder.getId());
@ -145,14 +146,13 @@ public abstract class ARepository<T> {
foldersWithFeeds.put(folder, feeds);
}
Folder noFolder = new Folder("no folder");
// feeds without folder
List<Feed> feedsWithoutFolder = database.feedDao().getFeedsWithoutFolder(account.getId());
for (Feed feed : feedsWithoutFolder) {
feed.setUnreadCount(database.itemDao().getUnreadCount(feed.getId()));
}
foldersWithFeeds.put(noFolder, feedsWithoutFolder);
foldersWithFeeds.put(null, feedsWithoutFolder);
emitter.onSuccess(foldersWithFeeds);
});

View File

@ -90,7 +90,7 @@ public class DrawerManager {
for (Map.Entry<Folder, List<Feed>> entry : folderListMap.entrySet()) {
Folder folder = entry.getKey();
if (folder.getId() != 0) {
if (folder != null) {
// no identifier for badge items, but if needed, be aware of not getting conflicts
// with secondary item identifiers (folder and feed ids can be the same)
ExpandableBadgeDrawerItem badgeDrawerItem = new ExpandableBadgeDrawerItem()

View File

@ -66,6 +66,7 @@ public class AccountViewModel extends AndroidViewModel {
return database.accountDao().getAccountCount();
}
@SuppressWarnings("unchecked")
public Single<Map<Folder, List<Feed>>> getFoldersWithFeeds() {
return repository.getFoldersWithFeeds();
}

View File

@ -124,6 +124,7 @@ public class MainViewModel extends AndroidViewModel {
return repository.getFeedCount(currentAccount.getId());
}
@SuppressWarnings("unchecked")
public Single<Map<Folder, List<Feed>>> getFoldersWithFeeds() {
return repository.getFoldersWithFeeds();
}