package Q;

import android.database.Cursor;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import d5.AbstractC0844a;
import n.F0;

/* JADX INFO: loaded from: classes.dex */
public abstract class c extends BaseAdapter implements Filterable {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public boolean f5541q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public boolean f5542r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public Cursor f5543s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public int f5544t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public a f5545u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public b f5546v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public d f5547w;

    public abstract void a(View view, Cursor cursor);

    public void b(Cursor cursor) {
        Cursor cursor2 = this.f5543s;
        if (cursor == cursor2) {
            cursor2 = null;
        } else {
            if (cursor2 != null) {
                a aVar = this.f5545u;
                if (aVar != null) {
                    cursor2.unregisterContentObserver(aVar);
                }
                b bVar = this.f5546v;
                if (bVar != null) {
                    cursor2.unregisterDataSetObserver(bVar);
                }
            }
            this.f5543s = cursor;
            if (cursor != null) {
                a aVar2 = this.f5545u;
                if (aVar2 != null) {
                    cursor.registerContentObserver(aVar2);
                }
                b bVar2 = this.f5546v;
                if (bVar2 != null) {
                    cursor.registerDataSetObserver(bVar2);
                }
                this.f5544t = cursor.getColumnIndexOrThrow("_id");
                this.f5541q = true;
                notifyDataSetChanged();
            } else {
                this.f5544t = -1;
                this.f5541q = false;
                notifyDataSetInvalidated();
            }
        }
        if (cursor2 != null) {
            cursor2.close();
        }
    }

    public abstract String c(Cursor cursor);

    public abstract View d(ViewGroup viewGroup);

    @Override // android.widget.Adapter
    public final int getCount() {
        Cursor cursor;
        if (!this.f5541q || (cursor = this.f5543s) == null) {
            return 0;
        }
        return cursor.getCount();
    }

    @Override // android.widget.BaseAdapter, android.widget.SpinnerAdapter
    public View getDropDownView(int i, View view, ViewGroup viewGroup) {
        if (!this.f5541q) {
            return null;
        }
        this.f5543s.moveToPosition(i);
        if (view == null) {
            F0 f02 = (F0) this;
            view = f02.f14722z.inflate(f02.f14721y, viewGroup, false);
        }
        a(view, this.f5543s);
        return view;
    }

    @Override // android.widget.Filterable
    public final Filter getFilter() {
        if (this.f5547w == null) {
            d dVar = new d();
            dVar.f5548a = this;
            this.f5547w = dVar;
        }
        return this.f5547w;
    }

    @Override // android.widget.Adapter
    public final Object getItem(int i) {
        Cursor cursor;
        if (!this.f5541q || (cursor = this.f5543s) == null) {
            return null;
        }
        cursor.moveToPosition(i);
        return this.f5543s;
    }

    @Override // android.widget.Adapter
    public final long getItemId(int i) {
        Cursor cursor;
        if (this.f5541q && (cursor = this.f5543s) != null && cursor.moveToPosition(i)) {
            return this.f5543s.getLong(this.f5544t);
        }
        return 0L;
    }

    @Override // android.widget.Adapter
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (!this.f5541q) {
            throw new IllegalStateException("this should only be called when the cursor is valid");
        }
        if (!this.f5543s.moveToPosition(i)) {
            throw new IllegalStateException(AbstractC0844a.j("couldn't move cursor to position ", i));
        }
        if (view == null) {
            view = d(viewGroup);
        }
        a(view, this.f5543s);
        return view;
    }
}
