package X6FRs_4.FSaI4_7.KQgRr5e_0;

import X6FRs_4.FSaI4_7.KQgRr5e_0.QxJ9d_1;
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;
/* compiled from: CursorAdapter.java */
/* loaded from: classes.dex */
public abstract class KQgRr5e_0 extends BaseAdapter implements Filterable, QxJ9d_1.KQgRr5e_0 {
    public int KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public C0034KQgRr5e_0 f361KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public X6FRs_4.FSaI4_7.KQgRr5e_0.QxJ9d_1 f362KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public Context f363KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public Cursor f364KQgRr5e_0;

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public DataSetObserver f365KQgRr5e_0;
    public boolean PGPF6hQ_2;
    public boolean QxJ9d_1;

    /* compiled from: CursorAdapter.java */
    /* renamed from: X6FRs_4.FSaI4_7.KQgRr5e_0.KQgRr5e_0$KQgRr5e_0  reason: collision with other inner class name */
    /* loaded from: classes.dex */
    public class C0034KQgRr5e_0 extends ContentObserver {
        public C0034KQgRr5e_0() {
            super(new Handler());
        }

        @Override // android.database.ContentObserver
        public boolean deliverSelfNotifications() {
            return true;
        }

        @Override // android.database.ContentObserver
        public void onChange(boolean z) {
            KQgRr5e_0.this.KQgRr5e_0();
        }
    }

    /* compiled from: CursorAdapter.java */
    /* loaded from: classes.dex */
    public class QxJ9d_1 extends DataSetObserver {
        public QxJ9d_1() {
        }

        @Override // android.database.DataSetObserver
        public void onChanged() {
            KQgRr5e_0 kQgRr5e_0 = KQgRr5e_0.this;
            kQgRr5e_0.QxJ9d_1 = true;
            kQgRr5e_0.notifyDataSetChanged();
        }

        @Override // android.database.DataSetObserver
        public void onInvalidated() {
            KQgRr5e_0 kQgRr5e_0 = KQgRr5e_0.this;
            kQgRr5e_0.QxJ9d_1 = false;
            kQgRr5e_0.notifyDataSetInvalidated();
        }
    }

    public KQgRr5e_0(Context context, Cursor cursor, boolean z) {
        KQgRr5e_0(context, cursor, z ? 1 : 2);
    }

    public abstract View KQgRr5e_0(Context context, Cursor cursor, ViewGroup viewGroup);

    @Override // X6FRs_4.FSaI4_7.KQgRr5e_0.QxJ9d_1.KQgRr5e_0
    public abstract CharSequence KQgRr5e_0(Cursor cursor);

    public void KQgRr5e_0(Context context, Cursor cursor, int i) {
        if ((i & 1) == 1) {
            i |= 2;
            this.PGPF6hQ_2 = true;
        } else {
            this.PGPF6hQ_2 = false;
        }
        boolean z = cursor != null;
        this.f364KQgRr5e_0 = cursor;
        this.QxJ9d_1 = z;
        this.f363KQgRr5e_0 = context;
        this.KQgRr5e_0 = z ? cursor.getColumnIndexOrThrow("_id") : -1;
        if ((i & 2) == 2) {
            this.f361KQgRr5e_0 = new C0034KQgRr5e_0();
            this.f365KQgRr5e_0 = new QxJ9d_1();
        } else {
            this.f361KQgRr5e_0 = null;
            this.f365KQgRr5e_0 = null;
        }
        if (z) {
            C0034KQgRr5e_0 c0034KQgRr5e_0 = this.f361KQgRr5e_0;
            if (c0034KQgRr5e_0 != null) {
                cursor.registerContentObserver(c0034KQgRr5e_0);
            }
            DataSetObserver dataSetObserver = this.f365KQgRr5e_0;
            if (dataSetObserver != null) {
                cursor.registerDataSetObserver(dataSetObserver);
            }
        }
    }

    public abstract void KQgRr5e_0(View view, Context context, Cursor cursor);

    public abstract View QxJ9d_1(Context context, Cursor cursor, ViewGroup viewGroup);

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

    @Override // android.widget.BaseAdapter, android.widget.SpinnerAdapter
    public View getDropDownView(int i, View view, ViewGroup viewGroup) {
        if (this.QxJ9d_1) {
            this.f364KQgRr5e_0.moveToPosition(i);
            if (view == null) {
                view = KQgRr5e_0(this.f363KQgRr5e_0, this.f364KQgRr5e_0, viewGroup);
            }
            KQgRr5e_0(view, this.f363KQgRr5e_0, this.f364KQgRr5e_0);
            return view;
        }
        return null;
    }

    @Override // android.widget.Filterable
    public Filter getFilter() {
        if (this.f362KQgRr5e_0 == null) {
            this.f362KQgRr5e_0 = new X6FRs_4.FSaI4_7.KQgRr5e_0.QxJ9d_1(this);
        }
        return this.f362KQgRr5e_0;
    }

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

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

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

    @Override // X6FRs_4.FSaI4_7.KQgRr5e_0.QxJ9d_1.KQgRr5e_0
    public Cursor KQgRr5e_0() {
        return this.f364KQgRr5e_0;
    }

    @Override // X6FRs_4.FSaI4_7.KQgRr5e_0.QxJ9d_1.KQgRr5e_0
    public void KQgRr5e_0(Cursor cursor) {
        Cursor KQgRr5e_0 = KQgRr5e_0(cursor);
        if (KQgRr5e_0 != null) {
            KQgRr5e_0.close();
        }
    }

    @Override // X6FRs_4.FSaI4_7.KQgRr5e_0.QxJ9d_1.KQgRr5e_0
    public Cursor KQgRr5e_0(Cursor cursor) {
        Cursor cursor2 = this.f364KQgRr5e_0;
        if (cursor == cursor2) {
            return null;
        }
        if (cursor2 != null) {
            C0034KQgRr5e_0 c0034KQgRr5e_0 = this.f361KQgRr5e_0;
            if (c0034KQgRr5e_0 != null) {
                cursor2.unregisterContentObserver(c0034KQgRr5e_0);
            }
            DataSetObserver dataSetObserver = this.f365KQgRr5e_0;
            if (dataSetObserver != null) {
                cursor2.unregisterDataSetObserver(dataSetObserver);
            }
        }
        this.f364KQgRr5e_0 = cursor;
        if (cursor != null) {
            C0034KQgRr5e_0 c0034KQgRr5e_02 = this.f361KQgRr5e_0;
            if (c0034KQgRr5e_02 != null) {
                cursor.registerContentObserver(c0034KQgRr5e_02);
            }
            DataSetObserver dataSetObserver2 = this.f365KQgRr5e_0;
            if (dataSetObserver2 != null) {
                cursor.registerDataSetObserver(dataSetObserver2);
            }
            this.KQgRr5e_0 = cursor.getColumnIndexOrThrow("_id");
            this.QxJ9d_1 = true;
            notifyDataSetChanged();
        } else {
            this.KQgRr5e_0 = -1;
            this.QxJ9d_1 = false;
            notifyDataSetInvalidated();
        }
        return cursor2;
    }

    @Override // X6FRs_4.FSaI4_7.KQgRr5e_0.QxJ9d_1.KQgRr5e_0
    public void KQgRr5e_0() {
        Cursor cursor;
        if (!this.PGPF6hQ_2 || (cursor = this.f364KQgRr5e_0) == null || cursor.isClosed()) {
            return;
        }
        this.QxJ9d_1 = this.f364KQgRr5e_0.requery();
    }
}
