diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java index 7f1aebfa5..5d3fffd1a 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java @@ -199,6 +199,7 @@ public class NavListAdapter extends RecyclerView.Adapter } else { int itemPos = position - getSubscriptionOffset(); NavDrawerData.DrawerItem item = itemAccess.getItem(itemPos); + bindListItem(item, (FeedHolder) holder); if (item.type == NavDrawerData.DrawerItem.Type.FEED) { bindFeedView((NavDrawerData.FeedDrawerItem) item, (FeedHolder) holder); } else { @@ -292,6 +293,17 @@ public class NavListAdapter extends RecyclerView.Adapter } } + private void bindListItem(NavDrawerData.DrawerItem item, FeedHolder holder) { + if (item.getCounter() > 0) { + holder.count.setVisibility(View.VISIBLE); + holder.count.setText(NumberFormat.getInstance().format(item.getCounter())); + } else { + holder.count.setVisibility(View.GONE); + } + holder.title.setText(item.getTitle()); + holder.itemView.setPadding(item.layer * 50, 0, 0, 0); // TODO + } + private void bindFeedView(NavDrawerData.FeedDrawerItem drawerItem, FeedHolder holder) { Feed feed = drawerItem.feed; Activity context = activity.get(); @@ -309,9 +321,7 @@ public class NavListAdapter extends RecyclerView.Adapter .dontAnimate()) .into(holder.image); - holder.title.setText(feed.getTitle()); - - if(feed.hasLastUpdateFailed()) { + if (feed.hasLastUpdateFailed()) { RelativeLayout.LayoutParams p = (RelativeLayout.LayoutParams) holder.title.getLayoutParams(); p.addRule(RelativeLayout.LEFT_OF, R.id.itxtvFailure); holder.failure.setVisibility(View.VISIBLE); @@ -320,28 +330,19 @@ public class NavListAdapter extends RecyclerView.Adapter p.addRule(RelativeLayout.LEFT_OF, R.id.txtvCount); holder.failure.setVisibility(View.GONE); } - int counter = itemAccess.getFeedCounter(feed.getId()); - if(counter > 0) { - holder.count.setVisibility(View.VISIBLE); - holder.count.setText(NumberFormat.getInstance().format(counter)); - } else { - holder.count.setVisibility(View.GONE); - } - holder.itemView.setPadding(drawerItem.layer * 50, 0, 0, 0); // TODO } - private void bindFolderView(NavDrawerData.FolderDrawerItem drawerItem, FeedHolder holder) { + private void bindFolderView(NavDrawerData.FolderDrawerItem folder, FeedHolder holder) { Activity context = activity.get(); if (context == null) { return; } + if (folder.isOpen) { + holder.count.setVisibility(View.GONE); + } holder.image.setImageResource(ThemeUtils.getDrawableFromAttr(context, R.attr.ic_folder)); - holder.title.setText(drawerItem.name); holder.failure.setVisibility(View.GONE); - holder.count.setText("?"); - - holder.itemView.setPadding(drawerItem.layer * 50, 0, 0, 0); // TODO } static class Holder extends RecyclerView.ViewHolder { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java index 5baa1ed4d..b7d968828 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/NavDrawerFragment.java @@ -425,7 +425,8 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS flatItems.add(item); if (item.type == NavDrawerData.DrawerItem.Type.FOLDER) { NavDrawerData.FolderDrawerItem folder = ((NavDrawerData.FolderDrawerItem) item); - if (openFolders.contains(folder.name)) { + folder.isOpen = openFolders.contains(folder.name); + if (folder.isOpen) { flatItems.addAll(makeFlatDrawerData(((NavDrawerData.FolderDrawerItem) item).children)); } } 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 8d917d81b..3af9ef9d3 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 @@ -50,6 +50,7 @@ public class NavDrawerData { public static class FolderDrawerItem extends DrawerItem { public final List children; public final String name; + public boolean isOpen; public FolderDrawerItem(String name, List children, int layer, long id) { super(DrawerItem.Type.FOLDER, layer, id); @@ -62,7 +63,11 @@ public class NavDrawerData { } public int getCounter() { - return -1; + int sum = 0; + for (DrawerItem item : children) { + sum += item.getCounter(); + } + return sum; } }