diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-04-23 16:00:06 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2020-04-24 15:12:11 +0300 |
commit | 729835de99acfc67d7837c64934f3ecde07a3076 (patch) | |
tree | 184d5adef6133219d1834d6ec5aadd76662a6677 /app/src/main/java/it/niedermann/nextcloud/deck/ui/stack | |
parent | 403c31533ca1f48287f96188c24783b0027e8d7c (diff) |
#396 Filter cards
Fix crash when changing theme
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/stack')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackFragment.java | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackFragment.java index a15c29c0b..257f185c2 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackFragment.java @@ -7,6 +7,7 @@ import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.fragment.app.FragmentActivity; import androidx.lifecycle.LiveData; import androidx.lifecycle.Observer; @@ -34,12 +35,13 @@ public class StackFragment extends BrandedFragment implements DragAndDropTab<Car private CardAdapter adapter = null; private FragmentStackBinding binding; - MainViewModel viewModel; private SyncManager syncManager; private FragmentActivity activity; private OnScrollListener onScrollListener; + @Nullable private LiveData<List<FullCard>> defaultCardsLiveData; + @Nullable private LiveData<List<FullCard>> filteredCardsLiveData; private Observer<List<FullCard>> cardObserver = (List<FullCard> cards) -> { activity.runOnUiThread(() -> { @@ -94,7 +96,7 @@ public class StackFragment extends BrandedFragment implements DragAndDropTab<Car binding = FragmentStackBinding.inflate(inflater, container, false); activity = requireActivity(); - viewModel = new ViewModelProvider(activity).get(MainViewModel.class); + final MainViewModel viewModel = new ViewModelProvider(activity).get(MainViewModel.class); syncManager = new SyncManager(activity); @@ -118,17 +120,17 @@ public class StackFragment extends BrandedFragment implements DragAndDropTab<Car } defaultCardsLiveData = syncManager.getFullCardsForStack(account.getId(), stackId); - defaultCardsLiveData.observe(getViewLifecycleOwner(), cardObserver); + defaultCardsLiveData.observe(activity, cardObserver); viewModel.getFilterInformation().observe(activity, (filterInformation -> { // Remove filter only if it has never been set before if (filterInformation == null && filteredCardsLiveData != null) { filteredCardsLiveData.removeObserver(cardObserver); - defaultCardsLiveData.observe(getViewLifecycleOwner(), cardObserver); + defaultCardsLiveData.observe(activity, cardObserver); } else { defaultCardsLiveData.removeObserver(cardObserver); filteredCardsLiveData = syncManager.getFullCardsForStack(account.getId(), stackId, filterInformation); - filteredCardsLiveData.observe(getViewLifecycleOwner(), cardObserver); + filteredCardsLiveData.observe(activity, cardObserver); } })); return binding.getRoot(); |