fixed #838
This commit is contained in:
parent
858b5a677f
commit
e655889b98
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -138,7 +138,7 @@ object mediaPreviewStyleKey : KSimpleKey<Int>(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<Int>(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
|
||||
|
|
|
@ -102,7 +102,7 @@ class CardMediaContainer(context: Context, attrs: AttributeSet? = null) : ViewGr
|
|||
private fun ImageView.displayImage(displayChildIndex: Int, media: Array<ParcelableMedia>,
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue