Generalize pinned nav menu counts

pull/194/merge
M66B 3 years ago
parent d63ddec037
commit 0e66f97804

@ -662,9 +662,6 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
protected void onPostCreate(Bundle savedInstanceState) { protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState); super.onPostCreate(savedInstanceState);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean nav_count = prefs.getBoolean("nav_count", false);
// Fixed menus // Fixed menus
final List<NavMenuItem> menus = new ArrayList<>(); final List<NavMenuItem> menus = new ArrayList<>();
@ -676,7 +673,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
drawerLayout.closeDrawer(drawerContainer); drawerLayout.closeDrawer(drawerContainer);
onMenuOperations(); onMenuOperations();
} }
}).setExtraCount(nav_count); });
menus.add(navOperations); menus.add(navOperations);
@ -827,6 +824,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
// Live data // Live data
DB db = DB.getInstance(this); DB db = DB.getInstance(this);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
db.account().liveAccountFolder().observe(owner, new Observer<List<TupleAccountFolder>>() { db.account().liveAccountFolder().observe(owner, new Observer<List<TupleAccountFolder>>() {
@Override @Override

@ -142,7 +142,9 @@ public class AdapterNavAccountFolder extends RecyclerView.Adapter<AdapterNavAcco
count = account.unseen; count = account.unseen;
ivBadge.setVisibility(count == 0 || expanded ? View.GONE : View.VISIBLE); ivBadge.setVisibility(count == 0 || expanded ? View.GONE : View.VISIBLE);
tvCount.setVisibility(View.GONE);
tvCount.setText(Helper.formatNumber(count, 99, NF));
tvCount.setVisibility(count == 0 || expanded || !nav_count ? View.GONE : View.VISIBLE);
Integer color = (account.folderName == null ? account.color : account.folderColor); Integer color = (account.folderName == null ? account.color : account.folderColor);
if (color == null || !ActivityBilling.isPro(context)) if (color == null || !ActivityBilling.isPro(context))

@ -46,6 +46,7 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
private Context context; private Context context;
private LifecycleOwner owner; private LifecycleOwner owner;
private LayoutInflater inflater; private LayoutInflater inflater;
private boolean nav_count;
private int colorUnread; private int colorUnread;
private int colorControlNormal; private int colorControlNormal;
@ -101,9 +102,8 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
ivBadge.setVisibility(count == null || count == 0 || expanded ivBadge.setVisibility(count == null || count == 0 || expanded
? View.GONE : View.VISIBLE); ? View.GONE : View.VISIBLE);
tvCount.setText(Helper.formatNumber(count, 99, NF));
tvCount.setText(count == null ? null : (count < 100 ? Integer.toString(count) : "99+")); tvCount.setVisibility(count == null || count == 0 || expanded || !nav_count
tvCount.setVisibility(count == null || count == 0 || expanded || !menu.getExtraCount()
? View.GONE : View.VISIBLE); ? View.GONE : View.VISIBLE);
if (count == null) if (count == null)
@ -152,6 +152,7 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
this.inflater = LayoutInflater.from(context); this.inflater = LayoutInflater.from(context);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
this.nav_count = prefs.getBoolean("nav_count", false);
boolean highlight_unread = prefs.getBoolean("highlight_unread", true); boolean highlight_unread = prefs.getBoolean("highlight_unread", true);
int colorHighlight = prefs.getInt("highlight_color", Helper.resolveColor(context, R.attr.colorUnreadHighlight)); int colorHighlight = prefs.getInt("highlight_color", Helper.resolveColor(context, R.attr.colorUnreadHighlight));
this.colorUnread = (highlight_unread ? colorHighlight : Helper.resolveColor(context, R.attr.colorUnread)); this.colorUnread = (highlight_unread ? colorHighlight : Helper.resolveColor(context, R.attr.colorUnread));

@ -105,7 +105,7 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
else else
ivItem.clearColorFilter(); ivItem.clearColorFilter();
long count; int count;
if (EntityFolder.OUTBOX.equals(folder.type) || if (EntityFolder.OUTBOX.equals(folder.type) ||
(!nav_unseen_drafts && EntityFolder.DRAFTS.equals(folder.type))) (!nav_unseen_drafts && EntityFolder.DRAFTS.equals(folder.type)))
count = folder.messages; count = folder.messages;
@ -113,7 +113,9 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
count = folder.unseen; count = folder.unseen;
ivBadge.setVisibility(count == 0 || expanded ? View.GONE : View.VISIBLE); ivBadge.setVisibility(count == 0 || expanded ? View.GONE : View.VISIBLE);
tvCount.setVisibility(View.GONE);
tvCount.setText(Helper.formatNumber(count, 99, NF));
tvCount.setVisibility(count == 0 || expanded || !nav_count ? View.GONE : View.VISIBLE);
if (count == 0) if (count == 0)
tvItem.setText(EntityFolder.localizeType(context, folder.type)); tvItem.setText(EntityFolder.localizeType(context, folder.type));

@ -133,6 +133,7 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -1523,6 +1524,12 @@ public class Helper {
return DateUtils.getRelativeTimeSpanString(context, millis); return DateUtils.getRelativeTimeSpanString(context, millis);
} }
static String formatNumber(Integer number, long max, NumberFormat nf) {
if (number == null)
return null;
return nf.format(Math.min(number, max)) + (number > max ? "+" : "");
}
static void linkPro(final TextView tv) { static void linkPro(final TextView tv) {
if (ActivityBilling.isPro(tv.getContext()) && !BuildConfig.DEBUG) if (ActivityBilling.isPro(tv.getContext()) && !BuildConfig.DEBUG)
hide(tv); hide(tv);

@ -28,7 +28,6 @@ public class NavMenuItem {
private String subtitle = null; private String subtitle = null;
private int extra_icon; private int extra_icon;
private Integer count = null; private Integer count = null;
private boolean extra_count = false;
private boolean warning = false; private boolean warning = false;
private boolean separated = false; private boolean separated = false;
private Runnable click; private Runnable click;
@ -68,11 +67,6 @@ public class NavMenuItem {
this.count = count; this.count = count;
} }
NavMenuItem setExtraCount(boolean value) {
this.extra_count = value;
return this;
}
NavMenuItem setExternal(boolean external) { NavMenuItem setExternal(boolean external) {
setExtraIcon(external ? R.drawable.twotone_open_in_new_24 : 0); setExtraIcon(external ? R.drawable.twotone_open_in_new_24 : 0);
return this; return this;
@ -112,10 +106,6 @@ public class NavMenuItem {
return this.count; return this.count;
} }
boolean getExtraCount() {
return this.extra_count;
}
boolean isSeparated() { boolean isSeparated() {
return this.separated; return this.separated;
} }
@ -153,7 +143,6 @@ public class NavMenuItem {
Objects.equals(this.subtitle, other.subtitle) && Objects.equals(this.subtitle, other.subtitle) &&
this.extra_icon == other.extra_icon && this.extra_icon == other.extra_icon &&
Objects.equals(this.count, other.count) && Objects.equals(this.count, other.count) &&
this.extra_count == other.extra_count &&
this.warning == other.warning && this.warning == other.warning &&
this.separated == other.separated); this.separated == other.separated);
} else } else
@ -162,6 +151,6 @@ public class NavMenuItem {
@Override @Override
public int hashCode() { public int hashCode() {
return Objects.hash(icon, color, title, subtitle, extra_icon, count, extra_count, warning, separated); return Objects.hash(icon, color, title, subtitle, extra_icon, count, warning, separated);
} }
} }

@ -148,7 +148,7 @@ public class Widget extends AppWidgetProvider {
} }
// Set count // Set count
views.setTextViewText(R.id.tvCount, unseen < 100 ? nf.format(unseen) : "99+"); views.setTextViewText(R.id.tvCount, Helper.formatNumber(unseen, 99, nf));
views.setViewVisibility(R.id.tvCount, layout == 1 && unseen == 0 ? View.GONE : View.VISIBLE); views.setViewVisibility(R.id.tvCount, layout == 1 && unseen == 0 ? View.GONE : View.VISIBLE);
// Set account name // Set account name

Loading…
Cancel
Save