]> git.ktnx.net Git - mobile-ledger.git/commitdiff
migrate themeWatch to LiveData
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Tue, 16 Apr 2019 17:49:34 +0000 (20:49 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Tue, 16 Apr 2019 17:49:34 +0000 (20:49 +0300)
app/src/main/java/net/ktnx/mobileledger/ui/MobileLedgerListFragment.java
app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java
app/src/main/java/net/ktnx/mobileledger/utils/Colors.java

index 85593a2138b52b40831c5b716a1c3c92959debff..ab11d20cae01b12a1c2b9a497a0b0a44ac8d2ae9 100644 (file)
 
 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);
+    }
 }
index 93975b05e59357bf40ae8f484dbe057ac7add7a6..94056ab80201c4412d7dea2d8f13677642b18771 100644 (file)
@@ -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();
index ea57ab7c0c3d897571f10cddc8658b27ebe73e9d..12447d26f42bc68da59cacbc9aa706aaf168597e 100644 (file)
@@ -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);
index 8f59c1cf23ccf0c1247cfa0b597431a9f1e3293f..588a498298054c620895d8194e2c01eb91718757 100644 (file)
@@ -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<Integer> themeWatch = new ObservableValue<>(0);
+    public static MutableLiveData<Integer> 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) {