X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FMainActivity.java;h=ad5da965d49ed5f11f059eb6eddd309f8c7c9c28;hp=641d296c2d502c28ec81e0de4f71b215031d56a7;hb=3c3ae0a0335f908a43efbfca7ac18e5bbee3ea7c;hpb=b4d5812942fdb2ca89c9f048e539c4c65a8994cf diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index 641d296c..ad5da965 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -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; @@ -104,6 +106,14 @@ public class MainActivity extends CrashReportingActivity { toolbar.setSubtitle(R.string.profile_subitlte_read_only); fab.hide(); } + + int newProfileTheme = profile.getThemeId(); + if (newProfileTheme != Colors.profileThemeId) { + Log.d("profiles", String.format("profile theme %d → %d", Colors.profileThemeId, + newProfileTheme)); + profileThemeChanged(); + Colors.profileThemeId = newProfileTheme; + } }); }); @@ -179,6 +189,14 @@ public class MainActivity extends CrashReportingActivity { findViewById(R.id.btn_add_transaction).setOnClickListener(this::fabNewTransactionClicked); } + private void profileThemeChanged() { + setupProfileColors(); + + // restart activity to reflect theme change + finish(); + Intent intent = new Intent(this, this.getClass()); + startActivity(intent); + } @Override protected void onResume() { super.onResume(); @@ -225,20 +243,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 +351,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);