package com.ss.android.ugc.aweme.account.login.v2.ui.fragments;

import X.070;
import X.2nK;
import X.9Wm;
import X.9Wn;
import X.APJ;
import X.C2162Rtm;
import X.C2171Rtv;
import X.C2172Rtw;
import X.C2202RuQ;
import X.C2306Rw6;
import X.C2315RwF;
import X.C2316RwG;
import X.C2317RwH;
import X.CE9;
import X.JtF;
import X.KOD;
import X.KaO;
import X.LgZ;
import X.Lga;
import X.M12;
import X.MCo;
import X.Qeg;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.lobby.auth.AuthResult;
import com.ss.android.ugc.aweme.account.login.v2.ui.SignUpOrLoginActivity;
import java.util.HashMap;
import java.util.Objects;
import kotlin.h.b.n;

public final class TermsConsentFragmentV2 extends BaseI18nLoginFragment {
    public String LIZ;
    public boolean LIZIZ;
    public boolean LIZJ;
    public int LIZLLL;
    public boolean LJIIL;
    public String LJIILIIL = "";
    public int LJIILJJIL = C2162Rtm.TERMS_CONSENT_SIGN_UP.getValue();
    public AuthResult LJIILL;
    public HashMap LJIIZILJ;

    static {
        Covode.recordClassIndex(51931);
    }

    public final int LIZ() {
        return 2131558766;
    }

    public final View LIZ(int i) {
        if (this.LJIIZILJ == null) {
            this.LJIIZILJ = new HashMap();
        }
        View view = (View) this.LJIIZILJ.get(Integer.valueOf(i));
        if (view != null) {
            return view;
        }
        View view2 = getView();
        if (view2 == null) {
            return null;
        }
        View findViewById = view2.findViewById(i);
        this.LJIIZILJ.put(Integer.valueOf(i), findViewById);
        return findViewById;
    }

    public final void LIZ(int i, String str) {
        M12.LIZ(str);
    }

    public final C2202RuQ LIZLLL() {
        return null;
    }

    public final void LJFF() {
    }

    public final void LJI() {
    }

    public final void LJIIJ() {
        HashMap hashMap = this.LJIIZILJ;
        if (hashMap != null) {
            hashMap.clear();
        }
    }

    public final /* synthetic */ void onDestroyView() {
        super.onDestroyView();
        LJIIJ();
    }

    public final boolean aA_() {
        if (!this.LIZIZ || this.LIZJ) {
            return super.aA_();
        }
        this.LIZLLL = 0;
        LJII();
        return true;
    }

    public final void LJII() {
        Bundle arguments = getArguments();
        if (arguments == null) {
            arguments = new Bundle();
        }
        n.LIZIZ(arguments, "");
        arguments.putInt("next_page", C2162Rtm.FINISH.getValue());
        arguments.putInt("result_code", this.LIZLLL);
        arguments.putInt("current_page", C2162Rtm.TERMS_CONSENT_SIGN_UP_THIRD_PARTY.getValue());
        LIZ(arguments);
    }

    public final void onCreate(Bundle bundle) {
        boolean z;
        String str;
        String string;
        AuthResult authResult;
        int value;
        String str2;
        TermsConsentFragmentV2.super.onCreate(bundle);
        Bundle arguments = getArguments();
        boolean z2 = true;
        if (ar_() == C2162Rtm.TERMS_CONSENT_SIGN_UP_THIRD_PARTY) {
            z = true;
        } else {
            z = false;
        }
        this.LIZIZ = z;
        String str3 = "";
        if (z) {
            if (arguments != null) {
                authResult = (AuthResult) arguments.getParcelable("key_auth_result");
            } else {
                authResult = null;
            }
            this.LJIILL = authResult;
            if (!(authResult == null || (str2 = authResult.LIZLLL) == null)) {
                str3 = str2;
            }
            this.LIZ = str3;
            int value2 = C2162Rtm.THIRD_PARTY_AGE_GATE.getValue();
            if (arguments != null) {
                value = arguments.getInt("previous_page", C2162Rtm.NONE.getValue());
            } else {
                value = C2162Rtm.NONE.getValue();
            }
            if (value2 != value) {
                z2 = false;
            }
            this.LIZJ = z2;
        } else {
            this.LJIILJJIL = ar_().getValue();
            if (!(arguments == null || (string = arguments.getString("sms_code_key", str3)) == null)) {
                str3 = string;
            }
            this.LJIILIIL = str3;
            if (this.LJIILJJIL == C2162Rtm.TERMS_CONSENT_NEW_PHONE_USER.getValue()) {
                str = "sms_verification";
            } else {
                str = "phone";
            }
            this.LIZ = str;
        }
        JtF jtF = new JtF();
        jtF.LIZ("enter_from", as_());
        jtF.LIZ("enter_method", LJIJI());
        jtF.LIZ("platform", this.LIZ);
        2nK.LIZ("register_terms_show", jtF.LIZ);
    }

    public final void LIZ(boolean z) {
        if (z) {
            Qeg LIZ2 = LIZ(2131363045);
            Context context = getContext();
            if (context == null) {
                n.LIZIZ();
            }
            LIZ2.setTextColor(070.LIZJ(context, 2131099659));
            Qeg LIZ3 = LIZ(2131363045);
            n.LIZIZ(LIZ3, "");
            Context context2 = getContext();
            if (context2 == null) {
                n.LIZIZ();
            }
            LIZ3.setBackground(context2.getDrawable(2131231101));
            APJ.LIZ(LIZ(2131363045), 0.5f);
            return;
        }
        Qeg LIZ4 = LIZ(2131363045);
        Context context3 = getContext();
        if (context3 == null) {
            n.LIZIZ();
        }
        LIZ4.setTextColor(070.LIZJ(context3, 2131099752));
        Qeg LIZ5 = LIZ(2131363045);
        n.LIZIZ(LIZ5, "");
        Context context4 = getContext();
        if (context4 == null) {
            n.LIZIZ();
        }
        LIZ5.setBackground(context4.getDrawable(2131231121));
        APJ.LIZ(LIZ(2131363045), 1.0f);
    }

    public static void LIZ(WebView webView, String str) {
        MethodCollector.i(315);
        String LIZ2 = KOD.LIZ.LIZ(webView, str);
        if (!TextUtils.isEmpty(LIZ2)) {
            str = LIZ2;
        }
        webView.loadUrl(str);
        MethodCollector.o(315);
    }

    public static void LIZ(WebView webView, WebViewClient webViewClient) {
        if (9Wm.LIZIZ.LIZ()) {
            WebSettings settings = webView.getSettings();
            String userAgentString = settings.getUserAgentString();
            if (!userAgentString.contains("BytedanceWebview/d8a21c6")) {
                StringBuilder sb = new StringBuilder(userAgentString);
                if (!TextUtils.isEmpty(sb)) {
                    sb.append(" ");
                }
                sb.append("BytedanceWebview/d8a21c6");
                settings.setUserAgentString(sb.toString());
            }
        }
        webView.setWebViewClient(9Wn.LIZ(webViewClient));
    }

    public final void LIZ(String str, boolean z) {
        int i;
        JtF jtF = new JtF();
        jtF.LIZ("enter_from", as_());
        jtF.LIZ("enter_method", LJIJI());
        jtF.LIZ("platform", this.LIZ);
        jtF.LIZ("content", str);
        if (z) {
            i = 1;
        } else {
            i = 2;
        }
        jtF.LIZ("click_type", i);
        2nK.LIZ("register_terms_click", jtF.LIZ);
    }

    public final void onViewCreated(View view, Bundle bundle) {
        String LIZIZ2;
        String LIZJ2;
        View view2 = view;
        M12.LIZ(view2);
        super.onViewCreated(view2, bundle);
        Qeg LIZ2 = LIZ(2131371476);
        n.LIZIZ(LIZ2, "");
        if (TextUtils.isEmpty(MCo.LIZIZ())) {
            LIZIZ2 = getString(2131831644);
        } else {
            LIZIZ2 = MCo.LIZIZ();
        }
        LIZ2.setText(LIZIZ2);
        Qeg LIZ3 = LIZ(2131371475);
        n.LIZIZ(LIZ3, "");
        if (TextUtils.isEmpty(MCo.LIZJ())) {
            LIZJ2 = getString(2131831643);
        } else {
            LIZJ2 = MCo.LIZJ();
        }
        LIZ3.setText(LIZJ2);
        if (getActivity() instanceof SignUpOrLoginActivity) {
            SignUpOrLoginActivity activity = getActivity();
            Objects.requireNonNull(activity, "null cannot be cast to non-null type com.ss.android.ugc.aweme.account.login.v2.ui.SignUpOrLoginActivity");
            activity.LIZJ = 1;
        }
        CE9 LIZ4 = LIZ(2131363191);
        n.LIZIZ(LIZ4, "");
        CE9 LIZ5 = LIZ(2131363193);
        n.LIZIZ(LIZ5, "");
        CE9 LIZ6 = LIZ(2131363192);
        n.LIZIZ(LIZ6, "");
        CE9 LIZ7 = LIZ(2131363190);
        n.LIZIZ(LIZ7, "");
        LIZ4.setOnCheckedChangeListener(new C2315RwF(this, LIZ5, LIZ6, LIZ7));
        LIZ5.setOnCheckedChangeListener(new C2316RwG(this, LIZ6, LIZ7, LIZ4, LIZ5));
        LIZ6.setOnCheckedChangeListener(new C2317RwH(this, LIZ5, LIZ7, LIZ4, LIZ6));
        LIZ7.setOnCheckedChangeListener(new C2306Rw6(this, LIZ5, LIZ6, LIZ4));
        String LIZIZ3 = MCo.LIZ.LIZIZ();
        n.LIZIZ(LIZIZ3, "");
        String LIZJ3 = MCo.LIZ.LIZJ();
        n.LIZIZ(LIZJ3, "");
        WebView webView = (WebView) LIZ(2131373160);
        n.LIZIZ(webView, "");
        LIZ(webView, (WebViewClient) new KaO(getActivity()));
        WebView webView2 = (WebView) LIZ(2131373160);
        n.LIZIZ(webView2, "");
        webView2.setWebChromeClient(new WebChromeClient());
        WebView webView3 = (WebView) LIZ(2131373160);
        n.LIZIZ(webView3, "");
        WebSettings settings = webView3.getSettings();
        n.LIZIZ(settings, "");
        settings.setJavaScriptEnabled(true);
        WebView webView4 = (WebView) LIZ(2131373160);
        n.LIZIZ(webView4, "");
        WebSettings settings2 = webView4.getSettings();
        n.LIZIZ(settings2, "");
        settings2.setDomStorageEnabled(true);
        LIZ((WebView) LIZ(2131373160), LIZIZ3);
        ((WebView) LIZ(2131373160)).setOnTouchListener(LgZ.LIZ);
        WebView webView5 = (WebView) LIZ(2131373159);
        n.LIZIZ(webView5, "");
        LIZ(webView5, (WebViewClient) new KaO(getActivity()));
        WebView webView6 = (WebView) LIZ(2131373159);
        n.LIZIZ(webView6, "");
        webView6.setWebChromeClient(new WebChromeClient());
        WebView webView7 = (WebView) LIZ(2131373159);
        n.LIZIZ(webView7, "");
        WebSettings settings3 = webView7.getSettings();
        n.LIZIZ(settings3, "");
        settings3.setJavaScriptEnabled(true);
        WebView webView8 = (WebView) LIZ(2131373159);
        n.LIZIZ(webView8, "");
        WebSettings settings4 = webView8.getSettings();
        n.LIZIZ(settings4, "");
        settings4.setDomStorageEnabled(true);
        LIZ((WebView) LIZ(2131373159), LIZJ3);
        ((WebView) LIZ(2131373159)).setOnTouchListener(Lga.LIZ);
        APJ.LIZ(LIZ(2131366667), 0.5f);
        LIZ(LIZ(2131366667), new C2172Rtw(this));
        LIZ(this.LJIIL);
        LIZ(LIZ(2131363045), new C2171Rtv(this));
    }
}
