]> git.ktnx.net Git - mobile-ledger.git/commitdiff
use Colors.* for run-time color control
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 17 Feb 2019 20:12:02 +0000 (22:12 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 17 Feb 2019 20:12:02 +0000 (22:12 +0200)
app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryAdapter.java
app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/AppCompatPreferenceActivity.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/CrashReportingActivity.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/TransactionListFragment.java
app/src/main/java/net/ktnx/mobileledger/utils/Globals.java

index da678a6a192d4a628d505b688c10f67474eec884..52b27229dc1d00dcfb4d83561eda8a6f77ea74a9 100644 (file)
@@ -20,7 +20,6 @@ package net.ktnx.mobileledger.ui.account_summary;
 import android.content.Context;
 import android.content.res.Resources;
 import android.graphics.Typeface;
-import android.os.Build;
 import android.support.annotation.NonNull;
 import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
@@ -33,6 +32,7 @@ import android.widget.TextView;
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.model.LedgerAccount;
+import net.ktnx.mobileledger.utils.Colors;
 
 import java.util.List;
 
@@ -68,14 +68,10 @@ 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_dark_bg, ctx.getTheme()));
-                else holder.row.setBackgroundColor(rm.getColor(R.color.table_row_dark_bg));
+                holder.row.setBackgroundColor(Colors.tableRowDarkBG);
             }
             else {
-                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) holder.row
-                        .setBackgroundColor(rm.getColor(R.color.drawer_background, ctx.getTheme()));
-                else holder.row.setBackgroundColor(rm.getColor(R.color.drawer_background));
+                holder.row.setBackgroundColor(Colors.tableRowLightBG);
             }
 
             holder.selectionCb.setVisibility(selectionActive ? View.VISIBLE : View.GONE);
index 2fcfe67f320bb180b453bf3932f1a277a063a2a7..04cde356a6e4096c5899b1e2103462059106d2af 100644 (file)
@@ -40,6 +40,7 @@ import net.ktnx.mobileledger.model.LedgerAccount;
 import net.ktnx.mobileledger.ui.MobileLedgerListFragment;
 import net.ktnx.mobileledger.ui.RecyclerItemListener;
 import net.ktnx.mobileledger.ui.activity.MainActivity;
+import net.ktnx.mobileledger.utils.Colors;
 
 import java.util.List;
 import java.util.Observer;
@@ -152,7 +153,9 @@ public class AccountSummaryFragment extends MobileLedgerListFragment {
             }
         });
         swiper = mActivity.findViewById(R.id.account_swiper);
-        swiper.setColorSchemeResources(R.color.colorPrimary, R.color.colorAccent);
+        Colors.themeWatch.addObserver(
+                (o, arg) -> swiper.setColorSchemeColors(Colors.primary));
+        swiper.setColorSchemeColors(Colors.primary);
         swiper.setOnRefreshListener(() -> {
             Log.d("ui", "refreshing accounts via swipe");
             mActivity.scheduleTransactionListRetrieval();
@@ -160,8 +163,8 @@ public class AccountSummaryFragment extends MobileLedgerListFragment {
 
         Data.accounts.addObserver(
                 (o, arg) -> mActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged()));
-        Data.profile.addObserver(
-                (o, arg) -> mActivity.runOnUiThread(() -> AccountSummaryViewModel.scheduleAccountListReload()));
+        Data.profile.addObserver((o, arg) -> mActivity.runOnUiThread(
+                AccountSummaryViewModel::scheduleAccountListReload));
         update_account_table();
     }
     private void update_account_table() {
index 932607ef320a367130c28fd8ee70dda57df44409..65274dfb36aeec7e0ed2644b21499dd0e48892ff 100644 (file)
@@ -30,6 +30,8 @@ import android.view.MenuInflater;
 import android.view.View;
 import android.view.ViewGroup;
 
+import net.ktnx.mobileledger.utils.Colors;
+
 /**
  * A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
  * to be used with AppCompat.
@@ -43,6 +45,7 @@ public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
         getDelegate().installViewFactory();
         getDelegate().onCreate(savedInstanceState);
         super.onCreate(savedInstanceState);
+        Colors.setupTheme(this);
     }
 
     @Override
index 0d72499d008945dd7f6cd849dc2d668b516181a2..72dec2237577eec92fbc54d2671fbfcb536af53d 100644 (file)
@@ -6,14 +6,24 @@ import android.support.v7.app.AppCompatActivity;
 import android.util.Log;
 
 import net.ktnx.mobileledger.ui.CrashReportDialogFragment;
+import net.ktnx.mobileledger.utils.Colors;
 
 import java.io.PrintWriter;
 import java.io.StringWriter;
 
-public class CrashReportingActivity extends AppCompatActivity {
+public abstract class CrashReportingActivity extends AppCompatActivity {
+    protected void setupProfileColors() {
+        Colors.setupTheme(this);
+    }
+    @Override
+    protected void onStart() {
+        super.onStart();
+        Colors.refreshColors(getTheme());
+    }
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        Colors.setupTheme(this);
 
         Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
             @Override
index 641d296c2d502c28ec81e0de4f71b215031d56a7..a96a0b976d6939a7fbfb8ab5898176afe720729c 100644 (file)
@@ -19,9 +19,10 @@ package net.ktnx.mobileledger.ui.activity;
 
 import android.content.Intent;
 import android.content.pm.PackageInfo;
+import android.content.res.ColorStateList;
+import android.graphics.Color;
 import android.os.Build;
 import android.os.Bundle;
-import android.support.annotation.ColorInt;
 import android.support.design.widget.FloatingActionButton;
 import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
@@ -46,6 +47,7 @@ import net.ktnx.mobileledger.model.LedgerAccount;
 import net.ktnx.mobileledger.model.MobileLedgerProfile;
 import net.ktnx.mobileledger.ui.account_summary.AccountSummaryFragment;
 import net.ktnx.mobileledger.ui.transaction_list.TransactionListFragment;
+import net.ktnx.mobileledger.utils.Colors;
 import net.ktnx.mobileledger.utils.MLDB;
 
 import java.lang.ref.WeakReference;
@@ -225,20 +227,13 @@ public class MainActivity extends CrashReportingActivity {
     }
     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_dark_bg, getTheme()));
-        }
-        else {
-            item.setBackgroundColor(getResources().getColor(R.color.table_row_dark_bg));
-        }
-
-        @ColorInt int transparent = getResources().getColor(android.R.color.transparent);
+        item.setBackgroundColor(Colors.tableRowDarkBG);
 
         LinearLayout actions = drawer.findViewById(R.id.nav_actions);
         for (int i = 0; i < actions.getChildCount(); i++) {
             View view = actions.getChildAt(i);
             if (view.getId() != id) {
-                view.setBackgroundColor(transparent);
+                view.setBackgroundColor(Color.TRANSPARENT);
             }
         }
     }
@@ -340,6 +335,8 @@ public class MainActivity extends CrashReportingActivity {
         else Toast.makeText(this, error, Toast.LENGTH_LONG).show();
     }
     public void onRetrieveStart() {
+        progressBar.setIndeterminateTintList(ColorStateList.valueOf(Colors.primary));
+        progressBar.setProgressTintList(ColorStateList.valueOf(Colors.primary));
         progressBar.setIndeterminate(true);
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) progressBar.setProgress(0, false);
         else progressBar.setProgress(0);
index 0980eacdae14d317f7a9699f284d4819d708101f..6cf729dc9d4bcfe977f2c9284b3ea35906cce967 100644 (file)
@@ -38,6 +38,7 @@ import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.model.LedgerTransaction;
 import net.ktnx.mobileledger.model.LedgerTransactionAccount;
 import net.ktnx.mobileledger.model.TransactionListItem;
+import net.ktnx.mobileledger.utils.Colors;
 import net.ktnx.mobileledger.utils.Globals;
 import net.ktnx.mobileledger.utils.MLDB;
 
@@ -162,8 +163,8 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
                 case HEAD:
                     holder.tvDescription.setText(step.getTransaction().getDescription());
 
-                    if (step.isOdd()) holder.row.setBackgroundColor(Globals.tableRowDarkBG);
-                    else holder.row.setBackgroundColor(Globals.tableRowLightBG);
+                    if (step.isOdd()) holder.row.setBackgroundColor(Colors.tableRowDarkBG);
+                    else holder.row.setBackgroundColor(Colors.tableRowLightBG);
 
                     break;
                 case ACCOUNTS:
@@ -209,8 +210,8 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
                     if ((boldAccountName != null) &&
                         acc.getAccountName().startsWith(boldAccountName))
                     {
-                        accName.setTextColor(Globals.primaryDark);
-                        accAmount.setTextColor(Globals.primaryDark);
+                        accName.setTextColor(Colors.accent);
+                        accAmount.setTextColor(Colors.accent);
 
                         SpannableString ss = new SpannableString(acc.getAccountName());
                         ss.setSpan(new StyleSpan(Typeface.BOLD), 0, boldAccountName.length(),
@@ -218,8 +219,8 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionRowH
                         accName.setText(ss);
                     }
                     else {
-                        accName.setTextColor(Globals.defaultTextColor);
-                        accAmount.setTextColor(Globals.defaultTextColor);
+                        accName.setTextColor(Colors.defaultTextColor);
+                        accAmount.setTextColor(Colors.defaultTextColor);
                         accName.setText(acc.getAccountName());
                     }
                     accAmount.setText(acc.toString());
index 6652120c040ebef49bf72743c38cc62315e1636f..62c4496cccff0aa09807a7965e6aac8c6e956846 100644 (file)
@@ -40,6 +40,7 @@ import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.ui.MobileLedgerListFragment;
 import net.ktnx.mobileledger.ui.activity.MainActivity;
+import net.ktnx.mobileledger.utils.Colors;
 import net.ktnx.mobileledger.utils.Globals;
 import net.ktnx.mobileledger.utils.MLDB;
 import net.ktnx.mobileledger.utils.ObservableValue;
@@ -166,7 +167,9 @@ public class TransactionListFragment extends MobileLedgerListFragment {
             mActivity.scheduleTransactionListRetrieval();
         });
 
-        swiper.setColorSchemeResources(R.color.colorPrimary, R.color.colorAccent);
+        Colors.themeWatch.addObserver(
+                (o, arg) -> swiper.setColorSchemeColors(Colors.primary));
+        swiper.setColorSchemeColors(Colors.primary);
 
         vAccountFilter = mActivity.findViewById(R.id.transaction_list_account_name_filter);
         accNameFilter = mActivity.findViewById(R.id.transaction_filter_account_name);
index 8a2c8366659e76253082e0915626a48c02b539bd..7a9913d8fae9e1a6f41361982e8555f3e11fb942 100644 (file)
@@ -19,7 +19,6 @@ package net.ktnx.mobileledger.utils;
 
 import android.app.Activity;
 import android.content.Context;
-import android.support.annotation.ColorInt;
 import android.view.View;
 import android.view.inputmethod.InputMethodManager;
 
@@ -32,12 +31,6 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 public final class Globals {
-    @ColorInt
-    public static int tableRowLightBG;
-    @ColorInt
-    public static int tableRowDarkBG;
-    @ColorInt
-    public static int primaryDark, defaultTextColor;
     public static String[] monthNames;
     public static String developerEmail = "dam+mole-crash@ktnx.net";
     private static SimpleDateFormat ledgerDateFormatter =