导航菜单

页面标题

页面副标题

Biko v2.0.23 - WebViewLiveStreamActivity.java 源代码

正在查看: Biko v2.0.23 应用的 WebViewLiveStreamActivity.java JAVA 源代码文件

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


package app.callpe.ui.livestreaming;

import android.app.Activity;
import android.app.Dialog;
import android.app.PictureInPictureParams;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Rational;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.webkit.JavascriptInterface;
import android.webkit.PermissionRequest;
import android.webkit.ValueCallback;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.ProgressBar;
import androidx.activity.ComponentActivity;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContract;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.ViewModelLazy;
import androidx.lifecycle.ViewModelProvider;
import androidx.lifecycle.ViewModelStore;
import androidx.lifecycle.viewmodel.CreationExtras;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import app.callpe.common.utils.Constants;
import app.callpe.common.utils.RxBus;
import app.callpe.common.utils.extensions.ActivityExtKt;
import app.callpe.common.utils.sharedpref.PrefKeys;
import app.callpe.common.utils.sharedpref.SharedPref;
import app.callpe.data.model.CohostRequestModel;
import app.callpe.data.model.LiveStreamModel;
import app.callpe.databinding.ActivityWebViewVideoCallBinding;
import com.asynctaskcoffee.audiorecorder.R;
import com.facebook.internal.NativeProtocol;
import com.google.gson.Gson;
import com.permissionx.guolindev.databinding.PermissionxDefaultDialogLayoutBinding;
import com.permissionx.guolindev.databinding.PermissionxPermissionItemBinding;
import dagger.hilt.android.AndroidEntryPoint;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import javax.inject.Inject;
import kotlin.Lazy;
import kotlin.Metadata;
import kotlin.collections.ArraysKt;
import kotlin.collections.CollectionsKt;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.Intrinsics;
import kotlin.jvm.internal.Reflection;
import kotlin.text.StringsKt;
import timber.log.Timber;

@Metadata(d1 = {"\u0000x\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010 \n\u0002\u0010\u000e\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u000b\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0010\u0002\n\u0002\b\u0006\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\u0010\u0011\n\u0000\n\u0002\u0010\u0015\n\u0002\b\u0011\b\u0007\u0018\u00002\u00020\u0001:\u0001KB\u0005¢\u0006\u0002\u0010\u0002J\b\u0010'\u001a\u00020(H\u0002J\b\u0010)\u001a\u00020(H\u0002J\b\u0010*\u001a\u00020(H\u0002J\b\u0010+\u001a\u00020(H\u0016J\b\u0010,\u001a\u00020(H\u0002J\u0012\u0010-\u001a\u00020(2\b\u0010.\u001a\u0004\u0018\u00010/H\u0016J\b\u00100\u001a\u00020(H\u0014J\u0018\u00101\u001a\u00020(2\u0006\u00102\u001a\u0002032\u0006\u00104\u001a\u000205H\u0017J+\u00106\u001a\u00020(2\u0006\u00107\u001a\u0002082\f\u0010\u0010\u001a\b\u0012\u0004\u0012\u00020\u0012092\u0006\u0010:\u001a\u00020;H\u0016¢\u0006\u0002\u0010<J\b\u0010=\u001a\u00020(H\u0016J\b\u0010>\u001a\u00020(H\u0016J\b\u0010?\u001a\u00020(H\u0014J\u0016\u0010@\u001a\u0002032\f\u0010\u0010\u001a\b\u0012\u0004\u0012\u00020\u00120\u0011H\u0002J\b\u0010A\u001a\u00020(H\u0002J\u0016\u0010B\u001a\u00020(2\f\u0010\u0010\u001a\b\u0012\u0004\u0012\u00020\u00120\u0011H\u0002J\u0018\u0010C\u001a\u00020(2\u0006\u0010D\u001a\u00020\u00122\u0006\u0010E\u001a\u00020\u0012H\u0002J\b\u0010F\u001a\u00020(H\u0003J\b\u0010G\u001a\u00020(H\u0002J\u001b\u0010H\u001a\u00020(2\f\u0010\u0010\u001a\b\u0012\u0004\u0012\u00020\u001209H\u0002¢\u0006\u0002\u0010IJ\b\u0010J\u001a\u00020(H\u0002R\u0010\u0010\u0003\u001a\u0004\u0018\u00010\u0004X\u0082\u000e¢\u0006\u0002\n\u0000R\u0014\u0010\u0005\u001a\u00020\u00048BX\u0082\u0004¢\u0006\u0006\u001a\u0004\b\u0006\u0010\u0007R\u000e\u0010\b\u001a\u00020\tX\u0082\u0004¢\u0006\u0002\n\u0000R\u0010\u0010\n\u001a\u0004\u0018\u00010\u000bX\u0082\u000e¢\u0006\u0002\n\u0000R\u001c\u0010\f\u001a\u0010\u0012\f\u0012\n \u000f*\u0004\u0018\u00010\u000e0\u000e0\rX\u0082\u0004¢\u0006\u0002\n\u0000R\u0017\u0010\u0010\u001a\b\u0012\u0004\u0012\u00020\u00120\u0011¢\u0006\b\n\u0000\u001a\u0004\b\u0013\u0010\u0014R\u001e\u0010\u0015\u001a\u00020\u00168\u0006@\u0006X\u0087.¢\u0006\u000e\n\u0000\u001a\u0004\b\u0017\u0010\u0018\"\u0004\b\u0019\u0010\u001aR$\u0010\u001b\u001a\u00020\u00128\u0006@\u0006X\u0087.¢\u0006\u0014\n\u0000\u0012\u0004\b\u001c\u0010\u0002\u001a\u0004\b\u001d\u0010\u001e\"\u0004\b\u001f\u0010 R\u001b\u0010!\u001a\u00020\"8BX\u0082\u0084\u0002¢\u0006\f\n\u0004\b%\u0010&\u001a\u0004\b#\u0010$¨\u0006L"}, d2 = {"Lapp/callpe/ui/livestreaming/WebViewLiveStreamActivity;", "Lapp/callpe/ui/call/BaseWebCallActivity;", "()V", "_binding", "Lapp/callpe/databinding/ActivityWebViewVideoCallBinding;", "binding", "getBinding", "()Lapp/callpe/databinding/ActivityWebViewVideoCallBinding;", "broadcastReceiver", "Landroid/content/BroadcastReceiver;", "dialog", "Landroid/app/Dialog;", "openSettingsLauncher", "Landroidx/activity/result/ActivityResultLauncher;", "Landroid/content/Intent;", "kotlin.jvm.PlatformType", NativeProtocol.RESULT_ARGS_PERMISSIONS, "", "", "getPermissions", "()Ljava/util/List;", "rxBus", "Lapp/callpe/common/utils/RxBus;", "getRxBus", "()Lapp/callpe/common/utils/RxBus;", "setRxBus", "(Lapp/callpe/common/utils/RxBus;)V", "userId", "getUserId$annotations", "getUserId", "()Ljava/lang/String;", "setUserId", "(Ljava/lang/String;)V", "viewModel", "Lapp/callpe/ui/livestreaming/LiveStreamViewModel;", "getViewModel", "()Lapp/callpe/ui/livestreaming/LiveStreamViewModel;", "viewModel$delegate", "Lkotlin/Lazy;", "enablePip", "", "endStream", "initUI", "onBackPressed", "onClicks", "onCreate", "savedInstanceState", "Landroid/os/Bundle;", "onDestroy", "onPictureInPictureModeChanged", "isInPictureInPictureMode", "", "newConfig", "Landroid/content/res/Configuration;", "onRequestPermissionsResult", "requestCode", "", "", "grantResults", "", "(I[Ljava/lang/String;[I)V", "onStart", "onStop", "onUserLeaveHint", "permissionsGranted", "registerReceiver", "requestPermissionsIfNeeded", "sendDataToWebView", "function", NativeProtocol.WEB_DIALOG_PARAMS, "setupDefaultSettings", "showOnLockScreen", "showOpenSettingDialog", "([Ljava/lang/String;)V", "unRegisterReceiver", "WebAppInterface", "app_bikoRelease"}, k = 1, mv = {1, 8, 0}, xi = 48)
@AndroidEntryPoint
public final class WebViewLiveStreamActivity extends Hilt_WebViewLiveStreamActivity {
    private ActivityWebViewVideoCallBinding _binding;
    private Dialog dialog;
    private final ActivityResultLauncher<Intent> openSettingsLauncher;

    @Inject
    public RxBus rxBus;

    @Inject
    public String userId;

    private final Lazy viewModel;
    private final List<String> permissions = CollectionsKt.listOf(new String[]{"android.permission.CAMERA", "android.permission.RECORD_AUDIO"});
    private final BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            boolean isStreamer;
            boolean isStreamer2;
            boolean isStreamer3;
            String stringExtra;
            boolean isStreamer4;
            String stringExtra2;
            boolean isStreamer5;
            String stringExtra3;
            LiveStreamViewModel viewModel;
            LiveStreamViewModel viewModel2;
            LiveStreamViewModel viewModel3;
            LiveStreamViewModel viewModel4;
            Intrinsics.checkNotNullParameter(context, "context");
            Intrinsics.checkNotNullParameter(intent, "intent");
            Timber.e("Action %s", new Object[]{intent.getAction()});
            String action = intent.getAction();
            if (action != null) {
                switch (action.hashCode()) {
                    case -853151216:
                        if (action.equals(LiveStreamingActivity.COHOST_END)) {
                            isStreamer = WebViewLiveStreamActivity.this.getIsStreamer();
                            if (!isStreamer) {
                                WebViewLiveStreamActivity.this.sendDataToWebView("coHostEnd", "{\"coHostEnd\":\"true\"}");
                                break;
                            }
                        }
                        break;
                    case 31643316:
                        if (action.equals(Constants.GIFT_RECEIVE)) {
                            isStreamer2 = WebViewLiveStreamActivity.this.getIsStreamer();
                            if (isStreamer2) {
                                String stringExtra4 = intent.getStringExtra("gift");
                                WebViewLiveStreamActivity webViewLiveStreamActivity = WebViewLiveStreamActivity.this;
                                if (stringExtra4 == null) {
                                    stringExtra4 = "";
                                }
                                webViewLiveStreamActivity.sendDataToWebView("handleGift", stringExtra4);
                                break;
                            }
                        }
                        break;
                    case 45045344:
                        if (action.equals(Constants.GIFT_REQUEST)) {
                            isStreamer3 = WebViewLiveStreamActivity.this.getIsStreamer();
                            if (!isStreamer3 && (stringExtra = intent.getStringExtra("gift")) != null) {
                                WebViewLiveStreamActivity.this.sendDataToWebView("handleGift", stringExtra);
                                break;
                            }
                        }
                        break;
                    case 240030167:
                        if (action.equals(LiveStreamingActivity.GIFT_RECEIVE_LIVESTREAM)) {
                            isStreamer4 = WebViewLiveStreamActivity.this.getIsStreamer();
                            if (!isStreamer4 && (stringExtra2 = intent.getStringExtra("gift")) != null) {
                                WebViewLiveStreamActivity.this.sendDataToWebView("handleGiftReceived", stringExtra2);
                                break;
                            }
                        }
                        break;
                    case 1624162403:
                        if (action.equals(LiveStreamingActivity.COHOST_REQUEST_ACCEPT)) {
                            isStreamer5 = WebViewLiveStreamActivity.this.getIsStreamer();
                            if (!isStreamer5 && (stringExtra3 = intent.getStringExtra("cohost")) != null) {
                                WebViewLiveStreamActivity webViewLiveStreamActivity2 = WebViewLiveStreamActivity.this;
                                CohostRequestModel cohostRequestModel = (CohostRequestModel) new Gson().fromJson(stringExtra3, CohostRequestModel.class);
                                if (cohostRequestModel != null) {
                                    viewModel = webViewLiveStreamActivity2.getViewModel();
                                    viewModel.setCohostRequestModel(cohostRequestModel);
                                    long livestreamId = cohostRequestModel.getLivestreamId();
                                    viewModel2 = webViewLiveStreamActivity2.getViewModel();
                                    if (livestreamId == viewModel2.getLiveStreamId()) {
                                        viewModel3 = webViewLiveStreamActivity2.getViewModel();
                                        long cohostId = cohostRequestModel.getCohostId();
                                        viewModel4 = webViewLiveStreamActivity2.getViewModel();
                                        viewModel3.joinAsCohost(cohostId, viewModel4.getCurrentPosition());
                                        break;
                                    }
                                }
                            }
                        }
                        break;
                    case 2112913146:
                        if (action.equals(LiveStreamingActivity.COHOST_REQUEST_REJECT)) {
                            ActivityExtKt.toast((Activity) WebViewLiveStreamActivity.this, "Streamer rejected your Co-host request");
                            break;
                        }
                        break;
                }
            }
        }
    };

    public static void getUserId$annotations() {
    }

    private final void onClicks() {
    }

    public void onBackPressed() {
    }

    public WebViewLiveStreamActivity() {
        final ComponentActivity componentActivity = (ComponentActivity) this;
        final Function0 function0 = null;
        this.viewModel = new ViewModelLazy(Reflection.getOrCreateKotlinClass(LiveStreamViewModel.class), new Function0<ViewModelStore>() {
            {
                super(0);
            }

            public final ViewModelStore m1859invoke() {
                return componentActivity.getViewModelStore();
            }
        }, new Function0<ViewModelProvider.Factory>() {
            {
                super(0);
            }

            public final ViewModelProvider.Factory m1858invoke() {
                return componentActivity.getDefaultViewModelProviderFactory();
            }
        }, new Function0<CreationExtras>() {
            {
                super(0);
            }

            public final CreationExtras m1860invoke() {
                CreationExtras creationExtras;
                Function0 function02 = function0;
                return (function02 == null || (creationExtras = (CreationExtras) function02.invoke()) == null) ? componentActivity.getDefaultViewModelCreationExtras() : creationExtras;
            }
        });
        ActivityResultLauncher<Intent> registerForActivityResult = registerForActivityResult((ActivityResultContract) new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback() {
            public final void onActivityResult(Object obj) {
                WebViewLiveStreamActivity.openSettingsLauncher$lambda$4(WebViewLiveStreamActivity.this, (ActivityResult) obj);
            }
        });
        Intrinsics.checkNotNullExpressionValue(registerForActivityResult, "registerForActivityResul…missions)\n        }\n    }");
        this.openSettingsLauncher = registerForActivityResult;
    }

    public final ActivityWebViewVideoCallBinding getBinding() {
        ActivityWebViewVideoCallBinding activityWebViewVideoCallBinding = this._binding;
        Intrinsics.checkNotNull(activityWebViewVideoCallBinding);
        return activityWebViewVideoCallBinding;
    }

    public final LiveStreamViewModel getViewModel() {
        return (LiveStreamViewModel) this.viewModel.getValue();
    }

    public final String getUserId() {
        String str = this.userId;
        if (str != null) {
            return str;
        }
        Intrinsics.throwUninitializedPropertyAccessException("userId");
        return null;
    }

    public final void setUserId(String str) {
        Intrinsics.checkNotNullParameter(str, "<set-?>");
        this.userId = str;
    }

    public final RxBus getRxBus() {
        RxBus rxBus = this.rxBus;
        if (rxBus != null) {
            return rxBus;
        }
        Intrinsics.throwUninitializedPropertyAccessException("rxBus");
        return null;
    }

    public final void setRxBus(RxBus rxBus) {
        Intrinsics.checkNotNullParameter(rxBus, "<set-?>");
        this.rxBus = rxBus;
    }

    public final List<String> getPermissions() {
        return this.permissions;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this._binding = ActivityWebViewVideoCallBinding.inflate(getLayoutInflater());
        showOnLockScreen();
        setContentView((View) getBinding().getRoot());
        initUI();
        onClicks();
    }

    private final void initUI() {
        String str;
        if (permissionsGranted(this.permissions)) {
            WebView webView = getBinding().webView;
            webView.addJavascriptInterface(new WebAppInterface(), "AppInterface");
            setupDefaultSettings();
            webView.setWebChromeClient(new WebChromeClient() {
                @Override
                public boolean onShowFileChooser(WebView webView2, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) {
                    return true;
                }

                @Override
                public void onPermissionRequest(PermissionRequest request) {
                    if (request != null) {
                        request.grant(request.getResources());
                    }
                }
            });
            webView.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageStarted(WebView view, String url, Bitmap favicon) {
                    ActivityWebViewVideoCallBinding binding;
                    super.onPageStarted(view, url, favicon);
                    binding = WebViewLiveStreamActivity.this.getBinding();
                    ProgressBar progressBar = binding.progress;
                    Intrinsics.checkNotNullExpressionValue(progressBar, "binding.progress");
                    progressBar.setVisibility(0);
                }

                @Override
                public void onPageFinished(WebView view, String url) {
                    ActivityWebViewVideoCallBinding binding;
                    super.onPageFinished(view, url);
                    binding = WebViewLiveStreamActivity.this.getBinding();
                    ProgressBar progressBar = binding.progress;
                    Intrinsics.checkNotNullExpressionValue(progressBar, "binding.progress");
                    progressBar.setVisibility(8);
                }

                @Override
                public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
                    Uri url;
                    String uri;
                    StringBuilder sb = new StringBuilder();
                    sb.append("New Url Detected: ");
                    sb.append(request != null ? request.getUrl() : null);
                    boolean z = false;
                    Timber.e(sb.toString(), new Object[0]);
                    if (request != null && (url = request.getUrl()) != null && (uri = url.toString()) != null && StringsKt.contains$default(uri, "/stream/end", false, 2, (Object) null)) {
                        z = true;
                    }
                    if (z) {
                        WebViewLiveStreamActivity.this.endStream();
                    }
                    return true;
                }
            });
            String string = SharedPref.getString((Context) this, PrefKeys.AUTH_TOKEN);
            Intent intent = getIntent();
            String valueOf = String.valueOf(intent != null ? intent.getStringExtra("RTC_PROVIDER") : null);
            Intent intent2 = getIntent();
            String stringExtra = intent2 != null ? intent2.getStringExtra(LiveStreamingActivity.LIVE_STREAM_MODEL) : null;
            String str2 = stringExtra;
            if (str2 == null || StringsKt.isBlank(str2)) {
                str = "";
            } else {
                getViewModel().setLiveStreamDetails((LiveStreamModel) new Gson().fromJson(stringExtra, LiveStreamModel.class));
                LiveStreamModel liveStreamDetails = getViewModel().getLiveStreamDetails();
                if (liveStreamDetails == null || (str = liveStreamDetails.getWebViewUrl()) == null) {
                    str = "https://livekit-indol.vercel.app/livestream";
                }
            }
            if (str.length() == 0) {
                ActivityExtKt.toast((Activity) this, "Web link is empty");
                finish();
            }
            Intent intent3 = getIntent();
            String str3 = str + "?liveStreamId=" + (intent3 != null ? intent3.getLongExtra(LiveStreamingActivity.LIVE_STREAM_ID, -1L) : -1L) + "&rtcProvider=" + valueOf + "&token=" + string;
            Timber.e("Url " + str3, new Object[0]);
            webView.loadUrl(str3);
            return;
        }
        requestPermissionsIfNeeded(this.permissions);
    }

    private final void setupDefaultSettings() {
        WebView webView = getBinding().webView;
        webView.getSettings().setLoadWithOverviewMode(true);
        webView.getSettings().setUseWideViewPort(true);
        webView.getSettings().setSupportZoom(true);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDisplayZoomControls(false);
        webView.getSettings().setDomStorageEnabled(true);
        webView.getSettings().setAllowFileAccess(true);
        webView.getSettings().setDomStorageEnabled(true);
        webView.getSettings().setDatabaseEnabled(true);
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
    }

    private final void showOnLockScreen() {
        try {
            if (Build.VERSION.SDK_INT == 30) {
                SharedPref.setInt((Context) this, PrefKeys.USER_COUNT_IN_ROOM, 0);
            }
            getWindow().addFlags(69730304);
        } catch (Exception e) {
            Timber.e(e);
        }
    }

    @Metadata(d1 = {"\u0000\u001a\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0003\b\u0086\u0004\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J\u0012\u0010\u0003\u001a\u00020\u00042\b\u0010\u0005\u001a\u0004\u0018\u00010\u0006H\u0007J\u0012\u0010\u0007\u001a\u00020\u00042\b\u0010\u0005\u001a\u0004\u0018\u00010\u0006H\u0007J\u0012\u0010\b\u001a\u00020\u00042\b\u0010\u0005\u001a\u0004\u0018\u00010\u0006H\u0002¨\u0006\t"}, d2 = {"Lapp/callpe/ui/livestreaming/WebViewLiveStreamActivity$WebAppInterface;", "", "(Lapp/callpe/ui/livestreaming/WebViewLiveStreamActivity;)V", "onRechargeClicked", "", NativeProtocol.WEB_DIALOG_PARAMS, "", "onTimerUpdate", "topUpClick", "app_bikoRelease"}, k = 1, mv = {1, 8, 0}, xi = 48)
    public final class WebAppInterface {
        private final void topUpClick(String params) {
        }

        public WebAppInterface() {
        }

        @JavascriptInterface
        public final void onRechargeClicked(String params) {
            topUpClick(params);
        }

        @JavascriptInterface
        public final void onTimerUpdate(String params) {
            Timber.d("Processing onTimerUpdate: " + params, new Object[0]);
        }
    }

    public final void sendDataToWebView(String function, String params) {
        WebView webView;
        ActivityWebViewVideoCallBinding activityWebViewVideoCallBinding = this._binding;
        if (activityWebViewVideoCallBinding == null || (webView = activityWebViewVideoCallBinding.webView) == null) {
            return;
        }
        webView.evaluateJavascript("javascript:" + function + '(' + params + ')', new ValueCallback() {
            @Override
            public final void onReceiveValue(Object obj) {
                WebViewLiveStreamActivity.sendDataToWebView$lambda$3$lambda$2((String) obj);
            }
        });
    }

    public static final void sendDataToWebView$lambda$3$lambda$2(String str) {
        Timber.d("JavaScript returned: " + str, new Object[0]);
    }

    public final void endStream() {
        LiveStreamViewModel.endStream$default(getViewModel(), getIsStreamer(), false, 0L, null, 14, null);
        getBinding().webView.destroy();
        finish();
    }

    protected void onUserLeaveHint() {
        super.onUserLeaveHint();
        enablePip();
    }

    public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, Configuration newConfig) {
        Intrinsics.checkNotNullParameter(newConfig, "newConfig");
        super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig);
        getViewModel().setInPictureInPictureMode(isInPictureInPictureMode);
        sendDataToWebView("handlePip", "{\"pip\":\"" + isInPictureInPictureMode + "\"}");
    }

    private final void enablePip() {
        try {
            Rational rational = new Rational(3, 4);
            if (Build.VERSION.SDK_INT >= 26) {
                if (getPackageManager().hasSystemFeature("android.software.picture_in_picture")) {
                    Timber.tag("PIP").e("*** Picture-in-Picture ***", new Object[0]);
                    enterPictureInPictureMode(new PictureInPictureParams.Builder().setAspectRatio(rational).setSourceRectHint(new Rect()).build());
                } else {
                    Timber.tag("PIP").e("*** No support Picture-in-Picture ***", new Object[0]);
                }
            }
        } catch (Exception e) {
            Activity activity = (Activity) this;
            String message = e.getMessage();
            if (message == null) {
                message = "";
            }
            ActivityExtKt.toast(activity, message);
        }
    }

    private final void registerReceiver() {
        LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance((Context) this);
        Intrinsics.checkNotNullExpressionValue(localBroadcastManager, "getInstance(this)");
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(Constants.GIFT_REQUEST);
        intentFilter.addAction(Constants.GIFT_RECEIVE);
        intentFilter.addAction(LiveStreamingActivity.GIFT_RECEIVE_LIVESTREAM);
        intentFilter.addAction(LiveStreamingActivity.COHOST_END);
        intentFilter.addAction(LiveStreamingActivity.COHOST_REQUEST_REJECT);
        intentFilter.addAction(LiveStreamingActivity.COHOST_REQUEST_ACCEPT);
        intentFilter.addAction(LiveStreamingActivity.COHOST_JOIN_REQUEST);
        localBroadcastManager.registerReceiver(this.broadcastReceiver, intentFilter);
    }

    private final void unRegisterReceiver() {
        LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance((Context) this);
        Intrinsics.checkNotNullExpressionValue(localBroadcastManager, "getInstance(this)");
        localBroadcastManager.unregisterReceiver(this.broadcastReceiver);
    }

    private final void requestPermissionsIfNeeded(List<String> permissions) {
        ActivityCompat.requestPermissions((Activity) this, (String[]) permissions.toArray(new String[0]), 1010);
    }

    public static final void openSettingsLauncher$lambda$4(WebViewLiveStreamActivity webViewLiveStreamActivity, ActivityResult activityResult) {
        Intrinsics.checkNotNullParameter(webViewLiveStreamActivity, "this$0");
        Intrinsics.checkNotNullParameter(activityResult, "<anonymous parameter 0>");
        if (webViewLiveStreamActivity.permissionsGranted(CollectionsKt.toList(webViewLiveStreamActivity.permissions))) {
            webViewLiveStreamActivity.initUI();
        } else {
            webViewLiveStreamActivity.requestPermissionsIfNeeded(webViewLiveStreamActivity.permissions);
        }
    }

    private final boolean permissionsGranted(List<String> permissions) {
        Iterator<String> it = permissions.iterator();
        boolean z = true;
        while (it.hasNext()) {
            if (ContextCompat.checkSelfPermission((Context) this, it.next()) != 0) {
                z = false;
            }
        }
        return z;
    }

    private final void showOpenSettingDialog(String[] permissions) {
        Window window;
        try {
            Dialog dialog = this.dialog;
            if (dialog != null) {
                if (dialog != null && dialog.isShowing()) {
                    return;
                }
            }
            this.dialog = new Dialog((Context) this);
            PermissionxDefaultDialogLayoutBinding inflate = PermissionxDefaultDialogLayoutBinding.inflate(LayoutInflater.from((Context) this));
            Intrinsics.checkNotNullExpressionValue(inflate, "inflate(\n               …      )\n                )");
            Dialog dialog2 = this.dialog;
            if (dialog2 != null) {
                dialog2.setContentView(inflate.getRoot());
            }
            Dialog dialog3 = this.dialog;
            if (dialog3 != null) {
                dialog3.setCancelable(false);
            }
            String string = getString(2131952424);
            Intrinsics.checkNotNullExpressionValue(string, "getString(R.string.permission_explain_camera_mic)");
            if (permissions.length == 1) {
                if (ArraysKt.contains(permissions, "android.permission.CAMERA")) {
                    string = getString(2131952423);
                    Intrinsics.checkNotNullExpressionValue(string, "this.getString(R.string.permission_explain_camera)");
                } else if (ArraysKt.contains(permissions, "android.permission.RECORD_AUDIO")) {
                    string = getString(2131952425);
                    Intrinsics.checkNotNullExpressionValue(string, "this.getString(R.string.permission_explain_mic)");
                }
            }
            inflate.positiveBtn.setText(getString(2131952579));
            Button button = inflate.negativeBtn;
            Intrinsics.checkNotNullExpressionValue(button, "binding.negativeBtn");
            button.setVisibility(8);
            inflate.messageText.setText(string);
            for (String str : permissions) {
                PermissionxPermissionItemBinding inflate2 = PermissionxPermissionItemBinding.inflate(getLayoutInflater(), inflate.permissionsLayout, false);
                Intrinsics.checkNotNullExpressionValue(inflate2, "inflate(\n               …, false\n                )");
                if (Intrinsics.areEqual(str, "android.permission.CAMERA")) {
                    inflate2.permissionText.setText(getString(2131952989));
                    inflate2.permissionIcon.setImageResource(2131231551);
                } else if (Intrinsics.areEqual(str, "android.permission.RECORD_AUDIO")) {
                    inflate2.permissionText.setText("Microphone");
                    inflate2.permissionIcon.setImageResource(R.drawable.ic_mic);
                }
                inflate2.permissionIcon.setColorFilter(ContextCompat.getColor((Context) this, 2131100837), PorterDuff.Mode.SRC_ATOP);
                inflate.permissionsLayout.addView(inflate2.getRoot());
            }
            inflate.positiveBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view) {
                    WebViewLiveStreamActivity.showOpenSettingDialog$lambda$5(WebViewLiveStreamActivity.this, view);
                }
            });
            Dialog dialog4 = this.dialog;
            if (dialog4 != null) {
                dialog4.show();
            }
            Dialog dialog5 = this.dialog;
            if (dialog5 == null || (window = dialog5.getWindow()) == null) {
                return;
            }
            window.setBackgroundDrawable(new ColorDrawable(0));
        } catch (Exception e) {
            Timber.e(e);
        }
    }

    public static final void showOpenSettingDialog$lambda$5(WebViewLiveStreamActivity webViewLiveStreamActivity, View view) {
        Intrinsics.checkNotNullParameter(webViewLiveStreamActivity, "this$0");
        Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
        intent.setData(Uri.fromParts("package", webViewLiveStreamActivity.getPackageName(), null));
        webViewLiveStreamActivity.openSettingsLauncher.launch(intent);
        Dialog dialog = webViewLiveStreamActivity.dialog;
        if (dialog != null) {
            dialog.dismiss();
        }
    }

    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        Intrinsics.checkNotNullParameter(permissions, NativeProtocol.RESULT_ARGS_PERMISSIONS);
        Intrinsics.checkNotNullParameter(grantResults, "grantResults");
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        if (requestCode == 1010) {
            boolean permissionsGranted = permissionsGranted(this.permissions);
            Timber.e("permission granted --- " + permissionsGranted, new Object[0]);
            if (permissionsGranted) {
                initUI();
                return;
            }
            if (grantResults.length == 0) {
                return;
            }
            ArrayList arrayList = new ArrayList();
            int length = permissions.length;
            for (int i = 0; i < length; i++) {
                if (grantResults[i] != 0) {
                    arrayList.add(permissions[i]);
                }
            }
            showOpenSettingDialog((String[]) arrayList.toArray(new String[0]));
        }
    }

    @Override
    protected void onDestroy() {
        Dialog dialog;
        super.onDestroy();
        Dialog dialog2 = this.dialog;
        if (dialog2 != null) {
            if ((dialog2 != null && dialog2.isShowing()) && (dialog = this.dialog) != null) {
                dialog.dismiss();
            }
        }
        if (isFinishing()) {
            endStream();
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        registerReceiver();
    }

    @Override
    public void onStop() {
        super.onStop();
        unRegisterReceiver();
    }
}