X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2FAccountSummary.java;h=dedc1005649fa6872b860029ea3d65c0b9459f62;hp=0885b0903ac1c7e14eb2639a2de58b7a987c59f8;hb=017a2f0a73f4fe28ba170bb6d6e5827b426727e3;hpb=6ad340af404bd6ffc6eb524894ca0f11f0ee6acf diff --git a/app/src/main/java/net/ktnx/mobileledger/AccountSummary.java b/app/src/main/java/net/ktnx/mobileledger/AccountSummary.java index 0885b090..dedc1005 100644 --- a/app/src/main/java/net/ktnx/mobileledger/AccountSummary.java +++ b/app/src/main/java/net/ktnx/mobileledger/AccountSummary.java @@ -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; @@ -24,9 +25,8 @@ import android.view.ViewGroup; import android.widget.EditText; import android.widget.LinearLayout; 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 +41,8 @@ public class AccountSummary extends AppCompatActivity { private static long account_list_last_updated; private static boolean account_list_needs_update = true; + private LinearLayout clickedAccountRow; + public static void preferences_changed() { account_list_needs_update = true; } @@ -73,9 +75,34 @@ public class AccountSummary extends AppCompatActivity { update_accounts(false); } + @Override + protected void onStart() { + super.onStart(); + LinearLayout grp = drawer.findViewById(R.id.nav_actions); + for (int i = 0; i < grp.getChildCount(); i++) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + grp.getChildAt(i).setBackgroundColor( + getResources().getColor(R.color.drawer_background, getTheme())); + } + else { + grp.getChildAt(i) + .setBackgroundColor(getResources().getColor(R.color.drawer_background)); + } + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + drawer.findViewById(R.id.nav_account_summary).setBackgroundColor( + getResources().getColor(R.color.table_row_even_bg, getTheme())); + } + else { + drawer.findViewById(R.id.nav_account_summary) + .setBackgroundColor(getResources().getColor(R.color.table_row_even_bg)); + } + } + public void fab_new_transaction_clicked(View view) { Intent intent = new Intent(this, NewTransactionActivity.class); startActivity(intent); + overridePendingTransition(R.anim.slide_in_right, R.anim.dummy); } public void nav_exit_clicked(View view) { @@ -103,7 +130,7 @@ public class AccountSummary extends AppCompatActivity { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.account_summary, menu); mRefresh = menu.findItem(R.id.menu_acc_summary_refresh); - assert mRefresh != null; + if (mRefresh == null) throw new AssertionError(); return true; } @@ -131,11 +158,10 @@ public class AccountSummary extends AppCompatActivity { MobileLedgerDB.setDb_filename(this.getApplicationInfo().deviceProtectedDataDir + "/" + MobileLedgerDB.DATABASE_NAME); } else { - MobileLedgerDB.setDb_filename(MobileLedgerDB.DATABASE_NAME); + MobileLedgerDB.setDb_filename( + this.getApplicationInfo().dataDir + "/" + MobileLedgerDB.DATABASE_NAME); } - MobileLedgerDB.initDB(); - - MobileLedgerDB.applyRevisions(getResources(), getPackageName()); + MobileLedgerDB.initDB(getResources(), getPackageName()); account_list_last_updated = MobileLedgerDB.get_option_value("last_refresh", (long) 0); @@ -150,7 +176,7 @@ public class AccountSummary extends AppCompatActivity { } private void update_accounts() { - mRefresh.setVisible(false); + if (mRefresh != null) mRefresh.setVisible(false); Resources rm = getResources(); ProgressBar pb = findViewById(R.id.progressBar); @@ -172,7 +198,7 @@ public class AccountSummary extends AppCompatActivity { protected void onPostExecute(Void result) { pb.setVisibility(GONE); pt.setVisibility(GONE); - mRefresh.setVisible(true); + if (mRefresh != null) mRefresh.setVisible(true); if (this.error != 0) { String err_text = rm.getString(this.error); Log.d("visual", String.format("showing snackbar: %s", err_text)); @@ -210,28 +236,52 @@ 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 = (LinearLayout) 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; while (cursor.moveToNext()) { String acc_name = cursor.getString(0); - TableLayout t = new TableLayout(this); - TableRow r = new TableRow(this); - r.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + LinearLayout r = new LinearLayout(this); + r.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); 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)); - if (even) - r.setBackgroundColor(getResources().getColor(R.color.table_row_even_bg, getTheme())); + r.setPadding(getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), dp2px(3), getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), dp2px(4)); + if (even) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + r.setBackgroundColor( + getResources().getColor(R.color.table_row_even_bg, getTheme())); + } + else { + r.setBackgroundColor(getResources().getColor(R.color.table_row_even_bg)); + } + } even = !even; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + 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)); + acc_tv.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, 5f)); + acc_tv.setGravity(Gravity.CENTER_VERTICAL); int[] indent_level = new int[]{0}; String short_acc_name = strip_higher_accounts(acc_name, indent_level); acc_tv.setPadding(indent_level[0] * getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin) / 2, 0, 0, 0); @@ -239,10 +289,11 @@ public class AccountSummary extends AppCompatActivity { r.addView(acc_tv); TextView amt_tv = new TextView(this, null, R.style.account_summary_amounts); - amt_tv.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, 1f)); + amt_tv.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT, 1f)); amt_tv.setTextAlignment(EditText.TEXT_ALIGNMENT_VIEW_END); - amt_tv.setGravity(Gravity.CENTER); - amt_tv.setMinWidth(dp2px(40f)); + amt_tv.setGravity(Gravity.CENTER_VERTICAL); +// amt_tv.setGravity(Gravity.CENTER); + amt_tv.setMinWidth(dp2px(60f)); StringBuilder amt_text = new StringBuilder(); try (Cursor cAmounts = db.rawQuery("SELECT currency, value FROM account_values WHERE account = ?", new String[]{acc_name})) { while (cAmounts.moveToNext()) { @@ -256,9 +307,7 @@ public class AccountSummary extends AppCompatActivity { r.addView(amt_tv); - t.addView(r); - - root.addView(t); + root.addView(r); } } }