mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-27 19:35:10 +01:00
Added experimental translate button (debug only)
This commit is contained in:
@@ -239,6 +239,7 @@ public class FragmentCompose extends FragmentBase {
|
||||
private TextView tvDsn;
|
||||
private TextView tvPlainTextOnly;
|
||||
private EditTextCompose etBody;
|
||||
private ImageButton ibTranslate;
|
||||
private TextView tvNoInternet;
|
||||
private TextView tvSignature;
|
||||
private CheckBox cbSignature;
|
||||
@@ -351,6 +352,7 @@ public class FragmentCompose extends FragmentBase {
|
||||
tvDsn = view.findViewById(R.id.tvDsn);
|
||||
tvPlainTextOnly = view.findViewById(R.id.tvPlainTextOnly);
|
||||
etBody = view.findViewById(R.id.etBody);
|
||||
ibTranslate = view.findViewById(R.id.ibTranslate);
|
||||
tvNoInternet = view.findViewById(R.id.tvNoInternet);
|
||||
tvSignature = view.findViewById(R.id.tvSignature);
|
||||
cbSignature = view.findViewById(R.id.cbSignature);
|
||||
@@ -696,6 +698,41 @@ public class FragmentCompose extends FragmentBase {
|
||||
}
|
||||
});
|
||||
|
||||
ibTranslate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (getParagraph() == null)
|
||||
return;
|
||||
|
||||
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(getContext(), getViewLifecycleOwner(), v);
|
||||
|
||||
List<Pair<String, String>> languages = DeepL.getTargetLanguages(getContext());
|
||||
if (languages != null) {
|
||||
String pkg = getContext().getPackageName();
|
||||
for (int i = 0; i < languages.size(); i++) {
|
||||
Pair<String, String> lang = languages.get(i);
|
||||
MenuItem item = popupMenu.getMenu().add(R.id.group_translate, i + 1, i + 1, lang.first)
|
||||
.setIntent(new Intent().putExtra("target", lang.second));
|
||||
|
||||
String resname = "language_" + lang.second.toLowerCase().replace('-', '_');
|
||||
int resid = getResources().getIdentifier(resname, "drawable", pkg);
|
||||
if (resid > 0)
|
||||
item.setIcon(resid);
|
||||
}
|
||||
}
|
||||
|
||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
onMenuTranslate(item.getIntent().getStringExtra("target"));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
popupMenu.showWithIcons(getContext(), v);
|
||||
}
|
||||
});
|
||||
|
||||
tvSignature.setTypeface(monospaced ? Typeface.MONOSPACE : Typeface.DEFAULT);
|
||||
|
||||
cbSignature.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@@ -879,6 +916,7 @@ public class FragmentCompose extends FragmentBase {
|
||||
grpAttachments.setVisibility(View.GONE);
|
||||
tvNoInternet.setVisibility(View.GONE);
|
||||
grpBody.setVisibility(View.GONE);
|
||||
ibTranslate.setVisibility(BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
|
||||
grpSignature.setVisibility(View.GONE);
|
||||
grpReferenceHint.setVisibility(View.GONE);
|
||||
ibReferenceEdit.setVisibility(View.GONE);
|
||||
|
||||
@@ -25,6 +25,7 @@ import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.view.Gravity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.SubMenu;
|
||||
@@ -33,6 +34,8 @@ import android.view.View;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.view.ContextThemeWrapper;
|
||||
import androidx.appcompat.view.menu.MenuBuilder;
|
||||
import androidx.appcompat.view.menu.MenuPopupHelper;
|
||||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
@@ -62,6 +65,13 @@ public class PopupMenuLifecycle extends PopupMenu implements LifecycleObserver {
|
||||
}
|
||||
}
|
||||
|
||||
public void showWithIcons(Context context, View anchor) {
|
||||
MenuPopupHelper menuHelper = new MenuPopupHelper(context, (MenuBuilder) getMenu(), anchor);
|
||||
menuHelper.setForceShowIcon(true);
|
||||
menuHelper.setGravity(Gravity.END);
|
||||
menuHelper.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnMenuItemClickListener(@Nullable OnMenuItemClickListener listener) {
|
||||
super.setOnMenuItemClickListener(new OnMenuItemClickListener() {
|
||||
|
||||
@@ -297,6 +297,17 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvPlainTextOnly" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/ibTranslate"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:padding="12dp"
|
||||
android:tint="?attr/colorSeparator"
|
||||
app:layout_constraintBottom_toBottomOf="@id/vSeparatorBody"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:srcCompat="@drawable/outline_translate_24" />
|
||||
|
||||
<eu.faircode.email.FixedTextView
|
||||
android:id="@+id/tvNoInternet"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
Reference in New Issue
Block a user