]> git.ktnx.net Git - mobile-ledger.git/commitdiff
rework account symmary activity using linear layouts
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 8 Dec 2018 07:40:33 +0000 (07:40 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 8 Dec 2018 07:40:33 +0000 (07:40 +0000)
tables are so 20th century and perhaps a bit slower

app/src/main/java/net/ktnx/mobileledger/AccountSummary.java
app/src/main/res/layout/content_account_summary.xml
app/src/main/res/values/styles.xml

index 25ba031733ddfad25c1374504a76c7cdc4c5671d..2b05c1b3b2559435208dc6455c4db3b1d4b6e67a 100644 (file)
@@ -25,8 +25,6 @@ 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;
 
@@ -43,7 +41,7 @@ public class AccountSummary extends AppCompatActivity {
 
     private static long account_list_last_updated;
     private static boolean account_list_needs_update = true;
-    private TableRow clickedAccountRow;
+    private LinearLayout clickedAccountRow;
 
     public static void preferences_changed() {
         account_list_needs_update = true;
@@ -107,7 +105,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;
     }
 
@@ -154,7 +152,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);
@@ -176,7 +174,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));
@@ -227,7 +225,7 @@ public class AccountSummary extends AppCompatActivity {
         View.OnCreateContextMenuListener ccml = new View.OnCreateContextMenuListener() {
             @Override
             public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
-                clickedAccountRow = (TableRow) v;
+                clickedAccountRow = (LinearLayout) v;
                 getMenuInflater().inflate(R.menu.account_summary_account_menu, menu);
             }
         };
@@ -237,9 +235,8 @@ public class AccountSummary extends AppCompatActivity {
             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(3), getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), dp2px(4));
                 if (even)
@@ -250,7 +247,8 @@ public class AccountSummary extends AppCompatActivity {
 
 
                 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);
@@ -258,10 +256,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()) {
@@ -275,9 +274,7 @@ public class AccountSummary extends AppCompatActivity {
 
                 r.addView(amt_tv);
 
-                t.addView(r);
-
-                root.addView(t);
+                root.addView(r);
             }
         }
     }
index 30a1d60f23b0b0c5d532c7ae040b9a9adbd065aa..c30125ee74c0dd9819ed49755348cbfc000e2357 100644 (file)
             android:layout_height="wrap_content"
             android:orientation="vertical">
 
-            <TableLayout style="@style/account_summary_account_entry_table">
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:gravity="center_vertical"
+                android:orientation="horizontal">
 
-                <TableRow
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent"
-                    android:background="@color/table_row_even_bg"
-                    android:gravity="center"
-                    android:paddingStart="@dimen/activity_horizontal_margin"
-                    android:paddingEnd="@dimen/activity_horizontal_margin">
+                <TextView
+                    android:id="@+id/textView"
+                    style="@style/account_summary_account_name"
+                    android:text="Account name, a really long one. A very very very long one. It may even spawn on more than two lines -- three, four or more." />
 
-                    <TextView
-                        android:id="@+id/textView"
-                        style="@style/account_summary_account_name"
-                        android:text="TextView" />
+                <TextView
+                    android:id="@+id/textView2"
+                    style="@style/account_summary_amounts"
+                    android:text="123,45\n678,90" />
+            </LinearLayout>
 
-                    <TextView
-                        android:id="@+id/textView2"
-                        style="@style/account_summary_amounts"
-                        android:text="123,45\n678,90" />
-                </TableRow>
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:gravity="center_vertical"
+                android:orientation="horizontal">
+
+                <TextView
+                    android:id="@+id/textView3"
+                    style="@style/account_summary_account_name"
+                    android:text="TextView" />
+
+                <TextView
+                    android:id="@+id/textView4"
+                    style="@style/account_summary_amounts"
+                    android:text="123,45\n678,90" />
+
+            </LinearLayout>
 
-            </TableLayout>
         </LinearLayout>
     </ScrollView>
 
index e08c79c2141082426bbecfa97e225f96534ebcab..7d26c558cea1a639ab6111f9a5b3aaa809baea0e 100644 (file)
@@ -28,9 +28,9 @@
     </style>
 
     <style name="account_summary_account_name">
-        <item name="android:layout_width">match_parent</item>
+        <item name="android:layout_width">wrap_content</item>
         <item name="android:layout_height">wrap_content</item>
-        <item name="android:layout_weight">9</item>
+        <item name="android:layout_weight">5</item>
     </style>
 
     <style name="account_summary_amounts">
@@ -38,8 +38,7 @@
         <item name="android:layout_height">wrap_content</item>
         <item name="android:layout_marginEnd">0dp</item>
         <item name="android:layout_weight">1</item>
-        <item name="android:width">0dp</item>
-        <item name="android:minWidth">40dp</item>
+        <item name="android:minWidth">60dp</item>
         <item name="android:textAlignment">viewEnd</item>
     </style>