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.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ImageView;
@ -21,6 +22,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.RejectedExecutionException;
import eu.siacs.conversations.Config;
import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.MediaBinding;
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));
}
@SuppressWarnings("rawtypes")
public static void setMediaSize(RecyclerView recyclerView, int mediaSize) {
RecyclerView.Adapter adapter = recyclerView.getAdapter();
final RecyclerView.Adapter adapter = recyclerView.getAdapter();
if (adapter instanceof MediaAdapter) {
((MediaAdapter) adapter).setMediaSize(mediaSize);
}
}
private static @AttrRes int getImageAttr(Attachment attachment) {
private static @AttrRes
int getImageAttr(Attachment attachment) {
final @AttrRes int attr;
if (attachment.getType() == Attachment.Type.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;
} else {
final String mime = attachment.getMime();
Log.d(Config.LOGTAG, "mime=" + mime);
if (mime == null) {
attr = R.attr.media_preview_unknown;
} else if (mime.startsWith("audio/")) {
@ -84,6 +89,8 @@ public class MediaAdapter extends RecyclerView.Adapter<MediaAdapter.MediaViewHol
attr = R.attr.media_preview_backup;
} else if (DOCUMENT_MIMES.contains(mime)) {
attr = R.attr.media_preview_document;
} else if (mime.equals("application/gpx+xml")) {
attr = R.attr.media_preview_tour;
} else {
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) {
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) {
cancelPotentialWork(attachment, imageView);
imageView.setImageBitmap(bm);

View file

@ -36,6 +36,8 @@ import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.common.base.MoreObjects;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
@ -87,6 +89,16 @@ public class Attachment implements Parcelable {
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 {
FILE, IMAGE, LOCATION, RECORDING
}

View file

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

View file

@ -298,7 +298,7 @@ public class UIHelper {
RtpSessionStatus rtpSessionStatus = RtpSessionStatus.of(message.getBody());
final boolean received = message.getStatus() == Message.STATUS_RECEIVED;
if (!rtpSessionStatus.successful && received) {
return new Pair<>(context.getString(R.string.missed_call),true);
return new Pair<>(context.getString(R.string.missed_call), true);
} else {
return new Pair<>(context.getString(received ? R.string.incoming_call : R.string.outgoing_call), true);
}
@ -361,7 +361,7 @@ public class UIHelper {
return false;
}
char first = line.charAt(0);
return first == '>' && isPositionFollowedByQuoteableCharacter(line,0) || first == '\u00bb';
return first == '>' && isPositionFollowedByQuoteableCharacter(line, 0) || first == '\u00bb';
}
public static CharSequence shorten(CharSequence input) {
@ -497,6 +497,8 @@ public class UIHelper {
return context.getString(R.string.event);
} else if (mime.equals("application/epub+zip") || mime.equals("application/vnd.amazon.mobi8-ebook")) {
return context.getString(R.string.ebook);
} else if (mime.equals("application/gpx+xml")) {
return context.getString(R.string.gpx_track);
} else {
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_audio" 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_app" 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="add_to_favorites">Add to favorites</string>
<string name="remove_from_favorites">Remove from favorites</string>
<string name="gpx_track">GPX track</string>
<plurals name="view_users">
<item quantity="one">View %1$d Participant</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_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_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_app" type="reference">@drawable/ic_android_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_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_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_app" type="reference">@drawable/ic_android_white_48dp</item>
<item name="media_preview_calendar" type="reference">@drawable/ic_event_white_48dp</item>