discord-jadx/app/src/main/java/androidx/loader/content/CursorLoader.java

201 lines
6.1 KiB
Java

package androidx.loader.content;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContentResolverCompat;
import androidx.core.os.CancellationSignal;
import androidx.core.os.OperationCanceledException;
import androidx.loader.content.Loader;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.Arrays;
public class CursorLoader extends AsyncTaskLoader<Cursor> {
public CancellationSignal mCancellationSignal;
public Cursor mCursor;
public final Loader<Cursor>.ForceLoadContentObserver mObserver = new Loader.ForceLoadContentObserver();
public String[] mProjection;
public String mSelection;
public String[] mSelectionArgs;
public String mSortOrder;
public Uri mUri;
public CursorLoader(@NonNull Context context) {
super(context);
}
public CursorLoader(@NonNull Context context, @NonNull Uri uri, @Nullable String[] strArr, @Nullable String str, @Nullable String[] strArr2, @Nullable String str2) {
super(context);
this.mUri = uri;
this.mProjection = strArr;
this.mSelection = str;
this.mSelectionArgs = strArr2;
this.mSortOrder = str2;
}
@Override // androidx.loader.content.AsyncTaskLoader
public void cancelLoadInBackground() {
super.cancelLoadInBackground();
synchronized (this) {
CancellationSignal cancellationSignal = this.mCancellationSignal;
if (cancellationSignal != null) {
cancellationSignal.cancel();
}
}
}
public void deliverResult(Cursor cursor) {
if (!isReset()) {
Cursor cursor2 = this.mCursor;
this.mCursor = cursor;
if (isStarted()) {
super.deliverResult((CursorLoader) cursor);
}
if (cursor2 != null && cursor2 != cursor && !cursor2.isClosed()) {
cursor2.close();
}
} else if (cursor != null) {
cursor.close();
}
}
@Override // androidx.loader.content.AsyncTaskLoader, androidx.loader.content.Loader
@Deprecated
public void dump(String str, FileDescriptor fileDescriptor, PrintWriter printWriter, String[] strArr) {
super.dump(str, fileDescriptor, printWriter, strArr);
printWriter.print(str);
printWriter.print("mUri=");
printWriter.println(this.mUri);
printWriter.print(str);
printWriter.print("mProjection=");
printWriter.println(Arrays.toString(this.mProjection));
printWriter.print(str);
printWriter.print("mSelection=");
printWriter.println(this.mSelection);
printWriter.print(str);
printWriter.print("mSelectionArgs=");
printWriter.println(Arrays.toString(this.mSelectionArgs));
printWriter.print(str);
printWriter.print("mSortOrder=");
printWriter.println(this.mSortOrder);
printWriter.print(str);
printWriter.print("mCursor=");
printWriter.println(this.mCursor);
printWriter.print(str);
printWriter.print("mContentChanged=");
printWriter.println(this.mContentChanged);
}
@Nullable
public String[] getProjection() {
return this.mProjection;
}
@Nullable
public String getSelection() {
return this.mSelection;
}
@Nullable
public String[] getSelectionArgs() {
return this.mSelectionArgs;
}
@Nullable
public String getSortOrder() {
return this.mSortOrder;
}
@NonNull
public Uri getUri() {
return this.mUri;
}
@Override // androidx.loader.content.AsyncTaskLoader
public Cursor loadInBackground() {
synchronized (this) {
if (!isLoadInBackgroundCanceled()) {
this.mCancellationSignal = new CancellationSignal();
} else {
throw new OperationCanceledException();
}
}
try {
Cursor query = ContentResolverCompat.query(getContext().getContentResolver(), this.mUri, this.mProjection, this.mSelection, this.mSelectionArgs, this.mSortOrder, this.mCancellationSignal);
if (query != null) {
try {
query.getCount();
query.registerContentObserver(this.mObserver);
} catch (RuntimeException e) {
query.close();
throw e;
}
}
synchronized (this) {
this.mCancellationSignal = null;
}
return query;
} catch (Throwable th) {
synchronized (this) {
this.mCancellationSignal = null;
throw th;
}
}
}
public void onCanceled(Cursor cursor) {
if (cursor != null && !cursor.isClosed()) {
cursor.close();
}
}
@Override // androidx.loader.content.Loader
public void onReset() {
super.onReset();
onStopLoading();
Cursor cursor = this.mCursor;
if (cursor != null && !cursor.isClosed()) {
this.mCursor.close();
}
this.mCursor = null;
}
@Override // androidx.loader.content.Loader
public void onStartLoading() {
Cursor cursor = this.mCursor;
if (cursor != null) {
deliverResult(cursor);
}
if (takeContentChanged() || this.mCursor == null) {
forceLoad();
}
}
@Override // androidx.loader.content.Loader
public void onStopLoading() {
cancelLoad();
}
public void setProjection(@Nullable String[] strArr) {
this.mProjection = strArr;
}
public void setSelection(@Nullable String str) {
this.mSelection = str;
}
public void setSelectionArgs(@Nullable String[] strArr) {
this.mSelectionArgs = strArr;
}
public void setSortOrder(@Nullable String str) {
this.mSortOrder = str;
}
public void setUri(@NonNull Uri uri) {
this.mUri = uri;
}
}