Added favorite languages menu separator

pull/204/head
M66B 3 years ago
parent f2a9708a90
commit 37db782e3c

@ -6731,7 +6731,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
final TextView tvText = view.findViewById(R.id.tvText);
final ContentLoadingProgressBar pbWait = view.findViewById(R.id.pbWait);
List<DeepL.Language> languages = DeepL.getTargetLanguages(context);
List<DeepL.Language> languages = DeepL.getTargetLanguages(context, false);
ArrayAdapter<DeepL.Language> adapter = new ArrayAdapter<DeepL.Language>(context, android.R.layout.simple_spinner_item, android.R.id.text1, languages) {
@NonNull
@Override

@ -86,7 +86,7 @@ public class DeepL {
return !TextUtils.isEmpty(deepl_key);
}
public static List<Language> getTargetLanguages(Context context) {
public static List<Language> 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

@ -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<DeepL.Language> languages = DeepL.getTargetLanguages(context);
boolean grouped = BuildConfig.DEBUG;
List<DeepL.Language> 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) {

Loading…
Cancel
Save