fixed external player crash #293

This commit is contained in:
Mariotaku Lee 2016-01-26 22:05:07 +08:00
parent 6f562b5582
commit eb805f8f22
6 changed files with 39 additions and 17 deletions

View File

@ -32,12 +32,12 @@ import com.hannesdorfmann.parcelableplease.annotation.Bagger;
import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.mariotaku.twidere.api.twitter.model.CardEntity;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;
@ -142,13 +142,13 @@ public final class ParcelableCardEntity implements Parcelable {
@Override
public String toString() {
return "ParcelableCardEntity{" +
"account_id=" + account_id +
", name='" + name + '\'' +
", url='" + url + '\'' +
", users=" + Arrays.toString(users) +
", values=" + values +
'}';
return new ToStringBuilder(this)
.append("account_id", account_id)
.append("name", name)
.append("url", url)
.append("users", users)
.append("values", values)
.toString();
}
@Override

View File

@ -181,7 +181,8 @@ public class ParcelableMedia implements Parcelable {
final ParcelableMedia media = new ParcelableMedia();
final BindingValue playerStreamUrl = card.getBindingValue("player_stream_url");
media.card = ParcelableCardEntity.fromCardEntity(card, -1);
media.url = card.getUrl();
StringValue appUrlResolved = (StringValue) card.getBindingValue("app_url_resolved");
media.url = appUrlResolved != null ? appUrlResolved.getValue() : card.getUrl();
if ("animated_gif".equals(name)) {
media.media_url = ((StringValue) playerStreamUrl).getValue();
media.type = Type.TYPE_CARD_ANIMATED_GIF;
@ -189,6 +190,10 @@ public class ParcelableMedia implements Parcelable {
media.media_url = ((StringValue) playerStreamUrl).getValue();
media.type = Type.TYPE_VIDEO;
} else {
StringValue playerUrl = (StringValue) card.getBindingValue("player_url");
if (playerUrl != null) {
media.media_url = playerUrl.getValue();
}
media.type = Type.TYPE_EXTERNAL_PLAYER;
}
final BindingValue playerImage = card.getBindingValue("player_image");

View File

@ -61,6 +61,7 @@ import org.mariotaku.twidere.R;
import org.mariotaku.twidere.adapter.support.SupportFixedFragmentStatePagerAdapter;
import org.mariotaku.twidere.fragment.support.CacheDownloadFragment;
import org.mariotaku.twidere.fragment.support.ViewStatusDialogFragment;
import org.mariotaku.twidere.fragment.support.card.CardBrowserFragment;
import org.mariotaku.twidere.loader.support.CacheDownloadLoader.Listener;
import org.mariotaku.twidere.loader.support.CacheDownloadLoader.Result;
import org.mariotaku.twidere.model.ParcelableMedia;
@ -70,7 +71,6 @@ import org.mariotaku.twidere.util.IntentUtils;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
import org.mariotaku.twidere.util.MenuUtils;
import org.mariotaku.twidere.util.ThemeUtils;
import org.mariotaku.twidere.util.TwitterCardFragmentFactory;
import org.mariotaku.twidere.util.Utils;
import java.util.concurrent.TimeUnit;
@ -424,6 +424,7 @@ public final class MediaViewerActivity extends BaseAppCompatActivity implements
return mMedia.length;
}
@NonNull
@Override
public Fragment getItem(int position) {
final ParcelableMedia media = mMedia[position];
@ -446,7 +447,7 @@ public final class MediaViewerActivity extends BaseAppCompatActivity implements
return Fragment.instantiate(mActivity, ImagePageFragment.class.getName(), args);
}
case ParcelableMedia.Type.TYPE_EXTERNAL_PLAYER: {
return TwitterCardFragmentFactory.createGenericPlayerFragment(media.card);
return CardBrowserFragment.show(media.media_url != null ? media.media_url : media.url, args);
}
}
return new UnsupportedPageFragment();

View File

@ -21,6 +21,7 @@ package org.mariotaku.twidere.fragment.support.card;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.webkit.WebSettings;
import android.webkit.WebView;
@ -38,9 +39,12 @@ public class CardBrowserFragment extends SupportBrowserFragment {
settings.setBuiltInZoomControls(false);
}
public static CardBrowserFragment show(@NonNull String uri) {
public static CardBrowserFragment show(@NonNull String uri, @Nullable Bundle extraArgs) {
final Bundle args = new Bundle();
args.putString(EXTRA_URI, uri);
if (extraArgs != null) {
args.putAll(extraArgs);
}
final CardBrowserFragment fragment = new CardBrowserFragment();
fragment.setArguments(args);
return fragment;

View File

@ -19,6 +19,7 @@
package org.mariotaku.twidere.util;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
@ -43,11 +44,11 @@ public abstract class TwitterCardFragmentFactory {
}
@Nullable
public static Fragment createGenericPlayerFragment(@Nullable ParcelableCardEntity card) {
public static Fragment createGenericPlayerFragment(@Nullable ParcelableCardEntity card, Bundle args) {
if (card == null) return null;
final String playerUrl = card.getString("player_url");
if (playerUrl == null) return null;
return CardBrowserFragment.show(playerUrl);
return CardBrowserFragment.show(playerUrl, args);
}
public static Fragment createCardPollFragment(ParcelableStatus status) {

View File

@ -24,8 +24,10 @@ import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.mariotaku.twidere.fragment.support.card.CardPollFragment;
import org.mariotaku.twidere.model.ParcelableCardEntity;
import org.mariotaku.twidere.model.ParcelableMedia;
import org.mariotaku.twidere.model.ParcelableStatus;
/**
@ -46,15 +48,15 @@ public class TwitterCardUtils {
if (CARD_NAME_PLAYER.equals(card.name)) {
final Fragment playerFragment = sFactory.createPlayerFragment(card);
if (playerFragment != null) return playerFragment;
return TwitterCardFragmentFactory.createGenericPlayerFragment(card);
return TwitterCardFragmentFactory.createGenericPlayerFragment(card, null);
} else if (CARD_NAME_AUDIO.equals(card.name)) {
final Fragment playerFragment = sFactory.createAudioFragment(card);
if (playerFragment != null) return playerFragment;
return TwitterCardFragmentFactory.createGenericPlayerFragment(card);
return TwitterCardFragmentFactory.createGenericPlayerFragment(card, null);
} else if (CARD_NAME_ANIMATED_GIF.equals(card.name)) {
final Fragment playerFragment = sFactory.createAnimatedGifFragment(card);
if (playerFragment != null) return playerFragment;
return TwitterCardFragmentFactory.createGenericPlayerFragment(card);
return TwitterCardFragmentFactory.createGenericPlayerFragment(card, null);
} else if (CardPollFragment.isPoll(card)) {
return TwitterCardFragmentFactory.createCardPollFragment(status);
}
@ -75,6 +77,15 @@ public class TwitterCardUtils {
if (status.card == null || status.card_name == null) return false;
switch (status.card_name) {
case CARD_NAME_PLAYER: {
if (!ArrayUtils.isEmpty(status.media)) {
String appUrlResolved = status.card.getString("app_url_resolved");
String cardUrl = status.card.url;
for (ParcelableMedia media : status.media) {
if (media.url.equals(appUrlResolved) || media.url.equals(cardUrl)) {
return false;
}
}
}
return TextUtils.isEmpty(status.card.getString("player_stream_url"));
}
case CARD_NAME_AUDIO: {