Initial commit
This commit is contained in:
224
sources/androidx/cursoradapter/widget/CursorAdapter.java
Normal file
224
sources/androidx/cursoradapter/widget/CursorAdapter.java
Normal file
@@ -0,0 +1,224 @@
|
||||
package androidx.cursoradapter.widget;
|
||||
|
||||
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 androidx.cursoradapter.widget.CursorFilter;
|
||||
import com.liulishuo.filedownloader.model.FileDownloadModel;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public abstract class CursorAdapter extends BaseAdapter implements Filterable, CursorFilter.CursorFilterClient {
|
||||
protected boolean a;
|
||||
protected boolean b;
|
||||
protected Cursor c;
|
||||
protected Context d;
|
||||
protected int e;
|
||||
protected ChangeObserver f;
|
||||
protected DataSetObserver g;
|
||||
protected CursorFilter h;
|
||||
|
||||
private class ChangeObserver extends ContentObserver {
|
||||
ChangeObserver() {
|
||||
super(new Handler());
|
||||
}
|
||||
|
||||
@Override // android.database.ContentObserver
|
||||
public boolean deliverSelfNotifications() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override // android.database.ContentObserver
|
||||
public void onChange(boolean z) {
|
||||
CursorAdapter.this.b();
|
||||
}
|
||||
}
|
||||
|
||||
private class MyDataSetObserver extends DataSetObserver {
|
||||
MyDataSetObserver() {
|
||||
}
|
||||
|
||||
@Override // android.database.DataSetObserver
|
||||
public void onChanged() {
|
||||
CursorAdapter cursorAdapter = CursorAdapter.this;
|
||||
cursorAdapter.a = true;
|
||||
cursorAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override // android.database.DataSetObserver
|
||||
public void onInvalidated() {
|
||||
CursorAdapter cursorAdapter = CursorAdapter.this;
|
||||
cursorAdapter.a = false;
|
||||
cursorAdapter.notifyDataSetInvalidated();
|
||||
}
|
||||
}
|
||||
|
||||
public CursorAdapter(Context context, Cursor cursor, boolean z) {
|
||||
a(context, cursor, z ? 1 : 2);
|
||||
}
|
||||
|
||||
public abstract View a(Context context, Cursor cursor, ViewGroup viewGroup);
|
||||
|
||||
void a(Context context, Cursor cursor, int i) {
|
||||
if ((i & 1) == 1) {
|
||||
i |= 2;
|
||||
this.b = true;
|
||||
} else {
|
||||
this.b = false;
|
||||
}
|
||||
boolean z = cursor != null;
|
||||
this.c = cursor;
|
||||
this.a = z;
|
||||
this.d = context;
|
||||
this.e = z ? cursor.getColumnIndexOrThrow(FileDownloadModel.ID) : -1;
|
||||
if ((i & 2) == 2) {
|
||||
this.f = new ChangeObserver();
|
||||
this.g = new MyDataSetObserver();
|
||||
} else {
|
||||
this.f = null;
|
||||
this.g = null;
|
||||
}
|
||||
if (z) {
|
||||
ChangeObserver changeObserver = this.f;
|
||||
if (changeObserver != null) {
|
||||
cursor.registerContentObserver(changeObserver);
|
||||
}
|
||||
DataSetObserver dataSetObserver = this.g;
|
||||
if (dataSetObserver != null) {
|
||||
cursor.registerDataSetObserver(dataSetObserver);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void a(View view, Context context, Cursor cursor);
|
||||
|
||||
public abstract View b(Context context, Cursor cursor, ViewGroup viewGroup);
|
||||
|
||||
public abstract CharSequence b(Cursor cursor);
|
||||
|
||||
protected void b() {
|
||||
Cursor cursor;
|
||||
if (!this.b || (cursor = this.c) == null || cursor.isClosed()) {
|
||||
return;
|
||||
}
|
||||
this.a = this.c.requery();
|
||||
}
|
||||
|
||||
public Cursor c(Cursor cursor) {
|
||||
Cursor cursor2 = this.c;
|
||||
if (cursor == cursor2) {
|
||||
return null;
|
||||
}
|
||||
if (cursor2 != null) {
|
||||
ChangeObserver changeObserver = this.f;
|
||||
if (changeObserver != null) {
|
||||
cursor2.unregisterContentObserver(changeObserver);
|
||||
}
|
||||
DataSetObserver dataSetObserver = this.g;
|
||||
if (dataSetObserver != null) {
|
||||
cursor2.unregisterDataSetObserver(dataSetObserver);
|
||||
}
|
||||
}
|
||||
this.c = cursor;
|
||||
if (cursor != null) {
|
||||
ChangeObserver changeObserver2 = this.f;
|
||||
if (changeObserver2 != null) {
|
||||
cursor.registerContentObserver(changeObserver2);
|
||||
}
|
||||
DataSetObserver dataSetObserver2 = this.g;
|
||||
if (dataSetObserver2 != null) {
|
||||
cursor.registerDataSetObserver(dataSetObserver2);
|
||||
}
|
||||
this.e = cursor.getColumnIndexOrThrow(FileDownloadModel.ID);
|
||||
this.a = true;
|
||||
notifyDataSetChanged();
|
||||
} else {
|
||||
this.e = -1;
|
||||
this.a = false;
|
||||
notifyDataSetInvalidated();
|
||||
}
|
||||
return cursor2;
|
||||
}
|
||||
|
||||
@Override // android.widget.Adapter
|
||||
public int getCount() {
|
||||
Cursor cursor;
|
||||
if (!this.a || (cursor = this.c) == null) {
|
||||
return 0;
|
||||
}
|
||||
return cursor.getCount();
|
||||
}
|
||||
|
||||
@Override // android.widget.BaseAdapter, android.widget.SpinnerAdapter
|
||||
public View getDropDownView(int i, View view, ViewGroup viewGroup) {
|
||||
if (!this.a) {
|
||||
return null;
|
||||
}
|
||||
this.c.moveToPosition(i);
|
||||
if (view == null) {
|
||||
view = a(this.d, this.c, viewGroup);
|
||||
}
|
||||
a(view, this.d, this.c);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override // android.widget.Filterable
|
||||
public Filter getFilter() {
|
||||
if (this.h == null) {
|
||||
this.h = new CursorFilter(this);
|
||||
}
|
||||
return this.h;
|
||||
}
|
||||
|
||||
@Override // android.widget.Adapter
|
||||
public Object getItem(int i) {
|
||||
Cursor cursor;
|
||||
if (!this.a || (cursor = this.c) == null) {
|
||||
return null;
|
||||
}
|
||||
cursor.moveToPosition(i);
|
||||
return this.c;
|
||||
}
|
||||
|
||||
@Override // android.widget.Adapter
|
||||
public long getItemId(int i) {
|
||||
Cursor cursor;
|
||||
if (this.a && (cursor = this.c) != null && cursor.moveToPosition(i)) {
|
||||
return this.c.getLong(this.e);
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
@Override // android.widget.Adapter
|
||||
public View getView(int i, View view, ViewGroup viewGroup) {
|
||||
if (!this.a) {
|
||||
throw new IllegalStateException("this should only be called when the cursor is valid");
|
||||
}
|
||||
if (this.c.moveToPosition(i)) {
|
||||
if (view == null) {
|
||||
view = b(this.d, this.c, viewGroup);
|
||||
}
|
||||
a(view, this.d, this.c);
|
||||
return view;
|
||||
}
|
||||
throw new IllegalStateException("couldn't move cursor to position " + i);
|
||||
}
|
||||
|
||||
@Override // androidx.cursoradapter.widget.CursorFilter.CursorFilterClient
|
||||
public Cursor a() {
|
||||
return this.c;
|
||||
}
|
||||
|
||||
public void a(Cursor cursor) {
|
||||
Cursor c = c(cursor);
|
||||
if (c != null) {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
}
|
52
sources/androidx/cursoradapter/widget/CursorFilter.java
Normal file
52
sources/androidx/cursoradapter/widget/CursorFilter.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package androidx.cursoradapter.widget;
|
||||
|
||||
import android.database.Cursor;
|
||||
import android.widget.Filter;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
class CursorFilter extends Filter {
|
||||
CursorFilterClient a;
|
||||
|
||||
interface CursorFilterClient {
|
||||
Cursor a();
|
||||
|
||||
Cursor a(CharSequence charSequence);
|
||||
|
||||
void a(Cursor cursor);
|
||||
|
||||
CharSequence b(Cursor cursor);
|
||||
}
|
||||
|
||||
CursorFilter(CursorFilterClient cursorFilterClient) {
|
||||
this.a = cursorFilterClient;
|
||||
}
|
||||
|
||||
@Override // android.widget.Filter
|
||||
public CharSequence convertResultToString(Object obj) {
|
||||
return this.a.b((Cursor) obj);
|
||||
}
|
||||
|
||||
@Override // android.widget.Filter
|
||||
protected Filter.FilterResults performFiltering(CharSequence charSequence) {
|
||||
Cursor a = this.a.a(charSequence);
|
||||
Filter.FilterResults filterResults = new Filter.FilterResults();
|
||||
if (a != null) {
|
||||
filterResults.count = a.getCount();
|
||||
filterResults.values = a;
|
||||
} else {
|
||||
filterResults.count = 0;
|
||||
filterResults.values = null;
|
||||
}
|
||||
return filterResults;
|
||||
}
|
||||
|
||||
@Override // android.widget.Filter
|
||||
protected void publishResults(CharSequence charSequence, Filter.FilterResults filterResults) {
|
||||
Cursor a = this.a.a();
|
||||
Object obj = filterResults.values;
|
||||
if (obj == null || obj == a) {
|
||||
return;
|
||||
}
|
||||
this.a.a((Cursor) obj);
|
||||
}
|
||||
}
|
@@ -0,0 +1,32 @@
|
||||
package androidx.cursoradapter.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public abstract class ResourceCursorAdapter extends CursorAdapter {
|
||||
private int i;
|
||||
private int j;
|
||||
private LayoutInflater k;
|
||||
|
||||
@Deprecated
|
||||
public ResourceCursorAdapter(Context context, int i, Cursor cursor, boolean z) {
|
||||
super(context, cursor, z);
|
||||
this.j = i;
|
||||
this.i = i;
|
||||
this.k = (LayoutInflater) context.getSystemService("layout_inflater");
|
||||
}
|
||||
|
||||
@Override // androidx.cursoradapter.widget.CursorAdapter
|
||||
public View a(Context context, Cursor cursor, ViewGroup viewGroup) {
|
||||
return this.k.inflate(this.j, viewGroup, false);
|
||||
}
|
||||
|
||||
@Override // androidx.cursoradapter.widget.CursorAdapter
|
||||
public View b(Context context, Cursor cursor, ViewGroup viewGroup) {
|
||||
return this.k.inflate(this.i, viewGroup, false);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user