package com.strmr.ps.ui.mobile.ratings;

import android.graphics.drawable.GradientDrawable;
import android.view.View;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.media3.container.NalUnitUtil;
import com.strmr.ps.data.repository.EpisodeRating;
import com.strmr.ps.ui.ratings.EpisodeRatingsViewModel;
import defpackage.cr4;
import defpackage.e6a;
import defpackage.js7;
import defpackage.ks7;
import defpackage.l43;
import defpackage.wo2;
import defpackage.wo5;
import defpackage.y41;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
final class a<T> implements l43 {
    public final /* synthetic */ MobileEpisodeRatingsFragment a;

    public a(MobileEpisodeRatingsFragment mobileEpisodeRatingsFragment) {
        this.a = mobileEpisodeRatingsFragment;
    }

    @Override // defpackage.l43
    public final Object emit(Object obj, Continuation continuation) {
        Iterator it;
        LinkedHashMap linkedHashMap;
        String str;
        ks7 ks7Var = (ks7) obj;
        MobileEpisodeRatingsFragment mobileEpisodeRatingsFragment = this.a;
        ProgressBar progressBar = mobileEpisodeRatingsFragment.m;
        if (progressBar == null) {
            cr4.n("loadingIndicator");
            throw null;
        }
        boolean z = ks7Var.a;
        int i = ks7Var.d;
        List list = ks7Var.c;
        String str2 = ks7Var.b;
        int i2 = 8;
        progressBar.setVisibility(z ? 0 : 8);
        TextView textView = mobileEpisodeRatingsFragment.n;
        if (textView == null) {
            cr4.n("errorText");
            throw null;
        }
        textView.setVisibility(str2 != null ? 0 : 8);
        TextView textView2 = mobileEpisodeRatingsFragment.n;
        if (textView2 == null) {
            cr4.n("errorText");
            throw null;
        }
        textView2.setText(str2);
        ScrollView scrollView = mobileEpisodeRatingsFragment.p;
        if (scrollView == null) {
            cr4.n("contentScroll");
            throw null;
        }
        if (!ks7Var.a && str2 == null && !list.isEmpty()) {
            i2 = 0;
        }
        scrollView.setVisibility(i2);
        if (!list.isEmpty()) {
            ArrayList<HorizontalScrollView> arrayList = mobileEpisodeRatingsFragment.q;
            LinearLayout linearLayout = mobileEpisodeRatingsFragment.o;
            if (linearLayout == null) {
                cr4.n("gridContainer");
                throw null;
            }
            linearLayout.removeAllViews();
            arrayList.clear();
            int iL = mobileEpisodeRatingsFragment.l(35);
            int iL2 = mobileEpisodeRatingsFragment.l(3);
            int iL3 = mobileEpisodeRatingsFragment.l(30);
            float fL = mobileEpisodeRatingsFragment.l(5);
            LinearLayout linearLayout2 = new LinearLayout(mobileEpisodeRatingsFragment.requireContext());
            linearLayout2.setOrientation(0);
            LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(-1, -2);
            layoutParams.bottomMargin = mobileEpisodeRatingsFragment.l(3);
            linearLayout2.setLayoutParams(layoutParams);
            TextView textView3 = new TextView(mobileEpisodeRatingsFragment.requireContext());
            textView3.setLayoutParams(new LinearLayout.LayoutParams(iL3, iL));
            textView3.setText("");
            linearLayout2.addView(textView3);
            HorizontalScrollView horizontalScrollView = new HorizontalScrollView(mobileEpisodeRatingsFragment.requireContext());
            horizontalScrollView.setLayoutParams(new LinearLayout.LayoutParams(-1, -2));
            horizontalScrollView.setHorizontalScrollBarEnabled(false);
            LinearLayout linearLayout3 = new LinearLayout(mobileEpisodeRatingsFragment.requireContext());
            linearLayout3.setOrientation(0);
            int i3 = 1;
            if (1 <= i) {
                while (true) {
                    TextView textView4 = new TextView(mobileEpisodeRatingsFragment.requireContext());
                    LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(iL, iL);
                    layoutParams2.setMarginEnd(iL2);
                    textView4.setLayoutParams(layoutParams2);
                    textView4.setGravity(17);
                    textView4.setText("E" + i3);
                    textView4.setTextColor(-1275068417);
                    textView4.setTextSize(2, 10.0f);
                    linearLayout3.addView(textView4);
                    if (i3 == i) {
                        break;
                    }
                    i3++;
                }
            }
            horizontalScrollView.addView(linearLayout3);
            linearLayout2.addView(horizontalScrollView);
            LinearLayout linearLayout4 = mobileEpisodeRatingsFragment.o;
            if (linearLayout4 == null) {
                cr4.n("gridContainer");
                throw null;
            }
            linearLayout4.addView(linearLayout2);
            arrayList.add(horizontalScrollView);
            Iterator it2 = ks7Var.e.iterator();
            while (it2.hasNext()) {
                int iIntValue = ((Number) it2.next()).intValue();
                List listB = ((EpisodeRatingsViewModel) mobileEpisodeRatingsFragment.f.getValue()).b(iIntValue);
                LinearLayout linearLayout5 = new LinearLayout(mobileEpisodeRatingsFragment.requireContext());
                linearLayout5.setOrientation(0);
                linearLayout5.setGravity(16);
                LinearLayout.LayoutParams layoutParams3 = new LinearLayout.LayoutParams(-1, -2);
                layoutParams3.bottomMargin = mobileEpisodeRatingsFragment.l(3);
                linearLayout5.setLayoutParams(layoutParams3);
                TextView textView5 = new TextView(mobileEpisodeRatingsFragment.requireContext());
                textView5.setLayoutParams(new LinearLayout.LayoutParams(iL3, iL));
                textView5.setGravity(17);
                textView5.setText("S" + iIntValue);
                textView5.setTextColor(-1275068417);
                textView5.setTextSize(2, 11.0f);
                linearLayout5.addView(textView5);
                HorizontalScrollView horizontalScrollView2 = new HorizontalScrollView(mobileEpisodeRatingsFragment.requireContext());
                horizontalScrollView2.setLayoutParams(new LinearLayout.LayoutParams(-1, -2));
                horizontalScrollView2.setHorizontalScrollBarEnabled(false);
                LinearLayout linearLayout6 = new LinearLayout(mobileEpisodeRatingsFragment.requireContext());
                linearLayout6.setOrientation(0);
                List list2 = listB;
                int iH = wo5.h(y41.p(list2, 10));
                LinkedHashMap linkedHashMap2 = new LinkedHashMap(iH >= 16 ? iH : 16);
                for (T t : list2) {
                    linkedHashMap2.put(Integer.valueOf(((EpisodeRating) t).getEpisode()), t);
                }
                if (1 <= i) {
                    int i4 = 1;
                    while (true) {
                        EpisodeRating episodeRating = (EpisodeRating) linkedHashMap2.get(Integer.valueOf(i4));
                        if (episodeRating != null) {
                            Float rating = episodeRating.getRating();
                            int iA = rating != null ? js7.a(rating.floatValue()) : -12434878;
                            if (rating != null) {
                                it = it2;
                                str = String.format("%.1f", Arrays.copyOf(new Object[]{Float.valueOf(rating.floatValue())}, 1));
                            } else {
                                it = it2;
                                str = "N/A";
                            }
                            GradientDrawable gradientDrawable = new GradientDrawable();
                            gradientDrawable.setColor(iA);
                            gradientDrawable.setCornerRadius(fL);
                            linkedHashMap = linkedHashMap2;
                            TextView textView6 = new TextView(mobileEpisodeRatingsFragment.requireContext());
                            LinearLayout.LayoutParams layoutParams4 = new LinearLayout.LayoutParams(iL, iL);
                            layoutParams4.setMarginEnd(iL2);
                            textView6.setLayoutParams(layoutParams4);
                            textView6.setGravity(17);
                            textView6.setText(str);
                            textView6.setTextColor(-1);
                            textView6.setTextSize(2, 11.0f);
                            textView6.setBackground(gradientDrawable);
                            linearLayout6.addView(textView6);
                        } else {
                            it = it2;
                            linkedHashMap = linkedHashMap2;
                            View view = new View(mobileEpisodeRatingsFragment.requireContext());
                            LinearLayout.LayoutParams layoutParams5 = new LinearLayout.LayoutParams(iL, iL);
                            layoutParams5.setMarginEnd(iL2);
                            view.setLayoutParams(layoutParams5);
                            linearLayout6.addView(view);
                        }
                        if (i4 == i) {
                            break;
                        }
                        i4++;
                        it2 = it;
                        linkedHashMap2 = linkedHashMap;
                    }
                } else {
                    it = it2;
                }
                horizontalScrollView2.addView(linearLayout6);
                linearLayout5.addView(horizontalScrollView2);
                LinearLayout linearLayout7 = mobileEpisodeRatingsFragment.o;
                if (linearLayout7 == null) {
                    cr4.n("gridContainer");
                    throw null;
                }
                linearLayout7.addView(linearLayout5);
                arrayList.add(horizontalScrollView2);
                it2 = it;
            }
            for (HorizontalScrollView horizontalScrollView3 : arrayList) {
                horizontalScrollView3.setOnScrollChangeListener(new wo2(mobileEpisodeRatingsFragment, horizontalScrollView3, 1));
            }
        }
        return e6a.a;
    }
}
