package com.ss.android.ugc.aweme.story.record.recordcontrol;

import X.0CB;
import X.0CC;
import X.0CD;
import X.0CH;
import X.0CN;
import X.1hK;
import X.2cN;
import X.2nK;
import X.7he;
import X.AnonymousClass5RW;
import X.AnonymousClass6J4;
import X.AnonymousClass711;
import X.AnonymousClass712;
import X.AnonymousClass714;
import X.AnonymousClass71F;
import X.AnonymousClass71H;
import X.AnonymousClass71K;
import X.AnonymousClass71N;
import X.AnonymousClass71P;
import X.AnonymousClass71S;
import X.AnonymousClass71V;
import X.AnonymousClass72Z;
import X.AnonymousClass7PQ;
import X.C31126Is;
import X.C35526Zq;
import X.C38316eL;
import X.C44106ng;
import X.C50366xm;
import X.C50386xo;
import X.C50466xw;
import X.C50526y2;
import X.C51206z8;
import X.Crj;
import X.FWb;
import X.I8D;
import X.Ls2;
import X.M12;
import X.Mk2;
import X.Mk3;
import X.N9p;
import X.NE6;
import X.NI0;
import X.NKa;
import X.NSR;
import X.NTD;
import X.NeQ;
import X.OAa;
import X.PhE;
import X.PlI;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.shortvideo.edit.multiedit.data.MultiEditVideoRecordData;
import com.ss.android.ugc.aweme.shortvideo.edit.multiedit.data.MultiEditVideoSegmentRecordData;
import com.ss.android.ugc.aweme.shortvideo.edit.multiedit.data.MultiEditVideoStatusRecordData;
import com.ss.android.ugc.aweme.shortvideo.ui.EmbaddedWindowInfo;
import com.ss.android.ugc.aweme.story.base.ui.StoryEditActivity;
import com.ss.android.ugc.aweme.story.edit.model.StoryEditModel;
import com.ss.android.ugc.aweme.story.record.StoryRecordBaseViewModel;
import com.ss.android.vesdk.VERecordData;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import kotlin.h.b.n;

public final class StoryRecordNextAction implements NTD, C31126Is, AnonymousClass72Z {
    public 2cN LIZ;
    public final 1hK LIZIZ;
    public final NeQ LIZJ;
    public final NE6 LIZLLL;
    public final C50386xo LJ;
    public final C51206z8 LJFF;
    public final StoryRecordBaseViewModel LJI;
    public final Ls2<String> LJII;
    public final int LJIIIIZZ = AnonymousClass71S.LIZ;
    public final int LJIIIZ = AnonymousClass71S.LIZIZ;
    public final Crj LJIIJ = 7he.LIZ(new AnonymousClass712(this));
    public StoryEditModel LJIIJJI;

    static {
        Covode.recordClassIndex(118147);
    }

    public final AnonymousClass71F LIZ() {
        return (AnonymousClass71F) this.LJIIJ.getValue();
    }

    public final void LIZ(AnonymousClass71N r1) {
        M12.LIZ(r1);
    }

    public final void onStateChanged(0CH r2, 0CB r3) {
        if (r3 == 0CB.ON_RESUME) {
            onResume();
        } else if (r3 == 0CB.ON_DESTROY) {
            onDestroy();
        }
    }

    @0CN(LIZ = 0CB.ON_DESTROY)
    public final void onDestroy() {
        2cN r0 = this.LIZ;
        if (r0 != null) {
            r0.dispose();
        }
    }

    @0CN(LIZ = 0CB.ON_RESUME)
    public final void onResume() {
        StoryEditModel storyEditModel = this.LJIIJJI;
        if (storyEditModel != null) {
            StoryEditActivity.LIZLLL.LIZ(this.LIZIZ, storyEditModel);
            this.LJIIJJI = null;
        }
    }

    public final void LIZ(StoryEditModel storyEditModel) {
        0CD lifecycle = this.LIZIZ.getLifecycle();
        n.LIZIZ(lifecycle, "");
        if (lifecycle.LIZ().isAtLeast(0CC.RESUMED)) {
            StoryEditActivity.LIZLLL.LIZ(this.LIZIZ, storyEditModel);
        } else {
            this.LJIIJJI = storyEditModel;
        }
    }

    public final void LIZ(NKa nKa) {
        String str;
        String str2;
        M12.LIZ(nKa);
        this.LJFF.LIZ();
        boolean z = true;
        if (this.LJ.LJIIIZ.LJI < 1000) {
            LIZ().LIZ(C38316eL.LIZ().LJI(this.LJ.LJIIIIZZ));
            LIZ().LIZIZ(C38316eL.LIZ().LJII(this.LJ.LJIIIIZZ));
            if (C44106ng.LIZ()) {
                NI0 ni0 = this.LIZLLL;
                if ((ni0 instanceof NI0) && ni0.LJJJJ() != null) {
                    ArrayList arrayList = new ArrayList();
                    NSR LJJIJLIJ = this.LIZJ.LJJIJLIJ();
                    n.LIZIZ(LJJIJLIJ, "");
                    AnonymousClass71V.LIZ(LJJIJLIJ, arrayList, this.LIZLLL);
                    AnonymousClass71F LIZ2 = LIZ();
                    int i = this.LJ.LJIIIZ.LIZJ;
                    int i2 = this.LJ.LJIIIZ.LIZLLL;
                    if (N9p.LIZ(this.LIZLLL) == null) {
                        z = false;
                    }
                    LIZ2.LIZ(i, i2, z, arrayList);
                    return;
                }
            }
            AnonymousClass71F LIZ3 = LIZ();
            int i3 = this.LJ.LJIIIZ.LIZJ;
            int i4 = this.LJ.LJIIIZ.LIZLLL;
            if (N9p.LIZ(this.LIZLLL) == null) {
                z = false;
            }
            LIZ3.LIZ(i3, i4, z);
            return;
        }
        this.LIZJ.LJJLJ();
        AnonymousClass711 r3 = new AnonymousClass711();
        File LIZ4 = this.LJ.LIZ().LIZ();
        if (LIZ4 != null) {
            str = LIZ4.getPath();
        } else {
            str = null;
        }
        r3.LIZ = str;
        File LIZIZ2 = this.LJ.LIZ().LIZIZ();
        if (LIZIZ2 != null) {
            str2 = LIZIZ2.getPath();
        } else {
            str2 = null;
        }
        r3.LIZIZ = str2;
        r3.LJ = this.LIZJ.LJIJJ.getMediaController();
        r3.LIZLLL = false;
        r3.LJI = true;
        r3.LJFF = FWb.LIZIZ.LIZ().LJIILIIL().getABService().getEnablePreReleaseGPUResource();
        File LIZ5 = this.LJ.LIZ().LIZ();
        n.LIZIZ(LIZ5, "");
        r3.LIZJ = AnonymousClass7PQ.LIZ(LIZ5.getPath(), Integer.valueOf((int) this.LJ.LJIIIZ.LJI), Integer.valueOf(this.LJ.LJIIIZ.LIZJ), Integer.valueOf(this.LJ.LJIIIZ.LIZLLL), (List<EmbaddedWindowInfo>) null);
        r3.LIZ((AnonymousClass71P) new AnonymousClass714(this));
    }

    public final MultiEditVideoStatusRecordData LIZ(C50386xo r8, String str) {
        boolean z = false;
        VERecordData create = VERecordData.create(new I8D(new AnonymousClass71H(r8.LIZ())), false);
        if (create == null) {
            AnonymousClass6J4 r1 = new AnonymousClass6J4();
            r1.LIZ("status", -1);
            2nK.LIZ("ve_create_record_data", r1.LIZ);
            C35526Zq.LIZIZ("record data == null");
            return null;
        }
        AnonymousClass6J4 r0 = new AnonymousClass6J4();
        r0.LIZ("status", 0);
        2nK.LIZ("ve_create_record_data", r0.LIZ);
        File LIZ2 = r8.LIZ().LIZ();
        n.LIZIZ(LIZ2, "");
        create.concatVideo = LIZ2.getAbsolutePath();
        File LIZIZ2 = r8.LIZ().LIZIZ();
        n.LIZIZ(LIZIZ2, "");
        create.concatAudio = LIZIZ2.getAbsolutePath();
        MultiEditVideoStatusRecordData multiEditVideoStatusRecordData = new MultiEditVideoStatusRecordData();
        File LJ2 = r8.LIZ().LJ();
        n.LIZIZ(LJ2, "");
        String absolutePath = LJ2.getAbsolutePath();
        n.LIZIZ(absolutePath, "");
        MultiEditVideoRecordData LIZ3 = AnonymousClass5RW.LIZ(create, absolutePath);
        if (LIZ3 == null) {
            return null;
        }
        List<MultiEditVideoSegmentRecordData> list = LIZ3.segmentDataList;
        if (list != null && list.size() == 1) {
            z = true;
        }
        LIZ3.isSingleVideo = z;
        multiEditVideoStatusRecordData.originMultiEditRecordData = LIZ3.cloneData();
        multiEditVideoStatusRecordData.curMultiEditVideoRecordData = LIZ3;
        multiEditVideoStatusRecordData.videoMetaData = str;
        return multiEditVideoStatusRecordData;
    }

    public final void LIZ(String str, List<String> list) {
        String str2;
        M12.LIZ(str);
        this.LIZJ.LJJIJLIJ().LIZJ();
        this.LJ.LIZ(this.LIZJ.LJJIJLIJ().LJ());
        C50386xo r5 = this.LJ;
        if (r5.LJIIIZ.LJI > 0) {
            str2 = (String) this.LJII.invoke();
        } else {
            str2 = "take_photo";
        }
        r5.LJFF = str2;
        C50466xw r3 = new C50466xw(true);
        r3.LIZ = System.currentTimeMillis();
        this.LIZ = new C50526y2(this.LJ.LJIIIIZZ, new OAa(), true).LIZ(str, true, C38316eL.LIZ().LJ(this.LJ.LJIIIIZZ)).LIZIZ(PhE.LIZIZ(PlI.LIZJ)).LIZ(Mk2.LIZ(Mk3.LIZ)).LIZ(new C50366xm(this, r3, str, list), new AnonymousClass71K(this));
    }

    public StoryRecordNextAction(1hK r8, NeQ neQ, NE6 ne6, C50386xo r11, C51206z8 r12, StoryRecordBaseViewModel storyRecordBaseViewModel, Ls2<String> ls2) {
        StoryRecordBaseViewModel storyRecordBaseViewModel2 = storyRecordBaseViewModel;
        NeQ neQ2 = neQ;
        Ls2<String> ls22 = ls2;
        1hK r0 = r8;
        NE6 ne62 = ne6;
        C50386xo r3 = r11;
        C51206z8 r4 = r12;
        M12.LIZ(r0, neQ2, ne62, r3, r4, storyRecordBaseViewModel2, ls22);
        this.LIZIZ = r0;
        this.LIZJ = neQ2;
        this.LIZLLL = ne62;
        this.LJ = r3;
        this.LJFF = r4;
        this.LJI = storyRecordBaseViewModel2;
        this.LJII = ls22;
        r0.getLifecycle().LIZ(this);
    }
}
