Added option to sort answers by frequency of use

This commit is contained in:
M66B 2022-03-10 09:12:59 +01:00
parent 688dbe7736
commit bca13b5156
7 changed files with 37 additions and 8 deletions

View File

@ -8,6 +8,7 @@
* Enabled [sqlite analyze](https://sqlite.org/lang_analyze.html)
* Added [linear back-off scheme](https://github.com/M66B/FairEmail/blob/master/FAQ.md#user-content-faq123)
* Added option to sort reply templates by frequency of use
* Small improvements and minor bug fixes
* Updated translations

View File

@ -8,6 +8,7 @@
* Enabled [sqlite analyze](https://sqlite.org/lang_analyze.html)
* Added [linear back-off scheme](https://github.com/M66B/FairEmail/blob/master/FAQ.md#user-content-faq123)
* Added option to sort reply templates by frequency of use
* Small improvements and minor bug fixes
* Updated translations

View File

@ -21,6 +21,7 @@ package eu.faircode.email;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
@ -37,6 +38,7 @@ import android.view.SubMenu;
import androidx.annotation.NonNull;
import androidx.core.view.MenuCompat;
import androidx.preference.PreferenceManager;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
@ -164,7 +166,8 @@ public class EntityAnswer implements Serializable {
}
static void fillMenu(Menu main, boolean compose, List<EntityAnswer> answers, Context context) {
boolean grouped = BuildConfig.DEBUG;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean sort_answers = prefs.getBoolean("sort_answers", false);
int iconSize = context.getResources().getDimensionPixelSize(R.dimen.menu_item_icon_size);
NumberFormat NF = NumberFormat.getNumberInstance();
@ -190,7 +193,7 @@ public class EntityAnswer implements Serializable {
public int compare(String g1, String g2) {
Integer a1 = groupApplied.get(g1);
Integer a2 = groupApplied.get(g2);
if (!grouped || a1.equals(a2))
if (!sort_answers || a1.equals(a2))
return collator.compare(g1, g2);
else
return -a1.compareTo(a2);
@ -200,7 +203,7 @@ public class EntityAnswer implements Serializable {
Collections.sort(answers, new Comparator<EntityAnswer>() {
@Override
public int compare(EntityAnswer a1, EntityAnswer a2) {
if (!grouped || a1.applied.equals(a2.applied))
if (!sort_answers || a1.applied.equals(a2.applied))
return collator.compare(a1.name, a2.name);
else
return -a1.applied.compareTo(a2.applied);
@ -221,7 +224,7 @@ public class EntityAnswer implements Serializable {
SpannableStringBuilder ssb = new SpannableStringBuilderEx(group);
int total = groupApplied.get(group);
if (grouped && total > 0) {
if (sort_answers && total > 0) {
int start = ssb.length();
ssb.append(" (").append(NF.format(total)).append(")");
ssb.setSpan(new RelativeSizeSpan(HtmlHelper.FONT_SMALL),
@ -247,7 +250,7 @@ public class EntityAnswer implements Serializable {
ssb.setSpan(imageSpan, 0, 1, 0);
}
if (grouped && answer.applied > 0) {
if (sort_answers && answer.applied > 0) {
int start = ssb.length();
ssb.append(" (").append(NF.format(answer.applied)).append(")");
ssb.setSpan(new RelativeSizeSpan(HtmlHelper.FONT_SMALL),
@ -349,7 +352,7 @@ public class EntityAnswer implements Serializable {
.setIntent(new Intent().putExtra("id", answer.id));
}
if (grouped)
if (sort_answers)
MenuCompat.setGroupDividerEnabled(main, true);
}

View File

@ -93,6 +93,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private SwitchCompat swPowerMenu;
private SwitchCompat swExternalSearch;
private SwitchCompat swSortAnswers;
private SwitchCompat swExternalAnswer;
private SwitchCompat swShortcuts;
private SwitchCompat swFts;
@ -192,7 +193,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
private final static long MIN_FILE_SIZE = 1024 * 1024L;
private final static String[] RESET_OPTIONS = new String[]{
"shortcuts", "fts",
"sort_answers", "shortcuts", "fts",
"classification", "class_min_probability", "class_min_difference",
"language", "deepl_enabled", "watchdog",
"updates", "weekly", "show_changelog",
@ -250,6 +251,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
swPowerMenu = view.findViewById(R.id.swPowerMenu);
swExternalSearch = view.findViewById(R.id.swExternalSearch);
swSortAnswers = view.findViewById(R.id.swSortAnswers);
swExternalAnswer = view.findViewById(R.id.swExternalAnswer);
swShortcuts = view.findViewById(R.id.swShortcuts);
swFts = view.findViewById(R.id.swFts);
@ -365,6 +367,13 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
}
});
swSortAnswers.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("sort_answers", checked).apply();
}
});
swExternalAnswer.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -1558,6 +1567,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
swSortAnswers.setChecked(prefs.getBoolean("sort_answers", false));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
swPowerMenu.setChecked(Helper.isComponentEnabled(getContext(), ServicePowerControl.class));
swExternalSearch.setChecked(Helper.isComponentEnabled(getContext(), ActivitySearch.class));

View File

@ -85,6 +85,18 @@
app:layout_constraintTop_toBottomOf="@id/swPowerMenu"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swSortAnswers"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:tag="nosuggest"
android:text="@string/title_advanced_sort_answers"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swExternalSearch"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swExternalAnswer"
android:layout_width="0dp"
@ -94,7 +106,7 @@
android:text="@string/title_advanced_external_answer"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swExternalSearch"
app:layout_constraintTop_toBottomOf="@id/swSortAnswers"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

View File

@ -671,6 +671,7 @@
<string name="title_advanced_power_menu">Add actions to the Android power menu</string>
<string name="title_advanced_external_search">Allow other apps to search in messages</string>
<string name="title_advanced_sort_answers">Sort reply templates by frequency of use</string>
<string name="title_advanced_external_answer" translatable="false">Provide reply templates to other apps</string>
<string name="title_advanced_shortcuts">Show frequently used contacts in Android share menu</string>
<string name="title_advanced_fts">Build search index</string>

View File

@ -8,6 +8,7 @@
* Enabled [sqlite analyze](https://sqlite.org/lang_analyze.html)
* Added [linear back-off scheme](https://github.com/M66B/FairEmail/blob/master/FAQ.md#user-content-faq123)
* Added option to sort reply templates by frequency of use
* Small improvements and minor bug fixes
* Updated translations