package ῲ.㳳.K;

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 ඓ.K.K.K.C1293;
import ῲ.㳳.K.C2248;

/* renamed from: ῲ.㳳.K.K  reason: contains not printable characters */
/* compiled from: CursorAdapter */
public abstract class AbstractC2250 extends BaseAdapter implements Filterable, C2248.AbstractC2249 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public boolean f7750;

    /* renamed from: ඓ  reason: contains not printable characters */
    public Context f7751;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public C2248 f7752;

    /* renamed from: ῲ  reason: contains not printable characters */
    public boolean f7753;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public C2252 f7754;

    /* renamed from: 㴹  reason: contains not printable characters */
    public int f7755;

    /* renamed from: 㸾  reason: contains not printable characters */
    public Cursor f7756;

    /* renamed from: 㿎  reason: contains not printable characters */
    public DataSetObserver f7757;

    /* renamed from: ῲ.㳳.K.K$ῲ  reason: contains not printable characters */
    /* compiled from: CursorAdapter */
    public class C2251 extends DataSetObserver {
        public C2251() {
        }

        public void onChanged() {
            AbstractC2250 k = AbstractC2250.this;
            k.f7753 = true;
            k.notifyDataSetChanged();
        }

        public void onInvalidated() {
            AbstractC2250 k = AbstractC2250.this;
            k.f7753 = false;
            k.notifyDataSetInvalidated();
        }
    }

    /* renamed from: ῲ.㳳.K.K$K  reason: contains not printable characters */
    /* compiled from: CursorAdapter */
    public class C2252 extends ContentObserver {
        public C2252() {
            super(new Handler());
        }

        public boolean deliverSelfNotifications() {
            return true;
        }

        public void onChange(boolean z) {
            Cursor cursor;
            AbstractC2250 k = AbstractC2250.this;
            if (k.f7750 && (cursor = k.f7756) != null && !cursor.isClosed()) {
                k.f7753 = k.f7756.requery();
            }
        }
    }

    public AbstractC2250(Context context, Cursor cursor, boolean z) {
        boolean z2 = true;
        int i = z ? 1 : 2;
        if ((i & 1) == 1) {
            i |= 2;
            this.f7750 = true;
        } else {
            this.f7750 = false;
        }
        z2 = cursor == null ? false : z2;
        this.f7756 = cursor;
        this.f7753 = z2;
        this.f7751 = context;
        this.f7755 = z2 ? cursor.getColumnIndexOrThrow("_id") : -1;
        if ((i & 2) == 2) {
            this.f7754 = new C2252();
            this.f7757 = new C2251();
        } else {
            this.f7754 = null;
            this.f7757 = null;
        }
        if (z2) {
            C2252 k = this.f7754;
            if (k != null) {
                cursor.registerContentObserver(k);
            }
            DataSetObserver dataSetObserver = this.f7757;
            if (dataSetObserver != null) {
                cursor.registerDataSetObserver(dataSetObserver);
            }
        }
    }

    public int getCount() {
        Cursor cursor;
        if (!this.f7753 || (cursor = this.f7756) == null) {
            return 0;
        }
        return cursor.getCount();
    }

    public View getDropDownView(int i, View view, ViewGroup viewGroup) {
        if (!this.f7753) {
            return null;
        }
        this.f7756.moveToPosition(i);
        if (view == null) {
            AbstractC2247 r2 = (AbstractC2247) this;
            view = r2.f7747.inflate(r2.f7746, viewGroup, false);
        }
        m5875(view, this.f7751, this.f7756);
        return view;
    }

    public Filter getFilter() {
        if (this.f7752 == null) {
            this.f7752 = new C2248(this);
        }
        return this.f7752;
    }

    public Object getItem(int i) {
        Cursor cursor;
        if (!this.f7753 || (cursor = this.f7756) == null) {
            return null;
        }
        cursor.moveToPosition(i);
        return this.f7756;
    }

    public long getItemId(int i) {
        Cursor cursor;
        if (!this.f7753 || (cursor = this.f7756) == null || !cursor.moveToPosition(i)) {
            return 0;
        }
        return this.f7756.getLong(this.f7755);
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        if (!this.f7753) {
            throw new IllegalStateException("this should only be called when the cursor is valid");
        } else if (this.f7756.moveToPosition(i)) {
            if (view == null) {
                view = m5873(this.f7751, this.f7756, viewGroup);
            }
            m5875(view, this.f7751, this.f7756);
            return view;
        } else {
            throw new IllegalStateException(C1293.m3408("couldn't move cursor to position ", i));
        }
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public abstract CharSequence m5872(Cursor cursor);

    /* renamed from: K  reason: contains not printable characters */
    public abstract View m5873(Context context, Cursor cursor, ViewGroup viewGroup);

    /* renamed from: K  reason: contains not printable characters */
    public void m5874(Cursor cursor) {
        Cursor cursor2 = this.f7756;
        if (cursor == cursor2) {
            cursor2 = null;
        } else {
            if (cursor2 != null) {
                C2252 k = this.f7754;
                if (k != null) {
                    cursor2.unregisterContentObserver(k);
                }
                DataSetObserver dataSetObserver = this.f7757;
                if (dataSetObserver != null) {
                    cursor2.unregisterDataSetObserver(dataSetObserver);
                }
            }
            this.f7756 = cursor;
            if (cursor != null) {
                C2252 k2 = this.f7754;
                if (k2 != null) {
                    cursor.registerContentObserver(k2);
                }
                DataSetObserver dataSetObserver2 = this.f7757;
                if (dataSetObserver2 != null) {
                    cursor.registerDataSetObserver(dataSetObserver2);
                }
                this.f7755 = cursor.getColumnIndexOrThrow("_id");
                this.f7753 = true;
                notifyDataSetChanged();
            } else {
                this.f7755 = -1;
                this.f7753 = false;
                notifyDataSetInvalidated();
            }
        }
        if (cursor2 != null) {
            cursor2.close();
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public abstract void m5875(View view, Context context, Cursor cursor);
}
