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;
} }

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
@ -53,6 +55,7 @@ public final class MimeUtils {
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");
@ -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.
*/ */

View file

@ -497,6 +497,8 @@ public class UIHelper {
return context.getString(R.string.event); return context.getString(R.string.event);
} else if (mime.equals("application/epub+zip") || mime.equals("application/vnd.amazon.mobi8-ebook")) { } else if (mime.equals("application/epub+zip") || mime.equals("application/vnd.amazon.mobi8-ebook")) {
return context.getString(R.string.ebook); return context.getString(R.string.ebook);
} else if (mime.equals("application/gpx+xml")) {
return context.getString(R.string.gpx_track);
} else { } else {
return mime; return mime;
} }

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>