From: Damyan Ivanov Date: Sat, 19 Sep 2020 14:47:26 +0000 (+0300) Subject: show the number of accounts in the account list head item X-Git-Tag: v0.15.0~9 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=a70ab69ce240fe26b46da00236f2f41844e7392a;p=mobile-ledger.git show the number of accounts in the account list head item --- diff --git a/app/src/main/java/net/ktnx/mobileledger/model/Data.java b/app/src/main/java/net/ktnx/mobileledger/model/Data.java index 6d51287f..0bd50ebb 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/Data.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/Data.java @@ -59,7 +59,10 @@ public final class Data { public static final MutableLiveData lastUpdateDate = new MutableLiveData<>(null); public static final MutableLiveData lastUpdateTransactionCount = new MutableLiveData<>(0); - public static final ObservableValue lastUpdateText = new ObservableValue<>(); + public static final MutableLiveData lastUpdateAccountCount = new MutableLiveData<>(0); + public static final ObservableValue lastTransactionsUpdateText = + new ObservableValue<>(); + public static final ObservableValue lastAccountsUpdateText = new ObservableValue<>(); private static final MutableLiveData profile = new InertMutableLiveData<>(); private static final AtomicInteger backgroundTaskCount = new AtomicInteger(0); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java b/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java index 4d232319..5ca0e0be 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java @@ -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"); } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java index cc6cff18..6faa82a7 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java @@ -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) { diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index 03617c59..3b440951 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -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"); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java index d9f4cf16..ff84c36e 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java @@ -166,7 +166,7 @@ public class TransactionListAdapter extends RecyclerView.Adapter 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) { diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 193a9fae..01ca5802 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -155,4 +155,5 @@ Затваряне на страничния панел Заглавна част на страничния панел %,d движения към %s + %,d сметки към %s diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9272c86a..2778846e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -165,4 +165,5 @@ Main app icon Sub-accounts expand/collapse trigger %,d transactions as of %s + %,d accounts as of %s