From e655889b981078c1a27a026d953725dcc730b77f Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Thu, 18 May 2017 11:25:28 +0800 Subject: [PATCH] fixed #838 --- .../twidere/annotation/PreviewStyle.java | 4 ++-- .../twidere/constant/PreferenceKeys.kt | 4 ++-- .../twidere/view/CardMediaContainer.kt | 23 ++++++++++++++----- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/twidere/src/main/java/org/mariotaku/twidere/annotation/PreviewStyle.java b/twidere/src/main/java/org/mariotaku/twidere/annotation/PreviewStyle.java index 9fa47073a..3c1add521 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/annotation/PreviewStyle.java +++ b/twidere/src/main/java/org/mariotaku/twidere/annotation/PreviewStyle.java @@ -8,7 +8,7 @@ import java.lang.annotation.RetentionPolicy; /** * Created by mariotaku on 2017/2/6. */ -@IntDef({PreviewStyle.NONE, PreviewStyle.SCALE, PreviewStyle.CROP, PreviewStyle.REAL_SIZE}) +@IntDef({PreviewStyle.NONE, PreviewStyle.SCALE, PreviewStyle.CROP, PreviewStyle.ACTUAL_SIZE}) @Retention(RetentionPolicy.SOURCE) public @interface PreviewStyle { @@ -16,5 +16,5 @@ public @interface PreviewStyle { int CROP = 1; int SCALE = 2; - int REAL_SIZE = 3; + int ACTUAL_SIZE = 3; } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt index 7c38904e4..fbab342c0 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/constant/PreferenceKeys.kt @@ -138,7 +138,7 @@ object mediaPreviewStyleKey : KSimpleKey(KEY_MEDIA_PREVIEW_STYLE, PreviewSt override fun read(preferences: SharedPreferences): Int { when (preferences.getString(key, null)) { VALUE_MEDIA_PREVIEW_STYLE_SCALE -> return PreviewStyle.SCALE - VALUE_MEDIA_PREVIEW_STYLE_REAL_SIZE -> return PreviewStyle.REAL_SIZE + VALUE_MEDIA_PREVIEW_STYLE_REAL_SIZE -> return PreviewStyle.ACTUAL_SIZE else -> return PreviewStyle.CROP } } @@ -146,7 +146,7 @@ object mediaPreviewStyleKey : KSimpleKey(KEY_MEDIA_PREVIEW_STYLE, PreviewSt override fun write(editor: SharedPreferences.Editor, value: Int): Boolean { editor.putString(key, when (value) { PreviewStyle.SCALE -> VALUE_MEDIA_PREVIEW_STYLE_SCALE - PreviewStyle.REAL_SIZE -> VALUE_MEDIA_PREVIEW_STYLE_REAL_SIZE + PreviewStyle.ACTUAL_SIZE -> VALUE_MEDIA_PREVIEW_STYLE_REAL_SIZE else -> VALUE_MEDIA_PREVIEW_STYLE_CROP }) return true diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/view/CardMediaContainer.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/view/CardMediaContainer.kt index b2647ade7..fabdfc82f 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/view/CardMediaContainer.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/view/CardMediaContainer.kt @@ -102,7 +102,7 @@ class CardMediaContainer(context: Context, attrs: AttributeSet? = null) : ViewGr private fun ImageView.displayImage(displayChildIndex: Int, media: Array, requestManager: RequestManager, accountKey: UserKey?, withCredentials: Boolean) { when (style) { - PreviewStyle.REAL_SIZE, PreviewStyle.CROP -> { + PreviewStyle.ACTUAL_SIZE, PreviewStyle.CROP -> { this.scaleType = ScaleType.CENTER_CROP } PreviewStyle.SCALE -> { @@ -117,12 +117,23 @@ class CardMediaContainer(context: Context, attrs: AttributeSet? = null) : ViewGr if (video) return@run null item.media_url } - if (withCredentials) { - val uri = Uri.parse(url) - requestManager.load(AuthenticatedUri(uri, accountKey)).asBitmap().into(this) + val request = if (withCredentials) { + requestManager.load(AuthenticatedUri(Uri.parse(url), accountKey)).asBitmap() } else { - requestManager.load(url).asBitmap().into(this) + requestManager.load(url).asBitmap() } + when (style) { + PreviewStyle.ACTUAL_SIZE -> { + request.fitCenter() + } + PreviewStyle.CROP -> { + request.centerCrop() + } + PreviewStyle.SCALE -> { + request.fitCenter() + } + } + request.into(this) if (this is MediaPreviewImageView) { setHasPlayIcon(ParcelableMediaUtils.hasPlayIcon(item.type)) } @@ -207,7 +218,7 @@ class CardMediaContainer(context: Context, attrs: AttributeSet? = null) : ViewGr private fun measure1Media(contentWidth: Int, childIndices: IntArray, ratioMultiplier: Float): Int { val child = getChildAt(childIndices[0]) var childHeight = Math.round(contentWidth.toFloat() * WIDTH_HEIGHT_RATIO * ratioMultiplier) - if (style == PreviewStyle.REAL_SIZE) { + if (style == PreviewStyle.ACTUAL_SIZE) { val media = (child.layoutParams as MediaLayoutParams).media if (media != null) { val aspectRatio = media.aspect_ratio