package ze;

import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.os.Looper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import xyz.netfly.ui.login.LoginActivity;
import xyz.netfly.ui.login.RoleActivity;
import xyz.stream.api.database.entity.LiveHistory;
import xyz.stream.api.entity.BaseEntity;
import xyz.stream.api.entity.LiveChannelEntity;
import xyz.stream.api.entity.LoginEntity;
import xyz.stream.api.entity.SupportConfigEntity;
import xyz.stream.api.o;
import xyz.stream.utils.f0;
import xyz.stream.utils.m;

/* 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 f37188a;

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

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

    public /* synthetic */ i(Object obj, Object obj2, int i10) {
        this.f37188a = i10;
        this.f37190c = obj;
        this.f37189b = obj2;
    }

    @Override // xyz.stream.api.e
    public final void a(String str) {
        int i10 = this.f37188a;
        Object obj = this.f37189b;
        switch (i10) {
            case 0:
                LoginActivity loginActivity = (LoginActivity) this.f37190c;
                if (!loginActivity.isFinishing() && !loginActivity.isDestroyed() && loginActivity.f35507f) {
                    new Handler(Looper.getMainLooper()).postDelayed(new h(this, (String) obj, 0), 5000L);
                    break;
                }
                break;
            case 1:
                break;
            default:
                ((xyz.stream.api.e) obj).a(str);
                break;
        }
    }

    public final void b(BaseEntity baseEntity) {
        int i10 = this.f37188a;
        Object obj = this.f37189b;
        switch (i10) {
            case 0:
                LoginActivity loginActivity = (LoginActivity) this.f37190c;
                if (!loginActivity.isFinishing() && !loginActivity.isDestroyed() && loginActivity.f35507f) {
                    if (baseEntity.getCode() == 200) {
                        LoginEntity loginEntity = (LoginEntity) m.f36162a.fromJson(baseEntity.getData(), LoginEntity.class);
                        f0.o().u("sp_is_login_new", Boolean.TRUE);
                        f0.o().w("sp_account", loginEntity.getAccount());
                        f0.o().v(0, "sp_account_type");
                        f0.o().w("flutter.spUnid", loginEntity.getUnid());
                        o.f().B();
                        loginActivity.startActivity(new Intent(loginActivity, (Class<?>) RoleActivity.class));
                        loginActivity.setResult(-1);
                        loginActivity.finish();
                        break;
                    } else if (!loginActivity.isFinishing() && !loginActivity.isDestroyed() && loginActivity.f35507f) {
                        new Handler(Looper.getMainLooper()).postDelayed(new h(this, (String) obj, 1), 5000L);
                        break;
                    }
                }
                break;
            default:
                if (baseEntity != null && baseEntity.getData() != null && !baseEntity.getData().toString().isEmpty()) {
                    try {
                        SupportConfigEntity supportConfigEntity = (SupportConfigEntity) m.f36162a.fromJson(baseEntity.getData(), SupportConfigEntity.class);
                        if (supportConfigEntity.getSupport() != null && !supportConfigEntity.getSupport().booleanValue() && ((Activity) obj) != null && !((Activity) obj).isFinishing() && !((Activity) obj).isDestroyed()) {
                            ((Activity) obj).runOnUiThread(new androidx.core.app.a((Activity) obj, 3));
                        }
                    } catch (Exception e10) {
                        u.a.g(e10, new StringBuilder("Error parsing support config: "));
                    }
                    break;
                }
                break;
        }
    }

    @Override // xyz.stream.api.e
    public final void onSuccess(Object obj) {
        switch (this.f37188a) {
            case 0:
                b((BaseEntity) obj);
                break;
            case 1:
                b((BaseEntity) obj);
                break;
            default:
                List<LiveHistory> list = (List) obj;
                if (list == null || list.isEmpty()) {
                    ((xyz.stream.api.e) this.f37189b).onSuccess(new ArrayList());
                } else {
                    ArrayList arrayList = new ArrayList();
                    ArrayList arrayListC = xyz.stream.api.live.g.c(((xyz.stream.api.live.g) this.f37190c).f35898a);
                    for (LiveHistory liveHistory : list) {
                        xyz.stream.api.live.g gVar = (xyz.stream.api.live.g) this.f37190c;
                        int iIntValue = liveHistory.getChannelId().intValue();
                        gVar.getClass();
                        LiveChannelEntity liveChannelEntityI = xyz.stream.api.live.g.i(iIntValue, arrayListC);
                        if (liveChannelEntityI != null) {
                            arrayList.add(new LiveHistory(liveHistory.getId(), liveChannelEntityI.getId(), liveChannelEntityI.getName(), liveChannelEntityI.getLogo(), liveChannelEntityI.getCategoryId(), null, null, null, null, null, null, liveHistory.getUpdateDate(), Integer.valueOf(liveChannelEntityI.getIsPremium()), Integer.valueOf(liveChannelEntityI.getIsIptv()), null, liveChannelEntityI.getBackupTurboUrl(), liveChannelEntityI.getEpgUrl(), Integer.valueOf(liveChannelEntityI.getProtocol()), liveChannelEntityI.getCategoryProperty()));
                        }
                    }
                    Collections.sort(arrayList, new androidx.browser.trusted.b(11));
                    ((xyz.stream.api.e) this.f37189b).onSuccess(arrayList);
                }
                break;
        }
    }
}
