package xyz.stream.api.viewmodel;

import android.content.Context;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;
import tv.danmaku.ijk.media.player.IjkEventListener;
import xyz.stream.api.entity.BaseEntity;
import xyz.stream.api.entity.LoginEntity;
import xyz.stream.utils.f0;

/* JADX INFO: loaded from: classes3.dex */
public final class p implements xyz.stream.api.e {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f35994a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final /* synthetic */ Serializable f35995b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final /* synthetic */ Object f35996c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final /* synthetic */ ApiViewModel f35997d;

    public /* synthetic */ p(ApiViewModel apiViewModel, Serializable serializable, Object obj, int i10) {
        this.f35994a = i10;
        this.f35997d = apiViewModel;
        this.f35995b = serializable;
        this.f35996c = obj;
    }

    @Override // xyz.stream.api.e
    public final void a(String str) {
        int i10 = this.f35994a;
        Object obj = this.f35996c;
        switch (i10) {
            case 0:
                LoginViewModel loginViewModel = (LoginViewModel) this.f35997d;
                loginViewModel.handleError((Context) obj, str);
                BaseEntity baseEntity = new BaseEntity();
                baseEntity.setCode(IjkEventListener.BUFFERING_START);
                baseEntity.setMsg(str);
                loginViewModel.registerLiveData.j(baseEntity);
                break;
            default:
                ((AtomicReference) this.f35995b).set(new ArrayList());
                ((CountDownLatch) obj).countDown();
                break;
        }
    }

    @Override // xyz.stream.api.e
    public final void onSuccess(Object obj) {
        int i10 = this.f35994a;
        Object obj2 = this.f35996c;
        Serializable serializable = this.f35995b;
        switch (i10) {
            case 0:
                BaseEntity baseEntity = (BaseEntity) obj;
                int code = baseEntity.getCode();
                ApiViewModel apiViewModel = this.f35997d;
                if (code != 200) {
                    LoginViewModel loginViewModel = (LoginViewModel) apiViewModel;
                    loginViewModel.registerLiveData.j(baseEntity);
                    loginViewModel.handleError((Context) obj2, baseEntity.getMsg());
                } else {
                    LoginEntity loginEntity = (LoginEntity) xyz.stream.utils.m.f36162a.fromJson(baseEntity.getData(), LoginEntity.class);
                    f0.o().w("sp_token", loginEntity.getToken());
                    f0.o().u("sp_is_login_new", Boolean.TRUE);
                    f0.o().w("sp_account", (String) serializable);
                    f0.o().v(0, "sp_account_type");
                    f0.o().w("flutter.spUnid", loginEntity.getUnid());
                    ((LoginViewModel) apiViewModel).registerLiveData.j(baseEntity);
                }
                break;
            default:
                Collection arrayList = (List) obj;
                AtomicReference atomicReference = (AtomicReference) serializable;
                if (arrayList == null) {
                    arrayList = new ArrayList();
                }
                atomicReference.set(arrayList);
                ((CountDownLatch) obj2).countDown();
                break;
        }
    }
}
