parent
4cd79dc78c
commit
f074e04713
|
@ -15,9 +15,6 @@ import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease;
|
|||
import com.hannesdorfmann.parcelableplease.annotation.ParcelableThisPlease;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.mariotaku.twidere.api.gnusocial.model.Attachment;
|
||||
import org.mariotaku.twidere.api.twitter.model.CardEntity;
|
||||
|
@ -206,7 +203,7 @@ public class ParcelableMedia implements Parcelable {
|
|||
final BindingValue playerStreamUrl = card.getBindingValue("player_stream_url");
|
||||
media.card = ParcelableCardEntity.fromCardEntity(card, -1);
|
||||
StringValue appUrlResolved = (StringValue) card.getBindingValue("app_url_resolved");
|
||||
media.url = appUrlResolved != null ? appUrlResolved.getValue() : card.getUrl();
|
||||
media.url = checkUrl(appUrlResolved) ? appUrlResolved.getValue() : card.getUrl();
|
||||
if ("animated_gif".equals(name)) {
|
||||
media.media_url = ((StringValue) playerStreamUrl).getValue();
|
||||
media.type = Type.TYPE_CARD_ANIMATED_GIF;
|
||||
|
@ -272,6 +269,13 @@ public class ParcelableMedia implements Parcelable {
|
|||
return new ParcelableMedia[0];
|
||||
}
|
||||
|
||||
private static boolean checkUrl(StringValue value) {
|
||||
if (value == null) return false;
|
||||
final String valueString = value.getValue();
|
||||
return valueString != null && (valueString.startsWith("http://")
|
||||
|| valueString.startsWith("https://"));
|
||||
}
|
||||
|
||||
private static int getTypeInt(String type) {
|
||||
switch (type) {
|
||||
case MediaEntity.Type.PHOTO:
|
||||
|
|
|
@ -21,6 +21,7 @@ import android.annotation.SuppressLint;
|
|||
import android.app.Activity;
|
||||
import android.app.DialogFragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.media.AudioManager;
|
||||
|
@ -63,6 +64,7 @@ import android.widget.ProgressBar;
|
|||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.commonsware.cwac.layouts.AspectLockedFrameLayout;
|
||||
import com.pnikosis.materialishprogress.ProgressWheel;
|
||||
import com.sprylab.android.widget.TextureVideoView;
|
||||
|
||||
|
@ -242,7 +244,7 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements
|
|||
}
|
||||
case ParcelableMedia.Type.TYPE_EXTERNAL_PLAYER: {
|
||||
final Bundle args = new Bundle();
|
||||
args.putString(EXTRA_URL, TextUtils.isEmpty(media.media_url) ? media.url : media.media_url);
|
||||
args.putParcelable(EXTRA_MEDIA, media);
|
||||
return (MediaViewerFragment) Fragment.instantiate(this,
|
||||
ExternalBrowserPageFragment.class.getName(), args);
|
||||
}
|
||||
|
@ -320,7 +322,11 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements
|
|||
}
|
||||
case R.id.open_in_browser: {
|
||||
final ParcelableMedia media = getMedia()[currentItem];
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(media.media_url)));
|
||||
try {
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(media.url)));
|
||||
} catch (ActivityNotFoundException e) {
|
||||
// TODO show error, or improve app url
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1117,6 +1123,7 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements
|
|||
|
||||
public static class ExternalBrowserPageFragment extends MediaViewerFragment {
|
||||
private WebView mWebView;
|
||||
private AspectLockedFrameLayout mWebViewContainer;
|
||||
|
||||
@Override
|
||||
protected View onCreateMediaView(LayoutInflater inflater, ViewGroup parent,
|
||||
|
@ -1131,12 +1138,26 @@ public final class MediaViewerActivity extends AbsMediaViewerActivity implements
|
|||
final WebSettings webSettings = mWebView.getSettings();
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
webSettings.setLoadsImagesAutomatically(true);
|
||||
mWebView.loadUrl(getArguments().getString(EXTRA_URL));
|
||||
final ParcelableMedia media = getArguments().getParcelable(EXTRA_MEDIA);
|
||||
if (media == null) throw new NullPointerException();
|
||||
mWebView.loadUrl(TextUtils.isEmpty(media.media_url) ? media.url : media.media_url);
|
||||
mWebViewContainer.setAspectRatioSource(new AspectLockedFrameLayout.AspectRatioSource() {
|
||||
@Override
|
||||
public int getWidth() {
|
||||
return media.width;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
return media.height;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
mWebViewContainer = ((AspectLockedFrameLayout) view.findViewById(R.id.webview_container));
|
||||
mWebView = (WebView) view.findViewById(R.id.webview);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,15 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<WebView
|
||||
android:id="@+id/webview"
|
||||
<com.commonsware.cwac.layouts.AspectLockedFrameLayout
|
||||
android:id="@+id/webview_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<WebView
|
||||
android:id="@+id/webview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
</com.commonsware.cwac.layouts.AspectLockedFrameLayout>
|
||||
</FrameLayout>
|
Loading…
Reference in New Issue