]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/AccountSummary.java
account summary: account rows with minimum height of an action bar
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / AccountSummary.java
index 7b4d25795e3bce580b013fc90e745fa5d09648d1..d653ced44ed798f4984bafbd59b0668d76226477 100644 (file)
@@ -79,9 +79,24 @@ public class AccountSummary extends AppCompatActivity {
     protected void onStart() {
         super.onStart();
         LinearLayout grp = drawer.findViewById(R.id.nav_actions);
-        for (int i = 0; i < grp.getChildCount(); i++)
-            grp.getChildAt(i).setBackgroundColor(getResources().getColor(R.color.drawer_background, getTheme()));
-        drawer.findViewById(R.id.nav_account_summary).setBackgroundColor(getResources().getColor(R.color.table_row_even_bg, getTheme()));
+        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) {
@@ -124,7 +139,7 @@ public class AccountSummary extends AppCompatActivity {
         // Handle action bar item clicks here. The action bar will
         // automatically handle clicks on the Home/Up button, so long
         // as you specify a parent activity in AndroidManifest.xml.
-        int id = item.getItemId();
+//        int id = item.getItemId();
 
         //noinspection SimplifiableIfStatement
         //if (id == R.id.action_settings) {
@@ -143,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);
 
@@ -240,6 +254,10 @@ public class AccountSummary extends AppCompatActivity {
             }
         };
 
+        int actionBarHeight =
+                getTheme().obtainStyledAttributes(new int[]{android.R.attr.actionBarSize})
+                        .getDimensionPixelSize(0, dp2px(56));
+
         try (Cursor cursor = db.rawQuery("SELECT name FROM accounts ORDER BY name;", null)) {
             boolean even = false;
             while (cursor.moveToNext()) {
@@ -249,10 +267,21 @@ public class AccountSummary extends AppCompatActivity {
                 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(3), getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), dp2px(4));
-                if (even)
-                    r.setBackgroundColor(getResources().getColor(R.color.table_row_even_bg, getTheme()));
+                r.setMinimumHeight(actionBarHeight);
+
+                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;
-                r.setContextClickable(true);
+                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+                    r.setContextClickable(true);
+                }
                 r.setOnCreateContextMenuListener(ccml);