Added option to show video thumbnails

pull/214/head
M66B 10 months ago
parent 74eef877d5
commit 725727af86

@ -28,11 +28,13 @@ import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.pdf.PdfRenderer; import android.graphics.pdf.PdfRenderer;
import android.media.ThumbnailUtils;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Size;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -144,6 +146,11 @@ public class AdapterMedia extends RecyclerView.Adapter<AdapterMedia.ViewHolder>
Log.w(ex); Log.w(ex);
return null; 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 { } else {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean webp = prefs.getBoolean("webp", true); boolean webp = prefs.getBoolean("webp", true);

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

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

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

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

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

@ -637,6 +637,7 @@
<string name="title_advanced_attachments_alt">Show attachments after the message text</string> <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_thumbnails">Show image thumbnails after the message text</string>
<string name="title_advanced_pdf_preview">Show PDF thumbnails</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_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_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> <string name="title_advanced_editor_text_zoom">Zoom message text also in the message editor</string>

Loading…
Cancel
Save