Language frequencies

This commit is contained in:
M66B 2022-02-24 10:20:53 +01:00
parent 7f2661502b
commit e4d00f9056
2 changed files with 17 additions and 4 deletions

View File

@ -115,7 +115,7 @@ public class DeepL {
languages.add(new Language(name, target, formality,
resid == 0 ? null : resid,
favorites && frequency > 0));
favorites && frequency > 0, frequency));
frequencies.put(target, frequency);
}
@ -312,13 +312,15 @@ public class DeepL {
public boolean formality;
public Integer icon;
public boolean favorite;
public int frequency;
private Language(String name, String target, boolean formality, Integer icon, boolean favorit) {
private Language(String name, String target, boolean formality, Integer icon, boolean favorite, int frequency) {
this.name = name;
this.target = target;
this.formality = formality;
this.icon = icon;
this.favorite = favorit;
this.favorite = favorite;
this.frequency = frequency;
}
@Override

View File

@ -2053,10 +2053,21 @@ public class FragmentCompose extends FragmentBase {
popupMenu.getMenu().add(Menu.NONE, 1, 1, R.string.title_translate_configure);
NumberFormat NF = NumberFormat.getNumberInstance();
for (int i = 0; i < languages.size(); i++) {
DeepL.Language lang = languages.get(i);
SpannableStringBuilder ssb = new SpannableStringBuilderEx(lang.name);
if (grouped && lang.frequency > 0) {
int start = ssb.length();
ssb.append(" (").append(NF.format(lang.frequency)).append(")");
ssb.setSpan(new RelativeSizeSpan(HtmlHelper.FONT_SMALL),
start, ssb.length(), 0);
}
MenuItem item = popupMenu.getMenu()
.add(lang.favorite ? Menu.FIRST : Menu.NONE, i + 2, i + 2, lang.name)
.add(lang.favorite ? Menu.FIRST : Menu.NONE, i + 2, i + 2, ssb)
.setIntent(new Intent().putExtra("target", lang.target));
if (lang.icon != null)
item.setIcon(lang.icon);