导航菜单

页面标题

页面副标题

Aptoide v9.22.5.3 - YoutubeWebViewPlayer.java 源代码

正在查看: Aptoide v9.22.5.3 应用的 YoutubeWebViewPlayer.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package cm.aptoide.aptoideviews.video;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.Build;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.ValueCallback;
import android.webkit.WebResourceError;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import cm.aptoide.aptoideviews.video.YoutubeWebViewPlayer;
import java.util.LinkedHashMap;
import java.util.Map;
import kotlin.Metadata;
import kotlin.a0.d.m;
import kotlin.u;

@Metadata(d1 = {"\u0000D\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\u0018\u00002\u00020\u0001:\u0001\u0017B\u000f\b\u0016\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004B\u0019\b\u0016\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\b\u0010\u0005\u001a\u0004\u0018\u00010\u0006¢\u0006\u0002\u0010\u0007B!\b\u0016\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\b\u0010\u0005\u001a\u0004\u0018\u00010\u0006\u0012\u0006\u0010\b\u001a\u00020\t¢\u0006\u0002\u0010\nJ\u0016\u0010\r\u001a\u00020\u000e2\u0006\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0011\u001a\u00020\u0012J\u0014\u0010\u0013\u001a\u00020\u000e2\f\u0010\u0014\u001a\b\u0012\u0004\u0012\u00020\u000e0\u0015J\u0014\u0010\u0016\u001a\u00020\u000e2\f\u0010\u0014\u001a\b\u0012\u0004\u0012\u00020\u000e0\u0015R\u000e\u0010\u000b\u001a\u00020\fX\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u0018"}, d2 = {"Lcm/aptoide/aptoideviews/video/YoutubeWebViewPlayer;", "Landroid/webkit/WebView;", "context", "Landroid/content/Context;", "(Landroid/content/Context;)V", "attrs", "Landroid/util/AttributeSet;", "(Landroid/content/Context;Landroid/util/AttributeSet;)V", "defStyleAttr", "", "(Landroid/content/Context;Landroid/util/AttributeSet;I)V", "youtubeWebViewClient", "Lcm/aptoide/aptoideviews/video/YoutubeWebViewPlayer$YoutubeWebViewClient;", "loadVideo", "", "videoId", "", "enableSubtitles", "", "setOnErrorAction", "action", "Lkotlin/Function0;", "setOnPageFinishedAction", "YoutubeWebViewClient", "aptoide-views_prodRelease"}, k = 1, mv = {1, 6, 0}, xi = 48)
public final class YoutubeWebViewPlayer extends WebView {
    public Map<Integer, View> _$_findViewCache;
    private final YoutubeWebViewClient youtubeWebViewClient;

    @Metadata(d1 = {"\u0000D\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\b\u0002\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J\u001a\u0010\n\u001a\u00020\b2\u0006\u0010\u000b\u001a\u00020\f2\b\u0010\r\u001a\u0004\u0018\u00010\u000eH\u0016J&\u0010\u000f\u001a\u00020\b2\b\u0010\u000b\u001a\u0004\u0018\u00010\f2\b\u0010\r\u001a\u0004\u0018\u00010\u000e2\b\u0010\u0010\u001a\u0004\u0018\u00010\u0011H\u0016J&\u0010\u0012\u001a\u00020\b2\b\u0010\u000b\u001a\u0004\u0018\u00010\f2\b\u0010\u0013\u001a\u0004\u0018\u00010\u00142\b\u0010\u0015\u001a\u0004\u0018\u00010\u0016H\u0016J\u0014\u0010\u0017\u001a\u00020\b2\f\u0010\u0018\u001a\b\u0012\u0004\u0012\u00020\b0\u0007J\u0014\u0010\u0019\u001a\u00020\b2\f\u0010\u0018\u001a\b\u0012\u0004\u0012\u00020\b0\u0007J\u001c\u0010\u001a\u001a\u00020\u00042\b\u0010\u000b\u001a\u0004\u0018\u00010\f2\b\u0010\u0013\u001a\u0004\u0018\u00010\u0014H\u0016R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0004X\u0082\u000e¢\u0006\u0002\n\u0000R\u0016\u0010\u0006\u001a\n\u0012\u0004\u0012\u00020\b\u0018\u00010\u0007X\u0082\u000e¢\u0006\u0002\n\u0000R\u0016\u0010\t\u001a\n\u0012\u0004\u0012\u00020\b\u0018\u00010\u0007X\u0082\u000e¢\u0006\u0002\n\u0000¨\u0006\u001b"}, d2 = {"Lcm/aptoide/aptoideviews/video/YoutubeWebViewPlayer$YoutubeWebViewClient;", "Landroid/webkit/WebViewClient;", "()V", "hasError", "", "hasLoaded", "onErrorAction", "Lkotlin/Function0;", "", "onPageFinishedAction", "onPageFinished", "view", "Landroid/webkit/WebView;", "url", "", "onPageStarted", "favicon", "Landroid/graphics/Bitmap;", "onReceivedError", "request", "Landroid/webkit/WebResourceRequest;", "error", "Landroid/webkit/WebResourceError;", "setOnError", "action", "setOnPageFinishedAction", "shouldOverrideUrlLoading", "aptoide-views_prodRelease"}, k = 1, mv = {1, 6, 0}, xi = 48)
    static final class YoutubeWebViewClient extends WebViewClient {
        private boolean hasError;
        private boolean hasLoaded;
        private kotlin.a0.c.a<u> onErrorAction;
        private kotlin.a0.c.a<u> onPageFinishedAction;

        public static final void m20onPageFinished$lambda1(YoutubeWebViewClient youtubeWebViewClient, String str) {
            m.f(youtubeWebViewClient, "this$0");
            if (youtubeWebViewClient.hasError) {
                return;
            }
            youtubeWebViewClient.hasLoaded = true;
            kotlin.a0.c.a<u> aVar = youtubeWebViewClient.onPageFinishedAction;
            if (aVar != null) {
                aVar.invoke();
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            m.f(view, "view");
            if (Build.VERSION.SDK_INT >= 19) {
                view.evaluateJavascript("document.getElementsByClassName('ytp-chrome-top')[0].remove();document.getElementsByClassName('ytp-icon-large-play-button-hover')[0].style.background=\"no-repeat url('https://cdn6.aptoide.com/includes/themes/2014/images/vanilla_appcoins_info_video_placeholder.svg')\";document.getElementsByClassName('ytp-icon-large-play-button-hover')[0].style.width=\"75px\";document.getElementsByClassName('ytp-icon-large-play-button-hover')[0].style.height=\"75px\";", new ValueCallback() {
                    @Override
                    public final void onReceiveValue(Object obj) {
                        YoutubeWebViewPlayer.YoutubeWebViewClient.m20onPageFinished$lambda1(YoutubeWebViewPlayer.YoutubeWebViewClient.this, (String) obj);
                    }
                });
            }
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            this.hasError = false;
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            if (this.hasLoaded) {
                return;
            }
            kotlin.a0.c.a<u> aVar = this.onErrorAction;
            if (aVar != null) {
                aVar.invoke();
            }
            this.hasError = true;
        }

        public final void setOnError(kotlin.a0.c.a<u> aVar) {
            m.f(aVar, "action");
            this.onErrorAction = aVar;
        }

        public final void setOnPageFinishedAction(kotlin.a0.c.a<u> aVar) {
            m.f(aVar, "action");
            this.onPageFinishedAction = aVar;
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            return true;
        }
    }

    public YoutubeWebViewPlayer(Context context) {
        this(context, null);
        m.f(context, "context");
    }

    public static final boolean m19_init_$lambda0(YoutubeWebViewPlayer youtubeWebViewPlayer, View view, MotionEvent motionEvent) {
        m.f(youtubeWebViewPlayer, "this$0");
        if (Build.VERSION.SDK_INT < 19) {
            return false;
        }
        youtubeWebViewPlayer.evaluateJavascript("document.getElementsByClassName('ytp-endscreen-content')[0].remove();document.getElementsByClassName('html5-endscreen')[0].remove();document.getElementsByClassName('ytp-replay-button')[0].style.top=0;document.getElementsByClassName('ytp-pause-overlay')[0].remove();", null);
        return false;
    }

    public void _$_clearFindViewByIdCache() {
        this._$_findViewCache.clear();
    }

    public View _$_findCachedViewById(int i) {
        Map<Integer, View> map = this._$_findViewCache;
        View view = map.get(Integer.valueOf(i));
        if (view != null) {
            return view;
        }
        View findViewById = findViewById(i);
        if (findViewById == null) {
            return null;
        }
        map.put(Integer.valueOf(i), findViewById);
        return findViewById;
    }

    public final void loadVideo(String videoId, boolean enableSubtitles) {
        m.f(videoId, "videoId");
        loadUrl("https://www.youtube.com/embed/" + videoId + "?rel=0" + (enableSubtitles ? "&cc_load_policy=1" : ""));
    }

    public final void setOnErrorAction(kotlin.a0.c.a<u> aVar) {
        m.f(aVar, "action");
        this.youtubeWebViewClient.setOnError(aVar);
    }

    public final void setOnPageFinishedAction(kotlin.a0.c.a<u> aVar) {
        m.f(aVar, "action");
        this.youtubeWebViewClient.setOnPageFinishedAction(aVar);
    }

    public YoutubeWebViewPlayer(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
        m.f(context, "context");
    }

    public YoutubeWebViewPlayer(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        m.f(context, "context");
        this._$_findViewCache = new LinkedHashMap();
        YoutubeWebViewClient youtubeWebViewClient = new YoutubeWebViewClient();
        this.youtubeWebViewClient = youtubeWebViewClient;
        setOnTouchListener(new View.OnTouchListener() {
            @Override
            public final boolean onTouch(View view, MotionEvent motionEvent) {
                boolean m19_init_$lambda0;
                m19_init_$lambda0 = YoutubeWebViewPlayer.m19_init_$lambda0(YoutubeWebViewPlayer.this, view, motionEvent);
                return m19_init_$lambda0;
            }
        });
        setWebViewClient(youtubeWebViewClient);
        setWebChromeClient(new WebChromeClientWithoutPlayerPlaceholder());
        getSettings().setJavaScriptEnabled(true);
    }
}