Skip to content

Commit

Permalink
Minor code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
naveensingh committed Jan 14, 2025
1 parent fd0bc29 commit feb711b
Showing 1 changed file with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ class QuickFilterEventTypeAdapter(
private val textColorActive = activity.getProperTextColor()
private val textColorInactive = textColorActive.adjustAlpha(LOWER_ALPHA)

private val minItemWidth = activity.resources.getDimensionPixelSize(R.dimen.quick_filter_min_width)
private val minItemWidth =
activity.resources.getDimensionPixelSize(R.dimen.quick_filter_min_width)
private var lastClickTS = 0L

private var lastLongClickedType: EventType? = null
private var lastActiveKeys = HashSet<Long>()

init {
quickFilterEventTypeIds.forEach { quickFilterEventType ->
val eventType = allEventTypes.firstOrNull { eventType -> eventType.id.toString() == quickFilterEventType } ?: return@forEach
val eventType = allEventTypes
.firstOrNull { eventType -> eventType.id.toString() == quickFilterEventType }
?: return@forEach
quickFilterEventTypes.add(eventType)

if (displayEventTypes.contains(eventType.id.toString())) {
Expand All @@ -57,7 +60,10 @@ class QuickFilterEventTypeAdapter(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QuickFilterViewHolder {
val parentWidth = parent.measuredWidth
val numberOfItems = quickFilterEventTypes.size
val binding = QuickFilterEventTypeViewBinding.inflate(activity.layoutInflater, parent, false)
val binding = QuickFilterEventTypeViewBinding.inflate(
activity.layoutInflater, parent, false
)

binding.root.updateLayoutParams<RecyclerView.LayoutParams> {
width = if (numberOfItems * minItemWidth > parentWidth) {
minItemWidth
Expand All @@ -76,16 +82,19 @@ class QuickFilterEventTypeAdapter(

override fun getItemCount() = quickFilterEventTypes.size

inner class QuickFilterViewHolder(val binding: QuickFilterEventTypeViewBinding) : RecyclerView.ViewHolder(binding.root) {
inner class QuickFilterViewHolder(val binding: QuickFilterEventTypeViewBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bindView(eventType: EventType) {
val isSelected = activeKeys.contains(eventType.id)
binding.apply {
quickFilterEventType.text = eventType.title
val textColor = if (isSelected) textColorActive else textColorInactive
quickFilterEventType.setTextColor(textColor)

val indicatorHeightRes = if (isSelected) R.dimen.quick_filter_active_line_size else R.dimen.quick_filter_inactive_line_size
quickFilterEventTypeColor.layoutParams.height = root.resources.getDimensionPixelSize(indicatorHeightRes)
val indicatorHeightRes =
if (isSelected) R.dimen.quick_filter_active_line_size else R.dimen.quick_filter_inactive_line_size
quickFilterEventTypeColor.layoutParams.height =
root.resources.getDimensionPixelSize(indicatorHeightRes)
quickFilterEventTypeColor.setBackgroundColor(eventType.color)

// avoid too quick clicks, could cause glitches
Expand All @@ -103,8 +112,16 @@ class QuickFilterEventTypeAdapter(
lastActiveKeys.clear()
}
val activeKeysCopy = HashSet(activeKeys)
allEventTypes.forEach { viewClicked(lastActiveKeys.contains(it.id!!), it) }
val shouldSelectCurrent = if (lastLongClickedType != eventType) true else lastActiveKeys.contains(eventType.id!!)
allEventTypes.forEach {
viewClicked(select = lastActiveKeys.contains(it.id!!), eventType = it)
}

val shouldSelectCurrent = if (lastLongClickedType != eventType) {
true
} else {
lastActiveKeys.contains(eventType.id!!)
}

viewClicked(shouldSelectCurrent, eventType)
notifyItemRangeChanged(0, itemCount)
callback()
Expand Down

0 comments on commit feb711b

Please sign in to comment.