package xyz.netfly.ads;

import android.app.Activity;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.widget.FrameLayout;
import androidx.emoji2.text.v;
import com.bytedance.sdk.openadsdk.api.nativeAd.PAGNativeAd;
import ed.t;
import ed.u;
import ie.w4;
import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import xyz.netfly.ui.vod_info.VodInfoActivity;
import xyz.stream.api.database.entity.ServerEntity;
import xyz.stream.api.entity.LiveChannelEntity;
import xyz.stream.api.entity.PageInfo;
import xyz.stream.api.entity.SeriesEntity;
import xyz.stream.api.entity.VideoCollectionEntity;
import xyz.stream.api.entity.VideoEntity;
import xyz.stream.download.DownloadManager;

/* JADX INFO: loaded from: classes3.dex */
public final /* synthetic */ class p implements Runnable {

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

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

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

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

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

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

    public /* synthetic */ p(Object obj, Object obj2, Object obj3, Object obj4, Object obj5, int i10) {
        this.f34875a = i10;
        this.f34876b = obj;
        this.f34877c = obj2;
        this.f34878d = obj3;
        this.f34879e = obj4;
        this.f34880f = obj5;
    }

    @Override // java.lang.Runnable
    public final void run() {
        int i10 = this.f34875a;
        int i11 = 11;
        int i12 = 0;
        Object obj = this.f34880f;
        Object obj2 = this.f34879e;
        Object obj3 = this.f34878d;
        Object obj4 = this.f34877c;
        Object obj5 = this.f34876b;
        switch (i10) {
            case 0:
                Activity activity = (Activity) obj4;
                FrameLayout frameLayout = (FrameLayout) obj3;
                PAGNativeAd pAGNativeAd = (PAGNativeAd) obj2;
                u uVar = (u) obj;
                r rVar = ((q) obj5).f34884d;
                rVar.getClass();
                try {
                    w4 w4VarInflate = w4.inflate(activity.getLayoutInflater(), null, false);
                    frameLayout.removeAllViews();
                    frameLayout.addView(w4VarInflate.f27632a);
                    ArrayList arrayList = new ArrayList();
                    arrayList.add(w4VarInflate.f27635d);
                    if (pAGNativeAd != null) {
                        rVar.a(frameLayout, w4VarInflate, arrayList, pAGNativeAd, pAGNativeAd.getNativeAdData());
                    }
                    w4VarInflate.f27633b.setOnClickListener(new i(rVar, uVar, i12));
                    frameLayout.setLayoutParams(new FrameLayout.LayoutParams(-1, 270));
                    frameLayout.setVisibility(0);
                    w4VarInflate.f27632a.post(new v(w4VarInflate, frameLayout, uVar, i11));
                    break;
                } catch (Throwable unused) {
                    frameLayout.removeAllViews();
                    frameLayout.setLayoutParams(new FrameLayout.LayoutParams(-1, 0));
                    frameLayout.setVisibility(8);
                    try {
                        uVar.invokeMethod("height", Double.valueOf(0.0d));
                        return;
                    } catch (Throwable unused2) {
                        return;
                    }
                }
                break;
            case 1:
                xyz.stream.api.q.g().getClass();
                new Handler(Looper.getMainLooper()).post(new xyz.netfly.mobile.plugin.d((t) obj, xyz.stream.api.q.l((String) obj5, (String) obj4, (String) obj3, (String) obj2), 0));
                break;
            case 2:
                xyz.netfly.ui.main.adapter.h hVar = (xyz.netfly.ui.main.adapter.h) obj5;
                xyz.netfly.ui.main.adapter.p pVar = (xyz.netfly.ui.main.adapter.p) obj4;
                PageInfo pageInfo = (PageInfo) obj3;
                String str = (String) obj2;
                List<VideoEntity> list = (List) obj;
                hVar.getClass();
                pVar.a(false);
                pageInfo.setLoading(false);
                xyz.netfly.ui.main.adapter.k kVar = hVar.f35562d;
                kVar.f35581l.put(str, pageInfo);
                List<VideoEntity> videoList = ((VideoCollectionEntity) t4.f.x(kVar.f35571b).e(new com.google.firebase.messaging.m(str, i11)).g().a()).getVideoList();
                int size = videoList.size();
                HashSet hashSet = new HashSet(Math.max(16, size * 2));
                Iterator<VideoEntity> it = videoList.iterator();
                while (it.hasNext()) {
                    hashSet.add(Integer.valueOf(it.next().getVideoId()));
                }
                for (VideoEntity videoEntity : list) {
                    if (hashSet.add(Integer.valueOf(videoEntity.getVideoId()))) {
                        videoList.add(videoEntity);
                        i12++;
                    }
                }
                if (i12 > 0) {
                    pVar.notifyItemRangeInserted(size, i12);
                }
                break;
            case 3:
                xyz.netfly.ui.main.adapter.h hVar2 = (xyz.netfly.ui.main.adapter.h) obj5;
                p000if.d dVar = (p000if.d) obj4;
                PageInfo pageInfo2 = (PageInfo) obj3;
                String str2 = (String) obj2;
                List<LiveChannelEntity> list2 = (List) obj;
                hVar2.getClass();
                dVar.a(false);
                pageInfo2.setLoading(false);
                xyz.netfly.ui.main.adapter.k kVar2 = hVar2.f35562d;
                kVar2.f35581l.put(str2, pageInfo2);
                List<LiveChannelEntity> channel = ((VideoCollectionEntity) t4.f.x(kVar2.f35571b).e(new com.google.firebase.messaging.m(str2, 12)).g().a()).getChannel();
                int size2 = channel.size();
                HashSet hashSet2 = new HashSet(Math.max(16, size2 * 2));
                Iterator<LiveChannelEntity> it2 = channel.iterator();
                while (it2.hasNext()) {
                    hashSet2.add(it2.next().getId());
                }
                for (LiveChannelEntity liveChannelEntity : list2) {
                    if (hashSet2.add(liveChannelEntity.getId())) {
                        channel.add(liveChannelEntity);
                        i12++;
                    }
                }
                if (i12 > 0) {
                    dVar.notifyItemRangeInserted(size2, i12);
                }
                break;
            case 4:
                VodInfoActivity vodInfoActivity = (VodInfoActivity) obj5;
                SeriesEntity seriesEntity = (SeriesEntity) obj4;
                String str3 = (String) obj3;
                String str4 = (String) obj2;
                String str5 = (String) obj;
                int i13 = VodInfoActivity.V;
                vodInfoActivity.getClass();
                if (Build.VERSION.SDK_INT >= 33 && g0.d.a(vodInfoActivity, "android.permission.POST_NOTIFICATIONS") != 0) {
                    androidx.core.app.f.c(vodInfoActivity, new String[]{"android.permission.POST_NOTIFICATIONS"}, 1001);
                }
                DownloadManager.getInstance().startDownload(vodInfoActivity.f35660b.getId().intValue(), vodInfoActivity.f35660b.getSourceType().intValue(), vodInfoActivity.f35660b.getTitle(), vodInfoActivity.f35660b.getBackdropPath(), Integer.valueOf(seriesEntity.getVideoId()), seriesEntity.getCover(), Integer.valueOf(seriesEntity.getRuntime()), String.valueOf(seriesEntity.getRuntime()), str3, vodInfoActivity.f35660b.getTitle(), str4, str5);
                break;
            default:
                xyz.stream.api.database.f fVar = (xyz.stream.api.database.f) obj5;
                String strReplaceFirst = (String) obj4;
                xyz.stream.api.database.e eVar = (xyz.stream.api.database.e) obj3;
                Integer num = (Integer) obj2;
                String str6 = (String) obj;
                xyz.stream.api.database.f fVar2 = xyz.stream.api.database.f.f35806f;
                fVar.getClass();
                try {
                    if (strReplaceFirst.startsWith("file://")) {
                        strReplaceFirst = strReplaceFirst.replaceFirst("^file://", "");
                    }
                    xyz.stream.utils.h.b("Reading IPTV file from path: " + strReplaceFirst);
                    File file = new File(strReplaceFirst);
                    if (file.exists()) {
                        String strK = kotlinx.coroutines.flow.h.K(file);
                        if (strK.isEmpty()) {
                            eVar.h("File is empty.");
                        } else {
                            ServerEntity serverEntityJ = fVar.j(num, str6, Uri.fromFile(file).toString(), strK, eVar);
                            if (serverEntityJ != null) {
                                int i14 = fVar.f35810c;
                                fVar.f35810c = 0;
                                eVar.n(serverEntityJ, i14);
                            } else {
                                eVar.h("Failed to parse IPTV data.");
                            }
                        }
                    } else {
                        eVar.h("File does not exist.");
                    }
                } catch (Exception e10) {
                    eVar.h("Error reading file: " + e10.getMessage());
                }
                break;
        }
    }
}
