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.
|
* 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)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
public @interface PreviewStyle {
|
public @interface PreviewStyle {
|
||||||
|
|
||||||
|
@ -16,5 +16,5 @@ public @interface PreviewStyle {
|
||||||
|
|
||||||
int CROP = 1;
|
int CROP = 1;
|
||||||
int SCALE = 2;
|
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 {
|
override fun read(preferences: SharedPreferences): Int {
|
||||||
when (preferences.getString(key, null)) {
|
when (preferences.getString(key, null)) {
|
||||||
VALUE_MEDIA_PREVIEW_STYLE_SCALE -> return PreviewStyle.SCALE
|
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
|
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 {
|
override fun write(editor: SharedPreferences.Editor, value: Int): Boolean {
|
||||||
editor.putString(key, when (value) {
|
editor.putString(key, when (value) {
|
||||||
PreviewStyle.SCALE -> VALUE_MEDIA_PREVIEW_STYLE_SCALE
|
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
|
else -> VALUE_MEDIA_PREVIEW_STYLE_CROP
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -102,7 +102,7 @@ class CardMediaContainer(context: Context, attrs: AttributeSet? = null) : ViewGr
|
||||||
private fun ImageView.displayImage(displayChildIndex: Int, media: Array<ParcelableMedia>,
|
private fun ImageView.displayImage(displayChildIndex: Int, media: Array<ParcelableMedia>,
|
||||||
requestManager: RequestManager, accountKey: UserKey?, withCredentials: Boolean) {
|
requestManager: RequestManager, accountKey: UserKey?, withCredentials: Boolean) {
|
||||||
when (style) {
|
when (style) {
|
||||||
PreviewStyle.REAL_SIZE, PreviewStyle.CROP -> {
|
PreviewStyle.ACTUAL_SIZE, PreviewStyle.CROP -> {
|
||||||
this.scaleType = ScaleType.CENTER_CROP
|
this.scaleType = ScaleType.CENTER_CROP
|
||||||
}
|
}
|
||||||
PreviewStyle.SCALE -> {
|
PreviewStyle.SCALE -> {
|
||||||
|
@ -117,12 +117,23 @@ class CardMediaContainer(context: Context, attrs: AttributeSet? = null) : ViewGr
|
||||||
if (video) return@run null
|
if (video) return@run null
|
||||||
item.media_url
|
item.media_url
|
||||||
}
|
}
|
||||||
if (withCredentials) {
|
val request = if (withCredentials) {
|
||||||
val uri = Uri.parse(url)
|
requestManager.load(AuthenticatedUri(Uri.parse(url), accountKey)).asBitmap()
|
||||||
requestManager.load(AuthenticatedUri(uri, accountKey)).asBitmap().into(this)
|
|
||||||
} else {
|
} 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) {
|
if (this is MediaPreviewImageView) {
|
||||||
setHasPlayIcon(ParcelableMediaUtils.hasPlayIcon(item.type))
|
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 {
|
private fun measure1Media(contentWidth: Int, childIndices: IntArray, ratioMultiplier: Float): Int {
|
||||||
val child = getChildAt(childIndices[0])
|
val child = getChildAt(childIndices[0])
|
||||||
var childHeight = Math.round(contentWidth.toFloat() * WIDTH_HEIGHT_RATIO * ratioMultiplier)
|
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
|
val media = (child.layoutParams as MediaLayoutParams).media
|
||||||
if (media != null) {
|
if (media != null) {
|
||||||
val aspectRatio = media.aspect_ratio
|
val aspectRatio = media.aspect_ratio
|
||||||
|
|
Loading…
Reference in New Issue