Added translation for received messages

pull/182/head
M66B 5 years ago
parent cb745e5d69
commit 32a22585b2

@ -410,6 +410,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private ImageButton ibDecrypt;
private ImageButton ibVerify;
private ImageButton ibUndo;
private ImageButton ibTranslate;
private ImageButton ibRule;
private ImageButton ibUnsubscribe;
private ImageButton ibAnswer;
@ -614,6 +615,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibDecrypt = vsBody.findViewById(R.id.ibDecrypt);
ibVerify = vsBody.findViewById(R.id.ibVerify);
ibUndo = vsBody.findViewById(R.id.ibUndo);
ibTranslate = vsBody.findViewById(R.id.ibTranslate);
ibRule = vsBody.findViewById(R.id.ibRule);
ibUnsubscribe = vsBody.findViewById(R.id.ibUnsubscribe);
ibAnswer = vsBody.findViewById(R.id.ibAnswer);
@ -703,6 +705,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibFull.setOnClickListener(this);
ibImages.setOnClickListener(this);
ibTranslate.setOnClickListener(this);
ibRule.setOnClickListener(this);
ibUnsubscribe.setOnClickListener(this);
ibDecrypt.setOnClickListener(this);
@ -792,6 +795,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibFull.setOnClickListener(null);
ibImages.setOnClickListener(null);
ibTranslate.setOnClickListener(null);
ibRule.setOnClickListener(null);
ibUnsubscribe.setOnClickListener(null);
ibDecrypt.setOnClickListener(null);
@ -1265,6 +1269,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibDecrypt.setVisibility(View.GONE);
ibVerify.setVisibility(View.GONE);
ibUndo.setVisibility(View.GONE);
ibTranslate.setVisibility(View.GONE);
ibRule.setVisibility(View.GONE);
ibUnsubscribe.setVisibility(View.GONE);
ibAnswer.setVisibility(View.GONE);
@ -1397,6 +1402,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibDecrypt.setVisibility(View.GONE);
ibVerify.setVisibility(View.GONE);
ibUndo.setVisibility(View.GONE);
ibTranslate.setVisibility(View.GONE);
ibRule.setVisibility(View.GONE);
ibUnsubscribe.setVisibility(View.GONE);
ibAnswer.setVisibility(View.GONE);
@ -1538,9 +1544,12 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
boolean button_unsubscribe = prefs.getBoolean("button_unsubscribe", true);
boolean button_rule = prefs.getBoolean("button_rule", false);
boolean full = properties.getValue("full", message.id);
ibTrash.setTag(delete);
ibUndo.setVisibility(outbox ? View.VISIBLE : View.GONE);
ibTranslate.setVisibility(tools && !full && !outbox ? View.VISIBLE : View.GONE);
ibRule.setVisibility(tools && button_rule && !outbox &&
message.accountProtocol == EntityAccount.TYPE_IMAP ? View.VISIBLE : View.GONE);
ibUnsubscribe.setVisibility(tools && button_unsubscribe && message.unsubscribe != null ? View.VISIBLE : View.GONE);
@ -2725,12 +2734,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
case R.id.ibImages:
onShow(message, false);
break;
case R.id.ibRule:
onMenuCreateRule(message);
break;
case R.id.ibUnsubscribe:
onActionUnsubscribe(message);
break;
case R.id.ibDecrypt:
boolean lock =
(EntityMessage.PGP_SIGNENCRYPT.equals(message.ui_encrypt) &&
@ -2749,6 +2752,15 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
case R.id.ibUndo:
onActionUndo(message);
break;
case R.id.ibTranslate:
onActionTranslate(message);
break;
case R.id.ibRule:
onMenuCreateRule(message);
break;
case R.id.ibUnsubscribe:
onActionUnsubscribe(message);
break;
case R.id.ibAnswer:
onActionAnswer(message, ibAnswer);
break;
@ -3536,7 +3548,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
properties.setHeight(message.id, null);
properties.setPosition(message.id, null);
bindBody(message, false);
setupTools(message, false, true);
}
private void onShowImagesConfirmed(TupleMessageEx message) {
@ -3559,6 +3571,30 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
.putExtra("type", encrypt));
}
private void onActionTranslate(TupleMessageEx message) {
CharSequence seq = (tvBody.hasSelection()
? tvBody.getText().subSequence(tvBody.getSelectionStart(), tvBody.getSelectionEnd())
: tvBody.getText());
FragmentDialogTranslate.Translate(
seq.toString(),
Locale.getDefault().getLanguage(),
new FragmentDialogTranslate.ITranslate() {
@Override
public void onTranslated(String text) {
new AlertDialog.Builder(context)
.setTitle(R.string.title_translate)
.setMessage(text)
.show();
}
@Override
public void onError(Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
});
}
private void onActionAnswer(TupleMessageEx message, View anchor) {
properties.reply(message, getSelectedText(), anchor);
}

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12.87,15.07l-2.54,-2.51 0.03,-0.03c1.74,-1.94 2.98,-4.17 3.71,-6.53L17,6L17,4h-7L10,2L8,2v2L1,4v1.99h11.17C11.5,7.92 10.44,9.75 9,11.35 8.07,10.32 7.3,9.19 6.69,8h-2c0.73,1.63 1.73,3.17 2.98,4.56l-5.09,5.02L4,19l5,-5 3.11,3.11 0.76,-2.04zM18.5,10h-2L12,22h2l1.12,-3h4.75L21,22h2l-4.5,-12zM15.88,17l1.62,-4.33L19.12,17h-3.24z"/>
</vector>

@ -41,7 +41,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="3dp"
app:constraint_referenced_ids="ibMore,ibInbox,ibJunk,ibTrash,ibArchive,ibMove,ibCopy,ibLabels,ibAnswer,ibUnsubscribe,ibRule,ibUndo"
app:constraint_referenced_ids="ibMore,ibInbox,ibJunk,ibTrash,ibArchive,ibMove,ibCopy,ibLabels,ibAnswer,ibUnsubscribe,ibRule,ibTranslate,ibUndo"
app:flow_horizontalBias="0"
app:flow_horizontalGap="3dp"
app:flow_horizontalStyle="packed"
@ -180,6 +180,18 @@
app:srcCompat="@drawable/baseline_rule_24"
tools:ignore="MissingConstraints" />
<ImageButton
android:id="@+id/ibTranslate"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_translate"
android:padding="6dp"
android:scaleType="fitCenter"
android:tooltipText="@string/title_translate"
app:srcCompat="@drawable/baseline_translate_24"
tools:ignore="MissingConstraints" />
<ImageButton
android:id="@+id/ibUndo"
android:layout_width="36dp"

Loading…
Cancel
Save