import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
+import android.os.AsyncTask;
+import net.ktnx.mobileledger.async.RetrieveTransactionsTask;
+import net.ktnx.mobileledger.ui.activity.MainActivity;
import net.ktnx.mobileledger.utils.LockHolder;
import net.ktnx.mobileledger.utils.Locker;
import net.ktnx.mobileledger.utils.Logger;
import net.ktnx.mobileledger.utils.ObservableList;
import net.ktnx.mobileledger.utils.ObservableValue;
+import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger;
public static MutableLiveData<String> accountFilter = new MutableLiveData<>();
private static AtomicInteger backgroundTaskCount = new AtomicInteger(0);
private static Locker profilesLocker = new Locker();
+ private static RetrieveTransactionsTask retrieveTransactionsTask;
public static void backgroundTaskStarted() {
int cnt = backgroundTaskCount.incrementAndGet();
debug("data",
}
return profile;
}
+ public synchronized static void scheduleTransactionListRetrieval(MainActivity activity) {
+ if (retrieveTransactionsTask != null) {
+ Logger.debug("db", "Ignoring request for transaction retrieval - already active");
+ return;
+ }
+ retrieveTransactionsTask =
+ new RetrieveTransactionsTask(new WeakReference<>(activity), profile.getValue());
+ Logger.debug("db", "Created a background transaction retrieval task");
+
+ retrieveTransactionsTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ }
+ public static synchronized void stopTransactionsRetrieval() {
+ if (retrieveTransactionsTask != null) retrieveTransactionsTask.cancel(false);
+ }
+ public static void transactionRetrievalDone() {
+ retrieveTransactionsTask = null;
+ }
}
import net.ktnx.mobileledger.ui.transaction_list.TransactionListViewModel;
import net.ktnx.mobileledger.utils.Colors;
import net.ktnx.mobileledger.utils.LockHolder;
-import net.ktnx.mobileledger.utils.Logger;
import net.ktnx.mobileledger.utils.MLDB;
import org.jetbrains.annotations.NotNull;
-import java.lang.ref.WeakReference;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
private LinearLayout profileListContainer;
private View profileListHeadArrow, profileListHeadMore, profileListHeadCancel;
private FragmentManager fragmentManager;
- private RetrieveTransactionsTask retrieveTransactionsTask;
private View bTransactionListCancelDownload;
private ProgressBar progressBar;
private LinearLayout progressLayout;
"WEB data last fetched at %1.3f and now is %1.3f. re-fetching",
lastUpdate.getTime() / 1000f, now / 1000f));
- scheduleTransactionListRetrieval();
+ Data.scheduleTransactionListRetrieval(this);
}
}
private void createShortcuts(List<MobileLedgerProfile> list) {
Data.lastUpdateDate.postValue(new Date(last_update));
}
}
- public void scheduleTransactionListRetrieval() {
- if (Data.profile.get() == null) return;
-
- retrieveTransactionsTask = new RetrieveTransactionsTask(new WeakReference<>(this));
-
- retrieveTransactionsTask.execute();
- }
public void onStopTransactionRefreshClick(View view) {
debug("interactive", "Cancelling transactions refresh");
- if (retrieveTransactionsTask != null) retrieveTransactionsTask.cancel(false);
+ Data.stopTransactionsRetrieval();
bTransactionListCancelDownload.setEnabled(false);
}
public void onRetrieveDone(String error) {
+ Data.transactionRetrievalDone();
progressLayout.setVisibility(View.GONE);
if (error == null) {