1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-27 02:07:12 +00:00

Added option to show catergory in nav menu

This commit is contained in:
M66B 2022-03-24 17:29:40 +01:00
parent 1962b88d8d
commit 78c676b873
6 changed files with 93 additions and 63 deletions

View file

@ -223,6 +223,7 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
" portrait rows=" + portrait2 + " cols=" + portrait2c + " min=" + portrait_min_size +
" landscape cols=" + landscape + " min=" + landscape);
boolean duo = Helper.isSurfaceDuo();
boolean nav_categories = prefs.getBoolean("nav_categories", false);
// 1=small, 2=normal, 3=large, 4=xlarge
if (layout > 0)
@ -459,70 +460,72 @@ public class ActivityView extends ActivityBilling implements FragmentManager.OnB
adapterNavAccount = new AdapterNavAccountFolder(this, this);
rvAccount.setAdapter(adapterNavAccount);
LayoutInflater inflater = LayoutInflater.from(this);
DividerItemDecoration categoryDecorator = new DividerItemDecoration(this, llmAccounts.getOrientation()) {
@Override
public void onDraw(@NonNull Canvas canvas, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
int count = parent.getChildCount();
for (int i = 0; i < count; i++) {
View view = parent.getChildAt(i);
int pos = parent.getChildAdapterPosition(view);
if (nav_categories) {
LayoutInflater inflater = LayoutInflater.from(this);
DividerItemDecoration categoryDecorator = new DividerItemDecoration(this, llmAccounts.getOrientation()) {
@Override
public void onDraw(@NonNull Canvas canvas, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
int count = parent.getChildCount();
for (int i = 0; i < count; i++) {
View view = parent.getChildAt(i);
int pos = parent.getChildAdapterPosition(view);
View header = getView(view, parent, pos);
if (header != null) {
canvas.save();
canvas.translate(0, parent.getChildAt(i).getTop() - header.getMeasuredHeight());
header.draw(canvas);
canvas.restore();
View header = getView(view, parent, pos);
if (header != null) {
canvas.save();
canvas.translate(0, parent.getChildAt(i).getTop() - header.getMeasuredHeight());
header.draw(canvas);
canvas.restore();
}
}
}
}
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int pos = parent.getChildAdapterPosition(view);
View header = getView(view, parent, pos);
if (header == null)
outRect.setEmpty();
else
outRect.top = header.getMeasuredHeight();
}
private View getView(View view, RecyclerView parent, int pos) {
if (pos == NO_POSITION)
return null;
if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
return null;
TupleAccountFolder prev = adapterNavAccount.getItemAtPosition(pos - 1);
TupleAccountFolder account = adapterNavAccount.getItemAtPosition(pos);
if (pos > 0 && prev == null)
return null;
if (account == null)
return null;
if (pos > 0) {
if (Objects.equals(prev.category, account.category))
return null;
} else {
if (account.category == null)
return null;
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int pos = parent.getChildAdapterPosition(view);
View header = getView(view, parent, pos);
if (header == null)
outRect.setEmpty();
else
outRect.top = header.getMeasuredHeight();
}
View header = inflater.inflate(R.layout.item_nav_group, parent, false);
TextView tvCategory = header.findViewById(R.id.tvCategory);
private View getView(View view, RecyclerView parent, int pos) {
if (pos == NO_POSITION)
return null;
tvCategory.setText(account.category);
if (!getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.STARTED))
return null;
header.measure(View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
TupleAccountFolder prev = adapterNavAccount.getItemAtPosition(pos - 1);
TupleAccountFolder account = adapterNavAccount.getItemAtPosition(pos);
if (pos > 0 && prev == null)
return null;
if (account == null)
return null;
return header;
}
};
rvAccount.addItemDecoration(categoryDecorator);
if (pos > 0) {
if (Objects.equals(prev.category, account.category))
return null;
} else {
if (account.category == null)
return null;
}
View header = inflater.inflate(R.layout.item_nav_group, parent, false);
TextView tvCategory = header.findViewById(R.id.tvCategory);
tvCategory.setText(account.category);
header.measure(View.MeasureSpec.makeMeasureSpec(parent.getWidth(), View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight());
return header;
}
};
rvAccount.addItemDecoration(categoryDecorator);
}
boolean nav_account = prefs.getBoolean("nav_account", true);
boolean nav_folder = prefs.getBoolean("nav_folder", true);

View file

@ -59,6 +59,8 @@ public class AdapterNavAccountFolder extends RecyclerView.Adapter<AdapterNavAcco
private boolean nav_count;
private boolean nav_count_pinned;
private boolean nav_categories;
private int dp6;
private int dp12;
@ -273,6 +275,7 @@ public class AdapterNavAccountFolder extends RecyclerView.Adapter<AdapterNavAcco
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
this.nav_count = prefs.getBoolean("nav_count", false);
this.nav_count_pinned = prefs.getBoolean("nav_count_pinned", false);
this.nav_categories = prefs.getBoolean("nav_categories", false);
boolean highlight_unread = prefs.getBoolean("highlight_unread", true);
int colorHighlight = prefs.getInt("highlight_color", Helper.resolveColor(context, R.attr.colorUnreadHighlight));
@ -309,11 +312,13 @@ public class AdapterNavAccountFolder extends RecyclerView.Adapter<AdapterNavAcco
if (p != 0)
return p;
int c = collator.compare(
a1.category == null ? "" : a1.category,
a2.category == null ? "" : a2.category);
if (c != 0)
return c;
if (nav_categories) {
int c = collator.compare(
a1.category == null ? "" : a1.category,
a2.category == null ? "" : a2.category);
if (c != 0)
return c;
}
int n = collator.compare(a1.name, a2.name);
if (n != 0)

View file

@ -135,7 +135,7 @@ public class FragmentOptions extends FragmentBase {
"cards", "beige", "tabular_card_bg", "shadow_unread", "shadow_highlight", "dividers",
"portrait2", "portrait2c", "portrait_min_size", "landscape", "landscape_min_size",
"column_width",
"nav_count", "nav_unseen_drafts", "nav_count_pinned", "navbar_colorize",
"nav_categories", "nav_count", "nav_unseen_drafts", "nav_count_pinned", "navbar_colorize",
"indentation", "date", "date_fixed", "date_bold", "threading", "threading_unread",
"highlight_unread", "highlight_color", "color_stripe", "color_stripe_wide",
"avatars", "bimi", "gravatars", "favicons", "generated_icons", "identicons", "circular", "saturation", "brightness", "threshold",

View file

@ -84,6 +84,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
private TextView tvColumnWidth;
private SeekBar sbColumnWidth;
private SwitchCompat swNavOptions;
private SwitchCompat swNavCategories;
private SwitchCompat swNavMessageCount;
private SwitchCompat swNavUnseenDrafts;
private SwitchCompat swNavPinnedCount;
@ -187,7 +188,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
"cards", "beige", "tabular_card_bg", "shadow_unread", "shadow_highlight", "dividers",
"date", "date_fixed", "date_bold",
"portrait2", "portrait2c", "landscape", "close_pane", "column_width",
"nav_options", "nav_count", "nav_unseen_drafts", "nav_count_pinned", "navbar_colorize",
"nav_options", "nav_categories", "nav_count", "nav_unseen_drafts", "nav_count_pinned", "navbar_colorize",
"threading", "threading_unread", "indentation", "seekbar", "actionbar", "actionbar_color",
"highlight_unread", "highlight_color", "color_stripe", "color_stripe_wide",
"avatars", "bimi", "gravatars", "libravatars", "favicons", "favicons_partial", "generated_icons", "identicons",
@ -237,6 +238,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
tvColumnWidth = view.findViewById(R.id.tvColumnWidth);
sbColumnWidth = view.findViewById(R.id.sbColumnWidth);
swNavOptions = view.findViewById(R.id.swNavOptions);
swNavCategories = view.findViewById(R.id.swNavCategories);
swNavMessageCount = view.findViewById(R.id.swNavMessageCount);
swNavUnseenDrafts = view.findViewById(R.id.swNavUnseenDrafts);
swNavPinnedCount = view.findViewById(R.id.swNavPinnedCount);
@ -535,6 +537,13 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
}
});
swNavCategories.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("nav_categories", checked).apply();
}
});
swNavMessageCount.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -1307,6 +1316,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
sbColumnWidth.setProgress(column_width);
swNavOptions.setChecked(prefs.getBoolean("nav_options", true));
swNavCategories.setChecked(prefs.getBoolean("nav_categories", false));
swNavMessageCount.setChecked(prefs.getBoolean("nav_count", false));
swNavUnseenDrafts.setChecked(prefs.getBoolean("nav_unseen_drafts", false));
swNavPinnedCount.setChecked(prefs.getBoolean("nav_count_pinned", false));

View file

@ -468,6 +468,17 @@
app:layout_constraintTop_toBottomOf="@id/sbColumnWidth"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swNavCategories"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_nav_categories"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swNavOptions"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swNavMessageCount"
android:layout_width="0dp"
@ -476,7 +487,7 @@
android:text="@string/title_advanced_nav_message_count"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swNavOptions"
app:layout_constraintTop_toBottomOf="@id/swNavCategories"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

View file

@ -448,6 +448,7 @@
<string name="title_advanced_close_pane">Collapse row or column when closing a conversation</string>
<string name="title_advanced_column_width">Message column width: %1$s %%</string>
<string name="title_advanced_nav_options">Show navigation menu options</string>
<string name="title_advanced_nav_categories">Show account categories in the navigation menu</string>
<string name="title_advanced_nav_pin">Pin navigation menu</string>
<string name="title_advanced_nav_hide_title">Hide navigation menu options?</string>
<string name="title_advanced_nav_hide_message">You can enable the options again in the display settings</string>