That fuck shit the fascists are using
at master 81 lines 1.8 kB view raw
1package org.tm.archive.util; 2 3/* 4 * Copyright (C) 2011 Alexander Blom 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19import android.content.Context; 20 21import androidx.loader.content.AsyncTaskLoader; 22 23/** 24 * Loader which extends AsyncTaskLoaders and handles caveats 25 * as pointed out in http://code.google.com/p/android/issues/detail?id=14944. 26 * 27 * Based on CursorLoader.java in the Fragment compatibility package 28 * 29 * @author Alexander Blom (me@alexanderblom.se) 30 * 31 * @param <D> data type 32 */ 33public abstract class AsyncLoader<D> extends AsyncTaskLoader<D> { 34 private D data; 35 36 public AsyncLoader(Context context) { 37 super(context); 38 } 39 40 @Override 41 public void deliverResult(D data) { 42 if (isReset()) { 43 // An async query came in while the loader is stopped 44 return; 45 } 46 47 this.data = data; 48 49 super.deliverResult(data); 50 } 51 52 53 @Override 54 protected void onStartLoading() { 55 if (data != null) { 56 deliverResult(data); 57 } 58 59 if (takeContentChanged() || data == null) { 60 forceLoad(); 61 } 62 } 63 64 @Override 65 protected void onStopLoading() { 66 // Attempt to cancel the current load task if possible. 67 cancelLoad(); 68 } 69 70 @Override 71 protected void onReset() { 72 super.onReset(); 73 74 // Ensure the loader is stopped 75 onStopLoading(); 76 77 data = null; 78 } 79 80 81}