]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/async/CommitAccountsTask.java
move setting case_sensitive_like=ON to helper.onOpen
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / async / CommitAccountsTask.java
index 8f8c1dac98e6c4ea5fc9bc16255bca64e10e066a..eb3dfbba51b0997424114ac55ba5a59782eebc80 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019 Damyan Ivanov.
+ * Copyright © 2020 Damyan Ivanov.
  * This file is part of MoLe.
  * MoLe is free software: you can distribute it and/or modify it
  * under the term of the GNU General Public License as published by
@@ -19,35 +19,36 @@ package net.ktnx.mobileledger.async;
 
 import android.database.sqlite.SQLiteDatabase;
 import android.os.AsyncTask;
-import android.util.Log;
 
+import net.ktnx.mobileledger.App;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.LedgerAccount;
-import net.ktnx.mobileledger.utils.MLDB;
+import net.ktnx.mobileledger.utils.LockHolder;
 
 import java.util.ArrayList;
 
+import static net.ktnx.mobileledger.utils.Logger.debug;
+
 public class CommitAccountsTask
         extends AsyncTask<CommitAccountsTaskParams, Void, ArrayList<LedgerAccount>> {
     protected ArrayList<LedgerAccount> doInBackground(CommitAccountsTaskParams... params) {
-        Data.backgroundTaskCount.incrementAndGet();
+        Data.backgroundTaskStarted();
         ArrayList<LedgerAccount> newList = new ArrayList<>();
-        String profile = Data.profile.get().getUuid();
+        String profile = Data.profile.getValue().getUuid();
         try {
 
-            SQLiteDatabase db = MLDB.getDatabase();
-            db.beginTransaction();
+            SQLiteDatabase db = App.getDatabase();
+            db.beginTransactionNonExclusive();
             try {
+                try (LockHolder lh = params[0].accountList.lockForWriting()) {
                     for (int i = 0; i < params[0].accountList.size(); i++ ){
                         LedgerAccount acc = params[0].accountList.get(i);
-                        Log.d("CAT", String.format("Setting %s to %s", acc.getName(),
+                        debug("CAT", String.format("Setting %s to %s", acc.getName(),
                                 acc.isHiddenByStarToBe() ? "hidden" : "starred"));
                         db.execSQL("UPDATE accounts SET hidden=? WHERE profile=? AND name=?",
                                 new Object[]{acc.isHiddenByStarToBe() ? 1 : 0, profile, acc.getName()
                                 });
-
-                        acc.setHiddenByStar(acc.isHiddenByStarToBe());
-                        if (!params[0].showOnlyStarred || !acc.isHiddenByStar()) newList.add(acc);
+                    }
                     db.setTransactionSuccessful();
                 }
             }
@@ -56,7 +57,7 @@ public class CommitAccountsTask
             }
         }
         finally {
-            Data.backgroundTaskCount.decrementAndGet();
+            Data.backgroundTaskFinished();
         }
 
         return newList;