]> git.ktnx.net Git - mobile-ledger.git/commitdiff
use getViewLifecycleOwner when observing LiveData from fragments
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 22 Dec 2019 07:13:32 +0000 (09:13 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 22 Dec 2019 07:13:32 +0000 (09:13 +0200)
app/src/main/java/net/ktnx/mobileledger/ui/account_summary/AccountSummaryFragment.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionFragment.java
app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java

index bb484929d9f221236bde6b05209cc5b07f5c25d4..6482dfd1397389d5c4eb4a75770c960a5e1d88fc 100644 (file)
@@ -54,7 +54,8 @@ public class AccountSummaryFragment extends MobileLedgerListFragment {
         debug("flow", "AccountSummaryFragment.onCreate()");
         setHasOptionsMenu(true);
 
-        Data.backgroundTasksRunning.observe(this, this::onBackgroundTaskRunningChanged);
+        Data.backgroundTasksRunning.observe(this.getViewLifecycleOwner(),
+                this::onBackgroundTaskRunningChanged);
     }
     public void onAttach(@NotNull Context context) {
         super.onAttach(context);
@@ -93,7 +94,7 @@ public class AccountSummaryFragment extends MobileLedgerListFragment {
         manageFabOnScroll();
 
         swiper = mActivity.findViewById(R.id.account_swiper);
-        Colors.themeWatch.observe(this, this::themeChanged);
+        Colors.themeWatch.observe(getViewLifecycleOwner(), this::themeChanged);
         swiper.setOnRefreshListener(() -> {
             debug("ui", "refreshing accounts via swipe");
             Data.scheduleTransactionListRetrieval(mActivity);
index 5cbbab71f5cb86c71ec23073437d2723e191972d..54c55fa54863be0e11c152340bd0bcc051fdead8 100644 (file)
@@ -98,7 +98,7 @@ public class NewTransactionFragment extends Fragment {
         listAdapter = new NewTransactionItemsAdapter(viewModel, mProfile);
         list.setAdapter(listAdapter);
         list.setLayoutManager(new LinearLayoutManager(activity));
-        Data.profile.observe(this, profile -> {
+        Data.profile.observe(getViewLifecycleOwner(), profile -> {
             mProfile = profile;
             listAdapter.setProfile(profile);
         });
@@ -142,7 +142,7 @@ public class NewTransactionFragment extends Fragment {
         }).attachToRecyclerView(list);
 
         viewModel.isSubmittable()
-                 .observe(this, isSubmittable -> {
+                 .observe(getViewLifecycleOwner(), isSubmittable -> {
                      if (isSubmittable) {
                          if (fab != null) {
                              fab.show();
index 8de45dce7712ceacb440240d31b068f118a21cc4..d71c0b417f851b0b19fea8edc4b1598117b67a89 100644 (file)
@@ -56,7 +56,8 @@ public class TransactionListFragment extends MobileLedgerListFragment {
     public void onCreate(@Nullable Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setHasOptionsMenu(true);
-        Data.backgroundTasksRunning.observe(this, this::onBackgroundTaskRunningChanged);
+        Data.backgroundTasksRunning.observe(getViewLifecycleOwner(),
+                this::onBackgroundTaskRunningChanged);
     }
     @Override
     public void onAttach(@NotNull Context context) {
@@ -111,7 +112,7 @@ public class TransactionListFragment extends MobileLedgerListFragment {
             Data.scheduleTransactionListRetrieval(mActivity);
         });
 
-        Colors.themeWatch.observe(this, this::themeChanged);
+        Colors.themeWatch.observe(getViewLifecycleOwner(), this::themeChanged);
 
         vAccountFilter = mActivity.findViewById(R.id.transaction_list_account_name_filter);
         accNameFilter = mActivity.findViewById(R.id.transaction_filter_account_name);
@@ -124,7 +125,7 @@ public class TransactionListFragment extends MobileLedgerListFragment {
             Globals.hideSoftKeyboard(mActivity);
         });
 
-        Data.accountFilter.observe(this, this::onAccountNameFilterChanged);
+        Data.accountFilter.observe(getViewLifecycleOwner(), this::onAccountNameFilterChanged);
 
         TransactionListViewModel.updating.addObserver(
                 (o, arg) -> swiper.setRefreshing(TransactionListViewModel.updating.get()));