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

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.media3.container.NalUnitUtil;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.appbar.MaterialToolbar;
import com.google.android.material.card.MaterialCardView;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.strmr.ps.R;
import com.strmr.ps.data.auth.FeatureGateManager;
import com.strmr.ps.data.local.dao.TraktUserItemDao;
import com.strmr.ps.data.local.entity.AllDebridAccount;
import com.strmr.ps.data.local.entity.EasyDebridAccount;
import com.strmr.ps.data.local.entity.PremiumizeAccount;
import com.strmr.ps.data.local.entity.RealDebridAccount;
import com.strmr.ps.data.local.entity.TorBoxAccount;
import com.strmr.ps.data.local.entity.TraktAccount;
import com.strmr.ps.data.remote.api.TraktApiService;
import com.strmr.ps.data.repository.AllDebridRepository;
import com.strmr.ps.data.repository.EasyDebridRepository;
import com.strmr.ps.data.repository.OmdbRepository;
import com.strmr.ps.data.repository.PreferencesRepository;
import com.strmr.ps.data.repository.PremiumizeRepository;
import com.strmr.ps.data.repository.RealDebridRepository;
import com.strmr.ps.data.repository.RpdbRepository;
import com.strmr.ps.data.repository.TorBoxRepository;
import com.strmr.ps.data.repository.TraktAccountRepository;
import com.strmr.ps.data.repository.TraktAuthRepository;
import com.strmr.ps.data.supabase.DeviceManager;
import com.strmr.ps.data.supabase.SettingsSyncManager;
import com.strmr.ps.ui.mobile.settings.MobileAccountsFragment;
import dagger.hilt.android.AndroidEntryPoint;
import defpackage.bd5;
import defpackage.by5;
import defpackage.cj7;
import defpackage.co;
import defpackage.cr4;
import defpackage.cy5;
import defpackage.dy5;
import defpackage.fx4;
import defpackage.fy5;
import defpackage.gv3;
import defpackage.ik2;
import defpackage.iy5;
import defpackage.ky5;
import defpackage.l54;
import defpackage.lr3;
import defpackage.lta;
import defpackage.m02;
import defpackage.m12;
import defpackage.mia;
import defpackage.n41;
import defpackage.osa;
import defpackage.qq3;
import defpackage.rx4;
import defpackage.sc2;
import defpackage.sf1;
import defpackage.sq3;
import defpackage.sr3;
import defpackage.v3;
import defpackage.vx8;
import defpackage.wj0;
import defpackage.wl3;
import defpackage.y41;
import defpackage.z3;
import defpackage.zs6;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import kotlin.Metadata;

/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\b\u0007\u0018\u00002\u00020\u0001B\u0007¢\u0006\u0004\b\u0002\u0010\u0003¨\u0006\u0004"}, d2 = {"Lcom/strmr/ps/ui/mobile/settings/MobileAccountsFragment;", "Landroidx/fragment/app/o;", "<init>", "()V", "app_sideloadRelease"}, k = 1, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
@AndroidEntryPoint
@vx8
public final class MobileAccountsFragment extends l54 {
    public PremiumizeAccount aa;
    public RealDebridAccount ab;
    public AllDebridAccount ac;
    public TorBoxAccount ad;
    public EasyDebridAccount ae;
    public boolean af;
    public fx4 ag;
    public String ai;
    public wl3 f;
    public TraktAuthRepository i;
    public TraktAccountRepository j;
    public TraktUserItemDao k;
    public TraktApiService l;
    public PremiumizeRepository m;
    public RealDebridRepository n;
    public AllDebridRepository o;
    public TorBoxRepository p;
    public EasyDebridRepository q;
    public RpdbRepository r;
    public OmdbRepository s;
    public PreferencesRepository t;
    public DeviceManager u;
    public FeatureGateManager v;
    public SettingsSyncManager w;
    public boolean y;
    public int z;
    public List x = ik2.a;
    public boolean ah = true;

    @Metadata(k = 3, mv = {2, 0, 0}, xi = NalUnitUtil.H265_NAL_UNIT_TYPE_UNSPECIFIED)
    public static final class a implements zs6, sr3 {
        public final /* synthetic */ co a;

        public a(co coVar) {
            this.a = coVar;
        }

        @Override // defpackage.zs6
        public final /* synthetic */ void a(Object obj) {
            this.a.invoke(obj);
        }

        @Override // defpackage.sr3
        public final lr3 b() {
            return this.a;
        }

        public final boolean equals(Object obj) {
            if (!(obj instanceof zs6) || !(obj instanceof sr3)) {
                return false;
            }
            return this.a.equals(((sr3) obj).b());
        }

        public final int hashCode() {
            return this.a.hashCode();
        }
    }

    public static final void l(MobileAccountsFragment mobileAccountsFragment, String str, String str2, String str3, int i, qq3 qq3Var) {
        Object systemService = mobileAccountsFragment.requireContext().getSystemService("clipboard");
        cr4.e(systemService, "null cannot be cast to non-null type android.content.ClipboardManager");
        Locale locale = Locale.US;
        cr4.f(locale, "US");
        String upperCase = str3.toUpperCase(locale);
        cr4.f(upperCase, "toUpperCase(...)");
        ((ClipboardManager) systemService).setPrimaryClip(ClipData.newPlainText("Authorization Code", upperCase));
        Toast.makeText(mobileAccountsFragment.getContext(), "Copied code to clipboard", 0).show();
        try {
            mobileAccountsFragment.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(str2)));
        } catch (Exception unused) {
        }
        Context contextRequireContext = mobileAccountsFragment.requireContext();
        cr4.f(contextRequireContext, "requireContext(...)");
        MaterialAlertDialogBuilder title = new gv3(contextRequireContext, R.style.StrmrDialogTheme).setTitle((CharSequence) "Authorize ".concat(str));
        Locale locale2 = Locale.US;
        cr4.f(locale2, "US");
        String upperCase2 = str3.toUpperCase(locale2);
        cr4.f(upperCase2, "toUpperCase(...)");
        title.setMessage((CharSequence) ("Code copied! Paste it on the website.\n\nCode: " + upperCase2 + "\n\nExpires in " + (i / 60) + " minutes")).setNegativeButton((CharSequence) "Cancel", (DialogInterface.OnClickListener) null).setOnDismissListener((DialogInterface.OnDismissListener) new v3(mobileAccountsFragment, 5)).show();
        qq3Var.invoke();
    }

    public final void aa() {
        androidx.lifecycle.n nVarE = n41.e(this, "getViewLifecycleOwner(...)");
        m12 m12Var = sc2.a;
        wj0.c(nVarE, m02.c, null, new d(this, null), 2);
    }

    public final void ab() {
        String strE = q().e();
        if (strE == null) {
            return;
        }
        androidx.lifecycle.n nVarE = n41.e(this, "getViewLifecycleOwner(...)");
        m12 m12Var = sc2.a;
        wj0.c(nVarE, m02.c, null, new e(this, strE, null), 2);
    }

    public final void ac() {
        String strE = q().e();
        if (strE == null) {
            return;
        }
        androidx.lifecycle.n nVarE = n41.e(this, "getViewLifecycleOwner(...)");
        m12 m12Var = sc2.a;
        wj0.c(nVarE, m02.c, null, new f(this, strE, null), 2);
    }

    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    /* JADX WARN: Multi-variable type inference failed */
    public final void ad() {
        Object fy5Var;
        wl3 wl3Var = this.f;
        cr4.d(wl3Var);
        wl3Var.a.removeAllViews();
        n("STRMR Account");
        LayoutInflater layoutInflater = getLayoutInflater();
        wl3 wl3Var2 = this.f;
        cr4.d(wl3Var2);
        View viewInflate = layoutInflater.inflate(R.layout.item_mobile_strmr_account_card, (ViewGroup) wl3Var2.a, false);
        ImageView imageView = (ImageView) viewInflate.findViewById(R.id.status_icon);
        TextView textView = (TextView) viewInflate.findViewById(R.id.status_text);
        TextView textView2 = (TextView) viewInflate.findViewById(R.id.device_count_text);
        TextView textView3 = (TextView) viewInflate.findViewById(R.id.btn_action);
        TextView textView4 = (TextView) viewInflate.findViewById(R.id.btn_sync);
        TextView textView5 = (TextView) viewInflate.findViewById(R.id.btn_unlink);
        if (this.y) {
            imageView.setImageResource(R.drawable.ic_check_circle_24);
            imageView.setColorFilter(sf1.getColor(requireContext(), R.color.status_connected));
            textView.setText("Device Linked");
            textView.setTextColor(sf1.getColor(requireContext(), R.color.status_connected));
            textView2.setVisibility(0);
            textView2.setText(this.z + " of 5 devices");
            textView3.setText("Manage");
            textView3.setOnClickListener(new by5(this, 4));
            textView4.setVisibility(0);
            textView4.setOnClickListener(new by5(this, 1));
            textView5.setVisibility(0);
            textView5.setOnClickListener(new by5(this, 5));
        } else {
            imageView.setImageResource(R.drawable.ic_link_off);
            imageView.setColorFilter(sf1.getColor(requireContext(), R.color.mobile_on_surface_variant));
            textView.setText("Not Linked");
            textView.setTextColor(sf1.getColor(requireContext(), R.color.mobile_on_surface_variant));
            textView2.setVisibility(8);
            textView3.setText("Link Device");
            textView3.setOnClickListener(new by5(this, 6));
            textView4.setVisibility(8);
            textView5.setVisibility(8);
        }
        wl3 wl3Var3 = this.f;
        cr4.d(wl3Var3);
        wl3Var3.a.addView(viewInflate);
        n("Trakt Profiles");
        if (!this.x.isEmpty()) {
            for (final TraktAccount traktAccount : this.x) {
                LayoutInflater layoutInflater2 = getLayoutInflater();
                wl3 wl3Var4 = this.f;
                cr4.d(wl3Var4);
                View viewInflate2 = layoutInflater2.inflate(R.layout.item_trakt_profile_card, (ViewGroup) wl3Var4.a, false);
                FrameLayout frameLayout = (FrameLayout) viewInflate2.findViewById(R.id.avatar_container);
                ImageView imageView2 = (ImageView) viewInflate2.findViewById(R.id.avatar_image);
                Integer avatarResourceId = traktAccount.getAvatarResourceId();
                imageView2.setImageResource(avatarResourceId != null ? avatarResourceId.intValue() : cj7.b);
                final int i = 1;
                frameLayout.setOnClickListener(new View.OnClickListener(this) { // from class: zx5
                    public final /* synthetic */ MobileAccountsFragment b;

                    {
                        this.b = this;
                    }

                    @Override // android.view.View.OnClickListener
                    public final void onClick(View view) {
                        String userName;
                        String str;
                        switch (i) {
                            case 0:
                                MobileAccountsFragment mobileAccountsFragment = this.b;
                                wj0.c(n41.e(mobileAccountsFragment, "getViewLifecycleOwner(...)"), null, null, new rz5(mobileAccountsFragment, traktAccount, null), 3);
                                break;
                            case 1:
                                TraktAccount traktAccount2 = traktAccount;
                                Integer avatarResourceId2 = traktAccount2.getAvatarResourceId();
                                int iIntValue = avatarResourceId2 != null ? avatarResourceId2.intValue() : cj7.b;
                                MobileAccountsFragment mobileAccountsFragment2 = this.b;
                                q2 q2Var = new q2(mobileAccountsFragment2, traktAccount2, 3);
                                e50 e50Var = new e50();
                                Bundle bundle = new Bundle();
                                bundle.putInt("current_avatar", iIntValue);
                                e50Var.setArguments(bundle);
                                e50Var.b = q2Var;
                                e50Var.show(mobileAccountsFragment2.getChildFragmentManager(), "avatar_picker");
                                break;
                            default:
                                TraktAccount traktAccount3 = traktAccount;
                                String userSlug = traktAccount3.getUserSlug();
                                MobileAccountsFragment mobileAccountsFragment3 = this.b;
                                if (cr4.b(userSlug, mobileAccountsFragment3.ai) && mobileAccountsFragment3.x.size() > 1) {
                                    userName = traktAccount3.getUserName();
                                    if (userName == null) {
                                        userName = traktAccount3.getUserSlug();
                                    }
                                    str = "? Another profile will become active.";
                                } else if (mobileAccountsFragment3.x.size() == 1) {
                                    userName = traktAccount3.getUserName();
                                    if (userName == null) {
                                        userName = traktAccount3.getUserSlug();
                                    }
                                    str = "? This will disconnect Trakt from STRMR.";
                                } else {
                                    userName = traktAccount3.getUserName();
                                    if (userName == null) {
                                        userName = traktAccount3.getUserSlug();
                                    }
                                    str = "?";
                                }
                                String strAb = vw2.ab("Remove ", userName, str);
                                Context contextRequireContext = mobileAccountsFragment3.requireContext();
                                cr4.f(contextRequireContext, "requireContext(...)");
                                new gv3(contextRequireContext, R.style.StrmrDialogTheme).setTitle((CharSequence) "Remove Profile").setMessage((CharSequence) strAb).setPositiveButton((CharSequence) "Remove", (DialogInterface.OnClickListener) new x3(mobileAccountsFragment3, traktAccount3, 6)).setNegativeButton((CharSequence) "Cancel", (DialogInterface.OnClickListener) null).show();
                                break;
                        }
                    }
                });
                boolean zB = cr4.b(traktAccount.getUserSlug(), this.ai);
                ((ImageView) viewInflate2.findViewById(R.id.active_indicator)).setVisibility(zB ? 0 : 8);
                TextView textView6 = (TextView) viewInflate2.findViewById(R.id.profile_name);
                String userName = traktAccount.getUserName();
                if (userName == null) {
                    userName = traktAccount.getUserSlug();
                }
                textView6.setText(userName);
                TextView textView7 = (TextView) viewInflate2.findViewById(R.id.profile_status);
                if (zB) {
                    textView7.setText(this.af ? "Syncing..." : "Active");
                    textView7.setVisibility(0);
                } else {
                    textView7.setVisibility(8);
                }
                TextView textView8 = (TextView) viewInflate2.findViewById(R.id.profile_info);
                Integer statsMoviesWatched = traktAccount.getStatsMoviesWatched();
                int iIntValue = statsMoviesWatched != null ? statsMoviesWatched.intValue() : 0;
                Integer statsShowsWatched = traktAccount.getStatsShowsWatched();
                int iIntValue2 = statsShowsWatched != null ? statsShowsWatched.intValue() : 0;
                if (iIntValue > 0 || iIntValue2 > 0) {
                    String quantityString = getResources().getQuantityString(R.plurals.plural_movies_watched, iIntValue, Integer.valueOf(iIntValue));
                    cr4.f(quantityString, "getQuantityString(...)");
                    String quantityString2 = getResources().getQuantityString(R.plurals.plural_shows_watched, iIntValue2, Integer.valueOf(iIntValue2));
                    cr4.f(quantityString2, "getQuantityString(...)");
                    textView8.setText(quantityString + " · " + quantityString2);
                    textView8.setVisibility(0);
                } else {
                    textView8.setVisibility(8);
                }
                Button button = (Button) viewInflate2.findViewById(R.id.btn_sync);
                if (zB) {
                    button.setVisibility(0);
                    button.setOnClickListener(new by5(this, 2));
                }
                ((LinearLayout) viewInflate2.findViewById(R.id.connected_badge)).setVisibility(zB ? 0 : 8);
                Button button2 = (Button) viewInflate2.findViewById(R.id.btn_switch);
                if (zB) {
                    button2.setVisibility(8);
                } else {
                    button2.setVisibility(0);
                    final int i2 = 0;
                    button2.setOnClickListener(new View.OnClickListener(this) { // from class: zx5
                        public final /* synthetic */ MobileAccountsFragment b;

                        {
                            this.b = this;
                        }

                        @Override // android.view.View.OnClickListener
                        public final void onClick(View view) {
                            String userName2;
                            String str;
                            switch (i2) {
                                case 0:
                                    MobileAccountsFragment mobileAccountsFragment = this.b;
                                    wj0.c(n41.e(mobileAccountsFragment, "getViewLifecycleOwner(...)"), null, null, new rz5(mobileAccountsFragment, traktAccount, null), 3);
                                    break;
                                case 1:
                                    TraktAccount traktAccount2 = traktAccount;
                                    Integer avatarResourceId2 = traktAccount2.getAvatarResourceId();
                                    int iIntValue3 = avatarResourceId2 != null ? avatarResourceId2.intValue() : cj7.b;
                                    MobileAccountsFragment mobileAccountsFragment2 = this.b;
                                    q2 q2Var = new q2(mobileAccountsFragment2, traktAccount2, 3);
                                    e50 e50Var = new e50();
                                    Bundle bundle = new Bundle();
                                    bundle.putInt("current_avatar", iIntValue3);
                                    e50Var.setArguments(bundle);
                                    e50Var.b = q2Var;
                                    e50Var.show(mobileAccountsFragment2.getChildFragmentManager(), "avatar_picker");
                                    break;
                                default:
                                    TraktAccount traktAccount3 = traktAccount;
                                    String userSlug = traktAccount3.getUserSlug();
                                    MobileAccountsFragment mobileAccountsFragment3 = this.b;
                                    if (cr4.b(userSlug, mobileAccountsFragment3.ai) && mobileAccountsFragment3.x.size() > 1) {
                                        userName2 = traktAccount3.getUserName();
                                        if (userName2 == null) {
                                            userName2 = traktAccount3.getUserSlug();
                                        }
                                        str = "? Another profile will become active.";
                                    } else if (mobileAccountsFragment3.x.size() == 1) {
                                        userName2 = traktAccount3.getUserName();
                                        if (userName2 == null) {
                                            userName2 = traktAccount3.getUserSlug();
                                        }
                                        str = "? This will disconnect Trakt from STRMR.";
                                    } else {
                                        userName2 = traktAccount3.getUserName();
                                        if (userName2 == null) {
                                            userName2 = traktAccount3.getUserSlug();
                                        }
                                        str = "?";
                                    }
                                    String strAb = vw2.ab("Remove ", userName2, str);
                                    Context contextRequireContext = mobileAccountsFragment3.requireContext();
                                    cr4.f(contextRequireContext, "requireContext(...)");
                                    new gv3(contextRequireContext, R.style.StrmrDialogTheme).setTitle((CharSequence) "Remove Profile").setMessage((CharSequence) strAb).setPositiveButton((CharSequence) "Remove", (DialogInterface.OnClickListener) new x3(mobileAccountsFragment3, traktAccount3, 6)).setNegativeButton((CharSequence) "Cancel", (DialogInterface.OnClickListener) null).show();
                                    break;
                            }
                        }
                    });
                }
                final int i3 = 2;
                ((Button) viewInflate2.findViewById(R.id.btn_logout)).setOnClickListener(new View.OnClickListener(this) { // from class: zx5
                    public final /* synthetic */ MobileAccountsFragment b;

                    {
                        this.b = this;
                    }

                    @Override // android.view.View.OnClickListener
                    public final void onClick(View view) {
                        String userName2;
                        String str;
                        switch (i3) {
                            case 0:
                                MobileAccountsFragment mobileAccountsFragment = this.b;
                                wj0.c(n41.e(mobileAccountsFragment, "getViewLifecycleOwner(...)"), null, null, new rz5(mobileAccountsFragment, traktAccount, null), 3);
                                break;
                            case 1:
                                TraktAccount traktAccount2 = traktAccount;
                                Integer avatarResourceId2 = traktAccount2.getAvatarResourceId();
                                int iIntValue3 = avatarResourceId2 != null ? avatarResourceId2.intValue() : cj7.b;
                                MobileAccountsFragment mobileAccountsFragment2 = this.b;
                                q2 q2Var = new q2(mobileAccountsFragment2, traktAccount2, 3);
                                e50 e50Var = new e50();
                                Bundle bundle = new Bundle();
                                bundle.putInt("current_avatar", iIntValue3);
                                e50Var.setArguments(bundle);
                                e50Var.b = q2Var;
                                e50Var.show(mobileAccountsFragment2.getChildFragmentManager(), "avatar_picker");
                                break;
                            default:
                                TraktAccount traktAccount3 = traktAccount;
                                String userSlug = traktAccount3.getUserSlug();
                                MobileAccountsFragment mobileAccountsFragment3 = this.b;
                                if (cr4.b(userSlug, mobileAccountsFragment3.ai) && mobileAccountsFragment3.x.size() > 1) {
                                    userName2 = traktAccount3.getUserName();
                                    if (userName2 == null) {
                                        userName2 = traktAccount3.getUserSlug();
                                    }
                                    str = "? Another profile will become active.";
                                } else if (mobileAccountsFragment3.x.size() == 1) {
                                    userName2 = traktAccount3.getUserName();
                                    if (userName2 == null) {
                                        userName2 = traktAccount3.getUserSlug();
                                    }
                                    str = "? This will disconnect Trakt from STRMR.";
                                } else {
                                    userName2 = traktAccount3.getUserName();
                                    if (userName2 == null) {
                                        userName2 = traktAccount3.getUserSlug();
                                    }
                                    str = "?";
                                }
                                String strAb = vw2.ab("Remove ", userName2, str);
                                Context contextRequireContext = mobileAccountsFragment3.requireContext();
                                cr4.f(contextRequireContext, "requireContext(...)");
                                new gv3(contextRequireContext, R.style.StrmrDialogTheme).setTitle((CharSequence) "Remove Profile").setMessage((CharSequence) strAb).setPositiveButton((CharSequence) "Remove", (DialogInterface.OnClickListener) new x3(mobileAccountsFragment3, traktAccount3, 6)).setNegativeButton((CharSequence) "Cancel", (DialogInterface.OnClickListener) null).show();
                                break;
                        }
                    }
                });
                wl3 wl3Var5 = this.f;
                cr4.d(wl3Var5);
                wl3Var5.a.addView(viewInflate2);
            }
        }
        if (this.ah) {
            LayoutInflater layoutInflater3 = getLayoutInflater();
            wl3 wl3Var6 = this.f;
            cr4.d(wl3Var6);
            View viewInflate3 = layoutInflater3.inflate(R.layout.item_add_trakt_profile_card, (ViewGroup) wl3Var6.a, false);
            viewInflate3.setOnClickListener(new by5(this, 0));
            wl3 wl3Var7 = this.f;
            cr4.d(wl3Var7);
            wl3Var7.a.addView(viewInflate3);
        }
        n("Debrid Services");
        String string = getString(R.string.note_debrid_section_hint);
        cr4.f(string, "getString(...)");
        TextView textView9 = new TextView(requireContext());
        textView9.setText(string);
        textView9.setTextColor(sf1.getColor(textView9.getContext(), R.color.mobile_on_surface_variant));
        textView9.setTextSize(12.0f);
        textView9.setPadding(textView9.getResources().getDimensionPixelSize(R.dimen.spacing_md_mobile), 0, textView9.getResources().getDimensionPixelSize(R.dimen.spacing_md_mobile), textView9.getResources().getDimensionPixelSize(R.dimen.spacing_sm_mobile));
        wl3 wl3Var8 = this.f;
        cr4.d(wl3Var8);
        wl3Var8.a.addView(textView9);
        List<String> debridPriorityOrder = t().getDebridPriorityOrder();
        ArrayList arrayList = new ArrayList();
        Iterator<T> it = debridPriorityOrder.iterator();
        while (true) {
            if (!it.hasNext()) {
                ArrayList arrayListBp = y41.bp(arrayList);
                RecyclerView recyclerView = new RecyclerView(requireContext(), null);
                recyclerView.setLayoutParams(new LinearLayout.LayoutParams(-1, -2));
                requireContext();
                recyclerView.setLayoutManager(new LinearLayoutManager());
                recyclerView.setNestedScrollingEnabled(false);
                iy5 iy5Var = new iy5(arrayListBp, this);
                recyclerView.setAdapter(iy5Var);
                androidx.recyclerview.widget.x xVar = new androidx.recyclerview.widget.x(new ky5(iy5Var, this));
                xVar.f(recyclerView);
                iy5Var.a = new co(xVar, 23);
                wl3 wl3Var9 = this.f;
                cr4.d(wl3Var9);
                wl3Var9.a.addView(recyclerView);
                n("Rating Posters");
                boolean zIsEnabled = w().isEnabled();
                m("RPDB", "Rating badges on posters (IMDb, RT, MC)", "R", -14326805, zIsEnabled, zIsEnabled ? "Connected" : null, zIsEnabled ? w().getPosterTypeLabel() : null, new dy5(this, 9));
                boolean zIsEnabled2 = s().isEnabled();
                String string2 = getString(R.string.omdb_name);
                cr4.f(string2, "getString(...)");
                String string3 = getString(R.string.omdb_desc);
                cr4.f(string3, "getString(...)");
                m(string2, string3, "O", -680437, zIsEnabled2, zIsEnabled2 ? "Connected" : null, null, new dy5(this, 12));
                return;
            }
            String str = (String) it.next();
            switch (str.hashCode()) {
                case -1517726582:
                    if (str.equals("realdebrid")) {
                        RealDebridAccount realDebridAccount = this.ab;
                        boolean z = realDebridAccount != null;
                        String username = realDebridAccount != null ? realDebridAccount.getUsername() : null;
                        RealDebridAccount realDebridAccount2 = this.ab;
                        fy5Var = new fy5(str, "Real-Debrid", "RD", R.color.brand_realdebrid, z, username, realDebridAccount2 != null ? v().getDaysRemaining(realDebridAccount2) : null, new dy5(this, 1));
                        obj = fy5Var;
                    }
                    break;
                case -867981036:
                    if (str.equals("torbox")) {
                        TorBoxAccount torBoxAccount = this.ad;
                        boolean z2 = torBoxAccount != null;
                        String planName = torBoxAccount != null ? torBoxAccount.getPlanName() : null;
                        TorBoxAccount torBoxAccount2 = this.ad;
                        fy5Var = new fy5(str, "TorBox", "TB", R.color.brand_torbox, z2, planName, torBoxAccount2 != null ? torBoxAccount2.getDaysRemaining() : null, new dy5(this, 3));
                        obj = fy5Var;
                    }
                    break;
                case -364706834:
                    if (str.equals(PreferencesRepository.DEBRID_EASYDEBRID)) {
                        EasyDebridAccount easyDebridAccount = this.ae;
                        fy5Var = new fy5(str, "Paradise Cloud", "ED", R.color.brand_easydebrid, easyDebridAccount != null, easyDebridAccount != null ? "Connected" : null, easyDebridAccount != null ? easyDebridAccount.getDaysRemaining() : null, new dy5(this, 4));
                        obj = fy5Var;
                    }
                    break;
                case 40904269:
                    if (str.equals("alldebrid")) {
                        AllDebridAccount allDebridAccount = this.ac;
                        boolean z3 = allDebridAccount != null;
                        String username2 = allDebridAccount != null ? allDebridAccount.getUsername() : null;
                        AllDebridAccount allDebridAccount2 = this.ac;
                        fy5Var = new fy5(str, "AllDebrid", "AD", R.color.brand_alldebrid, z3, username2, allDebridAccount2 != null ? p().getDaysRemaining(allDebridAccount2) : null, new dy5(this, 2));
                        obj = fy5Var;
                    }
                    break;
                case 575248285:
                    if (str.equals("premiumize")) {
                        PremiumizeAccount premiumizeAccount = this.aa;
                        boolean z4 = premiumizeAccount != null;
                        String accountStatus = premiumizeAccount != null ? premiumizeAccount.getAccountStatus() : null;
                        PremiumizeAccount premiumizeAccount2 = this.aa;
                        fy5Var = new fy5(str, "Premiumize", "P", R.color.brand_premiumize, z4, accountStatus, premiumizeAccount2 != null ? u().getDaysRemaining(premiumizeAccount2) : null, new dy5(this, 0));
                        obj = fy5Var;
                    }
                    break;
            }
            if (obj != null) {
                arrayList.add(obj);
            }
        }
    }

    public final void ae(String str, qq3 qq3Var, qq3 qq3Var2) {
        Context contextRequireContext = requireContext();
        cr4.f(contextRequireContext, "requireContext(...)");
        gv3 gv3Var = new gv3(contextRequireContext, R.style.StrmrDialogTheme);
        gv3Var.d = getString(R.string.note_api_key_for_bundles);
        gv3Var.b(new CharSequence[]{"Authorize with Code", "Enter API Key"}, new z3(qq3Var, qq3Var2, 1));
        gv3Var.setTitle((CharSequence) "Connect ".concat(str)).setNegativeButton((CharSequence) "Cancel", (DialogInterface.OnClickListener) null).show();
    }

    public final void m(String str, String str2, String str3, int i, boolean z, String str4, String str5, qq3 qq3Var) {
        LayoutInflater layoutInflater = getLayoutInflater();
        wl3 wl3Var = this.f;
        cr4.d(wl3Var);
        View viewInflate = layoutInflater.inflate(R.layout.item_mobile_account_card, (ViewGroup) wl3Var.a, false);
        cr4.e(viewInflate, "null cannot be cast to non-null type com.google.android.material.card.MaterialCardView");
        MaterialCardView materialCardView = (MaterialCardView) viewInflate;
        TextView textView = (TextView) materialCardView.findViewById(R.id.account_icon);
        textView.setText(str3);
        Drawable background = textView.getBackground();
        GradientDrawable gradientDrawable = background instanceof GradientDrawable ? (GradientDrawable) background : null;
        if (gradientDrawable != null) {
            gradientDrawable.setColor(i);
        } else {
            GradientDrawable gradientDrawable2 = new GradientDrawable();
            gradientDrawable2.setShape(1);
            gradientDrawable2.setColor(i);
            textView.setBackground(gradientDrawable2);
        }
        ((TextView) materialCardView.findViewById(R.id.account_name)).setText(str);
        TextView textView2 = (TextView) materialCardView.findViewById(R.id.account_status);
        if (z) {
            str2 = str4 == null ? "Connected" : str4;
        }
        textView2.setText(str2);
        TextView textView3 = (TextView) materialCardView.findViewById(R.id.connect_text);
        LinearLayout linearLayout = (LinearLayout) materialCardView.findViewById(R.id.connected_indicator);
        if (z) {
            textView3.setVisibility(8);
            linearLayout.setVisibility(0);
            Drawable background2 = materialCardView.findViewById(R.id.status_dot).getBackground();
            GradientDrawable gradientDrawable3 = background2 instanceof GradientDrawable ? (GradientDrawable) background2 : null;
            if (gradientDrawable3 != null) {
                gradientDrawable3.setColor(sf1.getColor(requireContext(), R.color.success_color));
            }
            materialCardView.setStrokeWidth(getResources().getDimensionPixelSize(R.dimen.stroke_width_thin));
            TypedValue typedValue = new TypedValue();
            requireContext().getTheme().resolveAttribute(R.attr.colorAccentBorder, typedValue, true);
            materialCardView.setStrokeColor(typedValue.data);
        } else {
            textView3.setVisibility(0);
            linearLayout.setVisibility(8);
            materialCardView.setStrokeWidth(getResources().getDimensionPixelSize(R.dimen.stroke_width_thin));
            materialCardView.setStrokeColor(sf1.getColor(requireContext(), R.color.mobile_card_stroke));
        }
        TextView textView4 = (TextView) materialCardView.findViewById(R.id.account_info);
        if (str5 == null || !z) {
            textView4.setVisibility(8);
        } else {
            textView4.setText(str5);
            textView4.setVisibility(0);
        }
        materialCardView.setOnClickListener(new cy5(0, qq3Var));
        wl3 wl3Var2 = this.f;
        cr4.d(wl3Var2);
        wl3Var2.a.addView(viewInflate);
    }

    public final void n(String str) {
        TextView textView = new TextView(requireContext());
        textView.setText(str);
        textView.setTextColor(sf1.getColor(textView.getContext(), R.color.mobile_section_header));
        textView.setTextSize(12.0f);
        textView.setLetterSpacing(0.1f);
        textView.setAllCaps(true);
        textView.setPadding(textView.getResources().getDimensionPixelSize(R.dimen.spacing_md_mobile), textView.getResources().getDimensionPixelSize(R.dimen.spacing_md_mobile), textView.getResources().getDimensionPixelSize(R.dimen.spacing_md_mobile), textView.getResources().getDimensionPixelSize(R.dimen.spacing_sm_mobile));
        wl3 wl3Var = this.f;
        cr4.d(wl3Var);
        wl3Var.a.addView(textView);
    }

    public final void o(qq3 qq3Var, sq3 sq3Var, String str) {
        wj0.c(n41.e(this, "getViewLifecycleOwner(...)"), null, null, new b(qq3Var, this, str, sq3Var, null), 3);
    }

    @Override // androidx.fragment.app.o
    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        cr4.g(layoutInflater, "inflater");
        View viewInflate = layoutInflater.inflate(R.layout.fragment_mobile_accounts, viewGroup, false);
        int i = R.id.accounts_container;
        LinearLayout linearLayout = (LinearLayout) mia.a(R.id.accounts_container, viewInflate);
        if (linearLayout != null) {
            i = R.id.progress_bar;
            ProgressBar progressBar = (ProgressBar) mia.a(R.id.progress_bar, viewInflate);
            if (progressBar != null) {
                i = R.id.toolbar;
                MaterialToolbar materialToolbar = (MaterialToolbar) mia.a(R.id.toolbar, viewInflate);
                if (materialToolbar != null) {
                    CoordinatorLayout coordinatorLayout = (CoordinatorLayout) viewInflate;
                    this.f = new wl3(coordinatorLayout, linearLayout, progressBar, materialToolbar);
                    cr4.f(coordinatorLayout, "getRoot(...)");
                    return coordinatorLayout;
                }
            }
        }
        throw new NullPointerException("Missing required view with ID: ".concat(viewInflate.getResources().getResourceName(i)));
    }

    @Override // androidx.fragment.app.o
    public final void onDestroyView() {
        super.onDestroyView();
        fx4 fx4Var = this.ag;
        if (fx4Var != null) {
            ((rx4) fx4Var).h(null);
        }
        this.f = null;
    }

    @Override // androidx.fragment.app.o
    public final void onViewCreated(View view, Bundle bundle) {
        cr4.g(view, "view");
        super.onViewCreated(view, bundle);
        wl3 wl3Var = this.f;
        cr4.d(wl3Var);
        wl3Var.c.setNavigationOnClickListener(new by5(this, 3));
        aa();
        Context contextRequireContext = requireContext();
        cr4.f(contextRequireContext, "requireContext(...)");
        osa osaVarD = osa.d(contextRequireContext);
        bd5.a(osaVarD.c.f().t("trakt_sync_worker"), lta.y, osaVarD.d).f(getViewLifecycleOwner(), new a(new co(this, 24)));
    }

    public final AllDebridRepository p() {
        AllDebridRepository allDebridRepository = this.o;
        if (allDebridRepository != null) {
            return allDebridRepository;
        }
        cr4.n("allDebridRepository");
        throw null;
    }

    public final DeviceManager q() {
        DeviceManager deviceManager = this.u;
        if (deviceManager != null) {
            return deviceManager;
        }
        cr4.n("deviceManager");
        throw null;
    }

    public final FeatureGateManager r() {
        FeatureGateManager featureGateManager = this.v;
        if (featureGateManager != null) {
            return featureGateManager;
        }
        cr4.n("featureGateManager");
        throw null;
    }

    public final OmdbRepository s() {
        OmdbRepository omdbRepository = this.s;
        if (omdbRepository != null) {
            return omdbRepository;
        }
        cr4.n("omdbRepository");
        throw null;
    }

    public final PreferencesRepository t() {
        PreferencesRepository preferencesRepository = this.t;
        if (preferencesRepository != null) {
            return preferencesRepository;
        }
        cr4.n("preferencesRepository");
        throw null;
    }

    public final PremiumizeRepository u() {
        PremiumizeRepository premiumizeRepository = this.m;
        if (premiumizeRepository != null) {
            return premiumizeRepository;
        }
        cr4.n("premiumizeRepository");
        throw null;
    }

    public final RealDebridRepository v() {
        RealDebridRepository realDebridRepository = this.n;
        if (realDebridRepository != null) {
            return realDebridRepository;
        }
        cr4.n("realDebridRepository");
        throw null;
    }

    public final RpdbRepository w() {
        RpdbRepository rpdbRepository = this.r;
        if (rpdbRepository != null) {
            return rpdbRepository;
        }
        cr4.n("rpdbRepository");
        throw null;
    }

    public final SettingsSyncManager x() {
        SettingsSyncManager settingsSyncManager = this.w;
        if (settingsSyncManager != null) {
            return settingsSyncManager;
        }
        cr4.n("settingsSyncManager");
        throw null;
    }

    public final TorBoxRepository y() {
        TorBoxRepository torBoxRepository = this.p;
        if (torBoxRepository != null) {
            return torBoxRepository;
        }
        cr4.n("torBoxRepository");
        throw null;
    }

    public final TraktAccountRepository z() {
        TraktAccountRepository traktAccountRepository = this.j;
        if (traktAccountRepository != null) {
            return traktAccountRepository;
        }
        cr4.n("traktAccountRepository");
        throw null;
    }
}
