package com.ss.android.ugc.aweme.ftc.pages;

import X.0Gf;
import X.0Gp;
import X.0Gq;
import X.0HH;
import X.1hK;
import X.3Bq;
import X.3P4;
import X.4Dk;
import X.4r1;
import X.805;
import X.8dY;
import X.AnonymousClass598;
import X.AnonymousClass5RW;
import X.C30456Gd;
import X.C30466Ge;
import X.C34036Tx;
import X.C35146Ye;
import X.C35526Zq;
import X.C42566lC;
import X.C42576lD;
import X.C44406oA;
import X.C44416oB;
import X.C44426oC;
import X.C44436oD;
import X.C44446oE;
import X.C44456oF;
import X.C44486oI;
import X.C44496oJ;
import X.C44526oM;
import X.C44576oR;
import X.C44586oS;
import X.C44596oT;
import X.C45066pE;
import X.C51676zt;
import X.Cv9;
import X.D8s;
import X.DAe;
import X.DAj;
import X.DAl;
import X.DBT;
import X.FWb;
import X.Lpl;
import X.LsC;
import X.M12;
import X.Mot;
import X.MpR;
import X.NuT;
import X.NuV;
import X.POl;
import X.Qeg;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Typeface;
import android.os.Bundle;
import android.transition.AutoTransition;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.effect.EffectPointModel;
import com.ss.android.ugc.aweme.shortvideo.edit.VideoPublishEditModel;
import com.ss.android.ugc.aweme.shortvideo.edit.model.EditPreviewInfo;
import com.ss.android.ugc.aweme.shortvideo.edit.multiedit.data.MultiEditVideoRecordData;
import com.ss.android.vesdk.VERecordData;
import com.ss.android.vesdk.VEUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import kotlin.h.b.n;
import kotlinx.coroutines.CoroutineExceptionHandler;

public final class FTCVideoPublishFragment extends Fragment {
    public static final C44586oS LJII = new C44586oS((byte) 0);
    public VideoPublishEditModel LIZ;
    public C51676zt LIZIZ;
    public final AtomicInteger LIZJ = new AtomicInteger(0);
    public final int LIZLLL = 150;
    public Bitmap LJ;
    public View.OnTouchListener LJFF = new C44526oM(this);
    public 3Bq LJI;
    public int LJIIIIZZ;
    public boolean LJIIIZ;
    public boolean LJIIJ;
    public final C44596oT LJIIJJI = new C44596oT(this);
    public final 4Dk LJIIL;
    public final CoroutineExceptionHandler LJIILIIL;
    public final Cv9 LJIILJJIL;
    public HashMap LJIILL;

    static {
        Covode.recordClassIndex(82702);
    }

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

    public final void LIZ() {
        3Bq r0;
        3Bq r02 = this.LJI;
        if (r02 != null && r02.isShowing() && (r0 = this.LJI) != null) {
            r0.dismiss();
        }
    }

    public final void onDestroyView() {
        LIZ(getView(), (View.OnTouchListener) null);
        FTCVideoPublishFragment.super.onDestroyView();
        HashMap hashMap = this.LJIILL;
        if (hashMap != null) {
            hashMap.clear();
        }
    }

    public FTCVideoPublishFragment() {
        4Dk LIZ2 = DAl.LIZ((DBT) null);
        this.LJIIL = LIZ2;
        C44496oJ r1 = new C44496oJ(CoroutineExceptionHandler.LIZLLL, this);
        this.LJIILIIL = r1;
        this.LJIILJJIL = DAj.LIZ(8dY.LIZ.plus(LIZ2).plus(r1));
    }

    private final void LIZIZ() {
        boolean z;
        int i;
        VideoPublishEditModel videoPublishEditModel = this.LIZ;
        if (videoPublishEditModel == null) {
            n.LIZ("");
        }
        if (videoPublishEditModel.isMvThemeVideoType()) {
            VideoPublishEditModel videoPublishEditModel2 = this.LIZ;
            if (videoPublishEditModel2 == null) {
                n.LIZ("");
            }
            String str = videoPublishEditModel2.mvCreateVideoData.videoCoverImgPath;
            if (805.LIZIZ(str)) {
                DAe.LIZ(DAj.LIZ(8dY.LIZ), (D8s) null, new C44446oE(this, str, (4r1) null), 3);
                return;
            }
            return;
        }
        VideoPublishEditModel videoPublishEditModel3 = this.LIZ;
        if (videoPublishEditModel3 == null) {
            n.LIZ("");
        }
        if (videoPublishEditModel3.isMultiVideoEdit()) {
            VideoPublishEditModel videoPublishEditModel4 = this.LIZ;
            if (videoPublishEditModel4 == null) {
                n.LIZ("");
            }
            MultiEditVideoRecordData curMultiEditVideoRecordData = videoPublishEditModel4.getCurMultiEditVideoRecordData();
            n.LIZIZ(curMultiEditVideoRecordData, "");
            VERecordData LIZ2 = AnonymousClass5RW.LIZ(curMultiEditVideoRecordData);
            VideoPublishEditModel videoPublishEditModel5 = this.LIZ;
            if (videoPublishEditModel5 == null) {
                n.LIZ("");
            }
            MultiEditVideoRecordData curMultiEditVideoRecordData2 = videoPublishEditModel5.getCurMultiEditVideoRecordData();
            n.LIZIZ(curMultiEditVideoRecordData2, "");
            Pair<Integer, Integer> playInOutTime = curMultiEditVideoRecordData2.getPlayInOutTime();
            LIZ2.setTimeRange(((Number) playInOutTime.first).longValue() * 1000, ((Number) playInOutTime.second).longValue() * 1000);
            VideoPublishEditModel videoPublishEditModel6 = this.LIZ;
            if (videoPublishEditModel6 == null) {
                n.LIZ("");
            }
            int i2 = (int) (videoPublishEditModel6.mVideoCoverStartTm * 1000.0f);
            VideoPublishEditModel videoPublishEditModel7 = this.LIZ;
            if (videoPublishEditModel7 == null) {
                n.LIZ("");
            }
            if (videoPublishEditModel7.isUseTimeReverseEffect()) {
                int intValue = ((Number) playInOutTime.second).intValue();
                Object obj = playInOutTime.first;
                n.LIZIZ(obj, "");
                i = (intValue - ((Number) obj).intValue()) - i2;
            } else {
                i = i2;
            }
            VideoPublishEditModel videoPublishEditModel8 = this.LIZ;
            if (videoPublishEditModel8 == null) {
                n.LIZ("");
            }
            int videoWidth = videoPublishEditModel8.videoWidth();
            VideoPublishEditModel videoPublishEditModel9 = this.LIZ;
            if (videoPublishEditModel9 == null) {
                n.LIZ("");
            }
            VEUtils.getVideoThumb(LIZ2, i, videoWidth, videoPublishEditModel9.videoHeight(), false, new C44456oF(this));
            return;
        }
        ArrayList arrayList = new ArrayList();
        VideoPublishEditModel videoPublishEditModel10 = this.LIZ;
        if (videoPublishEditModel10 == null) {
            n.LIZ("");
        }
        if (videoPublishEditModel10.getEffectList() != null) {
            VideoPublishEditModel videoPublishEditModel11 = this.LIZ;
            if (videoPublishEditModel11 == null) {
                n.LIZ("");
            }
            arrayList.addAll(videoPublishEditModel11.getEffectList());
        }
        VideoPublishEditModel videoPublishEditModel12 = this.LIZ;
        if (videoPublishEditModel12 == null) {
            n.LIZ("");
        }
        EffectPointModel timeEffect = videoPublishEditModel12.getTimeEffect();
        if (timeEffect != null) {
            arrayList.add(timeEffect);
            z = AnonymousClass598.LIZ(timeEffect);
        } else {
            z = false;
        }
        VideoPublishEditModel videoPublishEditModel13 = this.LIZ;
        if (videoPublishEditModel13 == null) {
            n.LIZ("");
        }
        String filterFolder = C30456Gd.LIZ(videoPublishEditModel13, FWb.LIZIZ.LIZ().LJIJI().LIZLLL()).getFilterFolder();
        VideoPublishEditModel videoPublishEditModel14 = this.LIZ;
        if (videoPublishEditModel14 == null) {
            n.LIZ("");
        }
        float f = videoPublishEditModel14.mSelectedFilterIntensity;
        VideoPublishEditModel videoPublishEditModel15 = this.LIZ;
        if (videoPublishEditModel15 == null) {
            n.LIZ("");
        }
        int i3 = (int) (videoPublishEditModel15.mVideoCoverStartTm * 1000.0f);
        VideoPublishEditModel videoPublishEditModel16 = this.LIZ;
        if (videoPublishEditModel16 == null) {
            n.LIZ("");
        }
        EditPreviewInfo previewInfo = videoPublishEditModel16.getPreviewInfo();
        VideoPublishEditModel videoPublishEditModel17 = this.LIZ;
        if (videoPublishEditModel17 == null) {
            n.LIZ("");
        }
        C45066pE.LIZ(arrayList, filterFolder, f, i3, z, previewInfo, videoPublishEditModel17.getVideoCoverPath(), new C44436oD(this));
    }

    private final void LIZJ() {
        boolean z;
        VideoPublishEditModel videoPublishEditModel = this.LIZ;
        if (videoPublishEditModel == null) {
            n.LIZ("");
        }
        if (videoPublishEditModel.mIsFromDraft) {
            0Gq r7 = new 0Gq();
            1hK activity = getActivity();
            if (activity != null) {
                n.LIZIZ(activity, "");
                this.LIZJ.incrementAndGet();
                if (this.LIZIZ == null && !activity.isFinishing()) {
                    this.LIZIZ = C51676zt.LIZ(activity, getString(2131831782));
                    C35526Zq.LIZLLL("FTCVideoPublish prepareEffectPlatformImpl:" + this.LIZIZ);
                }
            }
            FWb.LIZIZ.LIZ().LJIL();
            VideoPublishEditModel videoPublishEditModel2 = this.LIZ;
            if (videoPublishEditModel2 == null) {
                n.LIZ("");
            }
            ArrayList<EffectPointModel> effectList = videoPublishEditModel2.getEffectList();
            if (effectList == null || effectList.isEmpty()) {
                z = true;
            } else {
                z = false;
            }
            if (!z) {
                HashSet hashSet = new HashSet();
                VideoPublishEditModel videoPublishEditModel3 = this.LIZ;
                if (videoPublishEditModel3 == null) {
                    n.LIZ("");
                }
                Iterator<EffectPointModel> it = videoPublishEditModel3.getEffectList().iterator();
                while (it.hasNext()) {
                    EffectPointModel next = it.next();
                    n.LIZIZ(next, "");
                    if (!805.LIZIZ(next.getResDir())) {
                        hashSet.add(next.getKey());
                    }
                }
                if (!hashSet.isEmpty()) {
                    1hK requireActivity = requireActivity();
                    n.LIZIZ(requireActivity, "");
                    Mot LIZ2 = MpR.LIZ(requireActivity, (LsC) null);
                    LIZ2.LIZ(this);
                    LIZ2.LIZ(new ArrayList(hashSet), (Map) null, true, new C42566lC(r7));
                } else {
                    C35526Zq.LIZLLL("All effects needn't download");
                    r7.LIZ((Object) null);
                }
            } else {
                C35526Zq.LIZLLL("ignore fetch specialfilter because of empty effects");
                r7.LIZ((Object) null);
            }
            0Gp LIZ3 = 0Gp.LIZ((Object) null);
            0Gq r3 = new 0Gq();
            r3.LIZ((Object) null);
            ArrayList LIZ4 = POl.LIZ(new 0Gp[]{LIZ3, r7.LIZ, r3.LIZ});
            n.LIZIZ(LIZ4, "");
            0Gp.LIZIZ(LIZ4).LIZ(new C42576lD(this), 0Gp.LIZIZ, (0Gf) null);
        }
    }

    public static final /* synthetic */ VideoPublishEditModel LIZ(FTCVideoPublishFragment fTCVideoPublishFragment) {
        VideoPublishEditModel videoPublishEditModel = fTCVideoPublishFragment.LIZ;
        if (videoPublishEditModel == null) {
            n.LIZ("");
        }
        return videoPublishEditModel;
    }

    private final void LIZ(View view, View.OnTouchListener onTouchListener) {
        if (!(view instanceof EditText)) {
            if (view == null) {
                n.LIZIZ();
            }
            view.setOnTouchListener(onTouchListener);
        }
        if (view instanceof ViewGroup) {
            ViewGroup viewGroup = (ViewGroup) view;
            int childCount = viewGroup.getChildCount();
            for (int i = 0; i < childCount; i++) {
                LIZ(viewGroup.getChildAt(i), onTouchListener);
            }
        }
    }

    /* JADX WARNING: type inference failed for: r0v23, types: [android.view.View$OnClickListener, X.6Tx] */
    /* JADX WARNING: type inference failed for: r0v27, types: [android.view.View$OnClickListener, X.6oB] */
    /* JADX WARNING: type inference failed for: r0v29, types: [android.view.View$OnClickListener, X.6oA] */
    public final void onViewCreated(View view, Bundle bundle) {
        VideoPublishEditModel LIZ2;
        boolean z;
        int i;
        boolean z2;
        boolean z3;
        M12.LIZ(view);
        FTCVideoPublishFragment.super.onViewCreated(view, bundle);
        AutoTransition autoTransition = new AutoTransition();
        1hK requireActivity = requireActivity();
        n.LIZIZ(requireActivity, "");
        Window window = requireActivity.getWindow();
        n.LIZIZ(window, "");
        window.setSharedElementReenterTransition(autoTransition);
        1hK requireActivity2 = requireActivity();
        n.LIZIZ(requireActivity2, "");
        Window window2 = requireActivity2.getWindow();
        n.LIZIZ(window2, "");
        window2.setSharedElementExitTransition(new AutoTransition());
        LIZ(view, this.LJFF);
        Bundle arguments = getArguments();
        if (arguments != null && (LIZ2 = C30456Gd.LIZ(arguments)) != null) {
            this.LIZ = LIZ2;
            if (!LIZ2.isPreviewInfoValid()) {
                1hK activity = getActivity();
                if (activity != null) {
                    C44486oI r1 = C44486oI.LIZ;
                    n.LIZIZ(activity, "");
                    r1.LIZ(new C44576oR(activity));
                }
                C35526Zq.LIZIZ("VideoPublishPage finish because of null EditPreviewInfo");
                return;
            }
            VideoPublishEditModel videoPublishEditModel = this.LIZ;
            if (videoPublishEditModel == null) {
                n.LIZ("");
            }
            Bundle arguments2 = getArguments();
            if (arguments2 != null) {
                z = arguments2.getBoolean("fromDraft", false);
            } else {
                z = false;
            }
            videoPublishEditModel.mIsFromDraft = z;
            Bundle arguments3 = getArguments();
            if (arguments3 != null) {
                i = arguments3.getInt("extra_stick_point_type", 0);
            } else {
                i = 0;
            }
            this.LJIIIIZZ = i;
            Bundle arguments4 = getArguments();
            if (arguments4 != null) {
                z2 = arguments4.getBoolean("enter_record_from_other_platform", false);
            } else {
                z2 = false;
            }
            this.LJIIIZ = z2;
            Bundle arguments5 = getArguments();
            if (arguments5 != null) {
                z3 = arguments5.getBoolean("edit_publish_session_end_together", false);
            } else {
                z3 = false;
            }
            this.LJIIJ = z3;
            Typeface LIZ3 = NuT.LIZ().LIZ(NuV.LJI);
            if (LIZ3 != null) {
                Qeg LIZ4 = LIZ(2131371719);
                n.LIZIZ(LIZ4, "");
                LIZ4.setTypeface(LIZ3);
            }
            VideoPublishEditModel videoPublishEditModel2 = this.LIZ;
            if (videoPublishEditModel2 == null) {
                n.LIZ("");
            }
            String str = videoPublishEditModel2.title;
            if (!(str == null || str.length() == 0)) {
                LIZ(2131364624).setText(str);
            }
            LIZ(2131364624).setOnFocusChangeListener(new C44426oC(this));
            Lpl LIZ5 = LIZ(2131364624);
            n.LIZIZ(LIZ5, "");
            LIZ5.setFilters(new C35146Ye[]{new C35146Ye(this.LIZLLL)});
            LIZ(2131364624).removeTextChangedListener(this.LJIIJJI);
            LIZ(2131364624).addTextChangedListener(this.LJIIJJI);
            LIZ(2131371721).setOnClickListener(new C34036Tx(this));
            ImageView imageView = (ImageView) LIZ(2131366247);
            n.LIZIZ(imageView, "");
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            VideoPublishEditModel videoPublishEditModel3 = this.LIZ;
            if (videoPublishEditModel3 == null) {
                n.LIZ("");
            }
            if (videoPublishEditModel3.mIsFromDraft) {
                VideoPublishEditModel videoPublishEditModel4 = this.LIZ;
                if (videoPublishEditModel4 == null) {
                    n.LIZ("");
                }
                if (videoPublishEditModel4.getVideoCoverPath() != null) {
                    VideoPublishEditModel videoPublishEditModel5 = this.LIZ;
                    if (videoPublishEditModel5 == null) {
                        n.LIZ("");
                    }
                    805.LIZJ(videoPublishEditModel5.getVideoCoverPath());
                    VideoPublishEditModel videoPublishEditModel6 = this.LIZ;
                    if (videoPublishEditModel6 == null) {
                        n.LIZ("");
                    }
                    videoPublishEditModel6.generateVideoCoverPath();
                }
            }
            LIZIZ();
            ((ImageView) LIZ(2131366247)).setOnClickListener(new C44416oB(this));
            ((FrameLayout) LIZ(2131362935)).setOnClickListener(new C44406oA(this));
            LIZJ();
            3P4.LIZ(getActivity());
        }
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        M12.LIZ(layoutInflater);
        return 0HH.LIZ(layoutInflater, 2131559739, viewGroup, false);
    }

    public final void onActivityResult(int i, int i2, Intent intent) {
        VideoPublishEditModel LIZIZ2;
        FTCVideoPublishFragment.super.onActivityResult(i, i2, intent);
        if (i == 4 && i2 == -1 && intent != null && (LIZIZ2 = C30466Ge.LIZIZ(intent)) != null) {
            this.LIZ = LIZIZ2;
            LIZIZ();
        }
    }
}
