mirror of https://github.com/M66B/FairEmail.git
Generalize pinned nav menu counts
This commit is contained in:
parent
d63ddec037
commit
0e66f97804
|
@ -662,9 +662,6 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
boolean nav_count = prefs.getBoolean("nav_count", false);
|
||||
|
||||
// Fixed menus
|
||||
|
||||
final List<NavMenuItem> menus = new ArrayList<>();
|
||||
|
@ -676,7 +673,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|||
drawerLayout.closeDrawer(drawerContainer);
|
||||
onMenuOperations();
|
||||
}
|
||||
}).setExtraCount(nav_count);
|
||||
});
|
||||
|
||||
menus.add(navOperations);
|
||||
|
||||
|
@ -827,6 +824,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
|
|||
// Live data
|
||||
|
||||
DB db = DB.getInstance(this);
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
db.account().liveAccountFolder().observe(owner, new Observer<List<TupleAccountFolder>>() {
|
||||
@Override
|
||||
|
|
|
@ -142,7 +142,9 @@ public class AdapterNavAccountFolder extends RecyclerView.Adapter<AdapterNavAcco
|
|||
count = account.unseen;
|
||||
|
||||
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);
|
||||
if (color == null || !ActivityBilling.isPro(context))
|
||||
|
|
|
@ -46,6 +46,7 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
|
|||
private Context context;
|
||||
private LifecycleOwner owner;
|
||||
private LayoutInflater inflater;
|
||||
private boolean nav_count;
|
||||
|
||||
private int colorUnread;
|
||||
private int colorControlNormal;
|
||||
|
@ -101,9 +102,8 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
|
|||
ivBadge.setVisibility(count == null || count == 0 || expanded
|
||||
? View.GONE : View.VISIBLE);
|
||||
|
||||
|
||||
tvCount.setText(count == null ? null : (count < 100 ? Integer.toString(count) : "99+"));
|
||||
tvCount.setVisibility(count == null || count == 0 || expanded || !menu.getExtraCount()
|
||||
tvCount.setText(Helper.formatNumber(count, 99, NF));
|
||||
tvCount.setVisibility(count == null || count == 0 || expanded || !nav_count
|
||||
? View.GONE : View.VISIBLE);
|
||||
|
||||
if (count == null)
|
||||
|
@ -152,6 +152,7 @@ public class AdapterNavMenu extends RecyclerView.Adapter<AdapterNavMenu.ViewHold
|
|||
this.inflater = LayoutInflater.from(context);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
this.nav_count = prefs.getBoolean("nav_count", false);
|
||||
boolean highlight_unread = prefs.getBoolean("highlight_unread", true);
|
||||
int colorHighlight = prefs.getInt("highlight_color", Helper.resolveColor(context, R.attr.colorUnreadHighlight));
|
||||
this.colorUnread = (highlight_unread ? colorHighlight : Helper.resolveColor(context, R.attr.colorUnread));
|
||||
|
|
|
@ -105,7 +105,7 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
|
|||
else
|
||||
ivItem.clearColorFilter();
|
||||
|
||||
long count;
|
||||
int count;
|
||||
if (EntityFolder.OUTBOX.equals(folder.type) ||
|
||||
(!nav_unseen_drafts && EntityFolder.DRAFTS.equals(folder.type)))
|
||||
count = folder.messages;
|
||||
|
@ -113,7 +113,9 @@ public class AdapterNavUnified extends RecyclerView.Adapter<AdapterNavUnified.Vi
|
|||
count = folder.unseen;
|
||||
|
||||
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)
|
||||
tvItem.setText(EntityFolder.localizeType(context, folder.type));
|
||||
|
|
|
@ -133,6 +133,7 @@ import java.security.MessageDigest;
|
|||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -1523,6 +1524,12 @@ public class Helper {
|
|||
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) {
|
||||
if (ActivityBilling.isPro(tv.getContext()) && !BuildConfig.DEBUG)
|
||||
hide(tv);
|
||||
|
|
|
@ -28,7 +28,6 @@ public class NavMenuItem {
|
|||
private String subtitle = null;
|
||||
private int extra_icon;
|
||||
private Integer count = null;
|
||||
private boolean extra_count = false;
|
||||
private boolean warning = false;
|
||||
private boolean separated = false;
|
||||
private Runnable click;
|
||||
|
@ -68,11 +67,6 @@ public class NavMenuItem {
|
|||
this.count = count;
|
||||
}
|
||||
|
||||
NavMenuItem setExtraCount(boolean value) {
|
||||
this.extra_count = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
NavMenuItem setExternal(boolean external) {
|
||||
setExtraIcon(external ? R.drawable.twotone_open_in_new_24 : 0);
|
||||
return this;
|
||||
|
@ -112,10 +106,6 @@ public class NavMenuItem {
|
|||
return this.count;
|
||||
}
|
||||
|
||||
boolean getExtraCount() {
|
||||
return this.extra_count;
|
||||
}
|
||||
|
||||
boolean isSeparated() {
|
||||
return this.separated;
|
||||
}
|
||||
|
@ -153,7 +143,6 @@ public class NavMenuItem {
|
|||
Objects.equals(this.subtitle, other.subtitle) &&
|
||||
this.extra_icon == other.extra_icon &&
|
||||
Objects.equals(this.count, other.count) &&
|
||||
this.extra_count == other.extra_count &&
|
||||
this.warning == other.warning &&
|
||||
this.separated == other.separated);
|
||||
} else
|
||||
|
@ -162,6 +151,6 @@ public class NavMenuItem {
|
|||
|
||||
@Override
|
||||
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
|
||||
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);
|
||||
|
||||
// Set account name
|
||||
|
|
Loading…
Reference in New Issue