add icons for gpx files

This commit is contained in:
Daniel Gultsch 2020-07-19 21:27:43 +02:00
parent 32d55346cc
commit 28856aaf9f
17 changed files with 564 additions and 524 deletions

View File

@ -11,6 +11,7 @@ import android.support.annotation.AttrRes;
import android.support.annotation.DimenRes; import android.support.annotation.DimenRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
@ -21,6 +22,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.RejectedExecutionException;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.MediaBinding; import eu.siacs.conversations.databinding.MediaBinding;
import eu.siacs.conversations.services.ExportBackupService; import eu.siacs.conversations.services.ExportBackupService;
@ -51,14 +53,16 @@ public class MediaAdapter extends RecyclerView.Adapter<MediaAdapter.MediaViewHol
this.mediaSize = Math.round(activity.getResources().getDimension(mediaSize)); this.mediaSize = Math.round(activity.getResources().getDimension(mediaSize));
} }
@SuppressWarnings("rawtypes")
public static void setMediaSize(RecyclerView recyclerView, int mediaSize) { public static void setMediaSize(RecyclerView recyclerView, int mediaSize) {
RecyclerView.Adapter adapter = recyclerView.getAdapter(); final RecyclerView.Adapter adapter = recyclerView.getAdapter();
if (adapter instanceof MediaAdapter) { if (adapter instanceof MediaAdapter) {
((MediaAdapter) adapter).setMediaSize(mediaSize); ((MediaAdapter) adapter).setMediaSize(mediaSize);
} }
} }
private static @AttrRes int getImageAttr(Attachment attachment) { private static @AttrRes
int getImageAttr(Attachment attachment) {
final @AttrRes int attr; final @AttrRes int attr;
if (attachment.getType() == Attachment.Type.LOCATION) { if (attachment.getType() == Attachment.Type.LOCATION) {
attr = R.attr.media_preview_location; attr = R.attr.media_preview_location;
@ -66,6 +70,7 @@ public class MediaAdapter extends RecyclerView.Adapter<MediaAdapter.MediaViewHol
attr = R.attr.media_preview_recording; attr = R.attr.media_preview_recording;
} else { } else {
final String mime = attachment.getMime(); final String mime = attachment.getMime();
Log.d(Config.LOGTAG, "mime=" + mime);
if (mime == null) { if (mime == null) {
attr = R.attr.media_preview_unknown; attr = R.attr.media_preview_unknown;
} else if (mime.startsWith("audio/")) { } else if (mime.startsWith("audio/")) {
@ -84,6 +89,8 @@ public class MediaAdapter extends RecyclerView.Adapter<MediaAdapter.MediaViewHol
attr = R.attr.media_preview_backup; attr = R.attr.media_preview_backup;
} else if (DOCUMENT_MIMES.contains(mime)) { } else if (DOCUMENT_MIMES.contains(mime)) {
attr = R.attr.media_preview_document; attr = R.attr.media_preview_document;
} else if (mime.equals("application/gpx+xml")) {
attr = R.attr.media_preview_tour;
} else { } else {
attr = R.attr.media_preview_unknown; attr = R.attr.media_preview_unknown;
} }
@ -155,7 +162,7 @@ public class MediaAdapter extends RecyclerView.Adapter<MediaAdapter.MediaViewHol
private void loadPreview(Attachment attachment, ImageView imageView) { private void loadPreview(Attachment attachment, ImageView imageView) {
if (cancelPotentialWork(attachment, imageView)) { if (cancelPotentialWork(attachment, imageView)) {
final Bitmap bm = activity.xmppConnectionService.getFileBackend().getPreviewForUri(attachment,mediaSize,true); final Bitmap bm = activity.xmppConnectionService.getFileBackend().getPreviewForUri(attachment, mediaSize, true);
if (bm != null) { if (bm != null) {
cancelPotentialWork(attachment, imageView); cancelPotentialWork(attachment, imageView);
imageView.setImageBitmap(bm); imageView.setImageBitmap(bm);

View File

@ -36,6 +36,8 @@ import android.net.Uri;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import com.google.common.base.MoreObjects;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -87,6 +89,16 @@ public class Attachment implements Parcelable {
return type; return type;
} }
@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("uri", uri)
.add("type", type)
.add("uuid", uuid)
.add("mime", mime)
.toString();
}
public enum Type { public enum Type {
FILE, IMAGE, LOCATION, RECORDING FILE, IMAGE, LOCATION, RECORDING
} }

View File

@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package eu.siacs.conversations.utils; package eu.siacs.conversations.utils;
import android.content.Context; import android.content.Context;
import android.net.Uri; import android.net.Uri;
import android.util.Log; import android.util.Log;
@ -38,6 +39,7 @@ import eu.siacs.conversations.services.ExportBackupService;
public final class MimeUtils { public final class MimeUtils {
private static final Map<String, String> mimeTypeToExtensionMap = new HashMap<>(); private static final Map<String, String> mimeTypeToExtensionMap = new HashMap<>();
private static final Map<String, String> extensionToMimeTypeMap = new HashMap<>(); private static final Map<String, String> extensionToMimeTypeMap = new HashMap<>();
static { static {
// The following table is based on /etc/mime.types data minus // The following table is based on /etc/mime.types data minus
// chemical/* MIME types and MIME types that don't map to any // chemical/* MIME types and MIME types that don't map to any
@ -52,7 +54,8 @@ public final class MimeUtils {
// by guessExtensionFromMimeType. // by guessExtensionFromMimeType.
add("application/andrew-inset", "ez"); add("application/andrew-inset", "ez");
add("application/dsptype", "tsp"); add("application/dsptype", "tsp");
add("application/epub+zip","epub"); add("application/epub+zip", "epub");
add("application/gpx+xml", "gpx");
add("application/hta", "hta"); add("application/hta", "hta");
add("application/mac-binhex40", "hqx"); add("application/mac-binhex40", "hqx");
add("application/mathematica", "nb"); add("application/mathematica", "nb");
@ -68,9 +71,9 @@ public final class MimeUtils {
add("application/rdf+xml", "rdf"); add("application/rdf+xml", "rdf");
add("application/rss+xml", "rss"); add("application/rss+xml", "rss");
add("application/zip", "zip"); add("application/zip", "zip");
add("application/vnd.amazon.mobi8-ebook","azw3"); add("application/vnd.amazon.mobi8-ebook", "azw3");
add("application/vnd.amazon.mobi8-ebook","azw"); add("application/vnd.amazon.mobi8-ebook", "azw");
add("application/vnd.amazon.mobi8-ebook","kfx"); add("application/vnd.amazon.mobi8-ebook", "kfx");
add("application/vnd.android.package-archive", "apk"); add("application/vnd.android.package-archive", "apk");
add("application/vnd.cinderella", "cdy"); add("application/vnd.cinderella", "cdy");
add(ExportBackupService.MIME_TYPE, "ceb"); add(ExportBackupService.MIME_TYPE, "ceb");
@ -183,7 +186,7 @@ public final class MimeUtils {
add("application/x-maker", "book"); add("application/x-maker", "book");
add("application/x-maker", "fbdoc"); add("application/x-maker", "fbdoc");
add("application/x-mif", "mif"); add("application/x-mif", "mif");
add("application/x-mobipocket-ebook","mobi"); add("application/x-mobipocket-ebook", "mobi");
add("application/x-ms-wmd", "wmd"); add("application/x-ms-wmd", "wmd");
add("application/x-ms-wmz", "wmz"); add("application/x-ms-wmz", "wmz");
add("application/x-msi", "msi"); add("application/x-msi", "msi");
@ -242,7 +245,7 @@ public final class MimeUtils {
add("audio/mpeg", "mp2"); add("audio/mpeg", "mp2");
add("audio/mpeg", "m4a"); add("audio/mpeg", "m4a");
add("audio/mpegurl", "m3u"); add("audio/mpegurl", "m3u");
add("audio/ogg","oga"); add("audio/ogg", "oga");
add("audio/prs.sid", "sid"); add("audio/prs.sid", "sid");
add("audio/x-aiff", "aif"); add("audio/x-aiff", "aif");
add("audio/x-aiff", "aiff"); add("audio/x-aiff", "aiff");
@ -268,7 +271,7 @@ public final class MimeUtils {
add("image/ico", "cur"); add("image/ico", "cur");
add("image/ico", "ico"); add("image/ico", "ico");
add("image/ief", "ief"); add("image/ief", "ief");
add("image/heic","heic"); add("image/heic", "heic");
// add ".jpg" first so it will be the default for guessExtensionFromMimeType // add ".jpg" first so it will be the default for guessExtensionFromMimeType
add("image/jpeg", "jpg"); add("image/jpeg", "jpg");
add("image/jpeg", "jpeg"); add("image/jpeg", "jpeg");
@ -367,7 +370,7 @@ public final class MimeUtils {
add("video/fli", "fli"); add("video/fli", "fli");
add("video/m4v", "m4v"); add("video/m4v", "m4v");
add("video/mp2ts", "ts"); add("video/mp2ts", "ts");
add("video/ogg","ogv"); add("video/ogg", "ogv");
add("video/mpeg", "mpeg"); add("video/mpeg", "mpeg");
add("video/mpeg", "mpg"); add("video/mpeg", "mpg");
add("video/mpeg", "mpe"); add("video/mpeg", "mpe");
@ -393,6 +396,7 @@ public final class MimeUtils {
add("x-epoc/x-sisx-app", "sisx"); add("x-epoc/x-sisx-app", "sisx");
applyOverrides(); applyOverrides();
} }
private static void add(String mimeType, String extension) { private static void add(String mimeType, String extension) {
// If we have an existing x -> y mapping, we do not want to // If we have an existing x -> y mapping, we do not want to
// override it with another mapping x -> y2. // override it with another mapping x -> y2.
@ -406,6 +410,7 @@ public final class MimeUtils {
extensionToMimeTypeMap.put(extension, mimeType); extensionToMimeTypeMap.put(extension, mimeType);
} }
} }
private static InputStream getContentTypesPropertiesStream() { private static InputStream getContentTypesPropertiesStream() {
// User override? // User override?
String userTable = System.getProperty("content.types.user.table"); String userTable = System.getProperty("content.types.user.table");
@ -428,6 +433,7 @@ public final class MimeUtils {
} }
return null; return null;
} }
/** /**
* This isn't what the RI does. The RI doesn't have hard-coded defaults, so supplying your * This isn't what the RI does. The RI doesn't have hard-coded defaults, so supplying your
* own "content.types.user.table" means you don't get any of the built-ins, and the built-ins * own "content.types.user.table" means you don't get any of the built-ins, and the built-ins
@ -456,10 +462,13 @@ public final class MimeUtils {
} catch (IOException ignored) { } catch (IOException ignored) {
} }
} }
private MimeUtils() { private MimeUtils() {
} }
/** /**
* Returns true if the given MIME type has an entry in the map. * Returns true if the given MIME type has an entry in the map.
*
* @param mimeType A MIME type (i.e. text/plain) * @param mimeType A MIME type (i.e. text/plain)
* @return True iff there is a mimeType entry in the map. * @return True iff there is a mimeType entry in the map.
*/ */
@ -469,8 +478,10 @@ public final class MimeUtils {
} }
return mimeTypeToExtensionMap.containsKey(mimeType); return mimeTypeToExtensionMap.containsKey(mimeType);
} }
/** /**
* Returns the MIME type for the given extension. * Returns the MIME type for the given extension.
*
* @param extension A file extension without the leading '.' * @param extension A file extension without the leading '.'
* @return The MIME type for the given extension or null iff there is none. * @return The MIME type for the given extension or null iff there is none.
*/ */
@ -480,8 +491,10 @@ public final class MimeUtils {
} }
return extensionToMimeTypeMap.get(extension.toLowerCase()); return extensionToMimeTypeMap.get(extension.toLowerCase());
} }
/** /**
* Returns true if the given extension has a registered MIME type. * Returns true if the given extension has a registered MIME type.
*
* @param extension A file extension without the leading '.' * @param extension A file extension without the leading '.'
* @return True iff there is an extension entry in the map. * @return True iff there is an extension entry in the map.
*/ */
@ -491,10 +504,12 @@ public final class MimeUtils {
} }
return extensionToMimeTypeMap.containsKey(extension); return extensionToMimeTypeMap.containsKey(extension);
} }
/** /**
* Returns the registered extension for the given MIME type. Note that some * Returns the registered extension for the given MIME type. Note that some
* MIME types map to multiple extensions. This call will return the most * MIME types map to multiple extensions. This call will return the most
* common extension for the given MIME type. * common extension for the given MIME type.
*
* @param mimeType A MIME type (i.e. text/plain) * @param mimeType A MIME type (i.e. text/plain)
* @return The extension for the given MIME type or null iff there is none. * @return The extension for the given MIME type or null iff there is none.
*/ */
@ -506,7 +521,7 @@ public final class MimeUtils {
} }
public static String guessMimeTypeFromUriAndMime(final Context context, final Uri uri, final String mime) { public static String guessMimeTypeFromUriAndMime(final Context context, final Uri uri, final String mime) {
Log.d(Config.LOGTAG,"guessMimeTypeFromUriAndMime "+uri+" and mime="+mime); Log.d(Config.LOGTAG, "guessMimeTypeFromUriAndMime " + uri + " and mime=" + mime);
if (mime == null || mime.equals("application/octet-stream")) { if (mime == null || mime.equals("application/octet-stream")) {
final String guess = guessMimeTypeFromUri(context, uri); final String guess = guessMimeTypeFromUri(context, uri);
if (guess != null) { if (guess != null) {
@ -515,7 +530,7 @@ public final class MimeUtils {
return mime; return mime;
} }
} }
return guessMimeTypeFromUri(context ,uri); return guessMimeTypeFromUri(context, uri);
} }
public static String guessMimeTypeFromUri(Context context, Uri uri) { public static String guessMimeTypeFromUri(Context context, Uri uri) {
@ -565,7 +580,7 @@ public final class MimeUtils {
String extension = filename.substring(dotPosition + 1); String extension = filename.substring(dotPosition + 1);
// we want the real file extension, not the crypto one // we want the real file extension, not the crypto one
if (ignoreCryptoExtension && Transferable.VALID_CRYPTO_EXTENSIONS.contains(extension)) { if (ignoreCryptoExtension && Transferable.VALID_CRYPTO_EXTENSIONS.contains(extension)) {
return extractRelevantExtension(filename.substring(0,dotPosition)); return extractRelevantExtension(filename.substring(0, dotPosition));
} else { } else {
return extension; return extension;
} }

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 369 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 372 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 273 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 277 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 451 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 662 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 662 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 809 B

View File

@ -66,6 +66,7 @@
<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" />
<attr name="media_preview_tour" format="reference" />
<attr name="media_preview_contact" format="reference" /> <attr name="media_preview_contact" format="reference" />
<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" />

View File

@ -925,6 +925,7 @@
<string name="could_not_switch_camera">Could not switch camera</string> <string name="could_not_switch_camera">Could not switch camera</string>
<string name="add_to_favorites">Add to favorites</string> <string name="add_to_favorites">Add to favorites</string>
<string name="remove_from_favorites">Remove from favorites</string> <string name="remove_from_favorites">Remove from favorites</string>
<string name="gpx_track">GPX track</string>
<plurals name="view_users"> <plurals name="view_users">
<item quantity="one">View %1$d Participant</item> <item quantity="one">View %1$d Participant</item>
<item quantity="other">View %1$d Participants</item> <item quantity="other">View %1$d Participants</item>

View File

@ -85,6 +85,7 @@
<item name="media_preview_recording" type="reference">@drawable/ic_mic_black_48dp</item> <item name="media_preview_recording" type="reference">@drawable/ic_mic_black_48dp</item>
<item name="media_preview_audio" type="reference">@drawable/ic_headset_black_48dp</item> <item name="media_preview_audio" type="reference">@drawable/ic_headset_black_48dp</item>
<item name="media_preview_location" type="reference">@drawable/ic_room_black_48dp</item> <item name="media_preview_location" type="reference">@drawable/ic_room_black_48dp</item>
<item name="media_preview_tour" type="reference">@drawable/baseline_tour_black_48</item>
<item name="media_preview_contact" type="reference">@drawable/ic_person_black_48dp</item> <item name="media_preview_contact" type="reference">@drawable/ic_person_black_48dp</item>
<item name="media_preview_app" type="reference">@drawable/ic_android_black_48dp</item> <item name="media_preview_app" type="reference">@drawable/ic_android_black_48dp</item>
<item name="media_preview_calendar" type="reference">@drawable/ic_event_black_48dp</item> <item name="media_preview_calendar" type="reference">@drawable/ic_event_black_48dp</item>
@ -240,6 +241,7 @@
<item name="media_preview_recording" type="reference">@drawable/ic_mic_white_48dp</item> <item name="media_preview_recording" type="reference">@drawable/ic_mic_white_48dp</item>
<item name="media_preview_audio" type="reference">@drawable/ic_headset_white_48dp</item> <item name="media_preview_audio" type="reference">@drawable/ic_headset_white_48dp</item>
<item name="media_preview_location" type="reference">@drawable/ic_room_white_48dp</item> <item name="media_preview_location" type="reference">@drawable/ic_room_white_48dp</item>
<item name="media_preview_tour" type="reference">@drawable/baseline_tour_white_48</item>
<item name="media_preview_contact" type="reference">@drawable/ic_person_white_48dp</item> <item name="media_preview_contact" type="reference">@drawable/ic_person_white_48dp</item>
<item name="media_preview_app" type="reference">@drawable/ic_android_white_48dp</item> <item name="media_preview_app" type="reference">@drawable/ic_android_white_48dp</item>
<item name="media_preview_calendar" type="reference">@drawable/ic_event_white_48dp</item> <item name="media_preview_calendar" type="reference">@drawable/ic_event_white_48dp</item>