package o;

import android.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AlertController$RecycleListView;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import java.io.Serializable;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.g2, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C1254g2 implements S0 {
    public final /* synthetic */ int l;
    public int m;
    public Object n;

    public /* synthetic */ C1254g2(int i, int i2, Object obj) {
        this.l = i2;
        this.n = obj;
        this.m = i;
    }

    @Override // o.S0
    public boolean a(View view) {
        ((BottomSheetBehavior) this.n).B(this.m);
        return true;
    }

    public void b(long j) {
        if (d(j)) {
            return;
        }
        int i = this.m;
        long[] jArrCopyOf = (long[]) this.n;
        if (i >= jArrCopyOf.length) {
            jArrCopyOf = Arrays.copyOf(jArrCopyOf, Math.max(i + 1, jArrCopyOf.length * 2));
            this.n = jArrCopyOf;
        }
        jArrCopyOf[i] = j;
        if (i >= this.m) {
            this.m = i + 1;
        }
    }

    public void c() {
        WeakReference weakReference;
        this.m = 0;
        Iterator it = ((LinkedHashMap) this.n).values().iterator();
        while (it.hasNext()) {
            ArrayList arrayList = (ArrayList) it.next();
            if (arrayList.size() <= 1) {
                H00 h00 = (H00) AbstractC3117zi.f0(arrayList);
                if (((h00 == null || (weakReference = h00.b) == null) ? null : (Bitmap) weakReference.get()) == null) {
                    it.remove();
                }
            } else {
                int size = arrayList.size();
                int i = 0;
                for (int i2 = 0; i2 < size; i2++) {
                    int i3 = i2 - i;
                    if (((H00) arrayList.get(i3)).b.get() == null) {
                        arrayList.remove(i3);
                        i++;
                    }
                }
                if (arrayList.isEmpty()) {
                    it.remove();
                }
            }
        }
    }

    public boolean d(long j) {
        int i = this.m;
        for (int i2 = 0; i2 < i; i2++) {
            if (((long[]) this.n)[i2] == j) {
                return true;
            }
        }
        return false;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r7v1, types: [android.widget.ListAdapter] */
    /* JADX WARN: Type inference failed for: r7v3 */
    /* JADX WARN: Type inference failed for: r7v4 */
    public DialogInterfaceC1350h2 e() {
        C0871c2 c0871c2 = (C0871c2) this.n;
        DialogInterfaceC1350h2 dialogInterfaceC1350h2 = new DialogInterfaceC1350h2(c0871c2.a, this.m);
        View view = c0871c2.e;
        C1158f2 c1158f2 = dialogInterfaceC1350h2.r;
        if (view != null) {
            c1158f2.u = view;
        } else {
            CharSequence charSequence = c0871c2.d;
            if (charSequence != null) {
                c1158f2.d = charSequence;
                TextView textView = c1158f2.s;
                if (textView != null) {
                    textView.setText(charSequence);
                }
            }
            Drawable drawable = c0871c2.c;
            if (drawable != null) {
                c1158f2.q = drawable;
                ImageView imageView = c1158f2.r;
                if (imageView != null) {
                    imageView.setVisibility(0);
                    c1158f2.r.setImageDrawable(drawable);
                }
            }
        }
        String str = c0871c2.f;
        if (str != null) {
            c1158f2.e = str;
            TextView textView2 = c1158f2.t;
            if (textView2 != null) {
                textView2.setText(str);
            }
        }
        String str2 = c0871c2.g;
        if (str2 != null) {
            c1158f2.b(-1, str2, c0871c2.h);
        }
        String str3 = c0871c2.i;
        if (str3 != null) {
            c1158f2.b(-2, str3, c0871c2.j);
        }
        if (c0871c2.m != null) {
            AlertController$RecycleListView alertController$RecycleListView = (AlertController$RecycleListView) c0871c2.b.inflate(c1158f2.y, (ViewGroup) null);
            int i = c0871c2.f468o ? c1158f2.z : c1158f2.A;
            Object obj = c0871c2.m;
            ?? c1062e2 = obj;
            if (obj == null) {
                c1062e2 = new C1062e2(c0871c2.a, i, R.id.text1, null);
            }
            c1158f2.v = c1062e2;
            c1158f2.w = c0871c2.p;
            if (c0871c2.n != null) {
                alertController$RecycleListView.setOnItemClickListener(new C0776b2(c0871c2, c1158f2));
            }
            if (c0871c2.f468o) {
                alertController$RecycleListView.setChoiceMode(1);
            }
            c1158f2.f = alertController$RecycleListView;
        }
        dialogInterfaceC1350h2.setCancelable(c0871c2.k);
        if (c0871c2.k) {
            dialogInterfaceC1350h2.setCanceledOnTouchOutside(true);
        }
        dialogInterfaceC1350h2.setOnCancelListener(null);
        dialogInterfaceC1350h2.setOnDismissListener(null);
        EO eo = c0871c2.l;
        if (eo != null) {
            dialogInterfaceC1350h2.setOnKeyListener(eo);
        }
        return dialogInterfaceC1350h2;
    }

    public void f(int i, int i2) {
        int i3 = i2 + i;
        char[] cArr = (char[]) this.n;
        if (cArr.length <= i3) {
            int i4 = i * 2;
            if (i3 < i4) {
                i3 = i4;
            }
            this.n = Arrays.copyOf(cArr, i3);
        }
    }

    public void g() {
        C1976nh c1976nh = C1976nh.n;
        char[] cArr = (char[]) this.n;
        synchronized (c1976nh) {
            int i = c1976nh.l;
            if (cArr.length + i < AbstractC1934n9.a) {
                c1976nh.l = i + cArr.length;
                ((C1172f9) c1976nh.m).addLast(cArr);
            }
        }
    }

    public void h(long j) {
        int i = this.m;
        int i2 = 0;
        while (i2 < i) {
            if (j == ((long[]) this.n)[i2]) {
                int i3 = this.m - 1;
                while (i2 < i3) {
                    long[] jArr = (long[]) this.n;
                    int i4 = i2 + 1;
                    jArr[i2] = jArr[i4];
                    i2 = i4;
                }
                this.m--;
                return;
            }
            i2++;
        }
    }

    public synchronized void i(C2899xO c2899xO, Bitmap bitmap, Map map, int i) {
        try {
            LinkedHashMap linkedHashMap = (LinkedHashMap) this.n;
            Object arrayList = linkedHashMap.get(c2899xO);
            if (arrayList == null) {
                arrayList = new ArrayList();
                linkedHashMap.put(c2899xO, arrayList);
            }
            ArrayList arrayList2 = (ArrayList) arrayList;
            int iIdentityHashCode = System.identityHashCode(bitmap);
            H00 h00 = new H00(iIdentityHashCode, new WeakReference(bitmap), map, i);
            int size = arrayList2.size();
            int i2 = 0;
            while (true) {
                if (i2 >= size) {
                    arrayList2.add(h00);
                    break;
                }
                H00 h002 = (H00) arrayList2.get(i2);
                if (i < h002.d) {
                    i2++;
                } else if (h002.a == iIdentityHashCode && h002.b.get() == bitmap) {
                    arrayList2.set(i2, h00);
                } else {
                    arrayList2.add(i2, h00);
                }
            }
            int i3 = this.m;
            this.m = i3 + 1;
            if (i3 >= 10) {
                c();
            }
        } catch (Throwable th) {
            throw th;
        }
    }

    public void j(String str) {
        int length = str.length();
        if (length == 0) {
            return;
        }
        f(this.m, length);
        str.getChars(0, str.length(), (char[]) this.n, this.m);
        this.m += length;
    }

    public String toString() {
        switch (this.l) {
            case 4:
                return new String((char[]) this.n, 0, this.m);
            default:
                return super.toString();
        }
    }

    public /* synthetic */ C1254g2(int i, Serializable serializable, int i2) {
        this.l = i2;
        this.m = i;
        this.n = serializable;
    }

    public C1254g2(Context context) {
        this.l = 0;
        int iE = DialogInterfaceC1350h2.e(context, 0);
        this.n = new C0871c2(new ContextThemeWrapper(context, DialogInterfaceC1350h2.e(context, iE)));
        this.m = iE;
    }

    public C1254g2(int i) {
        this.l = i;
        switch (i) {
            case 7:
                this.n = new LinkedHashMap();
                break;
            default:
                this.m = 1;
                this.n = Collections.singletonList(null);
                break;
        }
    }

    public C1254g2(ArrayList arrayList) {
        this.l = 2;
        this.m = 0;
        this.n = arrayList;
    }
}
