From: Damyan Ivanov Date: Tue, 16 Apr 2019 17:49:34 +0000 (+0300) Subject: migrate themeWatch to LiveData X-Git-Tag: v0.10.0~107 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=d45a715886c1139da8e8bea91d374abbcffa7af2;p=mobile-ledger.git migrate themeWatch to LiveData --- diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/MobileLedgerListFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/MobileLedgerListFragment.java index 85593a21..ab11d20c 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/MobileLedgerListFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/MobileLedgerListFragment.java @@ -17,16 +17,20 @@ package net.ktnx.mobileledger.ui; -import androidx.fragment.app.Fragment; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; -import androidx.recyclerview.widget.RecyclerView; - import net.ktnx.mobileledger.ui.activity.MainActivity; import net.ktnx.mobileledger.ui.transaction_list.TransactionListAdapter; +import net.ktnx.mobileledger.utils.Colors; + +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.RecyclerView; +import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; public class MobileLedgerListFragment extends Fragment { protected MainActivity mActivity; public SwipeRefreshLayout swiper; protected RecyclerView root; public TransactionListAdapter modelAdapter; + protected void themeChanged(Integer counter) { + swiper.setColorSchemeColors(Colors.primary); + } } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java index 93975b05..94056ab8 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java @@ -158,8 +158,7 @@ public class AccountSummaryFragment extends MobileLedgerListFragment { } }); swiper = mActivity.findViewById(R.id.account_swiper); - Colors.themeWatch.addObserver((o, arg) -> swiper.setColorSchemeColors(Colors.primary)); - swiper.setColorSchemeColors(Colors.primary); + Colors.themeWatch.observe(this, this::themeChanged); swiper.setOnRefreshListener(() -> { Log.d("ui", "refreshing accounts via swipe"); mActivity.scheduleTransactionListRetrieval(); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java index ea57ab7c..12447d26 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java @@ -147,7 +147,7 @@ public class TransactionListFragment extends MobileLedgerListFragment { mActivity.scheduleTransactionListRetrieval(); }); - Colors.themeWatch.addObserver((o, arg) -> swiper.setColorSchemeColors(Colors.primary)); + Colors.themeWatch.observe(this, this::themeChanged); swiper.setColorSchemeColors(Colors.primary); vAccountFilter = mActivity.findViewById(R.id.transaction_list_account_name_filter); diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/Colors.java b/app/src/main/java/net/ktnx/mobileledger/utils/Colors.java index 8f59c1cf..588a4982 100644 --- a/app/src/main/java/net/ktnx/mobileledger/utils/Colors.java +++ b/app/src/main/java/net/ktnx/mobileledger/utils/Colors.java @@ -28,6 +28,7 @@ import net.ktnx.mobileledger.model.MobileLedgerProfile; import androidx.annotation.ColorInt; import androidx.annotation.ColorLong; +import androidx.lifecycle.MutableLiveData; import static java.lang.Math.abs; @@ -44,7 +45,7 @@ public class Colors { @ColorInt public static int primary, defaultTextColor; public static int profileThemeId = -1; - public static ObservableValue themeWatch = new ObservableValue<>(0); + public static MutableLiveData themeWatch = new MutableLiveData<>(0); public static void refreshColors(Resources.Theme theme) { TypedValue tv = new TypedValue(); theme.resolveAttribute(R.attr.table_row_dark_bg, tv, true); @@ -59,7 +60,7 @@ public class Colors { accent = tv.data; // trigger theme observers - themeWatch.notifyObservers(); + themeWatch.postValue(themeWatch.getValue()+1); } public static @ColorLong long hsvaColor(float hue, float saturation, float value, float alpha) {