Added option to show video thumbnails

This commit is contained in:
M66B 2024-01-24 18:10:33 +01:00
parent 74eef877d5
commit 725727af86
7 changed files with 43 additions and 3 deletions

View File

@ -28,11 +28,13 @@ import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.pdf.PdfRenderer;
import android.media.ThumbnailUtils;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.text.TextUtils;
import android.util.Size;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -144,6 +146,11 @@ public class AdapterMedia extends RecyclerView.Adapter<AdapterMedia.ViewHolder>
Log.w(ex);
return null;
}
} else if (type != null && type.startsWith("video/")) {
Bitmap bm = ThumbnailUtils.createVideoThumbnail(file, new Size(max, max), null);
if (bm == null)
return null;
return new BitmapDrawable(context.getResources(), bm);
} else {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean webp = prefs.getBoolean("webp", true);

View File

@ -303,6 +303,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private boolean attachments_alt;
private boolean thumbnails;
private boolean pdf_preview;
private boolean video_preview;
private boolean audio_preview;
private boolean contrast;
private boolean hyphenation;
@ -3687,6 +3688,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (thumbnails && bind_extras) {
for (EntityAttachment attachment : attachments)
if ((pdf_preview && attachment.isPDF()) ||
(video_preview && attachment.isVideo()) ||
(audio_preview && attachment.isAudio()) ||
(attachment.isAttachment() && attachment.isImage())) {
media.add(attachment);
@ -8040,6 +8042,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.attachments_alt = prefs.getBoolean("attachments_alt", false);
this.thumbnails = prefs.getBoolean("thumbnails", true);
this.pdf_preview = prefs.getBoolean("pdf_preview", true);
this.video_preview = prefs.getBoolean("video_preview", false);
this.audio_preview = prefs.getBoolean("audio_preview", false);
this.contrast = prefs.getBoolean("contrast", false);
this.hyphenation = prefs.getBoolean("hyphenation", false);

View File

@ -117,6 +117,11 @@ public class EntityAttachment {
return ImageHelper.isImage(getMimeType());
}
boolean isVideo() {
String type = getMimeType();
return (type != null && type.startsWith("video/"));
}
boolean isAudio() {
String type = getMimeType();
return (type != null && type.startsWith("audio/"));

View File

@ -155,7 +155,7 @@ public class FragmentOptions extends FragmentBase {
"subject_top", "subject_italic", "highlight_subject", "font_size_subject", "subject_ellipsize",
"keywords_header", "labels_header", "flags", "flags_background", "preview", "preview_italic", "preview_lines", "align_header",
"message_zoom", "overview_mode", "addresses", "button_extra", "attachments_alt",
"thumbnails", "pdf_preview", "audio_preview",
"thumbnails", "pdf_preview", "video_preview", "audio_preview",
"contrast", "hyphenation", "display_font", "monospaced_pre",
"list_count", "bundled_fonts", "narrow_fonts", "parse_classes",
"background_color", "text_color", "text_size", "text_font", "text_align", "text_titles", "text_separators",

View File

@ -185,6 +185,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
private SwitchCompat swAttachmentsAlt;
private SwitchCompat swThumbnails;
private SwitchCompat swPdfPreview;
private SwitchCompat swVideoPreview;
private SwitchCompat swAudioPreview;
private SwitchCompat swListCount;
@ -225,7 +226,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
"hyphenation", "display_font", "contrast", "monospaced_pre",
"text_separators",
"collapse_quotes", "image_placeholders", "inline_images", "button_extra",
"unzip", "attachments_alt", "thumbnails", "pdf_preview", "audio_preview",
"unzip", "attachments_alt", "thumbnails", "pdf_preview", "video_preview", "audio_preview",
"list_count", "bundled_fonts", "narrow_fonts", "parse_classes",
"background_color", "text_color", "text_size", "text_font", "text_align", "text_titles",
"authentication", "authentication_indicator"
@ -358,6 +359,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
swAttachmentsAlt = view.findViewById(R.id.swAttachmentsAlt);
swThumbnails = view.findViewById(R.id.swThumbnails);
swPdfPreview = view.findViewById(R.id.swPdfPreview);
swVideoPreview = view.findViewById(R.id.swVideoPreview);
swAudioPreview = view.findViewById(R.id.swAudioPreview);
swListCount = view.findViewById(R.id.swListCount);
@ -1320,6 +1322,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("thumbnails", checked).apply();
swPdfPreview.setEnabled(checked);
swVideoPreview.setEnabled(checked);
swAudioPreview.setEnabled(checked);
}
});
@ -1331,6 +1334,13 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
}
});
swVideoPreview.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("video_preview", checked).apply();
}
});
swAudioPreview.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -1681,6 +1691,8 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
swThumbnails.setChecked(prefs.getBoolean("thumbnails", true));
swPdfPreview.setChecked(prefs.getBoolean("pdf_preview", true));
swPdfPreview.setEnabled(swThumbnails.isChecked());
swVideoPreview.setChecked(prefs.getBoolean("video_preview", false));
swVideoPreview.setEnabled(swThumbnails.isChecked());
swAudioPreview.setChecked(prefs.getBoolean("audio_preview", false));
swAudioPreview.setEnabled(swThumbnails.isChecked());

View File

@ -2047,6 +2047,18 @@
app:layout_constraintTop_toBottomOf="@id/swThumbnails"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swVideoPreview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:text="@string/title_advanced_video_preview"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swPdfPreview"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAudioPreview"
android:layout_width="0dp"
@ -2056,7 +2068,7 @@
android:text="@string/title_advanced_audio_preview"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swPdfPreview"
app:layout_constraintTop_toBottomOf="@id/swVideoPreview"
app:switchPadding="12dp" />
<androidx.constraintlayout.widget.Group

View File

@ -637,6 +637,7 @@
<string name="title_advanced_attachments_alt">Show attachments after the message text</string>
<string name="title_advanced_thumbnails">Show image thumbnails after the message text</string>
<string name="title_advanced_pdf_preview">Show PDF thumbnails</string>
<string name="title_advanced_video_preview">Show video thumbnails</string>
<string name="title_advanced_audio_preview">Show mini audio player</string>
<string name="title_advanced_message_text_zoom2">Default message text zoom: %1$s %%</string>
<string name="title_advanced_editor_text_zoom">Zoom message text also in the message editor</string>