package com.bytedance.lobby.twitter;

import X.1hK;
import X.99V;
import X.99w;
import X.9As;
import X.C5659M8s;
import X.C5667M9a;
import X.C5697MAe;
import X.C5709MAq;
import X.M12;
import X.M7B;
import X.MA0;
import X.MA1;
import X.MAP;
import X.MAQ;
import X.MAT;
import X.MAW;
import X.MAZ;
import X.MB1;
import X.MBI;
import X.RY6;
import android.content.Intent;
import android.os.Bundle;
import com.bytedance.bpea.cert.token.TokenCert;
import com.bytedance.covode.number.Covode;
import com.bytedance.lobby.auth.AuthResult;
import com.bytedance.lobby.internal.LobbyCore;
import com.bytedance.lobby.internal.LobbyViewModel;
import com.twitter.sdk.android.core.TwitterAuthToken;
import java.util.Arrays;

public class TwitterAuth extends TwitterProvider<AuthResult> implements C5667M9a {
    public static final boolean LIZ = 99w.LIZ;
    public LobbyViewModel LIZIZ;
    public MAW LIZLLL;
    public MAP<MAZ> LJ;

    public final void LIZ() {
        this.LIZLLL = null;
    }

    public final void LIZ(int i) {
    }

    static {
        Covode.recordClassIndex(35512);
    }

    public final String LIZIZ() {
        C5709MAq LIZ2;
        TwitterAuthToken twitterAuthToken;
        MBI<C5709MAq> mbi = MB1.LIZ().LIZIZ;
        if (mbi == null || (LIZ2 = mbi.LIZ()) == null || (twitterAuthToken = (TwitterAuthToken) LIZ2.LIZ) == null) {
            return null;
        }
        return twitterAuthToken.LIZIZ;
    }

    public TwitterAuth(MA0 ma0) {
        super(LobbyCore.getApplication(), ma0);
    }

    public final void LIZIZ(1hK r3, Bundle bundle) {
        9As.LIZ(this.LIZIZ, this.LIZJ.LIZIZ);
    }

    public final void LIZ(1hK r4, Bundle bundle) {
        this.LIZIZ = LobbyViewModel.LIZ(r4);
        if (!J_()) {
            9As.LIZ(this.LIZIZ, this.LIZJ.LIZIZ, 1);
            return;
        }
        this.LIZLLL = new MAW(r4);
        AnonymousClass1 r2 = new MAP<MAZ>() {
            static {
                Covode.recordClassIndex(35513);
            }

            public final void LIZ(MAT mat) {
                String message = mat.getMessage();
                C5659M8s m8s = new C5659M8s(TwitterAuth.this.LIZJ.LIZIZ, 1);
                if (Arrays.asList(new String[]{"Authorize failed.", "Authorization failed, request was canceled.", "Failed to get authorization, bundle incomplete"}).contains(message)) {
                    m8s.LIZ = false;
                    m8s.LIZIZ = new M7B(4, message, "redirect_and_get_token");
                } else {
                    m8s.LIZ = false;
                    m8s.LIZIZ = new M7B(mat);
                }
                TwitterAuth.this.LIZIZ.LIZIZ(m8s.LIZ());
            }

            public final /* synthetic */ void LIZ(Object obj) {
                MAZ maz = (MAZ) obj;
                TwitterAuth twitterAuth = TwitterAuth.this;
                String str = ((TwitterAuthToken) maz.LIZ.LIZ).LIZIZ;
                M12.LIZ((Object) str);
                String str2 = ((TwitterAuthToken) maz.LIZ.LIZ).LIZJ;
                C5659M8s m8s = new C5659M8s(twitterAuth.LIZJ.LIZIZ, 1);
                m8s.LIZ = true;
                m8s.LJ = str;
                m8s.LJFF = str2;
                m8s.LIZLLL = String.valueOf(maz.LIZ.LIZIZ);
                99V r2 = new 99V();
                String str3 = maz.LIZ.LIZJ;
                M12.LIZ((Object) str3);
                r2.LIZ("username", str3);
                m8s.LJIIIZ = r2.LIZ();
                twitterAuth.LIZIZ.LIZIZ(m8s.LIZ());
            }
        };
        this.LJ = r2;
        MAW maw = this.LIZLLL;
        M12.LIZ((Object) r2);
        C5697MAe mAe = maw.LIZ;
        if (mAe != null) {
            mAe.setCallback(new MAQ(r2));
        }
        C5697MAe mAe2 = this.LIZLLL.LIZ;
        if (mAe2 != null) {
            mAe2.performClick();
        }
    }

    public final void LIZ(1hK r5, int i, int i2, Intent intent) {
        MAW maw = this.LIZLLL;
        if (maw != null) {
            TokenCert with = TokenCert.with("bpea-twitter_androidsdk_2009");
            M12.LIZ((Object) with);
            RY6.LIZ("Twitter", "onActivityResult", with, new MA1(intent, maw, i, i2));
        }
    }
}
