parent
6fdd829ce0
commit
bb4df20d02
|
@ -131,10 +131,15 @@ public class ParcelableMediaUtils {
|
|||
final String externalUrl = status.getExternalUrl();
|
||||
int i = 0;
|
||||
for (Attachment attachment : attachments) {
|
||||
final String mimetype = attachment.getMimetype();
|
||||
if (mimetype != null && mimetype.startsWith("image/")) {
|
||||
final String mimeType = attachment.getMimetype();
|
||||
if (mimeType == null) continue;
|
||||
ParcelableMedia media = new ParcelableMedia();
|
||||
|
||||
if (mimeType.startsWith("image/")) {
|
||||
media.type = ParcelableMedia.Type.IMAGE;
|
||||
} else if (mimeType.startsWith("video/")) {
|
||||
media.type = ParcelableMedia.Type.VIDEO;
|
||||
}
|
||||
media.width = attachment.getWidth();
|
||||
media.height = attachment.getHeight();
|
||||
media.url = TextUtils.isEmpty(externalUrl) ? attachment.getUrl() : externalUrl;
|
||||
|
@ -143,7 +148,6 @@ public class ParcelableMediaUtils {
|
|||
media.preview_url = attachment.getLargeThumbUrl();
|
||||
temp[i++] = media;
|
||||
}
|
||||
}
|
||||
return ArrayUtils.subarray(temp, 0, i);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import com.nostra13.universalimageloader.core.ImageLoader
|
|||
import com.nostra13.universalimageloader.core.assist.ImageSize
|
||||
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener
|
||||
import org.mariotaku.kpreferences.get
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.constant.mediaPreloadKey
|
||||
import org.mariotaku.twidere.constant.mediaPreloadOnWifiOnlyKey
|
||||
import org.mariotaku.twidere.model.*
|
||||
|
@ -68,6 +69,15 @@ class MediaLoaderWrapper(val imageLoader: ImageLoader) {
|
|||
.bitmapConfig(Bitmap.Config.RGB_565)
|
||||
.build()
|
||||
|
||||
private val videoPreviewDisplayOptions = DisplayImageOptions.Builder()
|
||||
.resetViewBeforeLoading(true)
|
||||
.cacheInMemory(true)
|
||||
.cacheOnDisk(true)
|
||||
.bitmapConfig(Bitmap.Config.RGB_565)
|
||||
.showImageForEmptyUri(R.color.material_grey)
|
||||
.showImageOnFail(R.color.material_grey)
|
||||
.build()
|
||||
|
||||
private val bannerDisplayOptions = DisplayImageOptions.Builder()
|
||||
.resetViewBeforeLoading(true)
|
||||
.showImageOnLoading(android.R.color.transparent)
|
||||
|
@ -85,21 +95,25 @@ class MediaLoaderWrapper(val imageLoader: ImageLoader) {
|
|||
.bitmapConfig(Bitmap.Config.ARGB_8888)
|
||||
.build()
|
||||
|
||||
fun displayPreviewImage(view: ImageView, url: String?) {
|
||||
imageLoader.displayImage(url, view, previewDisplayOptions)
|
||||
fun displayPreviewImage(view: ImageView, url: String?, video: Boolean = false) {
|
||||
val options = if (video) videoPreviewDisplayOptions else previewDisplayOptions
|
||||
imageLoader.displayImage(url, view, options)
|
||||
}
|
||||
|
||||
fun displayPreviewImage(view: ImageView, url: String?, loadingHandler: MediaLoadingHandler?) {
|
||||
imageLoader.displayImage(url, view, previewDisplayOptions, loadingHandler, loadingHandler)
|
||||
fun displayPreviewImage(view: ImageView, url: String?, loadingHandler: MediaLoadingHandler?,
|
||||
video: Boolean = false) {
|
||||
val options = if (video) videoPreviewDisplayOptions else previewDisplayOptions
|
||||
imageLoader.displayImage(url, view, options, loadingHandler, loadingHandler)
|
||||
}
|
||||
|
||||
fun displayPreviewImageWithCredentials(view: ImageView, url: String?, accountKey: UserKey?, loadingHandler: MediaLoadingHandler?) {
|
||||
fun displayPreviewImageWithCredentials(view: ImageView, url: String?, accountKey: UserKey?,
|
||||
loadingHandler: MediaLoadingHandler?, video: Boolean = false) {
|
||||
if (accountKey == null) {
|
||||
displayPreviewImage(view, url, loadingHandler)
|
||||
return
|
||||
}
|
||||
val b = DisplayImageOptions.Builder()
|
||||
b.cloneFrom(previewDisplayOptions)
|
||||
b.cloneFrom(if (video) videoPreviewDisplayOptions else previewDisplayOptions)
|
||||
val extra = MediaExtra()
|
||||
extra.accountKey = accountKey
|
||||
b.extraForDownloader(extra)
|
||||
|
|
|
@ -20,13 +20,11 @@
|
|||
package org.mariotaku.twidere.view
|
||||
|
||||
import android.content.Context
|
||||
import android.text.TextUtils
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import android.widget.ImageView.ScaleType
|
||||
import org.apache.commons.lang3.ObjectUtils
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.annotation.PreviewStyle
|
||||
import org.mariotaku.twidere.extension.model.aspect_ratio
|
||||
|
@ -102,19 +100,23 @@ class CardMediaContainer(context: Context, attrs: AttributeSet? = null) : ViewGr
|
|||
}
|
||||
if (i < mediaSize) {
|
||||
val item = media[i]
|
||||
val url = if (TextUtils.isEmpty(item.preview_url)) item.media_url else item.preview_url
|
||||
if (ObjectUtils.notEqual(url, imageView.tag) || imageView.drawable == null) {
|
||||
val video = item.type == ParcelableMedia.Type.VIDEO
|
||||
val url = item.preview_url ?: run {
|
||||
if (video) return@run null
|
||||
item.media_url
|
||||
}
|
||||
if (url != imageView.tag || imageView.drawable == null) {
|
||||
if (withCredentials) {
|
||||
loader.displayPreviewImageWithCredentials(imageView, url, accountId, loadingHandler)
|
||||
loader.displayPreviewImageWithCredentials(imageView, url, accountId, loadingHandler, video)
|
||||
} else {
|
||||
loader.displayPreviewImage(imageView, url, loadingHandler)
|
||||
loader.displayPreviewImage(imageView, url, loadingHandler, video)
|
||||
}
|
||||
}
|
||||
imageView.tag = url
|
||||
if (imageView is MediaPreviewImageView) {
|
||||
imageView.setHasPlayIcon(ParcelableMediaUtils.hasPlayIcon(item.type))
|
||||
}
|
||||
if (TextUtils.isEmpty(item.alt_text)) {
|
||||
if (item.alt_text.isNullOrEmpty()) {
|
||||
child.contentDescription = context.getString(R.string.media)
|
||||
} else {
|
||||
child.contentDescription = item.alt_text
|
||||
|
|
|
@ -35,7 +35,8 @@
|
|||
<com.sprylab.android.widget.TextureVideoView
|
||||
android:id="@+id/videoView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
</com.commonsware.cwac.layouts.AspectLockedFrameLayout>
|
||||
|
||||
|
|
Loading…
Reference in New Issue