This repository has been archived on 2026-05-26. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
weserplaner/app/src/main/java/com/denizk0461/studip/adapter/StudIPEventAdapter.kt
T

61 lines
2.1 KiB
Kotlin
Raw Normal View History

2023-04-08 13:43:26 +02:00
package com.denizk0461.studip.adapter
import android.view.LayoutInflater
2023-04-12 22:07:18 +02:00
import android.view.View
2023-04-08 13:43:26 +02:00
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
2023-04-08 18:53:51 +02:00
import com.denizk0461.studip.model.StudIPEvent
2023-04-08 13:43:26 +02:00
import com.denizk0461.studip.databinding.ItemEventBinding
2023-04-12 22:07:18 +02:00
class StudIPEventAdapter(
events: List<StudIPEvent>, private val currentDay: Int, private val onClickListener: OnClickListener
) : RecyclerView.Adapter<StudIPEventAdapter.EventViewHolder>() {
private val filteredEvents: List<StudIPEvent> = events.filter { it.day == currentDay }
2023-04-08 13:43:26 +02:00
class EventViewHolder(val binding: ItemEventBinding) : RecyclerView.ViewHolder(binding.root)
2023-04-08 13:43:26 +02:00
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EventViewHolder {
return EventViewHolder(
ItemEventBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
2023-04-08 13:43:26 +02:00
)
}
2023-04-08 13:43:26 +02:00
override fun getItemCount(): Int = filteredEvents.size
2023-04-08 13:43:26 +02:00
override fun onBindViewHolder(holder: EventViewHolder, position: Int) {
val currentItem = filteredEvents[position]
2023-04-08 17:30:05 +02:00
holder.binding.textTitle.text = currentItem.title
2023-04-08 17:30:05 +02:00
holder.binding.textLecturers.text = currentItem.lecturer
holder.binding.textRoom.text = currentItem.room
holder.binding.textTimeslot.text = currentItem.timeslot()
2023-04-08 17:30:05 +02:00
if (true) { // highlight
// holder.binding.cardBackground.cardForegroundColor = holder.binding.root.context.getColorStateList(
// R.color.list_card_selected)
} else { // un-highlight
// holder.binding.cardBackground.cardForegroundColor = Color.TRANSPARENT
}
2023-04-12 22:07:18 +02:00
holder.binding.cardBackground.setOnClickListener {
onClickListener.onClick(currentItem)
}
holder.binding.cardBackground.setOnLongClickListener {
onClickListener.onLongClick(currentItem)
true
}
2023-04-08 17:30:05 +02:00
// TODO inflate view saying "no events!" or sth
2023-04-08 13:43:26 +02:00
}
2023-04-12 22:07:18 +02:00
interface OnClickListener {
fun onClick(event: StudIPEvent)
fun onLongClick(event: StudIPEvent)
}
2023-04-08 13:43:26 +02:00
}