package com.ss.android.ugc.aweme.detail.panel;

import X.0HH;
import X.2GO;
import X.3GT;
import X.4q6;
import X.B2P;
import X.B2R;
import X.BSU;
import X.BSV;
import X.C3585BPx;
import X.LeS;
import X.Lel;
import X.M12;
import X.OCa;
import X.OD6;
import X.Qxn;
import android.app.Activity;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.Toast;
import com.bytedance.covode.number.Covode;
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.Video;
import com.ss.android.ugc.aweme.homepage.msadapt.MSAdaptionService;
import com.ss.android.ugc.aweme.music.model.Music;
import com.ss.android.ugc.aweme.out.AVExternalServiceImpl;
import com.ss.android.ugc.aweme.prop.impl.PropReuseServiceImpl;
import com.ss.android.ugc.aweme.services.IExternalService;
import com.ss.android.ugc.aweme.services.external.ui.RecordConfig;
import com.ss.android.ugc.aweme.shortvideo.library.LibraryMaterialInfoSv;
import com.ss.android.ugc.aweme.shortvideo.model.MusicModel;
import com.ss.android.ugc.aweme.tools.detail.IPropReuseService;
import java.io.Serializable;
import java.util.List;
import java.util.UUID;
import kotlin.h.b.n;
import kotlin.o.z;

public final class LibraryFeedPanel extends ShootFeedPanel implements 2GO {
    public final B2R LIZ;

    static {
        Covode.recordClassIndex(63738);
    }

    public final int LJIILIIL() {
        B2P materialType;
        B2R b2r = this.LIZ;
        if (b2r == null || (materialType = b2r.getMaterialType()) == null || materialType != B2P.Gif) {
            return 2131826591;
        }
        return 2131826592;
    }

    public LibraryFeedPanel(Bundle bundle) {
        Serializable serializable;
        if (bundle != null) {
            serializable = bundle.getSerializable("feed_data_material_info");
        } else {
            serializable = null;
        }
        this.LIZ = (B2R) serializable;
    }

    public final View LIZ(RelativeLayout relativeLayout) {
        String str;
        M12.LIZ(relativeLayout);
        View LIZ2 = 0HH.LIZ(LayoutInflater.from(this.LLL), 2131559533, relativeLayout, false);
        B2R b2r = this.LIZ;
        if (b2r != null) {
            OD6 findViewById = LIZ2.findViewById(2131370697);
            n.LIZIZ(findViewById, "");
            OD6 od6 = findViewById;
            UrlModel cover = b2r.getCover();
            if (cover == null || (str = cover.getUri()) == null) {
                str = b2r.getPreview();
            }
            if (str != null) {
                UrlModel urlModel = new UrlModel();
                urlModel.setUrlList(LeS.LIZLLL(new String[]{str}));
                urlModel.setUri(Uri.decode(str));
                OCa.LIZ(od6, urlModel);
            }
            Qxn findViewById2 = LIZ2.findViewById(2131364812);
            n.LIZIZ(findViewById2, "");
            Qxn qxn = findViewById2;
            String materialName = b2r.getMaterialName();
            if (materialName != null && 4q6.LIZ(materialName)) {
                LIZ(qxn, b2r.getMaterialName());
            } else if (b2r.getMaterialType() == B2P.Gif) {
                LIZ(qxn, this.LLL.getString(2131826595));
            } else {
                LIZ(qxn, this.LLL.getString(2131826596));
            }
        }
        n.LIZIZ(LIZ2, "");
        return LIZ2;
    }

    public final void LIZ(View view) {
        MusicModel musicModel;
        List list;
        M12.LIZ(view);
        if (this.LLL == null || !MSAdaptionService.LIZJ().LIZIZ(this.LLL)) {
            B2R b2r = this.LIZ;
            if (b2r != null) {
                Aweme LJJII = LJJII();
                n.LIZIZ(LJJII, "");
                Music music = LJJII.getMusic();
                Music music2 = null;
                if (music != null) {
                    musicModel = music.convertToMusicModel();
                } else {
                    musicModel = null;
                }
                Aweme LJJII2 = LJJII();
                n.LIZIZ(LJJII2, "");
                if (LJJII2.getStickerIDs() != null) {
                    Aweme LJJII3 = LJJII();
                    n.LIZIZ(LJJII3, "");
                    String stickerIDs = LJJII3.getStickerIDs();
                    n.LIZIZ(stickerIDs, "");
                    if (stickerIDs.length() != 0) {
                        boolean downloadEffectOrMusicAfterEnterCamera = AVExternalServiceImpl.LIZ().configService().avsettingsConfig().downloadEffectOrMusicAfterEnterCamera();
                        IPropReuseService LIZJ = PropReuseServiceImpl.LIZJ();
                        Activity activity = this.LLL;
                        n.LIZIZ(activity, "");
                        Aweme LJJII4 = LJJII();
                        n.LIZIZ(LJJII4, "");
                        String stickerIDs2 = LJJII4.getStickerIDs();
                        if (stickerIDs2 == null || (list = z.LIZ(stickerIDs2, new char[]{','})) == null) {
                            list = Lel.INSTANCE;
                        }
                        Aweme LJJII5 = LJJII();
                        n.LIZIZ(LJJII5, "");
                        Music music3 = LJJII5.getMusic();
                        n.LIZIZ(music3, "");
                        if (music3.isPgc()) {
                            Aweme LJJII6 = LJJII();
                            n.LIZIZ(LJJII6, "");
                            music2 = LJJII6.getMusic();
                        }
                        Aweme LJJII7 = LJJII();
                        n.LIZIZ(LJJII7, "");
                        Video video = LJJII7.getVideo();
                        n.LIZIZ(video, "");
                        LIZJ.LIZ(activity, list, new C3585BPx("library", music2, LibraryMaterialInfoSv.Companion.LIZ(b2r), true, "library_auto", "library_detail_page", (String) null, "library_detail_page", (String) null, (String) null, false, (String) null, Integer.valueOf(video.getVideoLength()), 228161), downloadEffectOrMusicAfterEnterCamera);
                        return;
                    }
                }
                RecordConfig.Builder builder = new RecordConfig.Builder();
                builder.shootWay("library");
                builder.creationId(UUID.randomUUID().toString());
                builder.enterFrom("library_detail_page");
                builder.libraryMaterialInfo(LibraryMaterialInfoSv.Companion.LIZ(b2r));
                builder.isThroughAnchor(true);
                if (musicModel == null || !musicModel.isPgc()) {
                    IExternalService LIZ2 = AVExternalServiceImpl.LIZ();
                    Activity activity2 = this.LLL;
                    n.LIZIZ(activity2, "");
                    LIZ2.asyncService(activity2, "library_detail_page", new BSV(builder, this));
                    return;
                }
                builder.musicModel(musicModel);
                Aweme LJJII8 = LJJII();
                n.LIZIZ(LJJII8, "");
                Music music4 = LJJII8.getMusic();
                if (music4 != null) {
                    music2 = Long.valueOf(music4.getId());
                }
                builder.autoUseMusic(String.valueOf(music2));
                IExternalService LIZ3 = AVExternalServiceImpl.LIZ();
                Activity activity3 = this.LLL;
                n.LIZIZ(activity3, "");
                LIZ3.asyncService(activity3, "library_detail_page", new BSU(builder, musicModel, this));
                return;
            }
            return;
        }
        Toast makeText = Toast.makeText(this.LLL, this.LLL.getString(2131824145), 0);
        if (Build.VERSION.SDK_INT == 25) {
            3GT.LIZ(makeText);
        }
        makeText.show();
    }
}
