add icons for gpx files

(cherry picked from commit 28856aaf9fb572a2d1fbf647047b5dfb3ec1cf83)
This commit is contained in:
Daniel Gultsch 2020-07-19 21:27:43 +02:00 committed by Christian Schneppe
parent c5327120be
commit 14252c04c4
17 changed files with 68 additions and 42 deletions

View file

@ -12,6 +12,7 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.util.Log;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -67,8 +68,9 @@ 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);
}
@ -83,6 +85,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/")) {
@ -101,6 +104,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;
}

View file

@ -37,6 +37,8 @@ import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import com.google.common.base.MoreObjects;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
@ -48,7 +50,28 @@ import eu.siacs.conversations.utils.Compatibility;
import eu.siacs.conversations.utils.MimeUtils;
public class Attachment implements Parcelable {
public static final Creator<Attachment> CREATOR = new Parcelable.Creator<Attachment>() {
Attachment(Parcel in) {
uri = in.readParcelable(Uri.class.getClassLoader());
mime = in.readString();
uuid = UUID.fromString(in.readString());
type = Type.valueOf(in.readString());
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(uri, flags);
dest.writeString(mime);
dest.writeString(uuid.toString());
dest.writeString(type.toString());
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<Attachment> CREATOR = new Creator<Attachment>() {
@Override
public Attachment createFromParcel(Parcel in) {
return new Attachment(in);
@ -59,18 +82,34 @@ public class Attachment implements Parcelable {
return new Attachment[size];
}
};
public String getMime() {
return mime;
}
public Type getType() {
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
}
private final Uri uri;
private final Type type;
private final UUID uuid;
private final String mime;
Attachment(Parcel in) {
uri = in.readParcelable(Uri.class.getClassLoader());
mime = in.readString();
uuid = UUID.fromString(in.readString());
type = Type.valueOf(in.readString());
}
private Attachment(UUID uuid, Uri uri, Type type, String mime) {
this.uri = uri;
this.type = type;
@ -136,27 +175,6 @@ public class Attachment implements Parcelable {
return uris;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeParcelable(uri, flags);
dest.writeString(mime);
dest.writeString(uuid.toString());
dest.writeString(type.toString());
}
@Override
public int describeContents() {
return 0;
}
public String getMime() {
return mime;
}
public Type getType() {
return type;
}
public boolean renderThumbnail() {
return type == Type.IMAGE || (type == Type.FILE && mime != null && renderFileThumbnail(mime));
}
@ -178,8 +196,4 @@ public class Attachment implements Parcelable {
private static boolean isImage(final String mime) {
return mime.startsWith("image/") && !mime.equals("image/svg+xml");
}
public enum Type {
FILE, IMAGE, LOCATION, RECORDING
}
}

View file

@ -55,6 +55,7 @@ public final class MimeUtils {
add("application/andrew-inset", "ez");
add("application/dsptype", "tsp");
add("application/epub+zip", "epub");
add("application/gpx+xml", "gpx");
add("application/hta", "hta");
add("application/mac-binhex40", "hqx");
add("application/mathematica", "nb");

View file

@ -305,14 +305,14 @@ public class UIHelper {
return new Pair<>(context.getString(R.string.omemo_decryption_failed), true);
} else if (message.isFileOrImage()) {
return new Pair<>(getFileDescriptionString(context, message), true);
} else if (message.getType() == Message.TYPE_RTP_SESSION) {
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);
} else {
return new Pair<>(context.getString(received ? R.string.incoming_call : R.string.outgoing_call), true);
}
} else if (message.getType() == Message.TYPE_RTP_SESSION) {
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);
} else {
return new Pair<>(context.getString(received ? R.string.incoming_call : R.string.outgoing_call), true);
}
} else {
final String body = MessageUtils.filterLtrRtl(message.getBody());
if (message.getBody().equals(DELETED_MESSAGE_BODY) || message.getBody().equals(DELETED_MESSAGE_BODY_OLD)) {
@ -511,6 +511,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

@ -58,6 +58,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

@ -1043,4 +1043,5 @@
<string name="add_to_favorites">Add to favorites</string>
<string name="remove_from_favorites">Remove from favorites</string>
<string name="improperly_formatted_provisioning">Improperly formatted provisioning code</string>
<string name="gpx_track">GPX track</string>
</resources>

View file

@ -76,6 +76,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>
@ -271,6 +272,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>