From: Damyan Ivanov Date: Sat, 6 Apr 2019 20:05:40 +0000 (+0300) Subject: use the activity's mProfile, not the global current profile in Data X-Git-Tag: v0.9.1~2 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=c4d80cd461385af945cd3e599ad2307ad5adcfe6;p=mobile-ledger.git use the activity's mProfile, not the global current profile in Data fixes a problem when the new transaction activity is invoked via an app shortcut and the main app is not running (and therefore there is no global current profile --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java index b4716075..310232d2 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionActivity.java @@ -56,7 +56,6 @@ import net.ktnx.mobileledger.model.MobileLedgerProfile; import net.ktnx.mobileledger.ui.DatePickerFragment; import net.ktnx.mobileledger.ui.OnSwipeTouchListener; import net.ktnx.mobileledger.utils.Globals; -import net.ktnx.mobileledger.utils.LockHolder; import net.ktnx.mobileledger.utils.MLDB; import java.text.ParseException; @@ -510,8 +509,7 @@ public class NewTransactionActivity extends ProfileThemedActivity Log.d("descr selected", description); if (!inputStateIsInitial()) return; - MobileLedgerProfile currentProfile = Data.profile.get(); - String accFilter = currentProfile.getPreferredAccountsFilter(); + String accFilter = mProfile.getPreferredAccountsFilter(); ArrayList params = new ArrayList<>(); StringBuilder sb = new StringBuilder( @@ -537,28 +535,17 @@ public class NewTransactionActivity extends ProfileThemedActivity String profileUUID = c.getString(0); int transactionId = c.getInt(1); LedgerTransaction tr; - try (LockHolder lh = Data.profiles.lockForReading()) { - MobileLedgerProfile profile = null; - for (int i = 0; i < Data.profiles.size(); i++) { - MobileLedgerProfile p = Data.profiles.get(i); - if (p.getUuid().equals(profileUUID)) { - profile = p; - break; - } - } - if (profile == null) throw new RuntimeException(String.format( - "Unable to find profile %s, which is supposed to contain " + - "transaction %d with description %s", profileUUID, transactionId, - description)); + MobileLedgerProfile profile = Data.getProfile(profileUUID); + if (profile == null) throw new RuntimeException(String.format( + "Unable to find profile %s, which is supposed to contain " + + "transaction %d with description %s", profileUUID, transactionId, description)); - tr = profile.loadTransaction(transactionId); - } - int i = 0; + tr = profile.loadTransaction(transactionId); table = findViewById(R.id.new_transaction_accounts_table); ArrayList accounts = tr.getAccounts(); TableRow firstNegative = null; int negativeCount = 0; - for (i = 0; i < accounts.size(); i++) { + for (int i = 0; i < accounts.size(); i++) { LedgerTransactionAccount acc = accounts.get(i); TableRow row = (TableRow) table.getChildAt(i); if (row == null) row = doAddAccountRow(false);