package com.ss.android.ugc.aweme.account.login.v2.base;

import X.0Bs;
import X.0Bv;
import X.0Bx;
import X.0By;
import X.1hU;
import X.2GD;
import X.3FR;
import X.7he;
import X.8gF;
import X.C2160Rtk;
import X.C2162Rtm;
import X.C2219Ruh;
import X.C2345Rwj;
import X.C2449RyP;
import X.C2463Ryd;
import X.C2464Rye;
import X.C2476Ryq;
import X.C2478Rys;
import X.C2537Rzp;
import X.C2578S1e;
import X.C2591S1r;
import X.Crj;
import X.Ecl;
import X.Ecp;
import X.K1p;
import X.M12;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.SparseArray;
import android.view.View;
import com.bytedance.apm.agent.v2.instrumentation.ActivityAgent;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.account.verify.EmailConsentPageFragment;
import java.util.HashMap;
import kotlin.h.b.n;

public class CommonFlowActivity extends C2463Ryd {
    public static SparseArray<C2449RyP> LJI = new SparseArray<>();
    public static final C2464Rye LJII = new C2464Rye((byte) 0);
    public C2162Rtm LIZ = C2162Rtm.PHONE_SMS_CHANGE_PASSWORD;
    public boolean LIZJ;
    public Bundle LIZLLL;
    public boolean LJ = true;
    public Integer LJFF;
    public final Crj LJIIIIZZ = 7he.LIZ(new K1p(this));
    public HashMap LJIIIZ;

    public static final void LIZ(Activity activity, C2162Rtm rtm, C2160Rtk rtk, Bundle bundle, C2449RyP ryP, Boolean bool) {
        LJII.LIZ(activity, rtm, rtk, bundle, ryP, bool);
    }

    public int LIZJ() {
        return 0;
    }

    public final Bundle LJIIIIZZ() {
        return (Bundle) this.LJIIIIZZ.getValue();
    }

    public void _$_clearFindViewByIdCache() {
        HashMap hashMap = this.LJIIIZ;
        if (hashMap != null) {
            hashMap.clear();
        }
    }

    public View _$_findCachedViewById(int i) {
        if (this.LJIIIZ == null) {
            this.LJIIIZ = new HashMap();
        }
        View view = (View) this.LJIIIZ.get(Integer.valueOf(i));
        if (view != null) {
            return view;
        }
        View findViewById = findViewById(i);
        this.LJIIIZ.put(Integer.valueOf(i), findViewById);
        return findViewById;
    }

    /* JADX WARNING: type inference failed for: r0v0, types: [com.ss.android.ugc.aweme.account.login.v2.base.CommonFlowActivity, X.Ryd, android.app.Activity] */
    public void onDestroy() {
        8gF.LJ(this);
        super.onDestroy();
    }

    /* JADX WARNING: type inference failed for: r0v0, types: [com.ss.android.ugc.aweme.account.login.v2.base.CommonFlowActivity, X.SNU, android.app.Activity] */
    public void onPause() {
        8gF.LIZJ(this);
        super.onPause();
    }

    /* JADX WARNING: type inference failed for: r3v0, types: [com.ss.android.ugc.aweme.account.login.v2.base.CommonFlowActivity, X.SNU, android.app.Activity] */
    public void onResume() {
        8gF.LIZIZ(this);
        ActivityAgent.onTrace("com.ss.android.ugc.aweme.account.login.v2.base.CommonFlowActivity", "onResume", true);
        super.onResume();
        ActivityAgent.onTrace("com.ss.android.ugc.aweme.account.login.v2.base.CommonFlowActivity", "onResume", false);
    }

    /* JADX WARNING: type inference failed for: r0v0, types: [com.ss.android.ugc.aweme.account.login.v2.base.CommonFlowActivity, X.SNU, android.app.Activity] */
    public void onStart() {
        8gF.LIZ(this);
        super.onStart();
    }

    /* JADX WARNING: type inference failed for: r0v0, types: [com.ss.android.ugc.aweme.account.login.v2.base.CommonFlowActivity, X.SNU, android.app.Activity] */
    public void onStop() {
        8gF.LIZLLL(this);
        super.onStop();
    }

    public void onWindowFocusChanged(boolean z) {
        ActivityAgent.onTrace("com.ss.android.ugc.aweme.account.login.v2.base.CommonFlowActivity", "onWindowFocusChanged", true);
        super.onWindowFocusChanged(z);
    }

    static {
        Covode.recordClassIndex(51457);
    }

    public void finish() {
        int i;
        super.finish();
        int intExtra = getIntent().getIntExtra("action_type", -1);
        if (intExtra != -1 && LJI.get(intExtra) != null) {
            if (!this.LJ || this.LIZJ) {
                C2449RyP ryP = LJI.get(intExtra);
                if (ryP == null) {
                    n.LIZIZ();
                }
                C2449RyP ryP2 = ryP;
                Integer num = this.LJFF;
                if (num != null) {
                    i = num.intValue();
                } else {
                    i = intExtra;
                }
                ryP2.onResult(i, 1, this.LIZLLL);
            } else {
                C2449RyP ryP3 = LJI.get(intExtra);
                if (ryP3 == null) {
                    n.LIZIZ();
                }
                ryP3.onResult(intExtra, 2, (Object) null);
            }
            LJI.remove(intExtra);
        }
    }

    public static Bundle LIZ(Intent intent) {
        try {
            return intent.getExtras();
        } catch (Exception unused) {
            return null;
        }
    }

    public void LIZ(Bundle bundle) {
        Bundle bundle2 = new Bundle(bundle);
        C2162Rtm LIZ2 = C2162Rtm.Companion.LIZ(bundle2.getInt("next_page", C2162Rtm.PHONE_SMS_CHANGE_PASSWORD.getValue()));
        int i = bundle2.getInt("previous_page", -1);
        if (i != LIZ2.getValue() || i == -1) {
            bundle2.putInt("previous_page", bundle2.getInt("current_page", -1));
            bundle2.putInt("current_page", LIZ2.getValue());
            int i2 = bundle2.getInt("next_next_page", -1);
            if (i2 != -1) {
                bundle2.putInt("next_page", i2);
                bundle2.remove("next_next_page");
            } else {
                bundle2.remove("next_page");
            }
            C2463Ryd.LIZ(this, C2219Ruh.LIZ.LIZ(LIZ2), bundle2);
            return;
        }
        onBackPressed();
    }

    public final void LIZIZ(Bundle bundle) {
        Bundle bundle2;
        String str;
        boolean z;
        this.LIZJ = true;
        if (bundle == null || (bundle2 = bundle.getBundle("final_data")) == null) {
            bundle2 = new Bundle();
        }
        this.LIZLLL = bundle2;
        Bundle LIZLLL2 = LIZLLL();
        if (LIZLLL2 != null) {
            str = LIZLLL2.getString("enter_from_item");
        } else {
            str = null;
        }
        Ecl ecl = C2476Ryq.LIZJ;
        if (str == null || str.length() == 0) {
            z = true;
        } else {
            z = false;
        }
        if (z || ((!Ecp.LIZ.LIZJ() && !Ecp.LIZ.LIZIZ()) || !C2476Ryq.LIZIZ.contains(str) || !ecl.LIZ("manage_account_page"))) {
            finish();
            return;
        }
        M12.LIZ(this, "manage_account_page");
        EmailConsentPageFragment emailConsentPageFragment = new EmailConsentPageFragment(new C2478Rys("manage_account_page", str, this));
        Bundle bundle3 = new Bundle();
        bundle3.putString("enter_from", "manage_account_page");
        emailConsentPageFragment.setArguments(bundle3);
        C2591S1r.LIZ.LIZ().LIZIZ(new 3FR(this, emailConsentPageFragment));
    }

    /* JADX WARNING: type inference failed for: r7v0, types: [com.ss.android.ugc.aweme.account.login.v2.base.CommonFlowActivity, X.Ryd, X.SNU, android.app.Activity] */
    public void onCreate(Bundle bundle) {
        8gF.LIZ(this, bundle);
        ActivityAgent.onTrace("com.ss.android.ugc.aweme.account.login.v2.base.CommonFlowActivity", "onCreate", true);
        activityConfiguration(new C2578S1e(this));
        super.onCreate(bundle);
        this.LIZ = C2162Rtm.Companion.LIZ(getIntent().getIntExtra("next_page", C2162Rtm.PHONE_SMS_CHANGE_PASSWORD.getValue()));
        if (bundle == null) {
            0Bx LIZ2 = 0By.LIZ(this, (0Bv) null);
            if (2GD.LIZ) {
                0Bs.LIZ(LIZ2, this);
            }
            1hU<Bundle> r5 = LIZ2.LIZ(ActionResultModel.class).LIZ;
            Bundle LIZ3 = LIZ(getIntent());
            if (LIZ3 == null) {
                LIZ3 = new Bundle();
            }
            LIZ3.putString("enter_from", LJFF());
            LIZ3.putString("enter_method", LJI());
            LIZ3.putString("enter_type", LJII());
            LIZ3.putInt("next_page", this.LIZ.getValue());
            r5.postValue(LIZ3);
        }
        C2345Rwj.LIZ().LIZ(C2537Rzp.LIZ);
        ActivityAgent.onTrace("com.ss.android.ugc.aweme.account.login.v2.base.CommonFlowActivity", "onCreate", false);
    }

    public final void LIZ(int i, Bundle bundle) {
        this.LIZLLL = bundle;
        this.LJFF = Integer.valueOf(i);
        this.LJ = false;
        finish();
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        C2345Rwj.LIZ();
    }
}
