Added show AMP button

pull/194/merge
M66B 3 years ago
parent da31e71d57
commit 34af1b4e72

@ -63,7 +63,6 @@ public class ActivityAMP extends ActivityBase {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeAsUpIndicator(R.drawable.twotone_bolt_24);
getSupportActionBar().setSubtitle("AMP");
View view = LayoutInflater.from(this).inflate(R.layout.activity_amp, null);

@ -421,6 +421,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private View vSeparator;
private ImageButton ibFull;
private ImageButton ibImages;
private ImageButton ibAmp;
private ImageButton ibDecrypt;
private ImageButton ibVerify;
private ImageButton ibUndo;
@ -814,6 +815,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
vSeparator = vsBody.findViewById(R.id.vSeparator);
ibFull = vsBody.findViewById(R.id.ibFull);
ibImages = vsBody.findViewById(R.id.ibImages);
ibAmp = vsBody.findViewById(R.id.ibAmp);
ibDecrypt = vsBody.findViewById(R.id.ibDecrypt);
ibVerify = vsBody.findViewById(R.id.ibVerify);
ibUndo = vsBody.findViewById(R.id.ibUndo);
@ -938,6 +940,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibFull.setOnClickListener(this);
ibFull.setOnLongClickListener(this);
ibImages.setOnClickListener(this);
ibAmp.setOnClickListener(this);
ibDecrypt.setOnClickListener(this);
ibVerify.setOnClickListener(this);
ibUndo.setOnClickListener(this);
@ -1044,6 +1047,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibFull.setOnClickListener(null);
ibFull.setOnLongClickListener(null);
ibImages.setOnClickListener(null);
ibAmp.setOnClickListener(null);
ibDecrypt.setOnClickListener(null);
ibVerify.setOnClickListener(null);
ibUndo.setOnClickListener(null);
@ -1593,6 +1597,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
vSeparator.setVisibility(View.GONE);
ibFull.setVisibility(View.GONE);
ibImages.setVisibility(View.GONE);
ibAmp.setVisibility(View.GONE);
ibDecrypt.setVisibility(View.GONE);
ibVerify.setVisibility(View.GONE);
ibUndo.setVisibility(View.GONE);
@ -1831,6 +1836,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibFull.setEnabled(false);
ibFull.setVisibility(View.VISIBLE);
ibImages.setVisibility(View.INVISIBLE);
ibAmp.setVisibility(View.GONE);
ibDecrypt.setVisibility(View.GONE);
ibVerify.setVisibility(View.GONE);
ibUndo.setVisibility(View.GONE);
@ -2666,6 +2672,15 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
db.endTransaction();
}
// Check for AMP
boolean has_amp = false;
for (EntityAttachment attachment : attachments)
if ("text/x-amp-html".equals(attachment.type)) {
has_amp = true;
break;
}
args.putBoolean("has_amp", has_amp);
// Format message
if (show_full) {
if (HtmlHelper.truncate(document, HtmlHelper.MAX_FULL_TEXT_SIZE))
@ -2797,6 +2812,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
(EntityMessage.SMIME_SIGNENCRYPT.equals(message.ui_encrypt) &&
!EntityMessage.SMIME_SIGNENCRYPT.equals(message.encrypt));
// Show AMP
ibAmp.setVisibility(args.getBoolean("has_amp") ? View.VISIBLE : View.GONE);
// Show encrypt actions
ibVerify.setVisibility(verifyable ? View.VISIBLE : View.GONE);
ibDecrypt.setImageResource(unlocked
@ -3025,6 +3043,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
List<EntityAttachment> a = new ArrayList<>();
for (EntityAttachment attachment : attachments) {
boolean inline = (attachment.isEncryption() ||
"text/x-amp-html".equals(attachment.type) ||
(attachment.isInline() && attachment.isImage()));
if (inline && attachment.available)
has_inline = true;
@ -3570,6 +3589,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
onShow(message, true);
} else if (id == R.id.ibImages) {
onShow(message, false);
} else if (id == R.id.ibAmp) {
onShowAmp(message);
} else if (id == R.id.ibDecrypt) {
boolean lock =
(EntityMessage.PGP_SIGNENCRYPT.equals(message.ui_encrypt) &&
@ -4748,6 +4769,42 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}.execute(context, owner, args, "message:full");
}
private void onShowAmp(final TupleMessageEx message) {
Bundle args = new Bundle();
args.putLong("id", message.id);
new SimpleTask<EntityAttachment>() {
@Override
protected EntityAttachment onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
DB db = DB.getInstance(context);
List<EntityAttachment> attachments = db.attachment().getAttachments(id);
if (attachments == null)
return null;
for (EntityAttachment attachment : attachments)
if ("text/x-amp-html".equals(attachment.type))
return attachment;
return null;
}
@Override
protected void onExecuted(Bundle args, EntityAttachment attachment) {
File file = attachment.getFile(context);
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
context.startActivity(new Intent(context, ActivityAMP.class)
.setData(uri));
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "message:amp");
}
private void onActionOpenFull(final TupleMessageEx message) {
boolean open_full_confirmed = prefs.getBoolean("open_full_confirmed", false);
if (open_full_confirmed)

@ -765,7 +765,8 @@
app:layout_constraintBottom_toBottomOf="@+id/tvOriginal"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/tvOriginal"
app:srcCompat="@drawable/twotone_fullscreen_24" />
app:srcCompat="@drawable/twotone_fullscreen_24"
app:tint="?attr/colorAccent" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvOriginal"
@ -788,7 +789,8 @@
app:layout_constraintBottom_toBottomOf="@+id/tvReformatted"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/tvReformatted"
app:srcCompat="@drawable/twotone_fullscreen_exit_24" />
app:srcCompat="@drawable/twotone_fullscreen_exit_24"
app:tint="?attr/colorAccent" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvReformatted"
@ -802,6 +804,30 @@
app:layout_constraintStart_toEndOf="@id/ivReformatted"
app:layout_constraintTop_toBottomOf="@id/tvOriginal" />
<eu.faircode.email.FixedImageView
android:id="@+id/ivAmp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/title_legend_show_amp"
android:padding="12dp"
app:layout_constraintBottom_toBottomOf="@+id/tvAmp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/tvAmp"
app:srcCompat="@drawable/twotone_bolt_24"
app:tint="?attr/colorAccent" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvAmp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="48dp"
android:text="@string/title_legend_show_amp"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/ivAmp"
app:layout_constraintTop_toBottomOf="@id/tvReformatted" />
<eu.faircode.email.FixedImageView
android:id="@+id/ivExternalImage"
android:layout_width="wrap_content"
@ -823,7 +849,7 @@
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/ivExternalImage"
app:layout_constraintTop_toBottomOf="@id/tvReformatted" />
app:layout_constraintTop_toBottomOf="@id/ivAmp" />
<eu.faircode.email.FixedImageView
android:id="@+id/ivEmbeddedImage"

@ -383,7 +383,7 @@
android:scaleType="fitCenter"
android:tooltipText="@string/title_verify"
app:layout_constraintEnd_toStartOf="@+id/ibDecrypt"
app:layout_constraintTop_toBottomOf="@+id/ibFull"
app:layout_constraintTop_toBottomOf="@+id/ibAmp"
app:srcCompat="@drawable/twotone_gesture_24" />
<eu.faircode.email.FixedImageButton
@ -396,9 +396,23 @@
android:scaleType="fitCenter"
android:tooltipText="@string/title_decrypt"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ibFull"
app:layout_constraintTop_toBottomOf="@+id/ibAmp"
app:srcCompat="@drawable/twotone_lock_open_24" />
<eu.faircode.email.FixedImageButton
android:id="@+id/ibAmp"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_legend_show_amp"
android:padding="3dp"
android:scaleType="fitCenter"
android:tooltipText="@string/title_legend_show_amp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/ibFull"
app:srcCompat="@drawable/twotone_bolt_24"
app:tint="?attr/colorAccent" />
<eu.faircode.email.FixedImageButton
android:id="@+id/ibImages"
android:layout_width="36dp"

@ -1688,6 +1688,7 @@
<string name="title_legend_show_unsubscribe">Unsubscribe from list</string>
<string name="title_legend_show_images">Show images</string>
<string name="title_legend_hide_images">Hide images</string>
<string name="title_legend_show_amp">Show AMP variant</string>
<string name="title_legend_show_full">Show original message</string>
<string name="title_legend_show_reformatted">Show reformatted message</string>
<string name="title_legend_edit">Edit</string>

Loading…
Cancel
Save