Added support for folder counter

This commit is contained in:
ByteHamster 2021-01-02 17:25:53 +01:00
parent b107e6da95
commit c4db0ffb1f
3 changed files with 25 additions and 18 deletions

View File

@ -199,6 +199,7 @@ public class NavListAdapter extends RecyclerView.Adapter<NavListAdapter.Holder>
} 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<NavListAdapter.Holder>
}
}
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<NavListAdapter.Holder>
.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<NavListAdapter.Holder>
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 {

View File

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

View File

@ -50,6 +50,7 @@ public class NavDrawerData {
public static class FolderDrawerItem extends DrawerItem {
public final List<DrawerItem> children;
public final String name;
public boolean isOpen;
public FolderDrawerItem(String name, List<DrawerItem> 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;
}
}