diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-04-23 14:44:31 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2020-04-24 15:12:11 +0300 |
commit | 8b3bb04267acadbb0c1e396affaa5d3d8eb9d466 (patch) | |
tree | 8d43c0ecc479abba2c6b0f2ab025d6704a68c1b5 /app/src/main/java/it/niedermann/nextcloud/deck/ui/stack | |
parent | 69c7b4dcfe9d04b3dabe3f4fa9aa3d5bd92c8c58 (diff) |
#396 🎚 Filter cards
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/StackAdapter.java | 14 | ||||
-rw-r--r-- | app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackFragment.java | 35 |
2 files changed, 34 insertions, 15 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackAdapter.java index 726613dbe..88e063bce 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/stack/StackAdapter.java @@ -10,13 +10,17 @@ import java.util.List; import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.full.FullStack; +import it.niedermann.nextcloud.deck.model.internal.FilterInformation; +import it.niedermann.nextcloud.deck.ui.filter.FilterChangeListener; -public class StackAdapter extends FragmentStateAdapter { +public class StackAdapter extends FragmentStateAdapter implements FilterChangeListener { @NonNull private List<FullStack> stackList = new ArrayList<>(); private Account account; private long boardId; private boolean canEdit; + @NonNull + private FilterInformation filterInformation; public StackAdapter(@NonNull FragmentActivity fragmentActivity) { super(fragmentActivity); @@ -49,7 +53,7 @@ public class StackAdapter extends FragmentStateAdapter { @NonNull @Override public Fragment createFragment(int position) { - return StackFragment.newInstance(boardId, stackList.get(position).getLocalId(), account, canEdit); + return StackFragment.newInstance(boardId, stackList.get(position).getLocalId(), account, canEdit, filterInformation); } public void setStacks(@NonNull List<FullStack> fullStacks, @NonNull Account currentAccount, long currentBoardId, boolean currentBoardHasEditPermission) { @@ -59,4 +63,10 @@ public class StackAdapter extends FragmentStateAdapter { this.canEdit = currentBoardHasEditPermission; notifyDataSetChanged(); } + + @Override + public void onFilterChanged(FilterInformation filterInformation) { + this.filterInformation = filterInformation; + notifyDataSetChanged(); + } }
\ No newline at end of file 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 d07629de3..74909bf08 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 @@ -8,6 +8,7 @@ import android.view.View; import android.view.ViewGroup; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; import java.util.List; @@ -16,6 +17,7 @@ import it.niedermann.android.crosstabdnd.DragAndDropTab; import it.niedermann.nextcloud.deck.databinding.FragmentStackBinding; import it.niedermann.nextcloud.deck.model.Account; import it.niedermann.nextcloud.deck.model.full.FullCard; +import it.niedermann.nextcloud.deck.model.internal.FilterInformation; import it.niedermann.nextcloud.deck.persistence.sync.SyncManager; import it.niedermann.nextcloud.deck.ui.branding.BrandedFragment; import it.niedermann.nextcloud.deck.ui.card.CardAdapter; @@ -27,7 +29,10 @@ public class StackFragment extends BrandedFragment implements DragAndDropTab<Car private static final String KEY_STACK_ID = "stackId"; private static final String KEY_ACCOUNT = "account"; private static final String KEY_HAS_EDIT_PERMISSION = "hasEditPermission"; + private static final String KEY_FILTER_INFORMATION = "filterInformation"; private CardAdapter adapter = null; + @Nullable + FilterInformation filterInformation; private SyncManager syncManager; private Activity activity; private OnScrollListener onScrollListener; @@ -39,17 +44,15 @@ public class StackFragment extends BrandedFragment implements DragAndDropTab<Car private FragmentStackBinding binding; - /** - * @param boardId of the current stack - * @return new fragment instance - * @see <a href="https://gunhansancar.com/best-practice-to-instantiate-fragments-with-arguments-in-android/">Best Practice to Instantiate Fragments with Arguments in Android</a> - */ - public static StackFragment newInstance(long boardId, long stackId, Account account, boolean hasEditPermission) { + public static StackFragment newInstance(long boardId, long stackId, Account account, boolean hasEditPermission, @Nullable FilterInformation filterInformation) { Bundle bundle = new Bundle(); bundle.putLong(KEY_BOARD_ID, boardId); bundle.putLong(KEY_STACK_ID, stackId); bundle.putBoolean(KEY_HAS_EDIT_PERMISSION, hasEditPermission); bundle.putSerializable(KEY_ACCOUNT, account); + if (filterInformation != null) { + bundle.putSerializable(KEY_FILTER_INFORMATION, filterInformation); + } StackFragment fragment = new StackFragment(); fragment.setArguments(bundle); @@ -61,16 +64,21 @@ public class StackFragment extends BrandedFragment implements DragAndDropTab<Car public void onAttach(@NonNull Context context) { super.onAttach(context); - Bundle bundle = getArguments(); - if (bundle == null || !bundle.containsKey(KEY_ACCOUNT) || !bundle.containsKey(KEY_BOARD_ID) || !bundle.containsKey(KEY_STACK_ID)) { + final Bundle args = getArguments(); + if (args == null || !args.containsKey(KEY_ACCOUNT) || !args.containsKey(KEY_BOARD_ID) || !args.containsKey(KEY_STACK_ID)) { throw new IllegalArgumentException("account, boardId and localStackId are required arguments."); } - boardId = bundle.getLong(KEY_BOARD_ID); - stackId = bundle.getLong(KEY_STACK_ID); - account = (Account) bundle.getSerializable(KEY_ACCOUNT); - - canEdit = bundle.getBoolean(KEY_HAS_EDIT_PERMISSION); + boardId = args.getLong(KEY_BOARD_ID); + stackId = args.getLong(KEY_STACK_ID); + account = (Account) args.getSerializable(KEY_ACCOUNT); + canEdit = args.getBoolean(KEY_HAS_EDIT_PERMISSION); + if (args.containsKey(KEY_FILTER_INFORMATION)) { + final Object info = args.getSerializable(KEY_FILTER_INFORMATION); + if (info != null) { + filterInformation = (FilterInformation) args.getSerializable(KEY_FILTER_INFORMATION); + } + } if (context instanceof OnScrollListener) { this.onScrollListener = (OnScrollListener) context; @@ -103,6 +111,7 @@ public class StackFragment extends BrandedFragment implements DragAndDropTab<Car binding.emptyContentView.hideDescription(); } + // TODO use FilterInformation syncManager.getFullCardsForStack(account.getId(), stackId).observe(getViewLifecycleOwner(), (List<FullCard> cards) -> { activity.runOnUiThread(() -> { if (cards != null && cards.size() > 0) { |