]> git.ktnx.net Git - mobile-ledger.git/commitdiff
show the number of accounts in the account list head item
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 19 Sep 2020 14:47:26 +0000 (17:47 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 19 Sep 2020 14:47:26 +0000 (17:47 +0300)
app/src/main/java/net/ktnx/mobileledger/model/Data.java
app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java
app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionRowHolder.java
app/src/main/res/values-bg/strings.xml
app/src/main/res/values/strings.xml

index 6d51287f35bfa6a74c138a15d4dbb0f83143b818..0bd50ebb771f4338f3851ea8eb9e27258908536d 100644 (file)
@@ -59,7 +59,10 @@ public final class Data {
     public static final MutableLiveData<Date> lastUpdateDate = new MutableLiveData<>(null);
     public static final MutableLiveData<Integer> lastUpdateTransactionCount =
             new MutableLiveData<>(0);
-    public static final ObservableValue<String> lastUpdateText = new ObservableValue<>();
+    public static final MutableLiveData<Integer> lastUpdateAccountCount = new MutableLiveData<>(0);
+    public static final ObservableValue<String> lastTransactionsUpdateText =
+            new ObservableValue<>();
+    public static final ObservableValue<String> lastAccountsUpdateText = new ObservableValue<>();
     private static final MutableLiveData<MobileLedgerProfile> profile =
             new InertMutableLiveData<>();
     private static final AtomicInteger backgroundTaskCount = new AtomicInteger(0);
index 4d232319e0a37bfa6d70230b36d66cbdd28b4b1b..5ca0e0be00c4cc5e05c73751a16be9eaba6e5ebc 100644 (file)
@@ -362,15 +362,20 @@ public class MainModel extends ViewModel {
             Logger.debug("dFilter", String.format(Locale.US,
                     "entered synchronized block (about to examine %d accounts)", list.size()));
             newDisplayed.add(new AccountListItem());    // header
+
+            int count = 0;
             for (LedgerAccount a : list) {
                 if (isInterrupted())
                     return;
 
-                if (a.isVisible())
+                if (a.isVisible()) {
                     newDisplayed.add(new AccountListItem(a));
+                    count++;
+                }
             }
             if (!isInterrupted()) {
                 model.displayedAccounts.postValue(newDisplayed);
+                Data.lastUpdateAccountCount.postValue(count);
             }
             Logger.debug("dFilter", "left synchronized block");
         }
index cc6cff1878a336620ff0df206abf2fc82a1d0d34..6faa82a73b8f271a198fe0eeffcc75c90bd17618 100644 (file)
@@ -256,7 +256,7 @@ public class AccountSummaryAdapter
 
                     break;
                 case HEADER:
-                    setLastUpdateText(Data.lastUpdateText.get());
+                    setLastUpdateText(Data.lastAccountsUpdateText.get());
                     break;
                 default:
                     throw new IllegalStateException("Unexpected value: " + newType);
@@ -270,15 +270,15 @@ public class AccountSummaryAdapter
             if (lastUpdateObserver != null)
                 return;
 
-            lastUpdateObserver = (o, arg) -> setLastUpdateText(Data.lastUpdateText.get());
+            lastUpdateObserver = (o, arg) -> setLastUpdateText(Data.lastAccountsUpdateText.get());
 
-            Data.lastUpdateText.addObserver(lastUpdateObserver);
+            Data.lastAccountsUpdateText.addObserver(lastUpdateObserver);
         }
         private void dropLastUpdateObserver() {
             if (lastUpdateObserver == null)
                 return;
 
-            Data.lastUpdateText.deleteObserver(lastUpdateObserver);
+            Data.lastAccountsUpdateText.deleteObserver(lastUpdateObserver);
             lastUpdateObserver = null;
         }
         private void setType(AccountListItem.Type newType) {
index 03617c5923c8fe9ef1f431bc35c86e13ebc0e2ac..3b44095117ee5ad105bfb45f056cbe1d406049b6 100644 (file)
@@ -336,6 +336,7 @@ public class MainActivity extends ProfileThemedActivity {
         Data.locale.observe(this, l -> refreshLastUpdateInfo());
         Data.lastUpdateDate.observe(this, date -> refreshLastUpdateInfo());
         Data.lastUpdateTransactionCount.observe(this, date -> refreshLastUpdateInfo());
+        Data.lastUpdateAccountCount.observe(this, date -> refreshLastUpdateInfo());
     }
     private void scheduleDataRetrievalIfStale(long lastUpdate) {
         long now = new Date().getTime();
@@ -468,6 +469,7 @@ public class MainActivity extends ProfileThemedActivity {
         Data.removeProfileObservers(this);
         Data.profiles.removeObservers(this);
         Data.lastUpdateTransactionCount.removeObservers(this);
+        Data.lastUpdateAccountCount.removeObservers(this);
         Data.lastUpdateDate.removeObservers(this);
 
         recreate();
@@ -572,13 +574,27 @@ public class MainActivity extends ProfileThemedActivity {
     private void refreshLastUpdateInfo() {
         final int formatFlags = DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_YEAR |
                                 DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_NUMERIC_DATE;
-        String template = getResources().getString(R.string.transaction_count_summary);
+        String templateForTransactions =
+                getResources().getString(R.string.transaction_count_summary);
+        String templateForAccounts = getResources().getString(R.string.account_count_summary);
+        Integer accountCount = Data.lastUpdateAccountCount.getValue();
         Integer transactionCount = Data.lastUpdateTransactionCount.getValue();
         Date lastUpdate = Data.lastUpdateDate.getValue();
-        Data.lastUpdateText.set((lastUpdate == null) ? "----" : String.format(
-                Objects.requireNonNull(Data.locale.getValue()), template,
-                (transactionCount == null) ? 0 : transactionCount,
-                DateUtils.formatDateTime(this, lastUpdate.getTime(), formatFlags)));
+        if (lastUpdate == null) {
+            Data.lastTransactionsUpdateText.set("----");
+            Data.lastAccountsUpdateText.set("----");
+        }
+        else {
+            Data.lastTransactionsUpdateText.set(
+                    String.format(Objects.requireNonNull(Data.locale.getValue()),
+                            templateForTransactions,
+                            transactionCount == null ? 0 : transactionCount,
+                            DateUtils.formatDateTime(this, lastUpdate.getTime(), formatFlags)));
+            Data.lastAccountsUpdateText.set(
+                    String.format(Objects.requireNonNull(Data.locale.getValue()),
+                            templateForAccounts, accountCount == null ? 0 : accountCount,
+                            DateUtils.formatDateTime(this, lastUpdate.getTime(), formatFlags)));
+        }
     }
     public void onStopTransactionRefreshClick(View view) {
         Logger.debug("interactive", "Cancelling transactions refresh");
index d9f4cf16a53a56a465926078af4964925d0d5fdf..ff84c36e5e2e8ba42db52cea1536408e9049f013 100644 (file)
@@ -166,7 +166,7 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
                 }
                 break;
             case HEADER:
-                holder.setLastUpdateText(Data.lastUpdateText.get());
+                holder.setLastUpdateText(Data.lastTransactionsUpdateText.get());
 
                 break;
             default:
index 658a338ae3af30c117dc96052e69690aba59f29d..0d41e19a1f93fa51003e16b29fb4f606a3911719 100644 (file)
@@ -63,9 +63,9 @@ class TransactionRowHolder extends RecyclerView.ViewHolder {
         if (lastUpdateObserver != null)
             return;
 
-        lastUpdateObserver = (o, arg) -> setLastUpdateText(Data.lastUpdateText.get());
+        lastUpdateObserver = (o, arg) -> setLastUpdateText(Data.lastTransactionsUpdateText.get());
 
-        Data.lastUpdateText.addObserver(lastUpdateObserver);
+        Data.lastTransactionsUpdateText.addObserver(lastUpdateObserver);
     }
     void setLastUpdateText(String text) {
         tvLastUpdate.setText(text);
@@ -74,7 +74,7 @@ class TransactionRowHolder extends RecyclerView.ViewHolder {
         if (lastUpdateObserver == null)
             return;
 
-        Data.lastUpdateText.deleteObserver(lastUpdateObserver);
+        Data.lastTransactionsUpdateText.deleteObserver(lastUpdateObserver);
         lastUpdateObserver = null;
     }
     void setType(TransactionListItem.Type newType) {
index 193a9faed85bb318e292ec61e811b8f00eadce79..01ca5802946cc0ad07b65e61e29d5bafa06d4a95 100644 (file)
     <string name="navigation_drawer_close">Затваряне на страничния панел</string>
     <string name="nav_header_desc">Заглавна част на страничния панел</string>
     <string name="transaction_count_summary">%,d движения към %s</string>
+    <string name="account_count_summary">%,d сметки към %s</string>
 </resources>
index 9272c86a0d768b758fce1bddb55ae6bd277cf4ea..2778846e44fa8f9bda559b6b9bf737fd07e7f4bb 100644 (file)
     <string name="splash_icon_description">Main app icon</string>
     <string name="sub_accounts_expand_collapse_trigger_description">Sub-accounts expand/collapse trigger</string>
     <string name="transaction_count_summary">%,d transactions as of %s</string>
+    <string name="account_count_summary">%,d accounts as of %s</string>
 </resources>