]> git.ktnx.net Git - mobile-ledger.git/commitdiff
fix transaction colouring to ignore delimiter items
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 12 Jan 2019 14:34:41 +0000 (14:34 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 12 Jan 2019 14:34:41 +0000 (14:34 +0000)
app/src/main/java/net/ktnx/mobileledger/MobileLedgerApplication.java
app/src/main/java/net/ktnx/mobileledger/async/UpdateTransactionsTask.java
app/src/main/java/net/ktnx/mobileledger/model/TransactionListItem.java
app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryViewModel.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListAdapter.java
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionLoaderStep.java
app/src/main/java/net/ktnx/mobileledger/utils/Globals.java
app/src/main/res/values/colors.xml

index 804575b4e33a7876c1e1af76163d59d6657f776b..6550765b3beb9e235137981b426a62a56ec1f37d 100644 (file)
@@ -64,14 +64,14 @@ public class MobileLedgerApplication extends Application {
         Resources rm = getResources();
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
             Resources.Theme theme = getTheme();
-            Globals.tableRowOddBG = rm.getColor(R.color.table_row_odd_bg, theme);
-            Globals.tableRowEvenBG = rm.getColor(R.color.table_row_even_bg, theme);
+            Globals.tableRowDarkBG = rm.getColor(R.color.table_row_dark_bg, theme);
+            Globals.tableRowLightBG = rm.getColor(R.color.table_row_light_bg, theme);
             Globals.primaryDark = rm.getColor(R.color.design_default_color_primary_dark, theme);
             Globals.defaultTextColor = rm.getColor(android.R.color.tab_indicator_text, theme);
         }
         else {
-            Globals.tableRowOddBG = rm.getColor(R.color.table_row_odd_bg);
-            Globals.tableRowEvenBG = rm.getColor(R.color.table_row_even_bg);
+            Globals.tableRowDarkBG = rm.getColor(R.color.table_row_dark_bg);
+            Globals.tableRowLightBG = rm.getColor(R.color.table_row_light_bg);
             Globals.primaryDark = rm.getColor(R.color.design_default_color_primary_dark);
             Globals.defaultTextColor = rm.getColor(android.R.color.tab_indicator_text);
         }
index b039b115316e17d842d58318564c238640901e62..f58d3e5cae25f8f9a06ea4c8b941a3af40cd0af2 100644 (file)
@@ -60,6 +60,7 @@ public class UpdateTransactionsTask extends AsyncTask<String, Void, List<Transac
             Log.d("UTT", sql);
             SQLiteDatabase db = MLDB.getReadableDatabase();
             Date lastDate = null;
+            boolean odd = true;
             try (Cursor cursor = db.rawQuery(sql, params)) {
                 while (cursor.moveToNext()) {
                     if (isCancelled()) return null;
@@ -76,10 +77,12 @@ public class UpdateTransactionsTask extends AsyncTask<String, Void, List<Transac
                                                                    lastDate.getYear());
                         newList.add(new TransactionListItem(date, showMonth));
                     }
-                    newList.add(new TransactionListItem(new LedgerTransaction(transaction_id)));
+                    newList.add(
+                            new TransactionListItem(new LedgerTransaction(transaction_id), odd));
 //                    Log.d("UTT", String.format("got transaction %d", transaction_id));
 
                     lastDate = date;
+                    odd = !odd;
                 }
                 Data.transactions.set(newList);
                 Log.d("UTT", "transaction list value updated");
index 7694578e8578effd36b9ac9c713b1f771c484c7c..55fe04ac7f224c0603e92c74e328a7a9d35227cc 100644 (file)
@@ -26,14 +26,16 @@ public class TransactionListItem {
     private Date date;
     private boolean monthShown;
     private LedgerTransaction transaction;
+    private boolean odd;
     public TransactionListItem(Date date, boolean monthShown) {
         this.type = Type.DELIMITER;
         this.date = date;
         this.monthShown = monthShown;
     }
-    public TransactionListItem(LedgerTransaction transaction) {
+    public TransactionListItem(LedgerTransaction transaction, boolean isOdd) {
         this.type = Type.TRANSACTION;
         this.transaction = transaction;
+        this.odd = isOdd;
     }
     @NonNull
     public Type getType() {
@@ -48,5 +50,8 @@ public class TransactionListItem {
     public LedgerTransaction getTransaction() {
         return transaction;
     }
+    public boolean isOdd() {
+        return odd;
+    }
     public enum Type {TRANSACTION, DELIMITER}
 }
index 32e719e707d1f8e9bdd95fe91753511421439920..446df6a5cef700da2edb1108768841998a754ef9 100644 (file)
@@ -105,8 +105,8 @@ class AccountSummaryAdapter extends RecyclerView.Adapter<AccountSummaryAdapter.L
 
         if (position % 2 == 0) {
             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) holder.row
-                    .setBackgroundColor(rm.getColor(R.color.table_row_even_bg, ctx.getTheme()));
-            else holder.row.setBackgroundColor(rm.getColor(R.color.table_row_even_bg));
+                    .setBackgroundColor(rm.getColor(R.color.table_row_dark_bg, ctx.getTheme()));
+            else holder.row.setBackgroundColor(rm.getColor(R.color.table_row_dark_bg));
         }
         else {
             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) holder.row
index 07e5cbf0bdcd94c30ab4a5061c115c7a605d6844..e079399eb641e80f9a8bd149f662974d9fa6a5f2 100644 (file)
@@ -234,10 +234,10 @@ public class MainActivity extends AppCompatActivity {
     public void markDrawerItemCurrent(int id) {
         TextView item = drawer.findViewById(id);
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
-            item.setBackgroundColor(getResources().getColor(R.color.table_row_even_bg, getTheme()));
+            item.setBackgroundColor(getResources().getColor(R.color.table_row_dark_bg, getTheme()));
         }
         else {
-            item.setBackgroundColor(getResources().getColor(R.color.table_row_even_bg));
+            item.setBackgroundColor(getResources().getColor(R.color.table_row_dark_bg));
         }
 
         @ColorInt int transparent = getResources().getColor(android.R.color.transparent);
index e265ee4a568505b8422bb36a971a1ee0c8829d97..6c245644d55db2742ca11d5ef7796c31a75d8461 100644 (file)
@@ -63,7 +63,8 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
 //                tr.getAccounts().size()));
 
             TransactionLoader loader = new TransactionLoader();
-            loader.execute(new TransactionLoaderParams(tr, holder, position, boldAccountName));
+            loader.execute(new TransactionLoaderParams(tr, holder, position, boldAccountName,
+                    item.isOdd()));
 
             // WORKAROUND what seems to be a bug in CardHolder somewhere
             // when a view that was previously holding a delimiter is re-purposed
@@ -116,11 +117,12 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
         @Override
         protected Void doInBackground(TransactionLoaderParams... p) {
             LedgerTransaction tr = p[0].transaction;
+            boolean odd = p[0].odd;
 
             SQLiteDatabase db = MLDB.getReadableDatabase();
             tr.loadData(db);
 
-            publishProgress(new TransactionLoaderStep(p[0].holder, p[0].position, tr));
+            publishProgress(new TransactionLoaderStep(p[0].holder, p[0].position, tr, odd));
 
             int rowIndex = 0;
             for (LedgerTransactionAccount acc : tr.getAccounts()) {
@@ -143,12 +145,8 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
                 case HEAD:
                     holder.tvDescription.setText(step.getTransaction().getDescription());
 
-                    if (step.getPosition() % 2 == 0) {
-                        holder.row.setBackgroundColor(Globals.tableRowEvenBG);
-                    }
-                    else {
-                        holder.row.setBackgroundColor(Globals.tableRowOddBG);
-                    }
+                    if (step.isOdd()) holder.row.setBackgroundColor(Globals.tableRowDarkBG);
+                    else holder.row.setBackgroundColor(Globals.tableRowLightBG);
 
                     break;
                 case ACCOUNTS:
@@ -225,12 +223,14 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
         TransactionRowHolder holder;
         int position;
         String boldAccountName;
+        boolean odd;
         TransactionLoaderParams(LedgerTransaction transaction, TransactionRowHolder holder,
-                                int position, String boldAccountName) {
+                                int position, String boldAccountName, boolean odd) {
             this.transaction = transaction;
             this.holder = holder;
             this.position = position;
             this.boldAccountName = boldAccountName;
+            this.odd = odd;
         }
     }
 }
\ No newline at end of file
index e5243584b9037a361d21ed0214b7b89caf80a7cf..c5253169a61ce77bf648d196965f86cf3ba4e326 100644 (file)
@@ -29,12 +29,14 @@ class TransactionLoaderStep {
     private LedgerTransactionAccount account;
     private int accountPosition;
     private String boldAccountName;
+    private boolean odd;
     public TransactionLoaderStep(TransactionRowHolder holder, int position,
-                                 LedgerTransaction transaction) {
+                                 LedgerTransaction transaction, boolean isOdd) {
         this.step = TransactionListAdapter.LoaderStep.HEAD;
         this.holder = holder;
         this.transaction = transaction;
         this.position = position;
+        this.odd = isOdd;
     }
     public TransactionLoaderStep(TransactionRowHolder holder, LedgerTransactionAccount account,
                                  int accountPosition, String boldAccountName) {
@@ -74,4 +76,7 @@ class TransactionLoaderStep {
     public LedgerTransactionAccount getAccount() {
         return account;
     }
+    public boolean isOdd() {
+        return odd;
+    }
 }
index e20e75b9df126b5d23674cc5eb8125d69e03678e..cd3f8741331835a9682710c6cafea6f75730427c 100644 (file)
@@ -30,9 +30,9 @@ import java.util.Locale;
 
 public final class Globals {
     @ColorInt
-    public static int tableRowEvenBG;
+    public static int tableRowLightBG;
     @ColorInt
-    public static int tableRowOddBG;
+    public static int tableRowDarkBG;
     @ColorInt
     public static int primaryDark, defaultTextColor;
     public static String[] monthNames;
index dd8e855853c2e41c6faaaa21075307db386259fa..85b8f48f71b81ee06478ef552d82e2d9145c6b02 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-  ~ Copyright © 2018 Damyan Ivanov.
+  ~ Copyright © 2019 Damyan Ivanov.
   ~ This file is part of Mobile-Ledger.
   ~ Mobile-Ledger is free software: you can distribute it and/or modify it
   ~ under the term of the GNU General Public License as published by
@@ -21,7 +21,7 @@
     <color name="colorPrimaryDark">#42148c</color>
     <color name="colorAccent">#724db6</color>
     <color name="drawer_background">#ffffffff</color>
-    <color name="table_row_even_bg">#286c33d4</color>
-    <color name="table_row_odd_bg">#28ddcbff</color>
+    <color name="table_row_dark_bg">#286c33d4</color>
+    <color name="table_row_light_bg">#28ddcbff</color>
     <color name="header_border">#804a148c</color>
 </resources>