]> git.ktnx.net Git - mobile-ledger.git/commitdiff
Lay the ground for hiding accounts from the summary
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 7 Dec 2018 19:05:03 +0000 (19:05 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 7 Dec 2018 19:05:03 +0000 (19:05 +0000)
hook context menu listener, add menu item to show hidden accounts

app/src/main/java/net/ktnx/mobileledger/AccountSummary.java
app/src/main/res/menu/account_summary.xml
app/src/main/res/values-bg/strings.xml
app/src/main/res/values/strings.xml

index 0885b0903ac1c7e14eb2639a2de58b7a987c59f8..25ba031733ddfad25c1374504a76c7cdc4c5671d 100644 (file)
@@ -16,6 +16,7 @@ import android.support.v7.app.AppCompatActivity;
 import android.support.v7.widget.Toolbar;
 import android.util.Log;
 import android.util.TypedValue;
+import android.view.ContextMenu;
 import android.view.Gravity;
 import android.view.Menu;
 import android.view.MenuItem;
@@ -27,6 +28,7 @@ import android.widget.ProgressBar;
 import android.widget.TableLayout;
 import android.widget.TableRow;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import java.util.Date;
 import java.util.regex.Matcher;
@@ -41,6 +43,8 @@ public class AccountSummary extends AppCompatActivity {
 
     private static long account_list_last_updated;
     private static boolean account_list_needs_update = true;
+    private TableRow clickedAccountRow;
+
     public static void preferences_changed() {
         account_list_needs_update = true;
     }
@@ -210,11 +214,23 @@ public class AccountSummary extends AppCompatActivity {
         return acc_name;
     }
 
+    public void hideAccountClicked(MenuItem item) {
+        TextView textView = (TextView) clickedAccountRow.getChildAt(0);
+        Toast.makeText(this, textView.getText(), Toast.LENGTH_SHORT).show();
+    }
+
     @SuppressLint("DefaultLocale")
     private void update_account_table() {
         LinearLayout root = findViewById(R.id.account_root);
         root.removeAllViewsInLayout();
 
+        View.OnCreateContextMenuListener ccml = new View.OnCreateContextMenuListener() {
+            @Override
+            public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
+                clickedAccountRow = (TableRow) v;
+                getMenuInflater().inflate(R.menu.account_summary_account_menu, menu);
+            }
+        };
 
         try (Cursor cursor = db.rawQuery("SELECT name FROM accounts ORDER BY name;", null)) {
             boolean even = false;
@@ -225,10 +241,13 @@ public class AccountSummary extends AppCompatActivity {
                 TableRow r = new TableRow(this);
                 r.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
                 r.setGravity(Gravity.CENTER_VERTICAL);
-                r.setPadding(getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), dp2px(2), getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), dp2px(4));
+                r.setPadding(getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), dp2px(3), getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), dp2px(4));
                 if (even)
                     r.setBackgroundColor(getResources().getColor(R.color.table_row_even_bg, getTheme()));
                 even = !even;
+                r.setContextClickable(true);
+                r.setOnCreateContextMenuListener(ccml);
+
 
                 TextView acc_tv = new TextView(this, null, R.style.account_summary_account_name);
                 acc_tv.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 9f));
index f416b53da6ce9ef667c4c219cb27d0753ffde7af..9c527466dbc3d5ba629eb7d8da848fe62e2d0423 100644 (file)
@@ -8,4 +8,7 @@
         android:title="@string/menu_acc_summary_refresh_title"
         android:onClick="onRefreshAccountSummaryClicked"
         app:showAsAction="ifRoom" />
+    <item
+        android:id="@+id/menu_acc_summary_show_hidden"
+        android:title="@string/menu_acc_summary_show_hidden_accounts_title" />
 </menu>
\ No newline at end of file
index ab25a3fae3f040cf94032aede645194a17be9b15..1d88ef22188279e75d7a4ee7b1cebfda03e48134 100644 (file)
@@ -25,4 +25,9 @@
     <string name="progress_N_accounts_loaded">Заредени са %d сметки</string>
     <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_summary_refresh_title">Обновяване</string>
+    <string name="err_net_error">Мрежова грешка</string>
+    <string name="menu_acc_summary_show_hidden_accounts_title">Показване на скритите сметки</string>
 </resources>
\ No newline at end of file
index 813ccf059681b928d6ffa3e7bdd6e834c295f974..d15a1134cd93ec61184fb4e5cf43a7b6aaf13077 100644 (file)
@@ -70,4 +70,7 @@
     <string name="action_submit_transaction_title">Save</string>
     <string name="account_summary_title">Account Summary</string>
     <string name="menu_acc_summary_refresh_title">Refresh</string>
+    <string name="menu_hide_acc_title">Hide account</string>
+    <string name="menu_hide_acc_condensed_title">Hide</string>
+    <string name="menu_acc_summary_show_hidden_accounts_title">Show hidden accounts</string>
 </resources>