package xyz.netfly.ui.live.epg;

import androidx.room.RoomDatabase;
import com.google.android.gms.measurement.internal.u1;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.TimeZone;
import xyz.stream.api.entity.LiveEpgEntity;

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

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

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

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

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final /* synthetic */ z f35413e;

    public x(z zVar, int i10, int i11, int i12, int i13) {
        this.f35413e = zVar;
        this.f35409a = i10;
        this.f35410b = i11;
        this.f35411c = i12;
        this.f35412d = i13;
    }

    @Override // xyz.stream.api.e
    public final void a(String str) {
        int i10 = this.f35409a;
        z zVar = this.f35413e;
        List listA = zVar.a();
        zVar.f35418c.runOnUiThread(new v(this.f35410b, this.f35411c, this.f35412d, i10, listA, zVar));
    }

    /* JADX WARN: Removed duplicated region for block: B:6:0x0015  */
    @Override // xyz.stream.api.e
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void onSuccess(Object obj) {
        int i10;
        List listA;
        List list;
        long time;
        int i11;
        Iterator it;
        long j10;
        long time2;
        List list2 = (List) obj;
        int i12 = this.f35409a;
        z zVar = this.f35413e;
        if (list2 != null) {
            zVar.getClass();
            if (list2.isEmpty()) {
                i10 = i12;
                listA = zVar.a();
            } else {
                String str = zVar.f35435t;
                ArrayList arrayList = new ArrayList();
                if (list2.isEmpty()) {
                    i10 = i12;
                } else {
                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault());
                    simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
                    Calendar calendarD = kotlinx.coroutines.y.D(str);
                    Calendar calendarU = kotlinx.coroutines.y.u(str);
                    calendarU.set(11, 23);
                    calendarU.set(12, 59);
                    calendarU.set(13, 59);
                    calendarU.set(14, RoomDatabase.MAX_BIND_PARAMETER_CNT);
                    long time3 = calendarD.getTime().getTime();
                    long time4 = calendarU.getTime().getTime();
                    String strH = kotlinx.coroutines.flow.h.h("yyyy-MM-dd'T'HH:mm:ss", kotlinx.coroutines.y.D(str).getTime());
                    String strV = kotlinx.coroutines.y.v(str);
                    for (Iterator it2 = list2.iterator(); it2.hasNext(); it2 = it) {
                        LiveEpgEntity liveEpgEntity = (LiveEpgEntity) it2.next();
                        try {
                            Date date = simpleDateFormat.parse(liveEpgEntity.getStartTime());
                            Date date2 = simpleDateFormat.parse(liveEpgEntity.getEndTime());
                            time = date != null ? date.getTime() : 0L;
                            if (date2 != null) {
                                try {
                                    time2 = date2.getTime();
                                } catch (Exception e10) {
                                    e = e10;
                                    u.a.g(e, new StringBuilder("filterEpgForCurrentTimeSlot: "));
                                    i11 = i12;
                                    it = it2;
                                    j10 = time;
                                    time2 = 0;
                                }
                            } else {
                                time2 = 0;
                            }
                            i11 = i12;
                            it = it2;
                            j10 = time;
                        } catch (Exception e11) {
                            e = e11;
                            time = 0;
                        }
                        if (Math.min(time2, time4) - Math.max(j10, time3) >= 60000) {
                            arrayList.add(liveEpgEntity);
                        }
                        i12 = i11;
                    }
                    i10 = i12;
                    if (!arrayList.isEmpty()) {
                        Collections.sort(arrayList, new androidx.browser.trusted.b(9));
                        String startTime = ((LiveEpgEntity) arrayList.get(0)).getStartTime();
                        if (kotlinx.coroutines.flow.h.E(startTime, strH)) {
                            arrayList.add(0, new LiveEpgEntity(-2, "", "", strH, startTime));
                        }
                        String endTime = arrayList.isEmpty() ? "" : ((LiveEpgEntity) u1.e(arrayList, 1)).getEndTime();
                        if (!kotlinx.coroutines.flow.h.E(endTime, strV) && !endTime.equals(strV)) {
                            arrayList.add(new LiveEpgEntity(-2, "", "", endTime, strV));
                        }
                    }
                }
                if (arrayList.isEmpty()) {
                    listA = zVar.a();
                } else {
                    list = arrayList;
                }
            }
            list = listA;
        }
        zVar.f35418c.runOnUiThread(new v(this.f35410b, this.f35411c, this.f35412d, i10, list, zVar));
    }
}
