package xyz.stream.api.viewmodel;

import com.google.gson.Gson;
import com.google.gson.JsonElement;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import tv.danmaku.ijk.media.player.IjkMediaMeta;
import xyz.stream.api.entity.BaseEntity;
import xyz.stream.api.entity.LiveChannelEntity;
import xyz.stream.api.entity.TagLiveEntity;
import xyz.stream.download.config.InnerConstant;

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

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

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

    public /* synthetic */ i(BaseLiveViewModel baseLiveViewModel, int i10) {
        this.f35979a = i10;
        this.f35980b = baseLiveViewModel;
    }

    @Override // xyz.stream.api.e
    public final void a(String str) {
        int i10 = this.f35979a;
        BaseLiveViewModel baseLiveViewModel = this.f35980b;
        switch (i10) {
            case 0:
                u.a.f(baseLiveViewModel.bannerLiveData);
                break;
            default:
                u.a.f(baseLiveViewModel.collectionLiveData);
                break;
        }
    }

    public final void b(BaseEntity baseEntity) {
        int i10 = this.f35979a;
        BaseLiveViewModel baseLiveViewModel = this.f35980b;
        switch (i10) {
            case 0:
                if (baseEntity.getCode() == 200) {
                    if (baseEntity.getData() == null) {
                        u.a.f(baseLiveViewModel.bannerLiveData);
                    } else {
                        JsonElement data = baseEntity.getData();
                        Type type = new BaseLiveViewModel$5$1().getType();
                        Gson gson = xyz.stream.utils.m.f36162a;
                        List<LiveChannelEntity> list = (List) gson.fromJson(gson.toJsonTree(((Map) gson.fromJson(data, type)).get("list")), new BaseLiveViewModel$5$2().getType());
                        if (list != null && !list.isEmpty()) {
                            re.a aVarO = xyz.stream.api.live.g.o();
                            ArrayList arrayList = new ArrayList();
                            for (LiveChannelEntity liveChannelEntity : list) {
                                LiveChannelEntity liveChannelEntityH = aVarO == null ? null : aVarO.h(liveChannelEntity.getId().intValue());
                                if (liveChannelEntityH != null) {
                                    liveChannelEntityH.setCoverUrl(liveChannelEntity.getCoverUrl());
                                    arrayList.add(liveChannelEntityH);
                                } else {
                                    liveChannelEntity.setId(0);
                                    arrayList.add(liveChannelEntity);
                                }
                            }
                            baseLiveViewModel.bannerLiveData.j(arrayList);
                        }
                    }
                }
                u.a.f(baseLiveViewModel.bannerLiveData);
                break;
            default:
                if (baseEntity.getCode() != 200) {
                    u.a.f(baseLiveViewModel.collectionLiveData);
                } else if (baseEntity.getData() == null) {
                    u.a.f(baseLiveViewModel.collectionLiveData);
                } else {
                    JsonElement data2 = baseEntity.getData();
                    Type type2 = new BaseLiveViewModel$6$1().getType();
                    Gson gson2 = xyz.stream.utils.m.f36162a;
                    Map map = (Map) gson2.fromJson(data2, type2);
                    if (map == null || map.get("list") == null) {
                        u.a.f(baseLiveViewModel.collectionLiveData);
                    } else {
                        List list2 = (List) gson2.fromJson(gson2.toJsonTree(map.get("list")), new BaseLiveViewModel$6$2().getType());
                        if (list2 == null || list2.isEmpty()) {
                            u.a.f(baseLiveViewModel.collectionLiveData);
                        } else {
                            ArrayList arrayList2 = new ArrayList();
                            for (Object obj : list2) {
                                Gson gson3 = xyz.stream.utils.m.f36162a;
                                Map map2 = (Map) gson3.fromJson(gson3.toJsonTree(obj), new BaseLiveViewModel$6$3().getType());
                                String str = (String) map2.get(IjkMediaMeta.IJKM_KEY_TITLE);
                                String strValueOf = String.valueOf(map2.get(InnerConstant.Db.f36069id));
                                List list3 = (List) gson3.fromJson(gson3.toJsonTree(map2.get("channels")), new BaseLiveViewModel$6$4().getType());
                                if (list3 != null && !list3.isEmpty()) {
                                    arrayList2.add(new TagLiveEntity(strValueOf, str, (List<LiveChannelEntity>) list3));
                                }
                            }
                            baseLiveViewModel.collectionLiveData.j(arrayList2);
                        }
                    }
                }
                break;
        }
    }

    @Override // xyz.stream.api.e
    public final /* bridge */ /* synthetic */ void onSuccess(Object obj) {
        switch (this.f35979a) {
            case 0:
                b((BaseEntity) obj);
                break;
            default:
                b((BaseEntity) obj);
                break;
        }
    }
}
