discord-jadx/app/src/main/java/androidx/cursoradapter/widget/SimpleCursorAdapter.java

145 lines
5.0 KiB
Java

package androidx.cursoradapter.widget;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.RestrictTo;
public class SimpleCursorAdapter extends ResourceCursorAdapter {
private CursorToStringConverter mCursorToStringConverter;
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
public int[] mFrom;
public String[] mOriginalFrom;
private int mStringConversionColumn = -1;
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP})
public int[] mTo;
private ViewBinder mViewBinder;
public interface CursorToStringConverter {
CharSequence convertToString(Cursor cursor);
}
public interface ViewBinder {
boolean setViewValue(View view, Cursor cursor, int i);
}
@Deprecated
public SimpleCursorAdapter(Context context, int i, Cursor cursor, String[] strArr, int[] iArr) {
super(context, i, cursor);
this.mTo = iArr;
this.mOriginalFrom = strArr;
findColumns(cursor, strArr);
}
public SimpleCursorAdapter(Context context, int i, Cursor cursor, String[] strArr, int[] iArr, int i2) {
super(context, i, cursor, i2);
this.mTo = iArr;
this.mOriginalFrom = strArr;
findColumns(cursor, strArr);
}
private void findColumns(Cursor cursor, String[] strArr) {
if (cursor != null) {
int length = strArr.length;
int[] iArr = this.mFrom;
if (iArr == null || iArr.length != length) {
this.mFrom = new int[length];
}
for (int i = 0; i < length; i++) {
this.mFrom[i] = cursor.getColumnIndexOrThrow(strArr[i]);
}
return;
}
this.mFrom = null;
}
@Override // androidx.cursoradapter.widget.CursorAdapter
public void bindView(View view, Context context, Cursor cursor) {
ViewBinder viewBinder = this.mViewBinder;
int[] iArr = this.mTo;
int length = iArr.length;
int[] iArr2 = this.mFrom;
for (int i = 0; i < length; i++) {
View findViewById = view.findViewById(iArr[i]);
if (findViewById != null) {
if (viewBinder != null ? viewBinder.setViewValue(findViewById, cursor, iArr2[i]) : false) {
continue;
} else {
String string = cursor.getString(iArr2[i]);
if (string == null) {
string = "";
}
if (findViewById instanceof TextView) {
setViewText((TextView) findViewById, string);
} else if (findViewById instanceof ImageView) {
setViewImage((ImageView) findViewById, string);
} else {
throw new IllegalStateException(findViewById.getClass().getName() + " is not a view that can be bounds by this SimpleCursorAdapter");
}
}
}
}
}
public void changeCursorAndColumns(Cursor cursor, String[] strArr, int[] iArr) {
this.mOriginalFrom = strArr;
this.mTo = iArr;
findColumns(cursor, strArr);
super.changeCursor(cursor);
}
@Override // androidx.cursoradapter.widget.CursorAdapter, androidx.cursoradapter.widget.CursorFilter.CursorFilterClient
public CharSequence convertToString(Cursor cursor) {
CursorToStringConverter cursorToStringConverter = this.mCursorToStringConverter;
if (cursorToStringConverter != null) {
return cursorToStringConverter.convertToString(cursor);
}
int i = this.mStringConversionColumn;
return i > -1 ? cursor.getString(i) : super.convertToString(cursor);
}
public CursorToStringConverter getCursorToStringConverter() {
return this.mCursorToStringConverter;
}
public int getStringConversionColumn() {
return this.mStringConversionColumn;
}
public ViewBinder getViewBinder() {
return this.mViewBinder;
}
public void setCursorToStringConverter(CursorToStringConverter cursorToStringConverter) {
this.mCursorToStringConverter = cursorToStringConverter;
}
public void setStringConversionColumn(int i) {
this.mStringConversionColumn = i;
}
public void setViewBinder(ViewBinder viewBinder) {
this.mViewBinder = viewBinder;
}
public void setViewImage(ImageView imageView, String str) {
try {
imageView.setImageResource(Integer.parseInt(str));
} catch (NumberFormatException unused) {
imageView.setImageURI(Uri.parse(str));
}
}
public void setViewText(TextView textView, String str) {
textView.setText(str);
}
@Override // androidx.cursoradapter.widget.CursorAdapter
public Cursor swapCursor(Cursor cursor) {
findColumns(cursor, this.mOriginalFrom);
return super.swapCursor(cursor);
}
}