]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
use Colors.* for run-time color control
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / activity / MainActivity.java
index 0fe1402687540ce20327e5e82cd22fcb8cfbeec1..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;
@@ -30,7 +31,6 @@ import android.support.v4.view.GravityCompat;
 import android.support.v4.view.ViewPager;
 import android.support.v4.widget.DrawerLayout;
 import android.support.v7.app.ActionBarDrawerToggle;
-import android.support.v7.app.AppCompatActivity;
 import android.support.v7.widget.Toolbar;
 import android.util.Log;
 import android.view.View;
@@ -47,13 +47,14 @@ 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;
 import java.text.DateFormat;
 import java.util.Date;
 
-public class MainActivity extends AppCompatActivity {
+public class MainActivity extends CrashReportingActivity {
     DrawerLayout drawer;
     private FragmentManager fragmentManager;
     private TextView tvLastUpdate;
@@ -226,20 +227,13 @@ 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_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);
             }
         }
     }
@@ -341,6 +335,8 @@ public class MainActivity extends AppCompatActivity {
         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);
@@ -396,6 +392,6 @@ public class MainActivity extends AppCompatActivity {
     }
     public void fabShouldShow() {
         MobileLedgerProfile profile = Data.profile.get();
-        if (profile.isPostingPermitted()) fab.show();
+        if ((profile != null) && profile.isPostingPermitted()) fab.show();
     }
 }