import net.ktnx.mobileledger.model.Data;
import net.ktnx.mobileledger.model.LedgerAccount;
+import net.ktnx.mobileledger.utils.LockHolder;
import net.ktnx.mobileledger.utils.MLDB;
import java.util.ArrayList;
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();
try {
SQLiteDatabase db = MLDB.getDatabase();
db.beginTransaction();
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(),
acc.setHiddenByStar(acc.isHiddenByStarToBe());
if (!params[0].showOnlyStarred || !acc.isHiddenByStar()) newList.add(acc);
+ }
db.setTransactionSuccessful();
}
}
}
}
finally {
- Data.backgroundTaskCount.decrementAndGet();
+ Data.backgroundTaskFinished();
}
return newList;