package com.ss.android.ugc.aweme.choosemusic.utils;

import X.0CB;
import X.0CH;
import X.3GT;
import X.6Is;
import X.7eC;
import X.7eD;
import X.7eE;
import X.7he;
import X.C5239ONu;
import X.C5241ONw;
import X.C5328ORf;
import X.C5331ORi;
import X.C5332ORj;
import X.C5336ORn;
import X.C5342ORt;
import X.Crj;
import X.M12;
import X.OSP;
import android.app.Activity;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.widget.Toast;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.music.ui.MusicDownloadPlayHelper;
import com.ss.android.ugc.aweme.shortvideo.model.MusicModel;
import kotlin.h.b.n;

public final class AVMusicDownloadPlayHelper extends MusicDownloadPlayHelper implements 6Is {
    public static final C5342ORt LIZIZ = new C5342ORt((byte) 0);
    public final C5332ORj LIZ;
    public final Crj LJIJJLI = 7he.LIZ(C5241ONw.LIZ);
    public Handler LJIL;
    public Toast LJJ;

    static {
        Covode.recordClassIndex(56365);
    }

    public final HandlerThread LIZ() {
        return (HandlerThread) this.LJIJJLI.getValue();
    }

    public final void onStateChanged(0CH r1, 0CB r2) {
        super.onStateChanged(r1, r2);
    }

    public final void LIZIZ() {
        this.LJFF.LIZ((7eE) new C5336ORn(this));
    }

    public final void LIZJ() {
        if (this.LJIILLIIL != null) {
            this.LJIILLIIL.cancel();
        }
        OSP osp = this.LJFF;
        if (osp != null) {
            osp.LIZLLL();
        }
        Handler handler = this.LJIL;
        if (handler != null) {
            Message obtain = Message.obtain();
            obtain.what = 2;
            handler.sendMessage(obtain);
        }
    }

    public final void LIZLLL() {
        super.LIZLLL();
        LIZ().quit();
        Handler handler = this.LJIL;
        if (handler != null) {
            handler.removeCallbacksAndMessages((Object) null);
        }
        this.LJFF.LIZ((7eC) null);
        this.LJFF.LIZ((7eD) null);
        this.LJFF.LIZ((7eE) null);
        this.LJFF.LJ();
    }

    public static void LIZ(Toast toast) {
        if (Build.VERSION.SDK_INT == 25) {
            3GT.LIZ(toast);
        }
        toast.show();
    }

    /* JADX INFO: super call moved to the top of the method (can break code semantics) */
    public AVMusicDownloadPlayHelper(C5332ORj oRj) {
        super(oRj);
        M12.LIZ(oRj);
        this.LIZ = oRj;
        Activity LJIIIZ = oRj.LJIIIZ();
        n.LIZIZ(LJIIIZ, "");
        C5239ONu oNu = new C5239ONu((Context) LJIIIZ, true, true, true, "av_record_player_music");
        oNu.LIZ(1);
        this.LJI = oNu;
        LIZIZ();
    }

    private final void LIZ(Context context, String str) {
        Toast toast = this.LJJ;
        if (toast != null) {
            toast.cancel();
        }
        Toast makeText = Toast.makeText(context, str, 0);
        makeText.setGravity(17, 0, 0);
        this.LJJ = makeText;
        LIZ(makeText);
    }

    public final boolean LIZ(MusicModel musicModel, Context context) {
        M12.LIZ(context);
        if (musicModel != null && !musicModel.isPlayUrlValid()) {
            String string = context.getString(2131827385);
            n.LIZIZ(string, "");
            LIZ(context, string);
            return false;
        } else if (musicModel == null || musicModel.getMusicStatus() != 0) {
            return true;
        } else {
            String offlineDesc = musicModel.getOfflineDesc();
            n.LIZIZ(offlineDesc, "");
            if (offlineDesc.length() == 0) {
                offlineDesc = context.getString(2131827384);
            }
            n.LIZIZ(offlineDesc, "");
            LIZ(context, offlineDesc);
            return false;
        }
    }

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

    public final void LIZ(MusicModel musicModel, int i, boolean z, int i2, int i3) {
        if (this.LJIL == null) {
            this.LJIL = new Handler(LIZ().getLooper(), new C5328ORf(this, i2, i3));
        }
        Handler handler = this.LJIL;
        if (handler != null) {
            Message obtain = Message.obtain();
            obtain.what = 1;
            obtain.obj = new C5331ORi(musicModel, i, z);
            handler.sendMessage(obtain);
        }
    }
}
