Skip to content

Commit

Permalink
Clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
s1g53gv committed Dec 3, 2024
1 parent b737b52 commit 730f9c8
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-FileCopyrightText: NOI Techpark <[email protected]>
//
// 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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -32,6 +33,7 @@ class MeetFiltersSectionAdapter(
}

var filters: List<FilterValue> = emptyList()
@SuppressLint("NotifyDataSetChanged")
set(value) {
field = value
notifyDataSetChanged()
Expand Down Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
})
}
}
}

Expand Down Expand Up @@ -214,6 +229,7 @@ class MeetFiltersFragment : Fragment() {
categoriesRecyclerView.apply {
layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false)
adapter = categoriesAdapter
addItemDecoration(CategoriesItemDecoration())
}
}
}
Expand Down
10 changes: 4 additions & 6 deletions app/src/main/res/layout/vh_header.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SPDX-FileCopyrightText: NOI Techpark <[email protected]>
SPDX-License-Identifier: CC0-1.0
-->

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout 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"
Expand All @@ -19,11 +19,9 @@ SPDX-License-Identifier: CC0-1.0

<TextView
android:id="@+id/headerTextView"
android:layout_width="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Header"
android:textColor="@color/secondary_color"
style="?attr/textAppearanceHeadline4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
style="?attr/textAppearanceHeadline4" />
</FrameLayout>

0 comments on commit 730f9c8

Please sign in to comment.