diff --git a/app/src/main/java/it/bz/noi/community/ui/meet/CategoriesItemDecoration.kt b/app/src/main/java/it/bz/noi/community/ui/meet/CategoriesItemDecoration.kt new file mode 100644 index 0000000..880169f --- /dev/null +++ b/app/src/main/java/it/bz/noi/community/ui/meet/CategoriesItemDecoration.kt @@ -0,0 +1,27 @@ +// SPDX-FileCopyrightText: NOI Techpark +// +// SPDX-License-Identifier: AGPL-3.0-or-later +package it.bz.noi.community.ui.meet + +import android.graphics.Rect +import android.view.View +import androidx.recyclerview.widget.RecyclerView +import androidx.recyclerview.widget.RecyclerView.ItemDecoration +import it.bz.noi.community.R + +/** + * Add spacing between items in the recyclerview. + */ +class CategoriesItemDecoration : ItemDecoration() { + + override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) { + val position = parent.getChildAdapterPosition(view) + val margin = view.resources.getDimensionPixelSize(R.dimen.chip_spacing) + when { + position != 0 -> { + outRect.left = margin + } + else -> Unit + } + } +} diff --git a/app/src/main/java/it/bz/noi/community/ui/meet/MeetFiltersAdapter.kt b/app/src/main/java/it/bz/noi/community/ui/meet/MeetFiltersAdapter.kt index ef7dceb..29f3fee 100644 --- a/app/src/main/java/it/bz/noi/community/ui/meet/MeetFiltersAdapter.kt +++ b/app/src/main/java/it/bz/noi/community/ui/meet/MeetFiltersAdapter.kt @@ -4,6 +4,7 @@ package it.bz.noi.community.ui.meet +import android.annotation.SuppressLint import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView @@ -32,6 +33,7 @@ class MeetFiltersSectionAdapter( } var filters: List = emptyList() + @SuppressLint("NotifyDataSetChanged") set(value) { field = value notifyDataSetChanged() @@ -81,6 +83,7 @@ class MeetFiltersSectionAdapter( override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { when (holder) { is HeaderViewHolder -> { + println("HeaderViewHolder: $initial") holder.bind("$initial") } is FilterViewHolder -> { diff --git a/app/src/main/java/it/bz/noi/community/ui/meet/MeetFiltersFragment.kt b/app/src/main/java/it/bz/noi/community/ui/meet/MeetFiltersFragment.kt index 6d96b4b..2cb9001 100644 --- a/app/src/main/java/it/bz/noi/community/ui/meet/MeetFiltersFragment.kt +++ b/app/src/main/java/it/bz/noi/community/ui/meet/MeetFiltersFragment.kt @@ -137,6 +137,21 @@ class MeetFiltersFragment : Fragment() { AccountsManager.updateSearchParam("") } + /** + * Estrae la prima lettera dalla descrizione del filtro, se รจ una lettera. Altrimenti restituisce '#'. + */ + private val FilterValue.initial: Char + get() = normalizedDesc().first().takeIf { it.isLetter() }?.uppercaseChar() ?: '#' + + /** + * Restituisce la descrizione del filtro normalizzata, senza caratteri diacritici. + * Usata sia per ordinare i filtri, sia per raggrupparli per iniziale. + */ + private fun FilterValue.normalizedDesc(): String { + return Normalizer.normalize(desc, Normalizer.Form.NFD) + .replace("\\p{M}".toRegex(), "") + } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -151,11 +166,11 @@ class MeetFiltersFragment : Fragment() { } filtersByType.values.flatten().groupedByInitial { - it.desc.first().uppercaseChar() + it.initial }.forEach { (initial, filters) -> - adapters[initial]?.filters = filters.sortedWith(Comparator { a, b -> + adapters[initial]?.filters = filters.sortedWith { a, b -> compareFilters(a.desc, b.desc) - }) + } } } @@ -214,6 +229,7 @@ class MeetFiltersFragment : Fragment() { categoriesRecyclerView.apply { layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false) adapter = categoriesAdapter + addItemDecoration(CategoriesItemDecoration()) } } } diff --git a/app/src/main/res/layout/vh_header.xml b/app/src/main/res/layout/vh_header.xml index 4e841b0..85376ab 100644 --- a/app/src/main/res/layout/vh_header.xml +++ b/app/src/main/res/layout/vh_header.xml @@ -6,7 +6,7 @@ SPDX-FileCopyrightText: NOI Techpark SPDX-License-Identifier: CC0-1.0 --> - - + style="?attr/textAppearanceHeadline4" /> +