]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
running totals when filtering transactions by account
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / MainActivity.java
index 5ca25061b277045987d0699a70ed9b51a99dd37c..1350daf03cec69026355282dbc4f57474539e535 100644 (file)
@@ -392,30 +392,30 @@ public class MainActivity extends ProfileThemedActivity implements FabManager.Fa
 
         createShortcuts(newList);
 
-        Profile currentProfile = Data.getProfile();
-        boolean currentProfilePresent = false;
+        final Profile currentProfile = Data.getProfile();
+        Profile replacementProfile = null;
         if (currentProfile != null) {
             for (Profile p : newList) {
                 if (p.getId() == currentProfile.getId()) {
-                    currentProfilePresent = true;
+                    replacementProfile = p;
                     break;
                 }
             }
         }
-        if (!currentProfilePresent) {
+
+        if (replacementProfile == null) {
             Logger.debug(TAG, "Switching profile because the current is no longer available");
             Data.setCurrentProfile(newList.get(0));
         }
+        else {
+            Data.setCurrentProfile(replacementProfile);
+        }
     }
     /**
      * called when the current profile has changed
      */
     private void onProfileChanged(@Nullable Profile newProfile) {
-        if (this.profile == null) {
-            if (newProfile == null)
-                return;
-        }
-        else {
+        if (this.profile != null) {
             if (this.profile.equals(newProfile))
                 return;
         }
@@ -427,7 +427,7 @@ public class MainActivity extends ProfileThemedActivity implements FabManager.Fa
         else
             setTitle(R.string.app_name);
 
-        int newProfileTheme = haveProfile ? newProfile.getTheme() : -1;
+        int newProfileTheme = haveProfile ? newProfile.getTheme() : Colors.DEFAULT_HUE_DEG;
         if (newProfileTheme != Colors.profileThemeId) {
             Logger.debug("profiles",
                     String.format(Locale.ENGLISH, "profile theme %d → %d", Colors.profileThemeId,
@@ -482,7 +482,7 @@ public class MainActivity extends ProfileThemedActivity implements FabManager.Fa
         Logger.debug(TAG, "account filter changed, reloading transactions");
 //                     mainModel.scheduleTransactionListReload();
         LiveData<List<TransactionWithAccounts>> transactions =
-                new MutableLiveData<>(new ArrayList<TransactionWithAccounts>());
+                new MutableLiveData<>(new ArrayList<>());
         if (profile != null) {
             if (accFilter == null || accFilter.isEmpty()) {
                 transactions = DB.get()
@@ -773,7 +773,7 @@ public class MainActivity extends ProfileThemedActivity implements FabManager.Fa
         }
         @Override
         public void run() {
-            TransactionAccumulator accumulator = new TransactionAccumulator(accFilter);
+            TransactionAccumulator accumulator = new TransactionAccumulator(accFilter, accFilter);
 
             for (TransactionWithAccounts tr : list) {
                 if (isInterrupted()) {