Added support for folder counter
This commit is contained in:
parent
b107e6da95
commit
c4db0ffb1f
|
@ -199,6 +199,7 @@ public class NavListAdapter extends RecyclerView.Adapter<NavListAdapter.Holder>
|
||||||
} else {
|
} else {
|
||||||
int itemPos = position - getSubscriptionOffset();
|
int itemPos = position - getSubscriptionOffset();
|
||||||
NavDrawerData.DrawerItem item = itemAccess.getItem(itemPos);
|
NavDrawerData.DrawerItem item = itemAccess.getItem(itemPos);
|
||||||
|
bindListItem(item, (FeedHolder) holder);
|
||||||
if (item.type == NavDrawerData.DrawerItem.Type.FEED) {
|
if (item.type == NavDrawerData.DrawerItem.Type.FEED) {
|
||||||
bindFeedView((NavDrawerData.FeedDrawerItem) item, (FeedHolder) holder);
|
bindFeedView((NavDrawerData.FeedDrawerItem) item, (FeedHolder) holder);
|
||||||
} else {
|
} 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) {
|
private void bindFeedView(NavDrawerData.FeedDrawerItem drawerItem, FeedHolder holder) {
|
||||||
Feed feed = drawerItem.feed;
|
Feed feed = drawerItem.feed;
|
||||||
Activity context = activity.get();
|
Activity context = activity.get();
|
||||||
|
@ -309,9 +321,7 @@ public class NavListAdapter extends RecyclerView.Adapter<NavListAdapter.Holder>
|
||||||
.dontAnimate())
|
.dontAnimate())
|
||||||
.into(holder.image);
|
.into(holder.image);
|
||||||
|
|
||||||
holder.title.setText(feed.getTitle());
|
if (feed.hasLastUpdateFailed()) {
|
||||||
|
|
||||||
if(feed.hasLastUpdateFailed()) {
|
|
||||||
RelativeLayout.LayoutParams p = (RelativeLayout.LayoutParams) holder.title.getLayoutParams();
|
RelativeLayout.LayoutParams p = (RelativeLayout.LayoutParams) holder.title.getLayoutParams();
|
||||||
p.addRule(RelativeLayout.LEFT_OF, R.id.itxtvFailure);
|
p.addRule(RelativeLayout.LEFT_OF, R.id.itxtvFailure);
|
||||||
holder.failure.setVisibility(View.VISIBLE);
|
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);
|
p.addRule(RelativeLayout.LEFT_OF, R.id.txtvCount);
|
||||||
holder.failure.setVisibility(View.GONE);
|
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();
|
Activity context = activity.get();
|
||||||
if (context == null) {
|
if (context == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (folder.isOpen) {
|
||||||
|
holder.count.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
holder.image.setImageResource(ThemeUtils.getDrawableFromAttr(context, R.attr.ic_folder));
|
holder.image.setImageResource(ThemeUtils.getDrawableFromAttr(context, R.attr.ic_folder));
|
||||||
holder.title.setText(drawerItem.name);
|
|
||||||
holder.failure.setVisibility(View.GONE);
|
holder.failure.setVisibility(View.GONE);
|
||||||
holder.count.setText("?");
|
|
||||||
|
|
||||||
holder.itemView.setPadding(drawerItem.layer * 50, 0, 0, 0); // TODO
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Holder extends RecyclerView.ViewHolder {
|
static class Holder extends RecyclerView.ViewHolder {
|
||||||
|
|
|
@ -425,7 +425,8 @@ public class NavDrawerFragment extends Fragment implements SharedPreferences.OnS
|
||||||
flatItems.add(item);
|
flatItems.add(item);
|
||||||
if (item.type == NavDrawerData.DrawerItem.Type.FOLDER) {
|
if (item.type == NavDrawerData.DrawerItem.Type.FOLDER) {
|
||||||
NavDrawerData.FolderDrawerItem folder = ((NavDrawerData.FolderDrawerItem) item);
|
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));
|
flatItems.addAll(makeFlatDrawerData(((NavDrawerData.FolderDrawerItem) item).children));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ public class NavDrawerData {
|
||||||
public static class FolderDrawerItem extends DrawerItem {
|
public static class FolderDrawerItem extends DrawerItem {
|
||||||
public final List<DrawerItem> children;
|
public final List<DrawerItem> children;
|
||||||
public final String name;
|
public final String name;
|
||||||
|
public boolean isOpen;
|
||||||
|
|
||||||
public FolderDrawerItem(String name, List<DrawerItem> children, int layer, long id) {
|
public FolderDrawerItem(String name, List<DrawerItem> children, int layer, long id) {
|
||||||
super(DrawerItem.Type.FOLDER, layer, id);
|
super(DrawerItem.Type.FOLDER, layer, id);
|
||||||
|
@ -62,7 +63,11 @@ public class NavDrawerData {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getCounter() {
|
public int getCounter() {
|
||||||
return -1;
|
int sum = 0;
|
||||||
|
for (DrawerItem item : children) {
|
||||||
|
sum += item.getCounter();
|
||||||
|
}
|
||||||
|
return sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue