package com.ss.android.ugc.aweme.im.sdk.share.viewmodel;

import X.0Bt;
import X.0CB;
import X.0CH;
import X.1Bn;
import X.32G;
import X.3WX;
import X.4rR;
import X.6Is;
import X.C0746D8s;
import X.C0789DAj;
import X.C5795F6x;
import X.C5796F6y;
import X.Cv9;
import X.IYQ;
import X.IYx;
import X.IvV;
import X.Leb;
import X.Lel;
import X.M12;
import android.content.Context;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.im.sdk.share.panel.viewmodel.SharePanelViewModel;
import com.ss.android.ugc.aweme.im.service.model.IMContact;
import com.ss.android.ugc.aweme.sharer.ui.SharePackage;
import java.util.List;
import java.util.concurrent.CancellationException;
import kotlin.h.b.n;
import kotlinx.coroutines.CoroutineExceptionHandler;

public final class DownloadAndShareViewModel extends 0Bt implements 6Is, 3WX {
    public final 1Bn<4rR> LIZ;
    public final 1Bn<Boolean> LIZIZ;
    public final 1Bn<Boolean> LIZJ;
    public final 1Bn<List<IMContact>> LIZLLL;
    public final SharePanelViewModel LJ;
    public final 32G LJFF;
    public final Cv9 LJI;

    static {
        Covode.recordClassIndex(87211);
    }

    public final void LIZ(List<? extends IMContact> list, Throwable th) {
        M12.LIZ(list, th);
    }

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

    public final void onCleared() {
        DownloadAndShareViewModel.super.onCleared();
        C0789DAj.LIZ(this.LJI, (CancellationException) null);
        this.LIZIZ.setValue(false);
        this.LIZJ.setValue(false);
    }

    public final void LIZ(IMContact iMContact) {
        M12.LIZ(iMContact);
        this.LIZIZ.setValue(true);
    }

    public DownloadAndShareViewModel(SharePackage sharePackage) {
        SharePackage sharePackage2 = sharePackage;
        M12.LIZ(sharePackage2);
        this.LIZ = new 1Bn<>();
        this.LIZIZ = new 1Bn<>(false);
        this.LIZJ = new 1Bn<>(false);
        this.LIZLLL = new 1Bn<>();
        this.LJI = C0789DAj.LIZ((C0746D8s) new C5796F6y(CoroutineExceptionHandler.LIZLLL));
        SharePanelViewModel LIZ2 = IYx.LIZ(SharePanelViewModel.LJIIL, sharePackage2, this, Lel.INSTANCE, IYQ.DOWNLOAD, 0, 16);
        this.LJ = LIZ2;
        this.LJFF = new 32G(LIZ2);
    }

    public final void LIZ(List<? extends IMContact> list) {
        boolean z;
        M12.LIZ(list);
        this.LIZLLL.setValue(list);
        32G r3 = this.LJFF;
        List LIZ2 = r3.LIZ();
        if (list == null || list.isEmpty()) {
            z = true;
        } else {
            z = false;
        }
        Integer num = null;
        if (!z && LIZ2 != null) {
            LIZ2.clear();
            if (list == null) {
                n.LIZIZ();
            }
            LIZ2.addAll(list);
            LIZ2.add(new IvV());
            r3.notifyDataSetChanged();
        }
        StringBuilder sb = new StringBuilder("setData: ");
        if (list != null) {
            num = Integer.valueOf(list.size());
        }
        sb.append(num);
        sb.append(", ");
        sb.append(r3.LIZ().size());
        M12.LIZ("DownloadShareListAdapter", sb.toString());
    }

    public /* synthetic */ DownloadAndShareViewModel(SharePackage sharePackage, byte b) {
        this(sharePackage);
    }

    public final void LIZ(4rR r3, Context context) {
        M12.LIZ(r3, context);
        if (r3.LJ) {
            Leb.LIZIZ(r3.LIZ, new C5795F6x(context));
        }
        this.LIZ.setValue(r3);
    }

    public final boolean LIZ(IMContact iMContact, boolean z) {
        M12.LIZ(iMContact);
        if (!(iMContact instanceof IvV)) {
            return false;
        }
        this.LIZJ.setValue(true);
        return false;
    }
}
