Show target language flags

This commit is contained in:
M66B 2021-06-29 17:02:55 +02:00
parent 21f7b95f4f
commit e26963f9be
3 changed files with 37 additions and 17 deletions

View File

@ -39,6 +39,7 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.Paint;
@ -6669,7 +6670,39 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
final ContentLoadingProgressBar pbWait = view.findViewById(R.id.pbWait);
List<DeepL.Language> languages = DeepL.getTargetLanguages(context);
ArrayAdapter<DeepL.Language> adapter = new ArrayAdapter<>(context, android.R.layout.simple_spinner_item, android.R.id.text1, languages);
ArrayAdapter<DeepL.Language> adapter = new ArrayAdapter<DeepL.Language>(context, android.R.layout.simple_spinner_item, android.R.id.text1, languages) {
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
return _getView(position, super.getView(position, convertView, parent));
}
@Override
public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
return _getView(position, super.getDropDownView(position, convertView, parent));
}
private View _getView(int position, View view) {
DeepL.Language language = getItem(position);
if (language != null) {
TextView tv = view.findViewById(android.R.id.text1);
Resources res = context.getResources();
Drawable icon = res.getDrawable(language.icon);
int iconSize = res.getDimensionPixelSize(R.dimen.menu_item_icon_size);
icon.setBounds(0, 0, iconSize, iconSize);
ImageSpan imageSpan = new CenteredImageSpan(icon);
SpannableStringBuilder ssb = new SpannableStringBuilder(language.name);
ssb.insert(0, "\uFFFC\u2002"); // object replacement character, en space
ssb.setSpan(imageSpan, 0, 1, 0);
tv.setText(ssb);
}
return view;
}
};
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spLanguage.setAdapter(adapter);

View File

@ -121,7 +121,7 @@ public class DeepL {
int freq1 = frequencies.get(l1.target);
int freq2 = frequencies.get(l2.target);
if (freq1 == freq2)
if (freq1 == freq2 || !BuildConfig.DEBUG)
return collator.compare(l1.name, l2.name);
else
return -Integer.compare(freq1, freq2);

View File

@ -16,7 +16,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:labelFor="@+id/etKeyword"
android:text="@string/title_translate"
android:text="@string/title_translate_tap"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
@ -30,19 +30,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTitle" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvUsage"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_translate_tap"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:textColorPrimary"
android:textStyle="bold|italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spLanguage" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvText"
android:layout_width="0dp"
@ -53,7 +40,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvUsage" />
app:layout_constraintTop_toBottomOf="@id/spLanguage" />
<eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbWait"