From: Damyan Ivanov Date: Sun, 31 Mar 2024 11:13:26 +0000 (+0300) Subject: more pronounced day/month delimiters in the transaction list X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=commitdiff_plain;h=HEAD;hp=8f07a6715eb45406651ce5afcb3253ee577d688a more pronounced day/month delimiters in the transaction list --- diff --git a/CHANGES.md b/CHANGES.md index e8b5efc7..02f84284 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,12 @@ # Changes +## [0.21.7] = 2024-03-19 + +* FIXES: + + allow user certificates in network security config +* OTHERS: + + bump gradle version + ## [0.21.6] - 2023-06-20 * FIXES diff --git a/app/build.gradle b/app/build.gradle index 7b29013a..71673f6e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -24,8 +24,8 @@ android { minSdkVersion 22 targetSdkVersion 31 vectorDrawables.useSupportLibrary true - versionCode 55 - versionName '0.21.6' + versionCode 56 + versionName '0.21.7' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" javaCompileOptions { annotationProcessorOptions { diff --git a/app/src/main/java/net/ktnx/mobileledger/dao/AccountDAO.java b/app/src/main/java/net/ktnx/mobileledger/dao/AccountDAO.java index 0c581787..5ad4c90f 100644 --- a/app/src/main/java/net/ktnx/mobileledger/dao/AccountDAO.java +++ b/app/src/main/java/net/ktnx/mobileledger/dao/AccountDAO.java @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Damyan Ivanov. + * Copyright © 2024 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -78,12 +78,19 @@ public abstract class AccountDAO extends BaseDAO { @Query("DELETE FROM accounts") public abstract void deleteAllSync(); - @Query("SELECT * FROM accounts WHERE profile_id=:profileId ORDER BY name") - public abstract LiveData> getAll(long profileId); + @Query("SELECT * FROM accounts WHERE profile_id=:profileId AND IIF(:includeZeroBalances=1, 1," + + " (EXISTS(SELECT 1 FROM account_values av WHERE av.account_id=accounts.id AND av.value" + + " <> 0) OR EXISTS(SELECT 1 FROM accounts a WHERE a.parent_name = accounts.name))) " + + "ORDER BY name") + public abstract LiveData> getAll(long profileId, boolean includeZeroBalances); @Transaction - @Query("SELECT * FROM accounts WHERE profile_id = :profileId ORDER BY name") - public abstract LiveData> getAllWithAmounts(long profileId); + @Query("SELECT * FROM accounts WHERE profile_id = :profileId AND IIF(:includeZeroBalances=1, " + + "1, (EXISTS(SELECT 1 FROM account_values av WHERE av.account_id=accounts.id AND av" + + ".value <> 0) OR EXISTS(SELECT 1 FROM accounts a WHERE a.parent_name = accounts.name))" + + ") ORDER BY name") + public abstract LiveData> getAllWithAmounts(long profileId, + boolean includeZeroBalances); @Query("SELECT * FROM accounts WHERE id=:id") public abstract Account getByIdSync(long id); diff --git a/app/src/main/java/net/ktnx/mobileledger/model/AccountListItem.java b/app/src/main/java/net/ktnx/mobileledger/model/AccountListItem.java index dfd3d982..807e93d3 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/AccountListItem.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/AccountListItem.java @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Damyan Ivanov. + * Copyright © 2024 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -34,12 +34,19 @@ public abstract class AccountListItem { else throw new RuntimeException("Unsupported sub-class " + this); } - @NotNull - public LedgerAccount getAccount() { - if (this instanceof Account) - return ((Account) this).account; - - throw new IllegalStateException(String.format("Item type is not Account, but %s", this)); + public boolean isAccount() { + return this instanceof Account; + } + public Account toAccount() { + assert isAccount(); + return ((Account) this); + } + public boolean isHeader() { + return this instanceof Header; + } + public Header toHeader() { + assert isHeader(); + return ((Header) this); } public enum Type {ACCOUNT, HEADER} @@ -59,6 +66,13 @@ public abstract class AccountListItem { ((Account) other).account.getAmountsString() .equals(account.getAmountsString()); } + @NotNull + public LedgerAccount getAccount() { + return account; + } + public boolean allAmountsAreZero() { + return account.allAmountsAreZero(); + } } public static class Header extends AccountListItem { diff --git a/app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java b/app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java index 1be684cf..c2e62772 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/LedgerAccount.java @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Damyan Ivanov. + * Copyright © 2024 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -201,13 +201,21 @@ public class LedgerAccount { if (amounts != null) amounts.clear(); } - public boolean amountsExpanded() { return amountsExpanded; } - public void setAmountsExpanded(boolean flag) { amountsExpanded = flag; } - public void toggleAmountsExpanded() { amountsExpanded = !amountsExpanded; } + public boolean amountsExpanded() {return amountsExpanded;} + public void setAmountsExpanded(boolean flag) {amountsExpanded = flag;} + public void toggleAmountsExpanded() {amountsExpanded = !amountsExpanded;} public void propagateAmountsTo(LedgerAccount acc) { for (LedgerAmount a : amounts) a.propagateToAccount(acc); } + public boolean allAmountsAreZero() { + for (LedgerAmount a : amounts) { + if (a.getAmount() != 0) + return false; + } + + return true; + } public List getAmounts() { return amounts; } 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 329109fd..a8b957dc 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/MainModel.java @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Damyan Ivanov. + * Copyright © 2024 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -38,6 +38,7 @@ import java.util.Locale; public class MainModel extends ViewModel { public final MutableLiveData foundTransactionItemIndex = new MutableLiveData<>(null); private final MutableLiveData updatingFlag = new MutableLiveData<>(false); + private final MutableLiveData showZeroBalanceAccounts = new MutableLiveData<>(true); private final MutableLiveData accountFilter = new MutableLiveData<>(null); private final MutableLiveData> displayedTransactions = new MutableLiveData<>(new ArrayList<>()); @@ -45,7 +46,6 @@ public class MainModel extends ViewModel { private SimpleDate firstTransactionDate; private SimpleDate lastTransactionDate; transient private RetrieveTransactionsTask retrieveTransactionsTask; - transient private Thread displayedAccountsUpdater; private TransactionsDisplayedFilter displayedTransactionsUpdater; public LiveData getUpdatingFlag() { return updatingFlag; @@ -66,6 +66,7 @@ public class MainModel extends ViewModel { public void setFirstTransactionDate(SimpleDate earliestDate) { this.firstTransactionDate = earliestDate; } + public MutableLiveData getShowZeroBalanceAccounts() {return showZeroBalanceAccounts;} public MutableLiveData getAccountFilter() { return accountFilter; } @@ -81,6 +82,7 @@ public class MainModel extends ViewModel { return; } Profile profile = Data.getProfile(); + assert profile != null; retrieveTransactionsTask = new RetrieveTransactionsTask(profile); Logger.debug("db", "Created a background transaction retrieval task"); 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 d7da335d..dcc16f36 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 @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Damyan Ivanov. + * Copyright © 2024 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -17,6 +17,8 @@ package net.ktnx.mobileledger.ui.account_summary; +import static net.ktnx.mobileledger.utils.Logger.debug; + import android.content.res.Resources; import android.view.LayoutInflater; import android.view.View; @@ -48,8 +50,6 @@ import org.jetbrains.annotations.NotNull; import java.util.List; import java.util.Locale; -import static net.ktnx.mobileledger.utils.Logger.debug; - public class AccountSummaryAdapter extends RecyclerView.Adapter { public static final int AMOUNT_LIMIT = 3; private static final int ITEM_TYPE_HEADER = 1; @@ -66,8 +66,10 @@ public class AccountSummaryAdapter extends RecyclerView.Adapter payloads) { - LedgerAccount acc = item.getAccount(); + LedgerAccount acc = item.toAccount() + .getAccount(); Change changes = new Change(); if (payloads != null) { diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java index 35a9edb7..807c16da 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Damyan Ivanov. + * Copyright © 2024 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -17,9 +17,14 @@ package net.ktnx.mobileledger.ui.account_summary; +import static net.ktnx.mobileledger.utils.Logger.debug; + import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -31,6 +36,7 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; +import net.ktnx.mobileledger.R; import net.ktnx.mobileledger.async.GeneralBackgroundTasks; import net.ktnx.mobileledger.databinding.AccountSummaryFragmentBinding; import net.ktnx.mobileledger.db.AccountWithAmounts; @@ -51,11 +57,11 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import static net.ktnx.mobileledger.utils.Logger.debug; - public class AccountSummaryFragment extends MobileLedgerListFragment { public AccountSummaryAdapter modelAdapter; private AccountSummaryFragmentBinding b; + private MenuItem menuShowZeroBalances; + private MainModel model; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -82,7 +88,7 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { debug("flow", "AccountSummaryFragment.onActivityCreated()"); super.onViewCreated(view, savedInstanceState); - MainModel model = new ViewModelProvider(requireActivity()).get(MainModel.class); + model = new ViewModelProvider(requireActivity()).get(MainModel.class); Data.backgroundTasksRunning.observe(this.getViewLifecycleOwner(), this::onBackgroundTaskRunningChanged); @@ -109,15 +115,40 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { model.scheduleTransactionListRetrieval(); }); - Data.observeProfile(this, this::onProfileChanged); + Data.observeProfile(this, profile -> onProfileChanged(profile, Boolean.TRUE.equals( + model.getShowZeroBalanceAccounts() + .getValue()))); + } + @Override + public void onCreateOptionsMenu(@NotNull Menu menu, @NotNull MenuInflater inflater) { + inflater.inflate(R.menu.account_list, menu); + + menuShowZeroBalances = menu.findItem(R.id.menu_account_list_show_zero_balances); + if ((menuShowZeroBalances == null)) + throw new AssertionError(); + + menuShowZeroBalances.setOnMenuItemClickListener(menuItem -> { + model.getShowZeroBalanceAccounts() + .setValue(Boolean.FALSE.equals(model.getShowZeroBalanceAccounts() + .getValue())); + return true; + }); + + model.getShowZeroBalanceAccounts() + .observe(this, v -> { + menuShowZeroBalances.setChecked(v); + onProfileChanged(Data.getProfile(), v); + }); + + super.onCreateOptionsMenu(menu, inflater); } - private void onProfileChanged(Profile profile) { + private void onProfileChanged(Profile profile, boolean showZeroBalanceAccounts) { if (profile == null) return; DB.get() .getAccountDAO() - .getAllWithAmounts(profile.getId()) + .getAllWithAmounts(profile.getId(), showZeroBalanceAccounts) .observe(getViewLifecycleOwner(), list -> GeneralBackgroundTasks.run(() -> { List adapterList = new ArrayList<>(); adapterList.add(new AccountListItem.Header(Data.lastAccountsUpdateText)); @@ -134,8 +165,57 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { adapterList.add(new AccountListItem.Account(account)); accMap.put(dbAcc.account.getName(), account); } + + if (!showZeroBalanceAccounts) { + removeZeroAccounts(adapterList); + } modelAdapter.setAccounts(adapterList); Data.lastUpdateAccountCount.postValue(adapterList.size() - 1); })); } + private void removeZeroAccounts(List list) { + boolean removed = true; + + while (removed) { + AccountListItem last = null; + removed = false; + List newList = new ArrayList<>(); + + for (AccountListItem item : list) { + if (last == null) { + last = item; + continue; + } + + if (!last.isAccount() || !last.toAccount() + .allAmountsAreZero() || last.toAccount() + .getAccount() + .isParentOf( + item.toAccount() + .getAccount())) + { + newList.add(last); + } + else { + removed = true; + } + + last = item; + } + + if (last != null) { + if (!last.isAccount() || !last.toAccount() + .allAmountsAreZero()) + { + newList.add(last); + } + else { + removed = true; + } + } + + list.clear(); + list.addAll(newList); + } + } } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListDelimiterRowHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListDelimiterRowHolder.java index 390b4941..b5fe883d 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListDelimiterRowHolder.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListDelimiterRowHolder.java @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Damyan Ivanov. + * Copyright © 2024 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -19,9 +19,12 @@ package net.ktnx.mobileledger.ui.transaction_list; import android.view.View; +import androidx.constraintlayout.widget.ConstraintLayout; + import net.ktnx.mobileledger.App; import net.ktnx.mobileledger.databinding.TransactionDelimiterBinding; import net.ktnx.mobileledger.model.TransactionListItem; +import net.ktnx.mobileledger.utils.DimensionUtils; import net.ktnx.mobileledger.utils.Globals; import net.ktnx.mobileledger.utils.SimpleDate; @@ -46,15 +49,21 @@ class TransactionListDelimiterRowHolder extends TransactionRowHolderBase { b.transactionDelimiterMonth.setText( Globals.monthNames[cal.get(GregorianCalendar.MONTH)]); b.transactionDelimiterMonth.setVisibility(View.VISIBLE); - // holder.vDelimiterLine.setBackgroundResource(R.drawable - // .dashed_border_8dp); b.transactionDelimiterThick.setVisibility(View.VISIBLE); + ConstraintLayout.LayoutParams lp = + (ConstraintLayout.LayoutParams) b.transactionDelimiterThick.getLayoutParams(); + lp.height = DimensionUtils.dp2px(b.getRoot() + .getContext(), 4); + b.transactionDelimiterThick.setLayoutParams(lp); } else { b.transactionDelimiterMonth.setVisibility(View.GONE); - // holder.vDelimiterLine.setBackgroundResource(R.drawable - // .dashed_border_1dp); - b.transactionDelimiterThick.setVisibility(View.GONE); + ConstraintLayout.LayoutParams lp = + (ConstraintLayout.LayoutParams) b.transactionDelimiterThick.getLayoutParams(); + lp.height = DimensionUtils.dp2px(b.getRoot() + .getContext(), 1.3f); + b.transactionDelimiterThick.setLayoutParams(lp); + b.transactionDelimiterThick.setVisibility(View.VISIBLE); } } diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/Colors.java b/app/src/main/java/net/ktnx/mobileledger/utils/Colors.java index 7cf710ac..348a5598 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/Colors.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/Colors.java @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Damyan Ivanov. + * Copyright © 2024 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -17,6 +17,8 @@ package net.ktnx.mobileledger.utils; +import static net.ktnx.mobileledger.utils.Logger.debug; + import android.app.Activity; import android.content.res.ColorStateList; import android.content.res.Resources; @@ -38,8 +40,6 @@ import java.util.List; import java.util.Locale; import java.util.Objects; -import static net.ktnx.mobileledger.utils.Logger.debug; - public class Colors { public static final int DEFAULT_HUE_DEG = 261; public static final MutableLiveData themeWatch = new MutableLiveData<>(0); @@ -76,7 +76,7 @@ public class Colors { TypedValue tv = new TypedValue(); theme.resolveAttribute(R.attr.table_row_dark_bg, tv, true); tableRowDarkBG = tv.data; - theme.resolveAttribute(R.attr.colorPrimary, tv, true); + theme.resolveAttribute(androidx.appcompat.R.attr.colorPrimary, tv, true); primary = tv.data; if (themePrimaryColor.size() == 0) { @@ -84,7 +84,7 @@ public class Colors { Resources.Theme tmpTheme = theme.getResources() .newTheme(); tmpTheme.applyStyle(themeId, true); - tmpTheme.resolveAttribute(R.attr.colorPrimary, tv, false); + tmpTheme.resolveAttribute(androidx.appcompat.R.attr.colorPrimary, tv, false); themePrimaryColor.put(themeId, tv.data); } } @@ -180,7 +180,7 @@ public class Colors { huesSB.append(", "); huesSB.append(h); } - debug("profiles", String.format("used hues: %s", huesSB.toString())); + debug("profiles", String.format("used hues: %s", huesSB)); } hues.add(hues.get(0)); diff --git a/app/src/main/res/menu/account_list.xml b/app/src/main/res/menu/account_list.xml new file mode 100644 index 00000000..5a761610 --- /dev/null +++ b/app/src/main/res/menu/account_list.xml @@ -0,0 +1,32 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index 4ba6fe38..ccb47516 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -1,6 +1,6 @@