supports video load for GNU social

fixed video gravity
This commit is contained in:
Mariotaku Lee 2017-02-13 11:03:09 +08:00
parent 6fdd829ce0
commit bb4df20d02
No known key found for this signature in database
GPG Key ID: 15C10F89D7C33535
4 changed files with 55 additions and 34 deletions

View File

@ -131,28 +131,32 @@ 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/")) {
ParcelableMedia media = new ParcelableMedia();
final String mimeType = attachment.getMimetype();
if (mimeType == null) continue;
ParcelableMedia media = new ParcelableMedia();
if (mimeType.startsWith("image/")) {
media.type = ParcelableMedia.Type.IMAGE;
media.width = attachment.getWidth();
media.height = attachment.getHeight();
media.url = TextUtils.isEmpty(externalUrl) ? attachment.getUrl() : externalUrl;
media.page_url = TextUtils.isEmpty(externalUrl) ? attachment.getUrl() : externalUrl;
media.media_url = attachment.getUrl();
media.preview_url = attachment.getLargeThumbUrl();
temp[i++] = media;
} 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;
media.page_url = TextUtils.isEmpty(externalUrl) ? attachment.getUrl() : externalUrl;
media.media_url = attachment.getUrl();
media.preview_url = attachment.getLargeThumbUrl();
temp[i++] = media;
}
return ArrayUtils.subarray(temp, 0, i);
}
@NonNull
private static ParcelableMedia[] fromCard(@Nullable CardEntity card,
@Nullable UrlEntity[] urlEntities,
@Nullable MediaEntity[] mediaEntities,
@Nullable MediaEntity[] extendedMediaEntities,
UserKey accountKey) {
@Nullable UrlEntity[] urlEntities,
@Nullable MediaEntity[] mediaEntities,
@Nullable MediaEntity[] extendedMediaEntities,
UserKey accountKey) {
if (card == null) return new ParcelableMedia[0];
final String name = card.getName();
if ("animated_gif".equals(name) || "player".equals(name)) {

View File

@ -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)

View File

@ -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
@ -75,8 +73,8 @@ class CardMediaContainer(context: Context, attrs: AttributeSet? = null) : ViewGr
}
fun displayMedia(loader: MediaLoaderWrapper, media: Array<ParcelableMedia>?, accountId: UserKey? = null,
extraId: Long = -1, withCredentials: Boolean = false,
mediaClickListener: OnMediaClickListener? = null, loadingHandler: MediaLoadingHandler? = null) {
extraId: Long = -1, withCredentials: Boolean = false,
mediaClickListener: OnMediaClickListener? = null, loadingHandler: MediaLoadingHandler? = null) {
if (media == null || style == PreviewStyle.NONE) {
for (i in 0 until childCount) {
val child = getChildAt(i)
@ -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
@ -222,8 +224,8 @@ class CardMediaContainer(context: Context, attrs: AttributeSet? = null) : ViewGr
}
private fun measureGridMedia(childCount: Int, columnCount: Int, contentWidth: Int,
widthHeightRatio: Float, horizontalSpacing: Int, verticalSpacing: Int,
childIndices: IntArray): Int {
widthHeightRatio: Float, horizontalSpacing: Int, verticalSpacing: Int,
childIndices: IntArray): Int {
val childWidth = (contentWidth - horizontalSpacing * (columnCount - 1)) / columnCount
val childHeight = Math.round(childWidth * widthHeightRatio)
val widthSpec = View.MeasureSpec.makeMeasureSpec(childWidth, View.MeasureSpec.EXACTLY)
@ -236,7 +238,7 @@ class CardMediaContainer(context: Context, attrs: AttributeSet? = null) : ViewGr
}
private fun layoutGridMedia(childCount: Int, columnCount: Int, horizontalSpacing: Int,
verticalSpacing: Int, childIndices: IntArray) {
verticalSpacing: Int, childIndices: IntArray) {
val initialLeft = paddingLeft
var left = initialLeft
var top = paddingTop
@ -257,7 +259,7 @@ class CardMediaContainer(context: Context, attrs: AttributeSet? = null) : ViewGr
}
private fun measure3Media(contentWidth: Int, horizontalSpacing: Int, childIndices: IntArray,
ratioMultiplier: Float): Int {
ratioMultiplier: Float): Int {
val child0 = getChildAt(childIndices[0])
val child1 = getChildAt(childIndices[1])
val child2 = getChildAt(childIndices[2])

View File

@ -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>