Fix real size media for mastodon

This commit is contained in:
Tlaster 2020-05-28 15:16:02 +08:00
parent aed42087ca
commit d88e7f331a
2 changed files with 53 additions and 0 deletions

View File

@ -18,8 +18,11 @@
package org.mariotaku.microblog.library.mastodon.model; package org.mariotaku.microblog.library.mastodon.model;
import androidx.annotation.Nullable;
import com.bluelinelabs.logansquare.annotation.JsonField; import com.bluelinelabs.logansquare.annotation.JsonField;
import com.bluelinelabs.logansquare.annotation.JsonObject; import com.bluelinelabs.logansquare.annotation.JsonObject;
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
/** /**
* {@see https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#attachment} * {@see https://github.com/tootsuite/documentation/blob/master/Using-the-API/API.md#attachment}
@ -59,6 +62,9 @@ public class Attachment {
@JsonField(name = "text_url") @JsonField(name = "text_url")
String textUrl; String textUrl;
@JsonField(name = "meta")
MetaInfo meta;
public String getId() { public String getId() {
return id; return id;
} }
@ -83,6 +89,51 @@ public class Attachment {
return textUrl; return textUrl;
} }
public MetaInfo getMeta() {
return meta;
}
@JsonObject
public static class MetaInfo {
@ParcelableThisPlease
@JsonField(name = "focus")
@Nullable
public FocusInfo focus;
@ParcelableThisPlease
@JsonField(name = "original")
@Nullable
public MetaDataInfo original;
@ParcelableThisPlease
@JsonField(name = "small")
@Nullable
public MetaDataInfo small;
@JsonObject
public static class FocusInfo {
@ParcelableThisPlease
@JsonField(name = "x")
public float x;
@ParcelableThisPlease
@JsonField(name = "y")
public float y;
}
@JsonObject
public static class MetaDataInfo {
@ParcelableThisPlease
@JsonField(name = "width")
public long width;
@ParcelableThisPlease
@JsonField(name = "height")
public long height;
@ParcelableThisPlease
@JsonField(name = "aspect")
public float aspect;
}
}
@Override @Override
public String toString() { public String toString() {
return "Attachment{" + return "Attachment{" +

View File

@ -38,6 +38,8 @@ fun Attachment.toParcelable(): ParcelableMedia {
"gifv" -> ParcelableMedia.Type.ANIMATED_GIF "gifv" -> ParcelableMedia.Type.ANIMATED_GIF
else -> ParcelableMedia.Type.UNKNOWN else -> ParcelableMedia.Type.UNKNOWN
} }
result.height = meta?.original?.height?.toInt() ?: 0
result.width = meta?.original?.width?.toInt() ?: 0
result.url = url ?: remoteUrl result.url = url ?: remoteUrl
result.media_url = result.url result.media_url = result.url
result.preview_url = previewUrl result.preview_url = previewUrl