package T;

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 m.I0;
import p0.AbstractC0928a;

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

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

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

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

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

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public a f2844o;
    public b p;
    public d q;

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

    public void b(Cursor cursor) {
        Cursor cursor2 = this.f2842m;
        if (cursor == cursor2) {
            cursor2 = null;
        } else {
            if (cursor2 != null) {
                a aVar = this.f2844o;
                if (aVar != null) {
                    cursor2.unregisterContentObserver(aVar);
                }
                b bVar = this.p;
                if (bVar != null) {
                    cursor2.unregisterDataSetObserver(bVar);
                }
            }
            this.f2842m = cursor;
            if (cursor != null) {
                a aVar2 = this.f2844o;
                if (aVar2 != null) {
                    cursor.registerContentObserver(aVar2);
                }
                b bVar2 = this.p;
                if (bVar2 != null) {
                    cursor.registerDataSetObserver(bVar2);
                }
                this.f2843n = cursor.getColumnIndexOrThrow("_id");
                this.f2840k = true;
                notifyDataSetChanged();
            } else {
                this.f2843n = -1;
                this.f2840k = 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.f2840k || (cursor = this.f2842m) == null) {
            return 0;
        }
        return cursor.getCount();
    }

    @Override // android.widget.BaseAdapter, android.widget.SpinnerAdapter
    public View getDropDownView(int i, View view, ViewGroup viewGroup) {
        if (!this.f2840k) {
            return null;
        }
        this.f2842m.moveToPosition(i);
        if (view == null) {
            I0 i02 = (I0) this;
            view = i02.f9040t.inflate(i02.f9039s, viewGroup, false);
        }
        a(view, this.f2842m);
        return view;
    }

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

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

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

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