package v0;

import android.content.Context;
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 com.google.android.gms.measurement.internal.u1;
import l.e2;
import l.i3;

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public e2 f33645g;

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

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

    public void b(Cursor cursor) {
        Cursor cursor2 = this.f33641c;
        if (cursor == cursor2) {
            cursor2 = null;
        } else {
            if (cursor2 != null) {
                a aVar = this.f33644f;
                if (aVar != null) {
                    cursor2.unregisterContentObserver(aVar);
                }
                e2 e2Var = this.f33645g;
                if (e2Var != null) {
                    cursor2.unregisterDataSetObserver(e2Var);
                }
            }
            this.f33641c = cursor;
            if (cursor != null) {
                a aVar2 = this.f33644f;
                if (aVar2 != null) {
                    cursor.registerContentObserver(aVar2);
                }
                e2 e2Var2 = this.f33645g;
                if (e2Var2 != null) {
                    cursor.registerDataSetObserver(e2Var2);
                }
                this.f33643e = cursor.getColumnIndexOrThrow("_id");
                this.f33639a = true;
                notifyDataSetChanged();
            } else {
                this.f33643e = -1;
                this.f33639a = 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.f33639a || (cursor = this.f33641c) == null) {
            return 0;
        }
        return cursor.getCount();
    }

    @Override // android.widget.BaseAdapter, android.widget.SpinnerAdapter
    public View getDropDownView(int i10, View view, ViewGroup viewGroup) {
        if (!this.f33639a) {
            return null;
        }
        this.f33641c.moveToPosition(i10);
        if (view == null) {
            i3 i3Var = (i3) this;
            view = i3Var.f29728k.inflate(i3Var.f29727j, viewGroup, false);
        }
        a(view, this.f33641c);
        return view;
    }

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

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

    @Override // android.widget.Adapter
    public final long getItemId(int i10) {
        Cursor cursor;
        if (this.f33639a && (cursor = this.f33641c) != null && cursor.moveToPosition(i10)) {
            return this.f33641c.getLong(this.f33643e);
        }
        return 0L;
    }

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