Calculate layer in makeFlatDrawerData
This commit is contained in:
parent
052884e081
commit
3104232e5d
|
@ -303,7 +303,7 @@ public class NavListAdapter extends RecyclerView.Adapter<NavListAdapter.Holder>
|
|||
holder.count.setVisibility(View.GONE);
|
||||
}
|
||||
holder.title.setText(item.getTitle());
|
||||
holder.itemView.setPadding(item.layer * 50, 0, 0, 0); // TODO
|
||||
holder.itemView.setPadding(item.getLayer() * 50, 0, 0, 0); // TODO
|
||||
}
|
||||
|
||||
private void bindFeedView(NavDrawerData.FeedDrawerItem drawerItem, FeedHolder holder) {
|
||||
|
|
|
@ -19,6 +19,7 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.util.Pair;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
@ -379,8 +380,15 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS
|
|||
} else {
|
||||
openFolders.add(folder.name);
|
||||
}
|
||||
flatItemList = makeFlatDrawerData(navDrawerData.items);
|
||||
navAdapter.notifyDataSetChanged();
|
||||
|
||||
disposable = Observable.fromCallable(() -> makeFlatDrawerData(navDrawerData.items, 0))
|
||||
.subscribeOn(Schedulers.computation())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
result -> {
|
||||
flatItemList = result;
|
||||
navAdapter.notifyDataSetChanged();
|
||||
}, error -> Log.e(TAG, Log.getStackTraceString(error)));
|
||||
}
|
||||
}
|
||||
} else if (UserPreferences.getSubscriptionsFilter().isEnabled()
|
||||
|
@ -403,13 +411,17 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS
|
|||
|
||||
private void loadData() {
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
disposable = Observable.fromCallable(DBReader::getNavDrawerData)
|
||||
disposable = Observable.fromCallable(
|
||||
() -> {
|
||||
NavDrawerData data = DBReader.getNavDrawerData();
|
||||
return new Pair<>(data, makeFlatDrawerData(data.items, 0));
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(
|
||||
result -> {
|
||||
navDrawerData = result;
|
||||
flatItemList = makeFlatDrawerData(navDrawerData.items); // TODO: This is the main thread!
|
||||
navDrawerData = result.first;
|
||||
flatItemList = result.second;
|
||||
updateSelection(); // Selected item might be a feed
|
||||
navAdapter.notifyDataSetChanged();
|
||||
progressBar.setVisibility(View.GONE);
|
||||
|
@ -419,15 +431,16 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS
|
|||
});
|
||||
}
|
||||
|
||||
private List<NavDrawerData.DrawerItem> makeFlatDrawerData(List<NavDrawerData.DrawerItem> items) {
|
||||
private List<NavDrawerData.DrawerItem> makeFlatDrawerData(List<NavDrawerData.DrawerItem> items, int layer) {
|
||||
List<NavDrawerData.DrawerItem> flatItems = new ArrayList<>();
|
||||
for (NavDrawerData.DrawerItem item : items) {
|
||||
item.setLayer(layer);
|
||||
flatItems.add(item);
|
||||
if (item.type == NavDrawerData.DrawerItem.Type.FOLDER) {
|
||||
NavDrawerData.FolderDrawerItem folder = ((NavDrawerData.FolderDrawerItem) item);
|
||||
folder.isOpen = openFolders.contains(folder.name);
|
||||
if (folder.isOpen) {
|
||||
flatItems.addAll(makeFlatDrawerData(((NavDrawerData.FolderDrawerItem) item).children));
|
||||
flatItems.addAll(makeFlatDrawerData(((NavDrawerData.FolderDrawerItem) item).children, layer + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -868,22 +868,22 @@ public final class DBReader {
|
|||
|
||||
List<NavDrawerData.DrawerItem> items = new ArrayList<>();
|
||||
for (int i = 0, feedsSize = feeds.size(); i < feedsSize; i++) {
|
||||
items.add(new NavDrawerData.FeedDrawerItem(feeds.get(i), 0, i, feedCounters.get(feeds.get(i).getId())));
|
||||
items.add(new NavDrawerData.FeedDrawerItem(feeds.get(i), i, feedCounters.get(feeds.get(i).getId())));
|
||||
}
|
||||
|
||||
List<NavDrawerData.DrawerItem> folderItems = new ArrayList<>();
|
||||
for (int i = 0, feedsSize = feeds.size(); i < feedsSize; i++) {
|
||||
folderItems.add(new NavDrawerData.FeedDrawerItem(feeds.get(i), 1, 10001 + 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, 0, 10000));
|
||||
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), 1, 20001 + 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, 0, 20000));
|
||||
items.add(new NavDrawerData.FolderDrawerItem("Folder 2", folderItems2, 20000));
|
||||
|
||||
NavDrawerData result = new NavDrawerData(items, queueSize, numNewItems, numDownloadedItems,
|
||||
feedCounters, UserPreferences.getEpisodeCleanupAlgorithm().getReclaimableItems());
|
||||
|
|
|
@ -33,15 +33,22 @@ public class NavDrawerData {
|
|||
}
|
||||
|
||||
public final Type type;
|
||||
public final int layer;
|
||||
private int layer;
|
||||
public final long id;
|
||||
|
||||
public DrawerItem(Type type, int layer, long id) {
|
||||
public DrawerItem(Type type, long id) {
|
||||
this.type = type;
|
||||
this.layer = layer;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public int getLayer() {
|
||||
return layer;
|
||||
}
|
||||
|
||||
public void setLayer(int layer) {
|
||||
this.layer = layer;
|
||||
}
|
||||
|
||||
public abstract String getTitle();
|
||||
|
||||
public abstract int getCounter();
|
||||
|
@ -52,8 +59,8 @@ public class NavDrawerData {
|
|||
public final String name;
|
||||
public boolean isOpen;
|
||||
|
||||
public FolderDrawerItem(String name, List<DrawerItem> children, int layer, long id) {
|
||||
super(DrawerItem.Type.FOLDER, layer, id);
|
||||
public FolderDrawerItem(String name, List<DrawerItem> children, long id) {
|
||||
super(DrawerItem.Type.FOLDER, id);
|
||||
this.children = children;
|
||||
this.name = name;
|
||||
}
|
||||
|
@ -75,8 +82,8 @@ public class NavDrawerData {
|
|||
public final Feed feed;
|
||||
public final int counter;
|
||||
|
||||
public FeedDrawerItem(Feed feed, int layer, long id, int counter) {
|
||||
super(DrawerItem.Type.FEED, layer, id);
|
||||
public FeedDrawerItem(Feed feed, long id, int counter) {
|
||||
super(DrawerItem.Type.FEED, id);
|
||||
this.feed = feed;
|
||||
this.counter = counter;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue