package com.ss.android.ugc.aweme.share;

import X.2ID;
import X.2UX;
import X.2aZ;
import X.2nK;
import X.2sG;
import X.3ZQ;
import X.3ae;
import X.3bC;
import X.3bg;
import X.46i;
import X.4BT;
import X.4Ev;
import X.4UX;
import X.4b1;
import X.4jd;
import X.4oZ;
import X.4px;
import X.4rS;
import X.4s9;
import X.4vv;
import X.878;
import X.8az;
import X.95y;
import X.9EH;
import X.9Z4;
import X.9ZQ;
import X.Aqv;
import X.Aqw;
import X.C2702J5x;
import X.C3119JLy;
import X.C3235JQk;
import X.C3254JRd;
import X.C3260JRj;
import X.C3415JXi;
import X.EcX;
import X.Ecz;
import X.EeC;
import X.Enn;
import X.F5Q;
import X.FF5;
import X.FF7;
import X.FI2;
import X.JO8;
import X.JOC;
import X.JOF;
import X.JOU;
import X.JPF;
import X.JR0;
import X.JR2;
import X.JR3;
import X.JRR;
import X.JRS;
import X.JRT;
import X.JRU;
import X.JT1;
import X.JUP;
import X.JV9;
import X.LeS;
import X.Lnj;
import X.M12;
import X.OCa;
import X.QNA;
import X.SfZ;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.Window;
import android.view.WindowManager;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.keva.Keva;
import com.ss.android.ugc.aweme.IAccountUserService;
import com.ss.android.ugc.aweme.base.model.UrlModel;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.feed.model.PhotoModeImageInfo;
import com.ss.android.ugc.aweme.out.AVExternalServiceImpl;
import com.ss.android.ugc.aweme.profile.model.User;
import com.ss.android.ugc.aweme.services.IExternalService;
import com.ss.android.ugc.aweme.share.improve.pkg.DownloadedVideoSharePackage;
import com.ss.android.ugc.aweme.share.improve.pkg.KtfDefaultSharePackage;
import com.ss.android.ugc.aweme.sharer.ui.SharePackage;
import com.ss.android.ugc.aweme.shortvideo.model.AVUploadSaveModel;
import com.ss.android.ugc.aweme.shortvideo.publish.CreateAwemeResponse;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import kotlin.h.b.n;

public final class ShareExtServiceImpl extends C3119JLy {
    static {
        Covode.recordClassIndex(106887);
    }

    public final int LJII() {
        return JRR.LIZ;
    }

    public final ArrayList<String> LJIIIIZZ() {
        return C3235JQk.LIZIZ;
    }

    public final Map<String, JOF> LJIIIZ() {
        return C3235JQk.LIZ;
    }

    public final boolean LIZ(Aweme aweme, Context context) {
        M12.LIZ(context);
        return 4vv.LIZ(aweme, context);
    }

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

    public final void LIZ(String str, Aweme aweme, Bundle bundle) {
        M12.LIZ(str);
        C3415JXi.LIZIZ.LIZ(str, aweme, bundle);
    }

    public final boolean LIZ(F5Q f5q, Activity activity) {
        List<JUP> LIZ;
        Aweme aweme;
        boolean z;
        List urlList;
        PhotoModeImageInfo photoModeImageInfo;
        List imageList;
        MethodCollector.i(12827);
        F5Q f5q2 = f5q;
        Activity activity2 = activity;
        M12.LIZ(f5q2, activity2);
        M12.LIZ(f5q2, activity2);
        CreateAwemeResponse createAwemeResponse = f5q2.LJII;
        if (createAwemeResponse != null) {
            CreateAwemeResponse createAwemeResponse2 = createAwemeResponse;
            AVUploadSaveModel aVUploadSaveModel = createAwemeResponse2.mSaveModel;
            if (aVUploadSaveModel == null) {
                MethodCollector.o(12827);
                return false;
            }
            Aweme aweme2 = createAwemeResponse2.aweme;
            String str = (aweme2 == null || aweme2.getDistributeType() == 1) ? "short" : "long";
            boolean isWaterMark = aVUploadSaveModel.isWaterMark();
            JR3 jr3 = Aqw.LIZIZ;
            n.LIZIZ(aweme2, "");
            int size = (!jr3.LIZ(aweme2) || (photoModeImageInfo = aweme2.getPhotoModeImageInfo()) == null || (imageList = photoModeImageInfo.getImageList()) == null) ? 0 : imageList.size();
            if (!JOC.LIZ && aVUploadSaveModel.getSaveToAlbum()) {
                8az.LIZ.LIZ(aweme2, "video_post_page", "download", str, (String) null, isWaterMark ? 1 : 0, size);
            }
            int saveType = aVUploadSaveModel.getSaveType();
            if (!9ZQ.LIZIZ.LIZ()) {
                LIZ = LeS.LIZIZ(new JUP[]{JUP.INSTAGRAM, JUP.INSTAGRAM_STORY});
            } else {
                LIZ = JUP.Companion.LIZ(activity2);
            }
            2sG r3 = new 2sG();
            FF5 ff5 = null;
            r3.element = null;
            Iterator<JUP> it = LIZ.iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                JUP next = it.next();
                if (next.getSaveType() == saveType) {
                    r3.element = next;
                    break;
                }
            }
            if (r3.element == null) {
                JOC.LIZ = true;
                MethodCollector.o(12827);
                return false;
            }
            UrlModel LIZ2 = C2702J5x.LIZ.LIZ(createAwemeResponse2);
            OCa.LIZIZ((LIZ2 == null || (urlList = LIZ2.getUrlList()) == null) ? null : (String) urlList.get(0));
            if (LIZ2 != null) {
                ff5 = new FF5(activity2, aweme2, ((JUP) r3.element).getLabel(), LIZ2);
            }
            JUP jup = (JUP) r3.element;
            if (ff5 != null) {
                z = true;
                aweme = aweme2;
                ff5.setOnDismissListener(new JO8(jup, createAwemeResponse2, activity2, aweme, r3, f5q2));
                FI2 fi2 = ff5.LIZ;
                if (fi2 == null) {
                    n.LIZ("");
                }
                fi2.LIZ();
                if (!ff5.isShowing()) {
                    View contentView = ff5.getContentView();
                    n.LIZIZ(contentView, "");
                    if (contentView.getParent() != null) {
                        View contentView2 = ff5.getContentView();
                        n.LIZIZ(contentView2, "");
                        ViewParent parent = contentView2.getParent();
                        if (parent != null) {
                            ((ViewGroup) parent).removeView(ff5.getContentView());
                        } else {
                            NullPointerException nullPointerException = new NullPointerException("null cannot be cast to non-null type android.view.ViewGroup");
                            MethodCollector.o(12827);
                            throw nullPointerException;
                        }
                    }
                    FI2 fi22 = ff5.LIZ;
                    if (fi22 == null) {
                        n.LIZ("");
                    }
                    fi22.postDelayed(new FF7(ff5), 3000);
                    Window window = ff5.LIZIZ.getWindow();
                    n.LIZIZ(window, "");
                    View decorView = window.getDecorView();
                    if (3bC.LIZ()) {
                        3bg.LIZ();
                    }
                    if (4UX.LIZ.LIZ()) {
                        try {
                            3bg.LIZIZ();
                            Window window2 = (Window) 3bg.LIZIZ.get((WindowManager) 3bg.LIZ.get(ff5));
                            WindowManager.LayoutParams attributes = window2.getAttributes();
                            int i = attributes.flags;
                            boolean booleanValue = ((Boolean) 3bg.LIZJ.get(window2)).booleanValue();
                            3bg.LIZJ.set(window2, false);
                            attributes.flags &= -16777217;
                            ff5.showAtLocation(decorView, 48, 0, 0);
                            3bg.LIZJ.set(window2, Boolean.valueOf(booleanValue));
                            attributes.flags = i;
                        } catch (Throwable unused) {
                        }
                    }
                    ff5.showAtLocation(decorView, 48, 0, 0);
                }
            } else {
                aweme = aweme2;
                z = true;
            }
            2UX r2 = new 2UX();
            r2.LIZ("enter_from", "video_post_page");
            r2.LIZ("platform", ((JUP) r3.element).getKey());
            2nK.LIZ("share_notice_after_post", r2.LIZ);
            if (!JOC.LIZ) {
                8az.LIZ.LIZ(aweme, "video_post_page", ((JUP) r3.element).getKey(), str, (String) null, isWaterMark ? 1 : 0, 1);
                JOC.LIZ = z;
            }
            MethodCollector.o(12827);
            return z;
        }
        NullPointerException nullPointerException2 = new NullPointerException("null cannot be cast to non-null type com.ss.android.ugc.aweme.shortvideo.publish.CreateAwemeResponse");
        MethodCollector.o(12827);
        throw nullPointerException2;
    }

    public final boolean LIZ(Aweme aweme) {
        M12.LIZ(aweme);
        return Aqw.LIZIZ.LIZ(aweme);
    }

    public final boolean LIZ(Aweme aweme, String str) {
        M12.LIZ(aweme);
        4s9 r5 = 4s9.LIZLLL;
        M12.LIZ(aweme);
        if (str == null) {
            str = "";
        }
        if (!n.LIZ("personal_homepage", str)) {
            return false;
        }
        String authorUid = aweme.getAuthorUid();
        User user = 4s9.LIZJ;
        n.LIZIZ(user, "");
        if ((!n.LIZ(authorUid, user.getUid())) || 4BT.LIZ == 0 || r5.LIZ(Keva.getRepo("repo_guide_share").getLong("last_publish_success_time", 0)) || 4s9.LIZIZ) {
            return false;
        }
        int i = 4BT.LIZ;
        if (i == 1) {
            return r5.LIZ(5);
        }
        if (i == 2) {
            return r5.LIZ(7);
        }
        if (i != 3) {
            if (i != 4) {
                if (i == 5 && !r5.LIZJ()) {
                    return true;
                }
                return false;
            } else if (!r5.LIZIZ()) {
                return r5.LIZ(7);
            } else {
                if (!r5.LIZJ()) {
                    return true;
                }
                return false;
            }
        } else if (!r5.LIZIZ()) {
            return r5.LIZ(5);
        } else {
            if (!r5.LIZJ()) {
                return true;
            }
            return false;
        }
    }

    public final void LIZ(String str, String str2) {
        M12.LIZ(str, str2);
        4s9.LIZLLL.LIZ(str, str2);
    }

    /* JADX WARNING: Code restructure failed: missing block: B:6:0x000f, code lost:
        r0 = (r0 = r4.getShareInfo()).getAcl();
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final boolean LIZ(com.ss.android.ugc.aweme.comment.model.Comment r4) {
        /*
            r3 = this;
            int r0 = X.JRT.LIZ
            r2 = 1
            r1 = 0
            if (r0 != 0) goto L_0x0007
        L_0x0006:
            return r1
        L_0x0007:
            if (r4 == 0) goto L_0x0006
            com.ss.android.ugc.aweme.comment.model.CommentShareInfo r0 = r4.getShareInfo()
            if (r0 == 0) goto L_0x0006
            com.ss.android.ugc.aweme.comment.model.CommentShareACL r0 = r0.getAcl()
            if (r0 == 0) goto L_0x0006
            int r0 = r0.getCode()
            if (r0 != 0) goto L_0x0006
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.share.ShareExtServiceImpl.LIZ(com.ss.android.ugc.aweme.comment.model.Comment):boolean");
    }

    public final 9Z4 LIZ() {
        return new JRS();
    }

    public final void LJFF() {
        Aqv.LJIILL = Aqv.LJIILJJIL;
    }

    public final boolean LJIIJJI() {
        return JRT.LIZIZ.LIZ();
    }

    public final boolean LJIIL() {
        return JRT.LIZIZ.LIZIZ();
    }

    public final boolean LJIILIIL() {
        return 4px.LIZ();
    }

    public final String LIZJ() {
        String LIZ = Enn.LIZ("guide").LIZ("last_share_way", "outside_channel");
        n.LIZIZ(LIZ, "");
        return LIZ;
    }

    public final boolean LJ() {
        if (Ecz.LIZIZ || Ecz.LIZJ || Aqv.LIZ) {
            return true;
        }
        return false;
    }

    public final boolean LJIIJ() {
        if (JRT.LIZ != 2 && !JRT.LIZIZ.LIZ() && !JRT.LIZIZ.LIZIZ()) {
            return false;
        }
        return true;
    }

    public final String LIZLLL() {
        C3260JRj LIZ = C3260JRj.LIZ();
        if (LIZ.LIZJ() == 0) {
            return null;
        }
        String[] LIZLLL = LIZ.LIZLLL();
        LIZ.LIZ(LIZLLL, 100);
        if (LIZLLL == null || LIZLLL.length <= 0) {
            return null;
        }
        for (String str : LIZLLL) {
            JOF LIZ2 = JOU.LIZ.LIZ(str, SfZ.LJIJ.LJIIIZ());
            if (LIZ2 != null && LIZ2.LIZIZ(9EH.LJJIFFI.LIZ())) {
                return str;
            }
        }
        return null;
    }

    public final boolean LJI() {
        String str;
        Activity LJIIIZ = SfZ.LJIJ.LJIIIZ();
        if (LJIIIZ != null) {
            str = LJIIIZ.getLocalClassName();
        } else {
            str = null;
        }
        boolean equals = TextUtils.equals(str, "shortvideo.ui.VideoRecordNewActivity");
        if (equals) {
            return equals;
        }
        IExternalService LIZ = AVExternalServiceImpl.LIZ();
        if (LIZ.configService().shortVideoConfig().isRecording() || (LJIIIZ != null && LIZ.publishService().inPublishPage(LJIIIZ))) {
            return true;
        }
        return false;
    }

    public static ShareExtService LJIILJJIL() {
        MethodCollector.i(10755);
        ShareExtService shareExtService = (ShareExtService) Lnj.LIZ(ShareExtService.class, false);
        if (shareExtService != null) {
            MethodCollector.o(10755);
            return shareExtService;
        }
        Object LIZIZ = Lnj.LIZIZ(ShareExtService.class, false);
        if (LIZIZ != null) {
            ShareExtService shareExtService2 = (ShareExtService) LIZIZ;
            MethodCollector.o(10755);
            return shareExtService2;
        }
        if (Lnj.bi == null) {
            synchronized (ShareExtService.class) {
                try {
                    if (Lnj.bi == null) {
                        Lnj.bi = new ShareExtServiceImpl();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(10755);
                    throw th;
                }
            }
        }
        C3119JLy jLy = (C3119JLy) Lnj.bi;
        MethodCollector.o(10755);
        return jLy;
    }

    public final String[] LIZIZ() {
        String[] strArr;
        n.LIZIZ(C3260JRj.LIZ(), "");
        if (JT1.LIZ == null || JT1.LIZ.isEmpty()) {
            strArr = new String[0];
        } else {
            ArrayList arrayList = new ArrayList();
            for (JPF jpf : JT1.LIZ) {
                arrayList.add(jpf.LIZ);
            }
            strArr = (String[]) arrayList.toArray(new String[0]);
        }
        n.LIZIZ(strArr, "");
        return strArr;
    }

    public final void LJ(Aweme aweme) {
        if (aweme != null) {
            Ecz.LJ = aweme;
        }
    }

    public final boolean LIZJ(String str) {
        M12.LIZ(str);
        return Aqw.LIZIZ.LIZ(str);
    }

    public final String LIZIZ(String str) {
        boolean z;
        JOF LIZ;
        String LIZIZ;
        if (str == null || str.length() == 0) {
            z = true;
        } else {
            z = false;
        }
        if (z || (LIZ = EeC.LIZ.LIZ(str, new JV9((String) null, new JRU(), (Drawable) null, (String) null))) == null || (LIZIZ = LIZ.LIZIZ()) == null) {
            return "";
        }
        return LIZIZ;
    }

    public final void LIZJ(Aweme aweme) {
        String str;
        if (4BT.LIZ != 0) {
            if (aweme != null) {
                str = aweme.getAuthorUid();
            } else {
                str = null;
            }
            User user = 4s9.LIZJ;
            n.LIZIZ(user, "");
            if (n.LIZ(str, user.getUid())) {
                4s9.LIZIZ = false;
            }
        }
    }

    public final String LIZIZ(Activity activity) {
        JOF LIZ;
        M12.LIZ(activity);
        C3260JRj.LIZ();
        String LIZJ = 4b1.LIZJ();
        String str = "download";
        if (!TextUtils.equals(LIZJ, str)) {
            if ("more".equalsIgnoreCase(LIZJ)) {
                LIZJ = "";
            }
            JOF LIZ2 = JOU.LIZ(LIZJ, activity);
            if (LIZ2 == null || !LIZ2.LIZIZ(activity)) {
                List asList = Arrays.asList(C3260JRj.LIZ().LIZIZ());
                if (!878.LIZ(asList)) {
                    Iterator it = asList.iterator();
                    while (true) {
                        if (!it.hasNext()) {
                            break;
                        }
                        String str2 = (String) it.next();
                        if (!TextUtils.equals(str2, "chat_merge") && (LIZ = JOU.LIZ(str2, activity)) != null && LIZ.LIZIZ(activity)) {
                            str = LIZ.LIZ();
                            break;
                        }
                    }
                }
                str = "more";
            } else {
                str = LIZJ;
            }
        }
        n.LIZIZ(str, "");
        return str;
    }

    public final void LIZLLL(Aweme aweme) {
        M12.LIZ(aweme);
        4s9 r2 = 4s9.LIZLLL;
        M12.LIZ(aweme);
        String aid = aweme.getAid();
        n.LIZIZ(aid, "");
        4s9.LIZ = aid;
        4s9.LIZIZ = false;
        r2.LIZ().storeLong("last_publish_success_time", System.currentTimeMillis());
    }

    public final Drawable LIZ(Activity activity) {
        Drawable LIZ;
        JOF LIZ2;
        M12.LIZ(activity);
        C3260JRj.LIZ();
        String LIZJ = 4b1.LIZJ();
        if (TextUtils.equals(LIZJ, "download")) {
            Drawable qna = new QNA(activity, 2131755017);
            qna.LIZ(activity, 2130968666);
            int LIZIZ = 4Ev.LIZIZ(32);
            qna.LIZ(LIZIZ);
            qna.LIZIZ(LIZIZ);
            3ae r7 = new 3ae();
            int LIZIZ2 = 4Ev.LIZIZ(48);
            r7.LJII = LIZIZ2;
            r7.LJI = LIZIZ2;
            r7.LIZJ = Float.valueOf(((float) LIZIZ2) / 2.0f);
            r7.LJFF = 2130968666;
            r7.LIZLLL = Integer.valueOf(4Ev.LIZIZ(1));
            r7.LIZIZ = 2130968595;
            LIZ = new LayerDrawable(new Drawable[]{r7.LIZ(activity), qna});
        } else {
            if ("more".equalsIgnoreCase(LIZJ)) {
                LIZJ = "";
            }
            JOF LIZ3 = JOU.LIZ(LIZJ, activity);
            if (LIZ3 == null || !LIZ3.LIZIZ(activity)) {
                List asList = Arrays.asList(C3260JRj.LIZ().LIZIZ());
                if (!878.LIZ(asList)) {
                    Iterator it = asList.iterator();
                    while (true) {
                        if (!it.hasNext()) {
                            break;
                        }
                        String str = (String) it.next();
                        if (!TextUtils.equals(str, "chat_merge") && (LIZ2 = JOU.LIZ(str, activity)) != null && LIZ2.LIZIZ(activity)) {
                            LIZ = LIZ2.LIZ((Context) activity);
                            break;
                        }
                    }
                }
                3ZQ r1 = new 3ZQ();
                r1.LIZ = 2131755283;
                LIZ = r1.LIZ(activity);
            } else {
                LIZ = LIZ3.LIZ((Context) activity);
            }
        }
        n.LIZIZ(LIZ, "");
        return LIZ;
    }

    public final void LIZIZ(Aweme aweme) {
        String str;
        if (4BT.LIZ != 0) {
            if (aweme != null) {
                str = aweme.getAuthorUid();
            } else {
                str = null;
            }
            User user = 4s9.LIZJ;
            n.LIZIZ(user, "");
            if (n.LIZ(str, user.getUid())) {
                4s9.LIZIZ = true;
            }
        }
    }

    public final void LIZ(C3254JRd jRd) {
        M12.LIZ(jRd);
        M12.LIZ(jRd);
        M12.LIZ(jRd);
        JRR.LIZLLL.add(jRd);
        if (!JRR.LJ) {
            JRR.LIZ = 2;
            if (!Ecz.LIZLLL) {
                JRR.LJFF.LIZ();
                JRR.LJFF.LIZIZ();
                JRR.LJ = true;
            }
        }
    }

    public final void LIZ(SharePackage sharePackage) {
        M12.LIZ(sharePackage);
        if (sharePackage instanceof DownloadedVideoSharePackage) {
            LIZJ(((KtfDefaultSharePackage) sharePackage).LIZIZ());
        }
    }

    public final void LIZ(String str) {
        M12.LIZ(str);
        M12.LIZ(str);
        2aZ r2 = new 2aZ();
        r2.LIZ("errorDesc", "url is illegal");
        r2.LIZ("url", str);
        95y.LIZ("save_video_success_rate", 4, r2.LIZ());
    }

    public final Drawable LIZ(Activity activity, String str) {
        M12.LIZ(activity);
        JOF LIZ = JOU.LIZ.LIZ(str, activity);
        if (LIZ != null) {
            return LIZ.LIZ((Context) activity);
        }
        return null;
    }

    public final void LIZ(JOF jof, 4rS r4) {
        M12.LIZ(jof, r4);
        M12.LIZ(jof, r4);
        if (n.LIZ(jof.LIZ(), "contact_list")) {
            IAccountUserService LJFF = 46i.LJFF();
            n.LIZIZ(LJFF, "");
            if (!LJFF.isLogin()) {
                return;
            }
        }
        r4.LIZ(jof);
    }

    public final void LIZ(Activity activity, 2ID r3) {
        M12.LIZ(activity, r3);
        EcX.LIZ.LIZ(activity, r3);
    }

    public final 4oZ LIZ(Aweme aweme, String str, String str2) {
        M12.LIZ(aweme);
        if (str == null) {
            str = "";
        }
        return new 4jd(aweme, str, str2);
    }

    public final 4oZ LIZ(Activity activity, Aweme aweme, String str, String str2, String str3) {
        Aweme aweme2 = aweme;
        Activity activity2 = activity;
        String str4 = str;
        M12.LIZ(activity2, aweme2);
        String str5 = "";
        if (str4 == null) {
            str4 = str5;
        }
        if (str3 != null) {
            str5 = str3;
        }
        return new JR2(activity2, aweme2, str4, str2, str5);
    }

    public final 4oZ LIZIZ(Activity activity, Aweme aweme, String str, String str2, String str3) {
        Aweme aweme2 = aweme;
        Activity activity2 = activity;
        String str4 = str;
        M12.LIZ(activity2, aweme2);
        if (str4 == null) {
            str4 = "";
        }
        return new JR0(activity2, aweme2, str4, str2, str3);
    }
}
