diff options
author | Stefan Niedermann <info@niedermann.it> | 2020-04-23 20:00:59 +0300 |
---|---|---|
committer | Niedermann IT-Dienstleistungen <stefan-niedermann@users.noreply.github.com> | 2020-04-24 15:12:11 +0300 |
commit | 2859cbcf0067182a0bdc6edde15fa0b648ba852c (patch) | |
tree | 799557948335a12270143f44230cc7885593466d /app/src | |
parent | 547ff69eb5b62f2cbc2db6c4a5c70a0d1892ff02 (diff) |
#396 Filter cards
RecyclerView with selection - working draft
Diffstat (limited to 'app/src')
7 files changed, 130 insertions, 71 deletions
diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/model/internal/FilterInformation.java b/app/src/main/java/it/niedermann/nextcloud/deck/model/internal/FilterInformation.java index b3ebb3e8f..c8619636f 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/model/internal/FilterInformation.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/model/internal/FilterInformation.java @@ -43,8 +43,12 @@ public class FilterInformation implements Serializable { userIDs.remove(id); } - public void addLabelId(long id) { - labelIDs.add(id); + public void addAllLabelIds(List<Long> ids) { + labelIDs.addAll(ids); + } + + public void clearLabelIds() { + labelIDs.clear(); } public void removeLabelId(Long id) { 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 38220c725..d25f4d28f 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 @@ -76,11 +76,9 @@ public class FilterDialogFragment extends BrandedDialogFragment { final DialogFilterBinding binding = DialogFilterBinding.inflate(requireActivity().getLayoutInflater()); overdueAdapter = new OverdueFilterAdapter(requireContext()); - labelAdapter = new LabelFilterAdapter(requireContext()); userAdapter = new UserFilterAdapter(requireContext()); binding.overdue.setAdapter(overdueAdapter); - binding.labels.setAdapter(labelAdapter); binding.people.setAdapter(userAdapter); binding.overdue.setSelection(overdueAdapter.getPosition(this.filterInformation.getDueType())); @@ -99,23 +97,9 @@ public class FilterDialogFragment extends BrandedDialogFragment { SyncManager syncManager = new SyncManager(requireActivity()); observeOnce(syncManager.findProposalsForLabelsToAssign(account.getId(), boardId), requireActivity(), (labels) -> { - labelAdapter.addAll(labels); - labelAdapter.notifyDataSetChanged(); - for (long labelId : this.filterInformation.getLabelIDs()) { - binding.labels.setSelection(labelAdapter.getPosition(labelId)); - } - binding.labels.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { - @Override - public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { - DeckLog.info("clicked position: " + position); - filterInformation.addLabelId(labelAdapter.getItemId(position)); - } - - @Override - public void onNothingSelected(AdapterView<?> parent) { - // Nothing to do - } - }); + labelAdapter = new LabelFilterAdapter(requireContext(), labels, this.filterInformation.getLabelIDs()); + binding.labels.setNestedScrollingEnabled(false); + binding.labels.setAdapter(labelAdapter); }); observeOnce(syncManager.findProposalsForUsersToAssign(account.getId(), boardId), requireActivity(), (users) -> { @@ -128,7 +112,7 @@ public class FilterDialogFragment extends BrandedDialogFragment { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { DeckLog.info("clicked position: " + position); - filterInformation.addLabelId(userAdapter.getItemId(position)); + filterInformation.addUserId(userAdapter.getItemId(position)); } @Override @@ -143,7 +127,11 @@ public class FilterDialogFragment extends BrandedDialogFragment { .setView(binding.getRoot()) .setNeutralButton(android.R.string.cancel, null) .setNegativeButton(R.string.simple_clear, (a, b) -> viewModel.postFilterInformation(null)) - .setPositiveButton(R.string.simple_filter, (a, b) -> viewModel.postFilterInformation(filterInformation)) + .setPositiveButton(R.string.simple_filter, (a, b) -> { + filterInformation.clearLabelIds(); + filterInformation.addAllLabelIds(labelAdapter.getSelected()); + viewModel.postFilterInformation(filterInformation); + }) .create(); } diff --git a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/LabelFilterAdapter.java b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/LabelFilterAdapter.java index 8fed859a5..1105de814 100644 --- a/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/LabelFilterAdapter.java +++ b/app/src/main/java/it/niedermann/nextcloud/deck/ui/filter/LabelFilterAdapter.java @@ -4,68 +4,81 @@ import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.ArrayAdapter; +import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; +import androidx.recyclerview.widget.RecyclerView; -import org.jetbrains.annotations.NotNull; - -import java.util.NoSuchElementException; +import java.util.List; +import it.niedermann.nextcloud.deck.R; import it.niedermann.nextcloud.deck.model.Label; -public class LabelFilterAdapter extends ArrayAdapter<Label> { +public class LabelFilterAdapter extends RecyclerView.Adapter<LabelFilterAdapter.LabelViewHolder> { + private Context context; + private List<Label> labels; + private List<Long> selectedLabelIds; - @NonNull - private final LayoutInflater inflater; + public LabelFilterAdapter(@NonNull Context context, @NonNull List<Label> labels, @NonNull List<Long> selectedLabelIds) { + super(); + this.context = context; + this.labels = labels; + this.selectedLabelIds = selectedLabelIds; + setHasStableIds(true); + notifyDataSetChanged(); + } - @SuppressWarnings("WeakerAccess") - public LabelFilterAdapter(@NonNull Context context) { - super(context, android.R.layout.simple_list_item_multiple_choice, android.R.id.text1); - inflater = LayoutInflater.from(context); + @Override + public long getItemId(int position) { + return labels.get(position).getLocalId(); } + @NonNull @Override - public boolean hasStableIds() { - return true; + public LabelViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) { + View view = LayoutInflater.from(context).inflate(R.layout.item_user, viewGroup, false); + return new LabelViewHolder(view); } @Override - public long getItemId(int position) { - final Label label = getItem(position); - if (label == null) { - throw new NoSuchElementException(); - } - return label.getLocalId(); + public void onBindViewHolder(@NonNull LabelViewHolder multiViewHolder, int position) { + multiViewHolder.bind(labels.get(position)); } @Override - public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) { - return getView(position, convertView, parent); + public int getItemCount() { + return labels.size(); } - @SuppressWarnings("WeakerAccess") - public int getPosition(long labelId) { - for (int i = 0; i < getCount(); i++) { - if (getItemId(i) == labelId) { - return i; - } - } - throw new NoSuchElementException(); + public List<Long> getSelected() { + return selectedLabelIds; } - @NotNull - @Override - public View getView(int position, View convertView, @NotNull ViewGroup parent) { - final View view; - if (convertView == null) { - view = inflater.inflate(android.R.layout.simple_list_item_multiple_choice, parent, false); - } else { - view = convertView; + class LabelViewHolder extends RecyclerView.ViewHolder { + + private TextView textView; + private ImageView imageView; + + LabelViewHolder(@NonNull View itemView) { + super(itemView); + textView = itemView.findViewById(R.id.displayname); + imageView = itemView.findViewById(R.id.avatar); + } + + void bind(final Label label) { + imageView.setVisibility(selectedLabelIds.contains(label.getLocalId()) ? View.VISIBLE : View.GONE); + textView.setText(label.getTitle()); + + itemView.setOnClickListener(view -> { + if (selectedLabelIds.contains(label.getLocalId())) { + selectedLabelIds.remove(label.getLocalId()); + itemView.setSelected(false); + } else { + selectedLabelIds.add(label.getLocalId()); + itemView.setSelected(true); + } + }); } - ((TextView) view.findViewById(android.R.id.text1)).setText(getItem(position).getTitle()); - return view; } } diff --git a/app/src/main/res/drawable/selected.xml b/app/src/main/res/drawable/selected.xml new file mode 100644 index 000000000..cc62aec0d --- /dev/null +++ b/app/src/main/res/drawable/selected.xml @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="utf-8"?> +<selector xmlns:android="http://schemas.android.com/apk/res/android"> + <item android:enterFadeDuration="@android:integer/config_shortAnimTime" android:state_activated="true"> + <layer-list> + <item> + <shape android:shape="oval"> + <solid android:color="@android:color/holo_green_light" /> + <stroke android:width="1dp" android:color="@android:color/white" /> + </shape> + </item> + <item android:drawable="@drawable/circle_alpha_check_36dp" /> + </layer-list> + </item> +</selector>
\ No newline at end of file diff --git a/app/src/main/res/layout/dialog_filter.xml b/app/src/main/res/layout/dialog_filter.xml index 89749c915..ccdd64e69 100644 --- a/app/src/main/res/layout/dialog_filter.xml +++ b/app/src/main/res/layout/dialog_filter.xml @@ -2,7 +2,8 @@ <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent"> + android:layout_height="match_parent" + xmlns:app="http://schemas.android.com/apk/res-auto"> <LinearLayout android:layout_width="match_parent" @@ -14,17 +15,16 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:labelFor="@id/overdue" - android:text="@string/filter_by_tag" - android:visibility="gone" /> + android:text="@string/filter_by_tag" /> - <ListView + <androidx.recyclerview.widget.RecyclerView android:id="@+id/labels" android:layout_width="match_parent" - android:layout_height="150dp" + android:layout_height="wrap_content" android:choiceMode="multipleChoice" - android:visibility="gone" - tools:layout_height="150dp" - tools:listitem="@android:layout/simple_list_item_multiple_choice" /> + app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" + tools:itemCount="4" + tools:listitem="@layout/item_user" /> <TextView android:layout_width="match_parent" diff --git a/app/src/main/res/layout/item_comment.xml b/app/src/main/res/layout/item_comment.xml index dc983564c..cb94a69e1 100644 --- a/app/src/main/res/layout/item_comment.xml +++ b/app/src/main/res/layout/item_comment.xml @@ -69,6 +69,7 @@ android:layout_height="wrap_content" android:layout_gravity="center" android:autofillHints="@null" + tools:maxLength="200" tools:text="@tools:sample/lorem/random" /> </LinearLayout> </LinearLayout>
\ No newline at end of file diff --git a/app/src/main/res/layout/item_user.xml b/app/src/main/res/layout/item_user.xml new file mode 100644 index 000000000..7d2f584f4 --- /dev/null +++ b/app/src/main/res/layout/item_user.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:padding="@dimen/spacer_2x"> + + <FrameLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content"> + + <ImageView + android:id="@+id/avatar" + android:layout_width="@dimen/avatar_size" + android:layout_height="@dimen/avatar_size" + android:layout_marginEnd="@dimen/spacer_2x" + android:layout_marginRight="@dimen/spacer_2x" + android:contentDescription="@null" + app:srcCompat="@drawable/ic_person_grey600_24dp" + tools:srcCompat="@tools:sample/avatars" /> + + <androidx.appcompat.widget.AppCompatImageView + android:layout_width="22dp" + android:layout_height="22dp" + android:layout_gravity="end|bottom" + android:background="@drawable/selected" /> + </FrameLayout> + + <TextView + android:id="@+id/displayname" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:textSize="16sp" + tools:text="@tools:sample/full_names" /> + +</LinearLayout>
\ No newline at end of file |