diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-04-23 15:21:48 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2020-04-24 15:12:11 +0300 |
commit | bd897e0087dc9c0cbd87df171792b4b682185bf7 (patch) | |
tree | 5183312afd315c174b88fdd874a4efd9ada148e2 /app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDialogFragment.java | |
parent | 87e8310af269b25b8b248bcfd63d12b6e43818b2 (diff) |
#396 Filter cards
Diffstat (limited to 'app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDialogFragment.java')
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/FilterDialogFragment.java | 15 |
1 files changed, 10 insertions, 5 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 57fe8578f..253ce6d1c 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 @@ -10,12 +10,15 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; +import androidx.lifecycle.ViewModelProvider; import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.databinding.DialogFilterBinding; import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.internal.FilterInformation; import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; +import it.niedermann.nextcloud.deck.ui.MainActivity; +import it.niedermann.nextcloud.deck.ui.MainViewModel; import it.niedermann.nextcloud.deck.ui.branding.BrandedAlertDialogBuilder; import it.niedermann.nextcloud.deck.ui.branding.BrandedDialogFragment; @@ -25,7 +28,8 @@ public class FilterDialogFragment extends BrandedDialogFragment { private static final String KEY_BOARD_ID = "board_id"; private static final String KEY_FILTER_INFORMATION = "filterInformation"; - private FilterChangeListener filterChangeListener; + private MainViewModel viewModel; + private DialogFilterBinding binding; private SyncManager syncManager; @@ -39,8 +43,8 @@ public class FilterDialogFragment extends BrandedDialogFragment { public void onAttach(@NonNull Context context) { super.onAttach(context); - if (!(requireActivity() instanceof FilterChangeListener)) { - throw new IllegalArgumentException("Caller must implement" + FilterChangeListener.class.getSimpleName()); + if (!(requireActivity() instanceof MainActivity)) { + throw new IllegalArgumentException("Dialog must be called from " + MainActivity.class.getSimpleName()); } final Bundle args = getArguments(); @@ -49,7 +53,6 @@ public class FilterDialogFragment extends BrandedDialogFragment { throw new IllegalArgumentException(KEY_ACCOUNT + " and " + KEY_BOARD_ID + " must be provided as arguments"); } - this.filterChangeListener = (FilterChangeListener) requireActivity(); this.boardId = args.getLong(KEY_BOARD_ID); this.account = (Account) args.getSerializable(KEY_ACCOUNT); @@ -70,6 +73,8 @@ public class FilterDialogFragment extends BrandedDialogFragment { public Dialog onCreateDialog(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + viewModel = new ViewModelProvider(requireActivity()).get(MainViewModel.class); + final AlertDialog.Builder dialogBuilder = new BrandedAlertDialogBuilder(requireContext()); binding = DialogFilterBinding.inflate(requireActivity().getLayoutInflater()); @@ -91,7 +96,7 @@ public class FilterDialogFragment extends BrandedDialogFragment { return dialogBuilder .setView(binding.getRoot()) .setNegativeButton(android.R.string.cancel, null) - .setPositiveButton(R.string.simple_filter, (a, b) -> filterChangeListener.onFilterChanged(filterInformation)) + .setPositiveButton(R.string.simple_filter, (a, b) -> viewModel.postFilterInformation(filterInformation)) .create(); } |