diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 4dcd0338a5..80d3d3fb3d 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -6731,7 +6731,7 @@ public class AdapterMessage extends RecyclerView.Adapter languages = DeepL.getTargetLanguages(context); + List languages = DeepL.getTargetLanguages(context, false); ArrayAdapter adapter = new ArrayAdapter(context, android.R.layout.simple_spinner_item, android.R.id.text1, languages) { @NonNull @Override diff --git a/app/src/main/java/eu/faircode/email/DeepL.java b/app/src/main/java/eu/faircode/email/DeepL.java index 3a81a90282..fd2740b0fe 100644 --- a/app/src/main/java/eu/faircode/email/DeepL.java +++ b/app/src/main/java/eu/faircode/email/DeepL.java @@ -86,7 +86,7 @@ public class DeepL { return !TextUtils.isEmpty(deepl_key); } - public static List getTargetLanguages(Context context) { + public static List getTargetLanguages(Context context, boolean favorites) { try { ensureLanguages(context); @@ -106,13 +106,13 @@ public class DeepL { name = locale.getDisplayName(); int frequency = prefs.getInt("translated_" + target, 0); - if (BuildConfig.DEBUG && frequency > 0) - name += " ★"; String resname = "language_" + target.toLowerCase().replace('-', '_'); int resid = res.getIdentifier(resname, "drawable", pkg); - languages.add(new Language(name, target, resid == 0 ? null : resid)); + languages.add(new Language(name, target, + resid == 0 ? null : resid, + favorites && frequency > 0)); frequencies.put(target, frequency); } @@ -124,7 +124,7 @@ public class DeepL { int freq1 = frequencies.get(l1.target); int freq2 = frequencies.get(l2.target); - if (freq1 == freq2 || !BuildConfig.DEBUG) + if (freq1 == freq2 || !favorites) return collator.compare(l1.name, l2.name); else return -Integer.compare(freq1, freq2); @@ -290,11 +290,13 @@ public class DeepL { public String name; public String target; public Integer icon; + public boolean favorite; - private Language(String name, String target, Integer icon) { + private Language(String name, String target, Integer icon, boolean favorit) { this.name = name; this.target = target; this.icon = icon; + this.favorite = favorit; } @Override diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index ef00d4960f..db5a8ae603 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -114,6 +114,7 @@ import androidx.appcompat.widget.PopupMenu; import androidx.appcompat.widget.SwitchCompat; import androidx.constraintlayout.widget.Group; import androidx.core.content.FileProvider; +import androidx.core.view.MenuCompat; import androidx.core.view.WindowInsetsCompat; import androidx.cursoradapter.widget.SimpleCursorAdapter; import androidx.documentfile.provider.DocumentFile; @@ -2043,7 +2044,8 @@ public class FragmentCompose extends FragmentBase { private void onTranslate(View anchor) { final Context context = anchor.getContext(); - List languages = DeepL.getTargetLanguages(context); + boolean grouped = BuildConfig.DEBUG; + List languages = DeepL.getTargetLanguages(context, grouped); if (languages == null) languages = new ArrayList<>(); @@ -2056,13 +2058,17 @@ public class FragmentCompose extends FragmentBase { for (int i = 0; i < languages.size(); i++) { DeepL.Language lang = languages.get(i); - MenuItem item = popupMenu.getMenu().add(Menu.NONE, i + 2, i + 2, lang.name) + MenuItem item = popupMenu.getMenu() + .add(lang.favorite ? Menu.FIRST : Menu.NONE, i + 2, i + 2, lang.name) .setIntent(new Intent().putExtra("target", lang.target)); if (lang.icon != null) item.setIcon(lang.icon); item.setEnabled(canTranslate); } + if (grouped) + MenuCompat.setGroupDividerEnabled(popupMenu.getMenu(), true); + popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) {