add icon for unknown file while keeping 'file' icon for documents

This commit is contained in:
Daniel Gultsch 2018-09-12 22:56:40 +02:00
parent b15777bd3a
commit c795cdb722
13 changed files with 20 additions and 5 deletions

View file

@ -17,6 +17,7 @@ import android.widget.ImageView;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.RejectedExecutionException;
@ -29,6 +30,15 @@ import eu.siacs.conversations.ui.util.StyledAttributes;
public class MediaPreviewAdapter extends RecyclerView.Adapter<MediaPreviewAdapter.MediaPreviewViewHolder> { public class MediaPreviewAdapter extends RecyclerView.Adapter<MediaPreviewAdapter.MediaPreviewViewHolder> {
private static final List<String> DOCUMENT_MIMES = Arrays.asList(
"application/pdf",
"application/vnd.oasis.opendocument.text",
"application/msword",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"text/x-tex",
"text/plain"
);
private final ArrayList<Attachment> mediaPreviews = new ArrayList<>(); private final ArrayList<Attachment> mediaPreviews = new ArrayList<>();
private final ConversationFragment conversationFragment; private final ConversationFragment conversationFragment;
@ -64,7 +74,7 @@ public class MediaPreviewAdapter extends RecyclerView.Adapter<MediaPreviewAdapte
} else { } else {
final String mime = attachment.getMime(); final String mime = attachment.getMime();
if (mime == null) { if (mime == null) {
attr = R.attr.media_preview_file; attr = R.attr.media_preview_unknown;
} else if (mime.startsWith("audio/")) { } else if (mime.startsWith("audio/")) {
attr = R.attr.media_preview_audio; attr = R.attr.media_preview_audio;
} else if (mime.equals("text/calendar") || (mime.equals("text/x-vcalendar"))) { } else if (mime.equals("text/calendar") || (mime.equals("text/x-vcalendar"))) {
@ -75,8 +85,10 @@ public class MediaPreviewAdapter extends RecyclerView.Adapter<MediaPreviewAdapte
attr = R.attr.media_preview_app; attr = R.attr.media_preview_app;
} else if (mime.equals("application/zip") || mime.equals("application/rar")) { } else if (mime.equals("application/zip") || mime.equals("application/rar")) {
attr = R.attr.media_preview_archive; attr = R.attr.media_preview_archive;
} else if (DOCUMENT_MIMES.contains(mime)) {
attr = R.attr.media_preview_document;
} else { } else {
attr = R.attr.media_preview_file; attr = R.attr.media_preview_unknown;
} }
} }
holder.binding.mediaPreview.setImageDrawable(StyledAttributes.getDrawable(context, attr)); holder.binding.mediaPreview.setImageDrawable(StyledAttributes.getDrawable(context, attr));

Binary file not shown.

After

Width:  |  Height:  |  Size: 834 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 842 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 579 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

View file

@ -52,7 +52,7 @@
<attr name="icon_alpha" format="float"/> <attr name="icon_alpha" format="float"/>
<attr name="delete_icon_alpha" format="float"/> <attr name="delete_icon_alpha" format="float"/>
<attr name="media_preview_file" format="reference"/> <attr name="media_preview_document" format="reference"/>
<attr name="media_preview_recording" format="reference"/> <attr name="media_preview_recording" format="reference"/>
<attr name="media_preview_audio" format="reference"/> <attr name="media_preview_audio" format="reference"/>
<attr name="media_preview_location" format="reference"/> <attr name="media_preview_location" format="reference"/>
@ -60,6 +60,7 @@
<attr name="media_preview_app" format="reference"/> <attr name="media_preview_app" format="reference"/>
<attr name="media_preview_calendar" format="reference"/> <attr name="media_preview_calendar" format="reference"/>
<attr name="media_preview_archive" format="reference" /> <attr name="media_preview_archive" format="reference" />
<attr name="media_preview_unknown" format="reference" />
<attr name="icon_add_group" format="reference"/> <attr name="icon_add_group" format="reference"/>

View file

@ -63,7 +63,7 @@
<item name="dialog_horizontal_padding">24dp</item> <item name="dialog_horizontal_padding">24dp</item>
<item name="dialog_vertical_padding">16dp</item> <item name="dialog_vertical_padding">16dp</item>
<item type="reference" name="media_preview_file">@drawable/ic_description_black_48dp</item> <item type="reference" name="media_preview_document">@drawable/ic_description_black_48dp</item>
<item type="reference" name="media_preview_recording">@drawable/ic_mic_black_48dp</item> <item type="reference" name="media_preview_recording">@drawable/ic_mic_black_48dp</item>
<item type="reference" name="media_preview_audio">@drawable/ic_headset_black_48dp</item> <item type="reference" name="media_preview_audio">@drawable/ic_headset_black_48dp</item>
<item type="reference" name="media_preview_location">@drawable/ic_room_black_48dp</item> <item type="reference" name="media_preview_location">@drawable/ic_room_black_48dp</item>
@ -71,6 +71,7 @@
<item type="reference" name="media_preview_app">@drawable/ic_android_black_48dp</item> <item type="reference" name="media_preview_app">@drawable/ic_android_black_48dp</item>
<item type="reference" name="media_preview_calendar">@drawable/ic_event_black_48dp</item> <item type="reference" name="media_preview_calendar">@drawable/ic_event_black_48dp</item>
<item type="reference" name="media_preview_archive">@drawable/ic_archive_black_48dp</item> <item type="reference" name="media_preview_archive">@drawable/ic_archive_black_48dp</item>
<item type="reference" name="media_preview_unknown">@drawable/ic_help_black_48dp</item>
<item type="reference" name="icon_add_group">@drawable/ic_group_add_white_24dp</item> <item type="reference" name="icon_add_group">@drawable/ic_group_add_white_24dp</item>
<item type="reference" name="icon_add_person">@drawable/ic_person_add_white_24dp</item> <item type="reference" name="icon_add_person">@drawable/ic_person_add_white_24dp</item>
@ -173,7 +174,7 @@
<item name="dialog_horizontal_padding">24dp</item> <item name="dialog_horizontal_padding">24dp</item>
<item name="dialog_vertical_padding">16dp</item> <item name="dialog_vertical_padding">16dp</item>
<item type="reference" name="media_preview_file">@drawable/ic_description_white_48dp</item> <item type="reference" name="media_preview_document">@drawable/ic_description_white_48dp</item>
<item type="reference" name="media_preview_recording">@drawable/ic_mic_white_48dp</item> <item type="reference" name="media_preview_recording">@drawable/ic_mic_white_48dp</item>
<item type="reference" name="media_preview_audio">@drawable/ic_headset_white_48dp</item> <item type="reference" name="media_preview_audio">@drawable/ic_headset_white_48dp</item>
<item type="reference" name="media_preview_location">@drawable/ic_room_white_48dp</item> <item type="reference" name="media_preview_location">@drawable/ic_room_white_48dp</item>
@ -181,6 +182,7 @@
<item type="reference" name="media_preview_app">@drawable/ic_android_white_48dp</item> <item type="reference" name="media_preview_app">@drawable/ic_android_white_48dp</item>
<item type="reference" name="media_preview_calendar">@drawable/ic_event_white_48dp</item> <item type="reference" name="media_preview_calendar">@drawable/ic_event_white_48dp</item>
<item type="reference" name="media_preview_archive">@drawable/ic_archive_white_48dp</item> <item type="reference" name="media_preview_archive">@drawable/ic_archive_white_48dp</item>
<item type="reference" name="media_preview_unknown">@drawable/ic_help_white_48dp</item>
<item type="reference" name="icon_add_group">@drawable/ic_group_add_white_24dp</item> <item type="reference" name="icon_add_group">@drawable/ic_group_add_white_24dp</item>
<item type="reference" name="icon_add_person">@drawable/ic_person_add_white_24dp</item> <item type="reference" name="icon_add_person">@drawable/ic_person_add_white_24dp</item>