package com.ss.android.ugc.aweme.music.ui;

import X.0CB;
import X.0CH;
import X.0CN;
import X.0Gf;
import X.0Gp;
import X.0HH;
import X.19Y;
import X.19u;
import X.2K7;
import X.2MD;
import X.2UX;
import X.2aZ;
import X.2kf;
import X.2nK;
import X.3aU;
import X.3af;
import X.4vZ;
import X.6Is;
import X.7eB;
import X.7eC;
import X.7eE;
import X.7eI;
import X.805;
import X.86a;
import X.C3930Nor;
import X.C3936Nox;
import X.C4491Nxu;
import X.C4493Nxw;
import X.C5178OLl;
import X.C5239ONu;
import X.C5332ORj;
import X.C5338ORp;
import X.C5341ORs;
import X.C5345ORw;
import X.OFT;
import X.OHG;
import X.ONF;
import X.ONL;
import X.OOZ;
import X.OS1;
import X.OSP;
import X.OSU;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.CountDownTimer;
import android.os.SystemClock;
import android.text.TextUtils;
import android.webkit.CookieManager;
import com.bytedance.covode.number.Covode;
import com.google.gson.Gson;
import com.ss.android.ugc.aweme.commerce.tools.common.CommerceToolsService;
import com.ss.android.ugc.aweme.common.MobClick;
import com.ss.android.ugc.aweme.component.music.MusicService;
import com.ss.android.ugc.aweme.internal.UIUXBugsExperimentService;
import com.ss.android.ugc.aweme.music.model.MusicCategory;
import com.ss.android.ugc.aweme.out.AVExternalServiceImpl;
import com.ss.android.ugc.aweme.shortvideo.model.MusicModel;
import com.ss.android.ugc.aweme.shortvideo.model.MusicWaveBean;
import java.io.File;
import java.util.HashMap;
import org.json.JSONException;
import org.json.JSONObject;

public class MusicDownloadPlayHelper implements 6Is, OFT {
    public Context LIZ;
    public 19Y<String, Boolean> LIZIZ;
    public C5332ORj LIZJ;
    public int LIZLLL;
    public ProgressDialog LJ;
    public OSP LJFF;
    public C5239ONu LJI;
    public C5345ORw LJII;
    public boolean LJIIIIZZ;
    public C4493Nxw LJIIIZ;
    public String LJIIJ;
    public MusicCategory LJIIJJI;
    public int LJIIL;
    public boolean LJIILIIL;
    public MusicModel LJIILJJIL;
    public int LJIILL;
    public CountDownTimer LJIILLIIL;
    public boolean LJIIZILJ;
    public long LJIJ;
    public boolean LJIJI;
    public 7eC LJIJJ;

    static {
        Covode.recordClassIndex(94142);
    }

    private String LIZ(int i) {
        switch (i) {
            case 0:
            case 1:
            case 5:
            case 6:
            case 8:
            case 9:
            case 10:
                return "change_music_page";
            case 2:
                return "search_music";
            case 3:
                return "change_music_page_detail";
            case 7:
                return "personal_homepage";
            case 11:
                return "music_chart_list";
            default:
                return "";
        }
    }

    private String LIZJ(int i) {
        if (i == 0) {
            return "music_library_hot";
        }
        if (i == 1) {
            return "music_library_mine";
        }
        if (i == 2) {
            return "music_library_search";
        }
        if (i == 3) {
            return "music_library_list";
        }
        return null;
    }

    public final String LIZ(int i, int i2) {
        if (i2 == 0) {
            switch (i) {
                case 0:
                    return "edit_page_list";
                case 1:
                    return "edit_page_favourite";
                case 2:
                    return "edit_page_search";
                case 3:
                    return "edit_page_banner";
                case 5:
                case 6:
                    return "edit_page_local";
                case 7:
                    return "single_song";
                case 8:
                    return "edit_page_fm";
                case 9:
                    return "sticker_rec";
                case 10:
                    return "challenge_rec";
                case 11:
                    return "music_chart_list";
                default:
                    return "";
            }
        } else if (i2 != 2) {
            return "";
        } else {
            switch (i) {
                case 0:
                    return "shoot_page_list";
                case 1:
                    return "shoot_page_favourite";
                case 2:
                    return "shoot_page_search";
                case 3:
                    return "shoot_page_banner";
                case 5:
                case 6:
                    return "shoot_page_local";
                case 8:
                    return "shoot_page_fm";
                case 9:
                    return "sticker_rec";
                case 10:
                    return "challenge_rec";
                case 11:
                    return "music_chart_list";
                default:
                    return "";
            }
        }
    }

    public void onStateChanged(0CH r2, 0CB r3) {
        if (r3 == 0CB.ON_DESTROY) {
            dismissDialog();
        }
    }

    public final void LJ() {
        LIZJ();
    }

    public void bd_() {
        LIZJ();
    }

    public void LIZ(MusicModel musicModel, int i, boolean z, int i2, int i3) {
        C5332ORj oRj;
        Activity LJIIIZ2;
        String str;
        this.LJIJ = SystemClock.elapsedRealtime();
        if (musicModel != null && (oRj = this.LIZJ) != null && (LJIIIZ2 = oRj.LJIIIZ()) != null) {
            if (LJIIIZ()) {
                this.LJIILL = i;
                if (LIZ(musicModel, (Context) LJIIIZ2)) {
                    this.LJIILJJIL = musicModel;
                    this.LJIIZILJ = z;
                    this.LJFF.LIZLLL();
                    String localPath = musicModel.getLocalPath();
                    7eI r3 = new 7eI();
                    r3.LJFF = musicModel.getMusicId();
                    r3.LJI = z;
                    r3.LJII = i2;
                    r3.LJIIIIZZ = i3;
                    if (musicModel.getMusicType() == MusicModel.MusicType.ONLINE || musicModel.getMusicType() == MusicModel.MusicType.REUSE_AUDIO) {
                        if (musicModel.getMusicType() == MusicModel.MusicType.REUSE_AUDIO) {
                            r3.LIZIZ = musicModel.getReuseAudioPlayUrl().getUrlList();
                            r3.LIZLLL = musicModel.getDuration();
                            str = (String) musicModel.getReuseAudioPlayUrl().getUrlList().get(0);
                        } else {
                            r3.LIZIZ = musicModel.getUrl().getUrlList();
                            r3.LIZLLL = musicModel.getRealAuditionDuration();
                            str = (String) musicModel.getUrl().getUrlList().get(0);
                        }
                        r3.LIZJ = 4;
                        String LIZ2 = ONL.LIZ().LIZ(localPath);
                        if (TextUtils.isEmpty(LIZ2) || !805.LIZIZ(LIZ2) || new File(LIZ2).length() <= 0) {
                            if (musicModel.isNeedSetCookie()) {
                                String cookie = CookieManager.getInstance().getCookie(str);
                                HashMap hashMap = new HashMap();
                                hashMap.put("cookie", cookie);
                                r3.LJ = hashMap;
                            }
                            this.LJFF.LIZ(r3);
                            return;
                        }
                        r3.LIZ = LIZ2;
                        this.LJFF.LIZ(r3);
                        C5345ORw oRw = this.LJII;
                        if (oRw != null) {
                            oRw.LIZ();
                        }
                    }
                }
            } else if (C3936Nox.LIZIZ.LIZ()) {
                C3930Nor.LIZ(LJIIIZ2, true);
            } else {
                3af r1 = new 3af(LJIIIZ2);
                r1.LJ(2131827476);
                3af.LIZ(r1);
            }
        }
    }

    public final void LIZ(MusicModel musicModel, int i, boolean z, boolean z2) {
        LIZ(musicModel, i, z, z2, false);
    }

    /* JADX WARNING: Code restructure failed: missing block: B:26:0x0096, code lost:
        if (r9 != false) goto L_0x0098;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final void LIZ(final com.ss.android.ugc.aweme.shortvideo.model.MusicModel r5, final int r6, boolean r7, boolean r8, boolean r9) {
        /*
            r4 = this;
            X.ORj r0 = r4.LIZJ
            if (r0 != 0) goto L_0x0005
            return
        L_0x0005:
            android.content.Context r0 = r4.LIZ
            if (r0 != 0) goto L_0x000a
            return
        L_0x000a:
            if (r5 != 0) goto L_0x000d
            return
        L_0x000d:
            r4.LJIILJJIL = r5
            r0 = 0
            r4.LJIILIIL = r0
            r4.LIZIZ(r5, r6)
            com.ss.android.ugc.aweme.shortvideo.model.MusicModel$MusicType r1 = r5.getMusicType()
            com.ss.android.ugc.aweme.shortvideo.model.MusicModel$MusicType r0 = com.ss.android.ugc.aweme.shortvideo.model.MusicModel.MusicType.LOCAL
            if (r1 != r0) goto L_0x0038
            com.ss.android.ugc.aweme.services.IExternalService r0 = com.ss.android.ugc.aweme.out.AVExternalServiceImpl.LIZ()
            com.ss.android.ugc.aweme.services.external.ability.IAbilityService r0 = r0.abilityService()
            com.ss.android.ugc.aweme.services.external.ability.IAVInfoService r3 = r0.infoService()
            android.content.Context r2 = r4.LIZ
            java.lang.String r1 = r5.getLocalPath()
            com.ss.android.ugc.aweme.music.ui.MusicDownloadPlayHelper$5 r0 = new com.ss.android.ugc.aweme.music.ui.MusicDownloadPlayHelper$5
            r0.<init>(r5, r6)
            r3.mp3Legal(r2, r1, r0)
            return
        L_0x0038:
            r4.LIZJ()
            X.ORj r0 = r4.LIZJ
            android.app.Activity r3 = r0.LJIIIZ()
            if (r3 == 0) goto L_0x0049
            boolean r0 = r4.LIZ((com.ss.android.ugc.aweme.shortvideo.model.MusicModel) r5, (android.content.Context) r3)
            if (r0 != 0) goto L_0x005b
        L_0x0049:
            X.ORj r2 = r4.LIZJ
            java.lang.Exception r1 = new java.lang.Exception
            r0 = 2131827384(0x7f111ab8, float:1.928768E38)
            java.lang.String r0 = r3.getString(r0)
            r1.<init>(r0)
            r2.LIZ((com.ss.android.ugc.aweme.shortvideo.model.MusicModel) r5, (java.lang.Exception) r1)
            return
        L_0x005b:
            com.ss.android.ugc.aweme.shortvideo.model.MusicModel$MusicType r1 = r5.getMusicType()
            com.ss.android.ugc.aweme.shortvideo.model.MusicModel$MusicType r0 = com.ss.android.ugc.aweme.shortvideo.model.MusicModel.MusicType.ONLINE
            boolean r0 = r1.equals(r0)
            if (r0 != 0) goto L_0x0073
            com.ss.android.ugc.aweme.shortvideo.model.MusicModel$MusicType r1 = r5.getMusicType()
            com.ss.android.ugc.aweme.shortvideo.model.MusicModel$MusicType r0 = com.ss.android.ugc.aweme.shortvideo.model.MusicModel.MusicType.REUSE_AUDIO
            boolean r0 = r1.equals(r0)
            if (r0 == 0) goto L_0x0095
        L_0x0073:
            if (r7 == 0) goto L_0x0096
            if (r9 != 0) goto L_0x0098
            java.lang.String r0 = r5.getMusicId()
            r4.LIZJ((java.lang.String) r0)
        L_0x007e:
            X.19Y<java.lang.String, java.lang.Boolean> r2 = r4.LIZIZ
            java.lang.String r1 = r5.getMusicId()
            r0 = 1
            java.lang.Boolean r0 = java.lang.Boolean.valueOf(r0)
            r2.put(r1, r0)
            int r0 = r4.LIZLLL
            java.lang.String r0 = r4.LIZ((int) r6, (int) r0)
            r4.LIZ((com.ss.android.ugc.aweme.shortvideo.model.MusicModel) r5, (java.lang.String) r0, (boolean) r8, (boolean) r9)
        L_0x0095:
            return
        L_0x0096:
            if (r9 == 0) goto L_0x007e
        L_0x0098:
            r4.LJI()
            goto L_0x007e
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.music.ui.MusicDownloadPlayHelper.LIZ(com.ss.android.ugc.aweme.shortvideo.model.MusicModel, int, boolean, boolean, boolean):void");
    }

    public final void LIZ(String str, MusicModel musicModel, String str2) {
        C5332ORj oRj = this.LIZJ;
        if (oRj != null) {
            this.LJIILIIL = true;
            if (oRj.LJIIIZ() != null) {
                LIZJ();
                OS1.LIZ().pause();
                a_(musicModel);
                ProgressDialog progressDialog = this.LJ;
                if (progressDialog != null) {
                    progressDialog.dismiss();
                }
                this.LJIIIIZZ = false;
                4vZ.LIZIZ(this.LJIIIZ);
                this.LIZJ.LIZ(str, musicModel, str2);
            }
        }
    }

    public final void LIZ(String str) {
        if (this.LJIILJJIL != null) {
            2UX r3 = new 2UX();
            if (OSU.LIZ().booleanValue()) {
                r3.LIZ("from_location", OSU.LJI);
                r3.LIZ("type", OSU.LJII);
                r3.LIZ("is_editor_pro", 1);
            }
            if (this.LJIILL == 2) {
                r3.LIZ("music_id", this.LJIILJJIL.getMusicId());
                r3.LIZ("enter_from", "search_music");
                r3.LIZ("search_keyword", ONF.LIZ);
                r3.LIZ("log_pb", new Gson().LIZIZ(this.LJIILJJIL.getLogPb()));
                2nK.LIZ(str, 2MD.LIZ(r3.LIZ));
                return;
            }
            r3.LIZ("music_id", this.LJIILJJIL.getMusicId());
            int i = this.LJIILL;
            String str2 = "";
            String str3 = "song_choose_page";
            if (i != 0) {
                if (i == 1) {
                    str3 = "collection_music";
                } else if (i != 2) {
                    str3 = i == 3 ? "song_category" : str2;
                }
            }
            r3.LIZ("enter_from", str3);
            r3.LIZ("enter_method", "click_play_music");
            int i2 = this.LIZLLL;
            if (i2 != 1) {
                if (i2 == 0) {
                    str2 = "video_edit_page";
                } else if (i2 == 2) {
                    str2 = "video_shoot_page";
                }
            }
            r3.LIZ("previous_page", str2);
            r3.LIZ("category_id", LJII());
            r3.LIZ("category_name", LJIIIIZZ());
            2nK.LIZ(str, r3.LIZ);
        }
    }

    public final void LJFF() {
        C5345ORw oRw = this.LJII;
        if (oRw != null) {
            oRw.LIZ();
        }
    }

    private String LJII() {
        MusicCategory musicCategory = this.LJIIJJI;
        if (musicCategory == null || musicCategory.categoryId == null) {
            return "";
        }
        return this.LJIIJJI.categoryId;
    }

    private String LJIIIIZZ() {
        MusicCategory musicCategory = this.LJIIJJI;
        if (musicCategory == null || musicCategory.categoryName == null) {
            return "";
        }
        return this.LJIIJJI.categoryName;
    }

    public static boolean LJIIIZ() {
        try {
            return 2K7.LIZ.LIZJ();
        } catch (Exception unused) {
            return false;
        }
    }

    public void LIZIZ() {
        this.LJFF.LIZ((7eE) new 7eE() {
            static {
                Covode.recordClassIndex(94143);
            }

            public final void LIZ(int i) {
                if (MusicDownloadPlayHelper.this.LJIILJJIL != null) {
                    MusicDownloadPlayHelper musicDownloadPlayHelper = MusicDownloadPlayHelper.this;
                    musicDownloadPlayHelper.LIZJ(musicDownloadPlayHelper.LJIILJJIL, MusicDownloadPlayHelper.this.LJIILL, MusicDownloadPlayHelper.this.LJIIZILJ);
                }
                if (MusicDownloadPlayHelper.this.LJIJI) {
                    MusicDownloadPlayHelper.this.LIZ("play_music");
                }
                if (MusicDownloadPlayHelper.this.LJIILIIL && MusicDownloadPlayHelper.this.LJFF != null) {
                    MusicDownloadPlayHelper.this.LIZJ();
                }
                if (MusicDownloadPlayHelper.this.LIZJ != null) {
                    if (!(MusicDownloadPlayHelper.this.LIZJ.LJIIIIZZ() == null || i == 0)) {
                        MusicDownloadPlayHelper.this.LIZJ.LJIIIIZZ().setDuration(i);
                    }
                    MusicDownloadPlayHelper.this.LIZJ.LIZ(MusicDownloadPlayHelper.this.LJIILJJIL, SystemClock.elapsedRealtime() - MusicDownloadPlayHelper.this.LJIJ);
                    MusicDownloadPlayHelper.this.LJFF();
                }
            }
        });
    }

    public void LIZJ() {
        CountDownTimer countDownTimer = this.LJIILLIIL;
        if (countDownTimer != null) {
            countDownTimer.cancel();
        }
        this.LJFF.LIZLLL();
    }

    /* JADX WARNING: Code restructure failed: missing block: B:3:0x0005, code lost:
        r0 = r0.LJIIIZ();
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private void LJI() {
        /*
            r4 = this;
            X.ORj r0 = r4.LIZJ
            if (r0 != 0) goto L_0x0005
            return
        L_0x0005:
            android.app.Activity r0 = r0.LJIIIZ()
            X.1hK r0 = (X.1hK) r0
            if (r0 != 0) goto L_0x000e
            return
        L_0x000e:
            com.ss.android.ugc.aweme.base.SafeHandler r3 = new com.ss.android.ugc.aweme.base.SafeHandler
            r3.<init>(r0)
            com.ss.android.ugc.aweme.music.ui.MusicDownloadPlayHelper$2 r2 = new com.ss.android.ugc.aweme.music.ui.MusicDownloadPlayHelper$2
            r2.<init>(r0)
            r0 = 300(0x12c, double:1.48E-321)
            r3.postDelayed(r2, r0)
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.music.ui.MusicDownloadPlayHelper.LJI():void");
    }

    @0CN(LIZ = 0CB.ON_DESTROY)
    public void dismissDialog() {
        ProgressDialog progressDialog = this.LJ;
        if (progressDialog != null) {
            progressDialog.dismiss();
            this.LJ = null;
        }
        this.LJIIIIZZ = false;
        4vZ.LIZIZ(this.LJIIIZ);
    }

    public void LIZLLL() {
        this.LIZIZ.clear();
        CountDownTimer countDownTimer = this.LJIILLIIL;
        if (countDownTimer != null) {
            countDownTimer.cancel();
        }
        if (this.LIZJ != null) {
            this.LIZJ = null;
        }
        if (this.LJII != null) {
            this.LJII = null;
        }
        this.LIZ = null;
        this.LJI.LIZ();
        this.LJFF.LJ();
    }

    public final MusicDownloadPlayHelper LIZIZ(int i) {
        this.LIZLLL = i;
        return this;
    }

    public MusicDownloadPlayHelper(C5332ORj oRj) {
        this(oRj, "music_choose_page");
    }

    public void a_(MusicModel musicModel) {
        AVExternalServiceImpl.LIZ().publishService().setCurMusic(musicModel);
    }

    public final /* synthetic */ void LIZIZ(String str) {
        this.LIZIZ.put(str, false);
        CountDownTimer countDownTimer = this.LJIILLIIL;
        if (countDownTimer != null) {
            countDownTimer.cancel();
        }
        this.LJI.LIZ(str);
        C5332ORj oRj = this.LIZJ;
        if (oRj != null) {
            oRj.LJIIZILJ();
        }
    }

    private void LIZIZ(MusicModel musicModel) {
        C5332ORj oRj = this.LIZJ;
        if (oRj != null) {
            this.LJIILIIL = true;
            if (oRj.LJIIIZ() != null) {
                LIZJ();
                OS1.LIZ().pause();
                a_(musicModel);
                ProgressDialog progressDialog = this.LJ;
                if (progressDialog != null) {
                    progressDialog.dismiss();
                }
                this.LJIIIIZZ = false;
                4vZ.LIZIZ(this.LJIIIZ);
                this.LIZJ.LIZLLL(musicModel);
            }
        }
    }

    private void LIZJ(String str) {
        C5332ORj oRj = this.LIZJ;
        if (oRj != null) {
            19u LJIIIZ2 = oRj.LJIIIZ();
            this.LJ = C4493Nxw.LIZ(LJIIIZ2, C4491Nxu.VISIBLE_AFTER_5S, new C5341ORs(this, str));
            LJIIIZ2.getLifecycle().LIZ(this);
        }
    }

    public boolean LIZ(MusicModel musicModel, Context context) {
        return ONF.LIZ(musicModel, context, true);
    }

    public void LIZ(int i, final 7eB r4) {
        this.LJFF.LIZ(i, new 7eB() {
            static {
                Covode.recordClassIndex(94145);
            }

            public final void LIZ(boolean z) {
                7eB r0 = r4;
                if (r0 != null) {
                    r0.LIZ(z);
                }
                if (z) {
                    MusicDownloadPlayHelper musicDownloadPlayHelper = MusicDownloadPlayHelper.this;
                    musicDownloadPlayHelper.LIZJ(musicDownloadPlayHelper.LJIILJJIL, MusicDownloadPlayHelper.this.LJIILL, MusicDownloadPlayHelper.this.LJIIZILJ);
                }
            }
        });
    }

    public MusicDownloadPlayHelper(C5332ORj oRj, String str) {
        this.LIZIZ = new 19Y<>();
        this.LJIJ = -1;
        this.LJIJI = true;
        this.LIZJ = oRj;
        this.LIZ = oRj.LJIIIZ();
        String str2 = str;
        this.LJFF = new OSP(str2);
        C5239ONu oNu = new C5239ONu((Context) this.LIZJ.LJIIIZ(), true, true, true, str2);
        this.LJI = oNu;
        oNu.LIZ(1);
    }

    private void LIZIZ(MusicModel musicModel, int i) {
        String str;
        String str2;
        2aZ r4 = new 2aZ();
        if (i == 2) {
            r4.LIZ("source", "search");
        }
        int i2 = this.LIZLLL;
        if (i2 != 1) {
            String str3 = "";
            if (i2 == 0) {
                str = "mid_page";
                str2 = "video_edit_page";
            } else if (i2 == 2) {
                str = "shoot_page";
                str2 = "video_shoot_page";
            } else {
                str = str3;
                str2 = str;
            }
            r4.LIZ("enter_from", LIZJ(i));
            if (musicModel.getMusicType() == MusicModel.MusicType.ONLINE || musicModel.getMusicType() == MusicModel.MusicType.REUSE_AUDIO) {
                if (!86a.LIZ(musicModel.getMusicId())) {
                    MobClick obtain = MobClick.obtain();
                    obtain.setEventName("music_add");
                    obtain.setLabelName(str);
                    obtain.setValue(musicModel.getMusicId());
                    obtain.setJsonObject(r4.LIZ());
                    2nK.onEvent(obtain);
                    String LIZ2 = LIZ(i);
                    if (TextUtils.equals("personal_homepage", LIZ2)) {
                        2UX r42 = new 2UX();
                        r42.LIZ("enter_from", LIZ2);
                        r42.LIZ("music_id", musicModel.getMusicId());
                        r42.LIZ("category_id", LJII());
                        r42.LIZ("category_name", LJIIIIZZ());
                        r42.LIZ("order", this.LJIIL + 1);
                        if (!TextUtils.equals("personal_homepage", LIZ2)) {
                            str3 = str2;
                        }
                        r42.LIZ("previous_page", str3);
                        if (ONF.LIZLLL(musicModel.getEditFrom())) {
                            r42.LIZ("is_edited_music", 1);
                            r42.LIZ("original_music_duration", musicModel.getDuration());
                            r42.LIZ("new_music_duration", OSU.LJFF);
                            r42.LIZ("music_edited_from", musicModel.getEditFrom());
                        } else {
                            r42.LIZ("is_edited_music", 0);
                        }
                        if (OSU.LIZ().booleanValue()) {
                            r42.LIZ("from_location", OSU.LJI);
                            r42.LIZ("type", OSU.LJII);
                            r42.LIZ("is_editor_pro", 1);
                        }
                        r42.LIZ(CommerceToolsService.LIZ().getPageContextMobValues("is_commercial", "commercial_music_suggestion_id"));
                        if (TextUtils.equals(LIZ2, "search_music")) {
                            r42.LIZ("search_keyword", ONF.LIZ);
                            r42.LIZ("log_pb", new Gson().LIZIZ(musicModel.getLogPb()));
                            2nK.LIZ("add_music", 2MD.LIZ(r42.LIZ));
                            return;
                        }
                        2nK.LIZ("add_music", r42.LIZ);
                    }
                }
            } else if (!86a.LIZ(musicModel.getSongId())) {
                MobClick obtain2 = MobClick.obtain();
                obtain2.setEventName("music_add");
                obtain2.setLabelName(str);
                obtain2.setValue(musicModel.getSongId());
                obtain2.setJsonObject(r4.LIZ());
                2nK.onEvent(obtain2);
            }
        } else if (!86a.LIZ(musicModel.getMusicId())) {
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.put("song_position", this.LJIIJ);
                if (i == 2) {
                    jSONObject.put("search_keyword", musicModel.getSearchKeyWords());
                }
            } catch (JSONException e) {
                0HH.LIZ(e);
            }
            MobClick obtain3 = MobClick.obtain();
            obtain3.setEventName("shoot");
            obtain3.setLabelName("popular_song");
            obtain3.setValue(musicModel.getMusicId());
            obtain3.setJsonObject(jSONObject);
            2nK.onEvent(obtain3);
        }
    }

    public final void LIZ(MusicModel musicModel, int i) {
        String str;
        String LIZ2 = LIZ(i);
        int i2 = this.LIZLLL;
        String str2 = "";
        if (i2 == 0) {
            str = "video_edit_page";
        } else if (i2 == 2) {
            str = "video_shoot_page";
        } else {
            str = str2;
        }
        2UX r3 = new 2UX();
        r3.LIZ("enter_from", LIZ2);
        r3.LIZ("music_id", musicModel.getMusicId());
        r3.LIZ("category_id", LJII());
        r3.LIZ("category_name", LJIIIIZZ());
        r3.LIZ("order", this.LJIIL + 1);
        if (!TextUtils.equals("personal_homepage", LIZ2)) {
            str2 = str;
        }
        r3.LIZ("previous_page", str2);
        2UX r4 = r3;
        r4.LIZ("music_name", musicModel.getName());
        r4.LIZ(CommerceToolsService.LIZ().getPageContextMobValues("is_commercial"));
        if (ONF.LIZLLL(musicModel.getEditFrom())) {
            r3.LIZ("is_edited_music", 1);
            r3.LIZ("original_music_duration", musicModel.getDuration());
            r3.LIZ("new_music_duration", OSU.LJFF);
            r3.LIZ("music_edited_from", musicModel.getEditFrom());
        } else {
            r3.LIZ("is_edited_music", 0);
        }
        if (OSU.LIZ().booleanValue()) {
            r3.LIZ("from_location", OSU.LJI);
            r3.LIZ("type", OSU.LJII);
            r3.LIZ("is_editor_pro", 1);
        }
        2nK.LIZ("add_music", 2MD.LIZ(r3.LIZ));
    }

    public final void LIZIZ(MusicModel musicModel, int i, boolean z) {
        LIZ(musicModel, i, z, false);
    }

    private void LIZ(final MusicModel musicModel, final String str, boolean z) {
        this.LJI.LIZ(musicModel, new OHG() {
            static {
                Covode.recordClassIndex(94148);
            }

            public final void LIZ() {
            }

            public final void LIZIZ() {
            }

            public final void LIZ(int i) {
                if (MusicDownloadPlayHelper.this.LIZJ != null && MusicDownloadPlayHelper.this.LIZJ.da_() && MusicDownloadPlayHelper.this.LIZJ.LJIIIZ() != null) {
                    UIUXBugsExperimentService.LIZ();
                }
            }

            public final void LIZ(C5178OLl oLl) {
                MusicDownloadPlayHelper.this.dismissDialog();
                if (MusicDownloadPlayHelper.this.LIZJ != null && MusicDownloadPlayHelper.this.LIZJ.da_() && MusicDownloadPlayHelper.this.LIZJ.LJIIIZ() != null) {
                    MusicDownloadPlayHelper.this.LIZJ.LIZ(musicModel, (Exception) oLl);
                    MobClick obtain = MobClick.obtain();
                    obtain.setEventName("music_download_end");
                    obtain.setLabelName("perf_monitor");
                    obtain.setExtValueString(musicModel.getMusicId());
                    3aU r2 = new 3aU();
                    r2.LIZ("is_success", "0");
                    r2.LIZ("sdk_type", String.valueOf(MusicService.LJIJ().LIZJ()));
                    obtain.setJsonObject(r2.LIZ());
                    2nK.onEvent(obtain);
                }
            }

            public final void LIZ(String str, MusicWaveBean musicWaveBean) {
                musicModel.setMusicWaveBean(musicWaveBean);
                MusicDownloadPlayHelper.this.LIZ(str, musicModel, str);
                MobClick obtain = MobClick.obtain();
                obtain.setEventName("music_download_end");
                obtain.setLabelName("perf_monitor");
                obtain.setExtValueString(musicModel.getMusicId());
                3aU r2 = new 3aU();
                r2.LIZ("is_success", "1");
                r2.LIZ("downloadStrategy", String.valueOf(MusicService.LJIJ().LIZJ()));
                obtain.setJsonObject(r2.LIZ());
                2nK.onEvent(obtain);
            }
        }, true, z);
    }

    public final void LIZJ(MusicModel musicModel, int i, boolean z) {
        CountDownTimer countDownTimer = this.LJIILLIIL;
        if (countDownTimer != null) {
            countDownTimer.cancel();
        }
        final MusicModel musicModel2 = musicModel;
        if (musicModel2.getDuration() != musicModel2.getAuditionDuration().intValue()) {
            long realAuditionDuration = (long) musicModel2.getRealAuditionDuration();
            if (realAuditionDuration <= 0) {
                2kf.LIZ("MusicDownloadPlayHelper: audition_duration is zero, music id: " + musicModel2.getMusicId());
                return;
            }
            final int i2 = i;
            final boolean z2 = z;
            AnonymousClass4 r1 = new CountDownTimer(realAuditionDuration) {
                static {
                    Covode.recordClassIndex(94146);
                }

                public final void onTick(long j) {
                }

                public final void onFinish() {
                    MusicDownloadPlayHelper.this.LJFF.LIZLLL();
                    if (MusicDownloadPlayHelper.this.LJIJJ != null) {
                        MusicDownloadPlayHelper.this.LJIJJ.LIZ();
                    }
                    if (z2) {
                        MusicDownloadPlayHelper.this.LIZ(musicModel2, i2, true);
                    }
                }
            };
            this.LJIILLIIL = r1;
            r1.start();
        }
    }

    public void LIZ(MusicModel musicModel, int i, boolean z) {
        LIZ(musicModel, i, z, 0, -1);
    }

    private void LIZ(MusicModel musicModel, String str, boolean z, boolean z2) {
        AVExternalServiceImpl.LIZ().provideAVPerformance().start("av_music_download", "MusicDownloadPlayHelper start");
        MusicModel musicModel2 = musicModel;
        String str2 = str;
        boolean z3 = z2;
        boolean z4 = z;
        if (!TextUtils.isEmpty(musicModel2.getBindChallengeId()) && !TextUtils.equals(musicModel2.getBindChallengeId(), "0")) {
            0Gp.LIZ(new OOZ(musicModel2)).LIZ(new C5338ORp(this, musicModel2, z3, str2, z4), 0Gp.LIZIZ, (0Gf) null);
        } else if (z3) {
            LIZIZ(musicModel2);
        } else {
            LIZ(musicModel2, str2, z4);
        }
    }

    public final /* synthetic */ Void LIZ(MusicModel musicModel, boolean z, String str, boolean z2, 0Gp r7) {
        if (!((Boolean) this.LIZIZ.get(musicModel.getMusicId())).booleanValue()) {
            return null;
        }
        if (r7.LIZIZ() || r7.LIZJ()) {
            dismissDialog();
            return null;
        } else if (z) {
            LIZIZ(musicModel);
            return null;
        } else {
            LIZ(musicModel, str, z2);
            return null;
        }
    }
}
