package b0; import android.content.Context; import android.database.ContentObserver; import android.database.Cursor; import android.database.DataSetObserver; import android.os.Handler; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Filter; import android.widget.Filterable; import b0.b; /* loaded from: classes.dex */ public abstract class a extends BaseAdapter implements Filterable, b.a { /* renamed from: a, reason: collision with root package name */ protected boolean f3055a; /* renamed from: b, reason: collision with root package name */ protected boolean f3056b; /* renamed from: c, reason: collision with root package name */ protected Cursor f3057c; /* renamed from: d, reason: collision with root package name */ protected Context f3058d; /* renamed from: e, reason: collision with root package name */ protected int f3059e; /* renamed from: f, reason: collision with root package name */ protected C0050a f3060f; /* renamed from: g, reason: collision with root package name */ protected DataSetObserver f3061g; /* renamed from: h, reason: collision with root package name */ protected b0.b f3062h; /* renamed from: b0.a$a, reason: collision with other inner class name */ private class C0050a extends ContentObserver { C0050a() { super(new Handler()); } @Override // android.database.ContentObserver public boolean deliverSelfNotifications() { return true; } @Override // android.database.ContentObserver public void onChange(boolean z10) { a.this.i(); } } private class b extends DataSetObserver { b() { } @Override // android.database.DataSetObserver public void onChanged() { a aVar = a.this; aVar.f3055a = true; aVar.notifyDataSetChanged(); } @Override // android.database.DataSetObserver public void onInvalidated() { a aVar = a.this; aVar.f3055a = false; aVar.notifyDataSetInvalidated(); } } public a(Context context, Cursor cursor, boolean z10) { f(context, cursor, z10 ? 1 : 2); } public void a(Cursor cursor) { Cursor j10 = j(cursor); if (j10 != null) { j10.close(); } } @Override // b0.b.a public Cursor b() { return this.f3057c; } public abstract CharSequence c(Cursor cursor); public abstract void e(View view, Context context, Cursor cursor); void f(Context context, Cursor cursor, int i10) { if ((i10 & 1) == 1) { i10 |= 2; this.f3056b = true; } else { this.f3056b = false; } boolean z10 = cursor != null; this.f3057c = cursor; this.f3055a = z10; this.f3058d = context; this.f3059e = z10 ? cursor.getColumnIndexOrThrow("_id") : -1; if ((i10 & 2) == 2) { this.f3060f = new C0050a(); this.f3061g = new b(); } else { this.f3060f = null; this.f3061g = null; } if (z10) { C0050a c0050a = this.f3060f; if (c0050a != null) { cursor.registerContentObserver(c0050a); } DataSetObserver dataSetObserver = this.f3061g; if (dataSetObserver != null) { cursor.registerDataSetObserver(dataSetObserver); } } } public abstract View g(Context context, Cursor cursor, ViewGroup viewGroup); @Override // android.widget.Adapter public int getCount() { Cursor cursor; if (!this.f3055a || (cursor = this.f3057c) == null) { return 0; } return cursor.getCount(); } @Override // android.widget.BaseAdapter, android.widget.SpinnerAdapter public View getDropDownView(int i10, View view, ViewGroup viewGroup) { if (!this.f3055a) { return null; } this.f3057c.moveToPosition(i10); if (view == null) { view = g(this.f3058d, this.f3057c, viewGroup); } e(view, this.f3058d, this.f3057c); return view; } @Override // android.widget.Filterable public Filter getFilter() { if (this.f3062h == null) { this.f3062h = new b0.b(this); } return this.f3062h; } @Override // android.widget.Adapter public Object getItem(int i10) { Cursor cursor; if (!this.f3055a || (cursor = this.f3057c) == null) { return null; } cursor.moveToPosition(i10); return this.f3057c; } @Override // android.widget.Adapter public long getItemId(int i10) { Cursor cursor; if (this.f3055a && (cursor = this.f3057c) != null && cursor.moveToPosition(i10)) { return this.f3057c.getLong(this.f3059e); } return 0L; } @Override // android.widget.Adapter public View getView(int i10, View view, ViewGroup viewGroup) { if (!this.f3055a) { throw new IllegalStateException("this should only be called when the cursor is valid"); } if (this.f3057c.moveToPosition(i10)) { if (view == null) { view = h(this.f3058d, this.f3057c, viewGroup); } e(view, this.f3058d, this.f3057c); return view; } throw new IllegalStateException("couldn't move cursor to position " + i10); } public abstract View h(Context context, Cursor cursor, ViewGroup viewGroup); protected void i() { Cursor cursor; if (!this.f3056b || (cursor = this.f3057c) == null || cursor.isClosed()) { return; } this.f3055a = this.f3057c.requery(); } public Cursor j(Cursor cursor) { Cursor cursor2 = this.f3057c; if (cursor == cursor2) { return null; } if (cursor2 != null) { C0050a c0050a = this.f3060f; if (c0050a != null) { cursor2.unregisterContentObserver(c0050a); } DataSetObserver dataSetObserver = this.f3061g; if (dataSetObserver != null) { cursor2.unregisterDataSetObserver(dataSetObserver); } } this.f3057c = cursor; if (cursor != null) { C0050a c0050a2 = this.f3060f; if (c0050a2 != null) { cursor.registerContentObserver(c0050a2); } DataSetObserver dataSetObserver2 = this.f3061g; if (dataSetObserver2 != null) { cursor.registerDataSetObserver(dataSetObserver2); } this.f3059e = cursor.getColumnIndexOrThrow("_id"); this.f3055a = true; notifyDataSetChanged(); } else { this.f3059e = -1; this.f3055a = false; notifyDataSetInvalidated(); } return cursor2; } }