]> git.ktnx.net Git - mobile-ledger.git/commitdiff
rework showing of account's transactions with a context menu
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 28 Mar 2019 17:45:40 +0000 (19:45 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 28 Mar 2019 18:28:55 +0000 (20:28 +0200)
not a common option and the ordinary click on the amounts will be used
to expand large commodity lists

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/res/layout/account_summary_row.xml
app/src/main/res/values-bg/strings.xml
app/src/main/res/values/arrays.xml [new file with mode: 0644]
app/src/main/res/values/strings.xml

index c2ec0e96cf1053d27dca49b0e25292b495d3cab5..bd71fd74d792fed851130202e581af1a5537392a 100644 (file)
@@ -31,9 +31,11 @@ import android.widget.TextView;
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.LedgerAccount;
+import net.ktnx.mobileledger.ui.activity.MainActivity;
 import net.ktnx.mobileledger.utils.LockHolder;
 
 import androidx.annotation.NonNull;
+import androidx.appcompat.app.AlertDialog;
 import androidx.constraintlayout.widget.ConstraintLayout;
 import androidx.recyclerview.widget.RecyclerView;
 
@@ -159,6 +161,8 @@ public class AccountSummaryAdapter
             this.expanderContainer = itemView.findViewById(R.id.account_expander_container);
             this.expander = itemView.findViewById(R.id.account_expander);
 
+            MainActivity activity = (MainActivity) row.getContext();
+
             expanderContainer.addOnLayoutChangeListener(
                     (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
                         int w = right - left;
@@ -169,6 +173,27 @@ public class AccountSummaryAdapter
                         }
                         else v.setPadding(0, 0, 0, 0);
                     });
+
+            itemView.setOnLongClickListener(new View.OnLongClickListener() {
+                @Override
+                public boolean onLongClick(View v) {
+                    AlertDialog.Builder builder = new AlertDialog.Builder(itemView.getContext());
+                    LedgerAccount acc =
+                            (LedgerAccount) v.findViewById(R.id.account_summary_row).getTag();
+                    builder.setTitle(acc.getName());
+                    builder.setItems(R.array.acc_ctx_menu, (dialog, which) -> {
+                        switch(which) {
+                            case 0:
+                                // show transactions
+                                activity.showAccountTransactions(acc);
+                                break;
+                        }
+                        dialog.dismiss();
+                    });
+                    builder.show();
+                    return true;
+                }
+            });
         }
     }
 }
index cd58740e0c9951547ed421dafb82a6ff113f5b22..9f2777b2fa01b24bf0257f1803b3b0ee3c8bc574 100644 (file)
@@ -378,14 +378,18 @@ public class MainActivity extends ProfileThemedActivity {
     public void onLatestTransactionsClicked(View view) {
         drawer.closeDrawers();
 
-        showTransactionsFragment(null);
+        showTransactionsFragment((String) null);
     }
     private void resetFragmentBackStack() {
 //        fragmentManager.popBackStack(0, FragmentManager.POP_BACK_STACK_INCLUSIVE);
     }
-    private void showTransactionsFragment(LedgerAccount account) {
-        if (account != null) TransactionListFragment.accountFilter.set(account.getName());
+    private void showTransactionsFragment(String accName) {
+        TransactionListFragment.accountFilter.set(accName);
+        TransactionListFragment.accountFilter.notifyObservers();
         mViewPager.setCurrentItem(1, true);
+    }
+    private void showTransactionsFragment(LedgerAccount account) {
+        showTransactionsFragment((account == null) ? (String) null : account.getName());
 //        FragmentTransaction ft = fragmentManager.beginTransaction();
 //        if (transactionListFragment == null) {
 //            Log.d("flow", "MainActivity creating TransactionListFragment");
index 257ef6021b8ca29ba5dfa8a50287ccbe50c6e50e..1fb4588c5207dd174bdeb480af0ba7c44ab1a42b 100644 (file)
@@ -23,6 +23,7 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:id="@+id/account_summary_row"
     android:layout_width="match_parent"
+    android:longClickable="true"
     android:layout_height="wrap_content">
 
     <CheckBox
index 9c015e99eccb3635a02bae11c90d036870376ecc..ab4f238da8564dc75f3b5a8829f8d3ddc65f29ef 100644 (file)
@@ -41,7 +41,7 @@
     <string name="action_submit_transaction_title">Запазване</string>
     <string name="account_summary_title">Сметки</string>
     <string name="menu_hide_acc_condensed_title">Скриване</string>
-    <string name="menu_hide_acc_title">Скриване на сметката</string>
+    <string name="menu_acc_view_transactions">Преглед на трансакциите</string>
     <string name="menu_acc_summary_refresh_title">Обновяване</string>
     <string name="err_net_error">Мрежова грешка</string>
     <string name="menu_acc_summary_show_only_starred_title">Показване само на любимите</string>
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
new file mode 100644 (file)
index 0000000..17b6329
--- /dev/null
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+  ~ Copyright © 2019 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
+  ~ the Free Software Foundation, either version 3 of the License, or
+  ~ (at your opinion), any later version.
+  ~
+  ~ MoLe is distributed in the hope that it will be useful,
+  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+  ~ GNU General Public License terms for details.
+  ~
+  ~ You should have received a copy of the GNU General Public License
+  ~ along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+  -->
+
+<resources>
+    <string-array name="acc_ctx_menu">
+        <item>Show transactions</item>
+        <!--<item>Expand all</item>-->
+        <!--<item>Collapse all</item>-->
+    </string-array>
+</resources>
\ No newline at end of file
index c2d25380c4c397cccca6ff9931a1d6ccbaec632b..50b808c8867a97ee7299ad106228e0f6c346ffaf 100644 (file)
@@ -86,7 +86,7 @@
     <string name="action_submit_transaction_title">Save</string>
     <string name="account_summary_title">Accounts</string>
     <string name="menu_acc_summary_refresh_title">Refresh</string>
-    <string name="menu_hide_acc_title">Hide account</string>
+    <string name="menu_acc_view_transactions">View transactions</string>
     <string name="menu_hide_acc_condensed_title">Hide</string>
     <string name="menu_acc_summary_show_only_starred_title">Show only starred</string>
     <string name="err_bad_auth">Invalid username or password</string>