diff options
author | Stefan Niedermann <info@niedermann.it> | 2023-03-01 14:43:53 +0300 |
---|---|---|
committer | Stefan Niedermann <info@niedermann.it> | 2023-03-09 11:53:19 +0300 |
commit | 3ea462ca9e2ae18ba9d869125da8d8d07f2c7854 (patch) | |
tree | 30257c67768325d5972ec499a6eb41e11017ac6d /app/src/main/java/it/niedermann/nextcloud/deck/ui/filter | |
parent | bfab286b0bc6dbfac1211eec64d74b66b2ce1e6d (diff) |
refactor: Unidirectional data flow and single point of truth for current state
Signed-off-by: Stefan Niedermann <info@niedermann.it>
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/filter')
8 files changed, 129 insertions, 64 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDialogFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDialogFragment.java index 87427209d..08512c5c6 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDialogFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDialogFragment.java @@ -5,6 +5,7 @@ import android.graphics.Color; import android.graphics.drawable.Drawable; import android.os.Bundle; +import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; import androidx.fragment.app.DialogFragment; @@ -66,7 +67,7 @@ public class FilterDialogFragment extends ThemedDialogFragment { tab.setIcon(draft.getDueType() != EDueType.NO_FILTER ? indicator : null); break; default: - throw new IllegalStateException("position must be between 0 and 2"); + throw new IllegalStateException("position must be between 0 and 2 but was " + position); } }); tab.setText(tabTitles[position]); @@ -104,7 +105,7 @@ public class FilterDialogFragment extends ThemedDialogFragment { } @Override - public void applyTheme(int color) { + public void applyTheme(@ColorInt int color) { final var utils = ThemeUtils.of(color, requireContext()); utils.deck.themeTabLayout(binding.tabLayout, Color.TRANSPARENT); @@ -128,7 +129,7 @@ public class FilterDialogFragment extends ThemedDialogFragment { case 2: return new FilterDueTypeFragment(); default: - throw new IllegalArgumentException("position must be between 0 and 2"); + throw new IllegalArgumentException("position must be between 0 and 2 but was " + position); } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDueTypeAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDueTypeAdapter.java index dab5bb9f7..7d218e19e 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDueTypeAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDueTypeAdapter.java @@ -1,8 +1,10 @@ package it.niedermann.nextcloud.deck.ui.filter; +import android.os.Build; import android.view.LayoutInflater; import android.view.ViewGroup; +import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; @@ -11,6 +13,8 @@ import java.util.Arrays; import it.niedermann.nextcloud.deck.databinding.ItemFilterDuetypeBinding; import it.niedermann.nextcloud.deck.model.enums.EDueType; +import it.niedermann.nextcloud.deck.ui.theme.ThemeUtils; +import it.niedermann.nextcloud.deck.ui.theme.Themed; public class FilterDueTypeAdapter extends RecyclerView.Adapter<FilterDueTypeAdapter.DueTypeViewHolder> { @NonNull @@ -18,14 +22,16 @@ public class FilterDueTypeAdapter extends RecyclerView.Adapter<FilterDueTypeAdap private int selectedDueTypePosition; @Nullable private final SelectionListener<EDueType> selectionListener; + @ColorInt + private final int color; @SuppressWarnings("WeakerAccess") - public FilterDueTypeAdapter(@NonNull EDueType selectedDueType, @Nullable SelectionListener<EDueType> selectionListener) { + public FilterDueTypeAdapter(@NonNull EDueType selectedDueType, @Nullable SelectionListener<EDueType> selectionListener, @ColorInt int color) { super(); this.selectedDueTypePosition = Arrays.binarySearch(dueTypes, selectedDueType); this.selectionListener = selectionListener; + this.color = color; setHasStableIds(true); - notifyDataSetChanged(); } @NonNull @@ -49,8 +55,8 @@ public class FilterDueTypeAdapter extends RecyclerView.Adapter<FilterDueTypeAdap return dueTypes.length; } - class DueTypeViewHolder extends RecyclerView.ViewHolder { - private ItemFilterDuetypeBinding binding; + class DueTypeViewHolder extends RecyclerView.ViewHolder implements Themed { + private final ItemFilterDuetypeBinding binding; DueTypeViewHolder(@NonNull ItemFilterDuetypeBinding binding) { super(binding.getRoot()); @@ -60,6 +66,7 @@ public class FilterDueTypeAdapter extends RecyclerView.Adapter<FilterDueTypeAdap void bind(final EDueType dueType) { binding.dueType.setText(dueType.toString(binding.dueType.getContext())); itemView.setSelected(dueTypes[selectedDueTypePosition].equals(dueType)); + applyTheme(color); itemView.setOnClickListener(view -> { final int oldSelection = selectedDueTypePosition; @@ -80,5 +87,13 @@ public class FilterDueTypeAdapter extends RecyclerView.Adapter<FilterDueTypeAdap notifyItemChanged(oldSelection); }); } + + @Override + public void applyTheme(int color) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + final var utils = ThemeUtils.of(color, itemView.getContext()); + utils.deck.colorSelectedCheck(binding.selectedCheck.getContext(), binding.selectedCheck.getDrawable()); + } + } } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDueTypeFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDueTypeFragment.java index ac23faf6c..c173433e1 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDueTypeFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDueTypeFragment.java @@ -28,7 +28,8 @@ public class FilterDueTypeFragment extends Fragment implements SelectionListener filterViewModel = new ViewModelProvider(requireActivity()).get(FilterViewModel.class); binding.dueType.setItemAnimator(null); - binding.dueType.setAdapter(new FilterDueTypeAdapter(requireNonNull(filterViewModel.getFilterInformationDraft().getValue()).getDueType(), this)); + filterViewModel.getCurrentBoardColor$().observe(getViewLifecycleOwner(), + color -> binding.dueType.setAdapter(new FilterDueTypeAdapter(requireNonNull(filterViewModel.getFilterInformationDraft().getValue()).getDueType(), this, color))); return binding.getRoot(); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterLabelsAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterLabelsAdapter.java index 83b8f8f3e..194540139 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterLabelsAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterLabelsAdapter.java @@ -1,21 +1,26 @@ package it.niedermann.nextcloud.deck.ui.filter; import android.content.res.ColorStateList; +import android.os.Build; import android.view.LayoutInflater; import android.view.ViewGroup; +import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import it.niedermann.android.util.ColorUtil; import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.databinding.ItemFilterLabelBinding; import it.niedermann.nextcloud.deck.model.Label; +import it.niedermann.nextcloud.deck.ui.theme.ThemeUtils; +import it.niedermann.nextcloud.deck.ui.theme.Themed; @SuppressWarnings("WeakerAccess") public class FilterLabelsAdapter extends RecyclerView.Adapter<FilterLabelsAdapter.LabelViewHolder> { @@ -27,8 +32,10 @@ public class FilterLabelsAdapter extends RecyclerView.Adapter<FilterLabelsAdapte private static final Label NOT_ASSIGNED = null; @Nullable private final SelectionListener<Label> selectionListener; + @ColorInt + private final int color; - public FilterLabelsAdapter(@NonNull List<Label> labels, @NonNull List<Label> selectedLabels, boolean noAssignedLabel, @Nullable SelectionListener<Label> selectionListener) { + public FilterLabelsAdapter(@NonNull Collection<Label> labels, @NonNull Collection<Label> selectedLabels, boolean noAssignedLabel, @Nullable SelectionListener<Label> selectionListener, @ColorInt int color) { super(); this.labels.add(NOT_ASSIGNED); this.labels.addAll(labels); @@ -37,8 +44,8 @@ public class FilterLabelsAdapter extends RecyclerView.Adapter<FilterLabelsAdapte } this.selectedLabels.addAll(selectedLabels); this.selectionListener = selectionListener; + this.color = color; setHasStableIds(true); - notifyDataSetChanged(); } @Override @@ -67,8 +74,8 @@ public class FilterLabelsAdapter extends RecyclerView.Adapter<FilterLabelsAdapte return labels.size(); } - class LabelViewHolder extends RecyclerView.ViewHolder { - private ItemFilterLabelBinding binding; + class LabelViewHolder extends RecyclerView.ViewHolder implements Themed { + private final ItemFilterLabelBinding binding; LabelViewHolder(@NonNull ItemFilterLabelBinding binding) { super(binding.getRoot()); @@ -80,9 +87,10 @@ public class FilterLabelsAdapter extends RecyclerView.Adapter<FilterLabelsAdapte binding.label.setText(label.getTitle()); final int labelColor = label.getColor(); binding.label.setChipBackgroundColor(ColorStateList.valueOf(labelColor)); - final int color = ColorUtil.INSTANCE.getForegroundColorForBackgroundColor(labelColor); - binding.label.setTextColor(color); + final int textColor = ColorUtil.INSTANCE.getForegroundColorForBackgroundColor(labelColor); + binding.label.setTextColor(textColor); itemView.setSelected(selectedLabels.contains(label)); + applyTheme(color); bindClickListener(label); } @@ -93,6 +101,7 @@ public class FilterLabelsAdapter extends RecyclerView.Adapter<FilterLabelsAdapte binding.label.setChipBackgroundColor(ColorStateList.valueOf(ContextCompat.getColor(itemView.getContext(), R.color.primary))); binding.label.setRippleColor(null); itemView.setSelected(selectedLabels.contains(NOT_ASSIGNED)); + applyTheme(color); bindClickListener(NOT_ASSIGNED); } @@ -113,5 +122,13 @@ public class FilterLabelsAdapter extends RecyclerView.Adapter<FilterLabelsAdapte } }); } + + @Override + public void applyTheme(int color) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + final var utils = ThemeUtils.of(color, itemView.getContext()); + utils.deck.colorSelectedCheck(binding.selectedCheck.getContext(), binding.selectedCheck.getDrawable()); + } + } } } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterLabelsFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterLabelsFragment.java index b4eb17d0e..a69ced0ea 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterLabelsFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterLabelsFragment.java @@ -1,7 +1,6 @@ package it.niedermann.nextcloud.deck.ui.filter; import static java.util.Objects.requireNonNull; -import static it.niedermann.nextcloud.deck.persistence.sync.adapters.db.util.LiveDataHelper.observeOnce; import android.os.Bundle; import android.view.LayoutInflater; @@ -13,9 +12,9 @@ import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; +import it.niedermann.android.reactivelivedata.ReactiveLiveData; import it.niedermann.nextcloud.deck.databinding.DialogFilterLabelsBinding; import it.niedermann.nextcloud.deck.model.Label; -import it.niedermann.nextcloud.deck.ui.MainViewModel; public class FilterLabelsFragment extends Fragment implements SelectionListener<Label> { @@ -26,18 +25,20 @@ public class FilterLabelsFragment extends Fragment implements SelectionListener< public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { final var binding = DialogFilterLabelsBinding.inflate(requireActivity().getLayoutInflater()); - final var mainViewModel = new ViewModelProvider(requireActivity()).get(MainViewModel.class); filterViewModel = new ViewModelProvider(requireActivity()).get(FilterViewModel.class); - observeOnce(filterViewModel.findProposalsForLabelsToAssign(mainViewModel.getCurrentAccount().getId(), mainViewModel.getCurrentBoardLocalId()), requireActivity(), (labels) -> { - binding.labels.setNestedScrollingEnabled(false); - binding.labels.setAdapter(new FilterLabelsAdapter( - labels, - requireNonNull(filterViewModel.getFilterInformationDraft().getValue()).getLabels(), - requireNonNull(filterViewModel.getFilterInformationDraft().getValue()).isNoAssignedLabel(), - this)); - }); + new ReactiveLiveData<>(filterViewModel.findProposalsForLabelsToAssign()) + .combineWith(() -> filterViewModel.getCurrentBoardColor$()) + .observeOnce(getViewLifecycleOwner(), pair -> { + binding.labels.setNestedScrollingEnabled(false); + binding.labels.setAdapter(new FilterLabelsAdapter( + pair.first, + requireNonNull(filterViewModel.getFilterInformationDraft().getValue()).getLabels(), + requireNonNull(filterViewModel.getFilterInformationDraft().getValue()).isNoAssignedLabel(), + this, + pair.second)); + }); return binding.getRoot(); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterUserAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterUserAdapter.java index 4b75b985f..b042954be 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterUserAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterUserAdapter.java @@ -1,28 +1,31 @@ package it.niedermann.nextcloud.deck.ui.filter; +import android.os.Build; import android.view.LayoutInflater; import android.view.ViewGroup; +import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.annotation.Px; import androidx.recyclerview.widget.RecyclerView; import com.bumptech.glide.Glide; +import com.bumptech.glide.request.RequestOptions; import java.util.ArrayList; +import java.util.Collection; import java.util.List; +import it.niedermann.android.util.DimensionUtil; import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.databinding.ItemFilterUserBinding; import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.User; -import it.niedermann.nextcloud.deck.util.ViewUtil; +import it.niedermann.nextcloud.deck.ui.theme.ThemeUtils; +import it.niedermann.nextcloud.deck.ui.theme.Themed; @SuppressWarnings("WeakerAccess") public class FilterUserAdapter extends RecyclerView.Adapter<FilterUserAdapter.UserViewHolder> { - @Px - final int avatarSize; @NonNull private final Account account; @Nullable @@ -33,10 +36,11 @@ public class FilterUserAdapter extends RecyclerView.Adapter<FilterUserAdapter.Us private final List<User> selectedUsers = new ArrayList<>(); @Nullable private final SelectionListener<User> selectionListener; + @ColorInt + private final int color; - public FilterUserAdapter(@Px int avatarSize, @NonNull Account account, @NonNull List<User> users, @NonNull List<User> selectedUsers, boolean noAssignedUser, @Nullable SelectionListener<User> selectionListener) { + public FilterUserAdapter(@NonNull Account account, @NonNull Collection<User> users, @NonNull Collection<User> selectedUsers, boolean noAssignedUser, @Nullable SelectionListener<User> selectionListener, @ColorInt int color) { super(); - this.avatarSize = avatarSize; this.account = account; this.users.add(NOT_ASSIGNED); this.users.addAll(users); @@ -45,8 +49,8 @@ public class FilterUserAdapter extends RecyclerView.Adapter<FilterUserAdapter.Us } this.selectedUsers.addAll(selectedUsers); this.selectionListener = selectionListener; + this.color = color; setHasStableIds(true); - notifyDataSetChanged(); } @Override @@ -75,8 +79,8 @@ public class FilterUserAdapter extends RecyclerView.Adapter<FilterUserAdapter.Us return users.size(); } - class UserViewHolder extends RecyclerView.ViewHolder { - private ItemFilterUserBinding binding; + class UserViewHolder extends RecyclerView.ViewHolder implements Themed { + private final ItemFilterUserBinding binding; UserViewHolder(@NonNull ItemFilterUserBinding binding) { super(binding.getRoot()); @@ -85,8 +89,14 @@ public class FilterUserAdapter extends RecyclerView.Adapter<FilterUserAdapter.Us void bind(@NonNull final User user) { binding.title.setText(user.getDisplayname()); - ViewUtil.addAvatar(binding.avatar, account.getUrl(), user.getUid(), avatarSize, R.drawable.ic_person_grey600_24dp); + Glide.with(binding.avatar.getContext()) + .load(account.getAvatarUrl(DimensionUtil.INSTANCE.dpToPx(binding.avatar.getContext(), R.dimen.avatar_size), user.getUid())) + .placeholder(R.drawable.ic_person_grey600_24dp) + .error(R.drawable.ic_person_grey600_24dp) + .apply(RequestOptions.circleCropTransform()) + .into(binding.avatar); itemView.setSelected(selectedUsers.contains(user)); + applyTheme(color); bindClickListener(user); } @@ -96,6 +106,7 @@ public class FilterUserAdapter extends RecyclerView.Adapter<FilterUserAdapter.Us .load(R.drawable.ic_baseline_block_24) .into(binding.avatar); itemView.setSelected(selectedUsers.contains(NOT_ASSIGNED)); + applyTheme(color); bindClickListener(NOT_ASSIGNED); } @@ -116,5 +127,13 @@ public class FilterUserAdapter extends RecyclerView.Adapter<FilterUserAdapter.Us } }); } + + @Override + public void applyTheme(int color) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + final var utils = ThemeUtils.of(color, itemView.getContext()); + utils.deck.colorSelectedCheck(binding.selectedCheck.getContext(), binding.selectedCheck.getDrawable()); + } + } } }
\ No newline at end of file diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterUserFragment.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterUserFragment.java index 59768de39..977e4bbd2 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterUserFragment.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterUserFragment.java @@ -1,7 +1,6 @@ package it.niedermann.nextcloud.deck.ui.filter; import static java.util.Objects.requireNonNull; -import static it.niedermann.nextcloud.deck.persistence.sync.adapters.db.util.LiveDataHelper.observeOnce; import android.os.Bundle; import android.view.LayoutInflater; @@ -10,14 +9,13 @@ import android.view.ViewGroup; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.lifecycle.ViewModelProvider; -import it.niedermann.android.util.DimensionUtil; -import it.niedermann.nextcloud.deck.R; +import it.niedermann.android.reactivelivedata.ReactiveLiveData; import it.niedermann.nextcloud.deck.databinding.DialogFilterAssigneesBinding; import it.niedermann.nextcloud.deck.model.User; -import it.niedermann.nextcloud.deck.ui.MainViewModel; public class FilterUserFragment extends Fragment implements SelectionListener<User> { @@ -28,20 +26,20 @@ public class FilterUserFragment extends Fragment implements SelectionListener<Us @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { binding = DialogFilterAssigneesBinding.inflate(requireActivity().getLayoutInflater()); - final var mainViewModel = new ViewModelProvider(requireActivity()).get(MainViewModel.class); filterViewModel = new ViewModelProvider(requireActivity()).get(FilterViewModel.class); - observeOnce(filterViewModel.findProposalsForUsersToAssign(mainViewModel.getCurrentAccount().getId(), mainViewModel.getCurrentBoardLocalId()), requireActivity(), (users) -> { - binding.users.setNestedScrollingEnabled(false); - binding.users.setAdapter(new FilterUserAdapter( - DimensionUtil.INSTANCE.dpToPx(requireContext(), R.dimen.avatar_size), - mainViewModel.getCurrentAccount(), - users, - requireNonNull(filterViewModel.getFilterInformationDraft().getValue()).getUsers(), - requireNonNull(filterViewModel.getFilterInformationDraft().getValue()).isNoAssignedUser(), - this)); - }); + new ReactiveLiveData<>(filterViewModel.findProposalsForUsersToAssign()) + .combineWith(() -> filterViewModel.getCurrentBoardColor$()) + .observeOnce(getViewLifecycleOwner(), pair -> { + binding.users.setNestedScrollingEnabled(false); + filterViewModel.getCurrentAccount().thenAcceptAsync(account -> binding.users.setAdapter(new FilterUserAdapter( + account, pair.first, + requireNonNull(filterViewModel.getFilterInformationDraft().getValue()).getUsers(), + requireNonNull(filterViewModel.getFilterInformationDraft().getValue()).isNoAssignedUser(), + this, + pair.second)), ContextCompat.getMainExecutor(requireContext())); + }); return binding.getRoot(); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterViewModel.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterViewModel.java index acdab52e7..09f2f4fa1 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterViewModel.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterViewModel.java @@ -1,29 +1,26 @@ package it.niedermann.nextcloud.deck.ui.filter; -import static androidx.lifecycle.Transformations.distinctUntilChanged; -import static androidx.lifecycle.Transformations.map; - import android.app.Application; import androidx.annotation.IntRange; import androidx.annotation.NonNull; -import androidx.lifecycle.AndroidViewModel; import androidx.lifecycle.LiveData; import androidx.lifecycle.MutableLiveData; import java.util.List; +import java.util.concurrent.CompletableFuture; +import it.niedermann.android.reactivelivedata.ReactiveLiveData; import it.niedermann.nextcloud.deck.DeckLog; +import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.Label; import it.niedermann.nextcloud.deck.model.User; import it.niedermann.nextcloud.deck.model.enums.EDueType; import it.niedermann.nextcloud.deck.model.internal.FilterInformation; -import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; +import it.niedermann.nextcloud.deck.ui.viewmodel.BaseViewModel; @SuppressWarnings("WeakerAccess") -public class FilterViewModel extends AndroidViewModel { - - private final SyncManager syncManager; +public class FilterViewModel extends BaseViewModel { @IntRange(from = 0, to = 2) private int currentFilterTab = 0; @@ -35,7 +32,10 @@ public class FilterViewModel extends AndroidViewModel { public FilterViewModel(@NonNull Application application) { super(application); - this.syncManager = new SyncManager(application); + } + + public CompletableFuture<Account> getCurrentAccount() { + return baseRepository.getCurrentAccountId().thenApplyAsync(baseRepository::readAccountDirectly); } public void publishFilterInformationDraft() { @@ -60,7 +60,9 @@ public class FilterViewModel extends AndroidViewModel { @NonNull public LiveData<Boolean> hasActiveFilter() { - return distinctUntilChanged(map(getFilterInformation(), FilterInformation::hasActiveFilter)); + return new ReactiveLiveData<>(getFilterInformation()) + .map(FilterInformation::hasActiveFilter) + .distinctUntilChanged(); } public void createFilterInformationDraft() { @@ -130,11 +132,22 @@ public class FilterViewModel extends AndroidViewModel { return this.currentFilterTab; } - public LiveData<List<User>> findProposalsForUsersToAssign(final long accountId, long boardId) { - return syncManager.findProposalsForUsersToAssign(accountId, boardId, -1L, -1); + // TODO Use in Filter fragments + public LiveData<Integer> getCurrentBoardColor$() { + return new ReactiveLiveData<>(baseRepository.getCurrentAccountId$()) + .combineWith(baseRepository::getCurrentBoardId$) + .flatMap(ids -> baseRepository.getBoardColor$(ids.first, ids.second)); + } + + public LiveData<List<User>> findProposalsForUsersToAssign() { + return new ReactiveLiveData<>(baseRepository.getCurrentAccountId$()) + .combineWith(baseRepository::getCurrentBoardId$) + .flatMap(ids -> baseRepository.findProposalsForUsersToAssignForCards(ids.first, ids.second, -1L, -1)); } - public LiveData<List<Label>> findProposalsForLabelsToAssign(final long accountId, final long boardId) { - return syncManager.findProposalsForLabelsToAssign(accountId, boardId, -1L); + public LiveData<List<Label>> findProposalsForLabelsToAssign() { + return new ReactiveLiveData<>(baseRepository.getCurrentAccountId$()) + .combineWith(baseRepository::getCurrentBoardId$) + .flatMap(ids -> baseRepository.findProposalsForLabelsToAssign(ids.first, ids.second, -1L)); } } |