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>() {
|
2023-04-12 10:49:30 +02:00
|
|
|
|
|
|
|
|
private val filteredEvents: List<StudIPEvent> = events.filter { it.day == currentDay }
|
2023-04-08 13:43:26 +02:00
|
|
|
|
2023-04-08 15:44:07 +02:00
|
|
|
class EventViewHolder(val binding: ItemEventBinding) : RecyclerView.ViewHolder(binding.root)
|
2023-04-08 13:43:26 +02:00
|
|
|
|
2023-04-12 10:49:30 +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-12 10:49:30 +02:00
|
|
|
}
|
2023-04-08 13:43:26 +02:00
|
|
|
|
2023-04-12 10:49:30 +02:00
|
|
|
override fun getItemCount(): Int = filteredEvents.size
|
2023-04-08 13:43:26 +02:00
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: EventViewHolder, position: Int) {
|
2023-04-12 10:49:30 +02:00
|
|
|
val currentItem = filteredEvents[position]
|
2023-04-08 17:30:05 +02:00
|
|
|
|
2023-04-08 15:44:07 +02:00
|
|
|
holder.binding.textTitle.text = currentItem.title
|
2023-04-08 17:30:05 +02:00
|
|
|
holder.binding.textLecturers.text = currentItem.lecturer
|
2023-04-08 15:44:07 +02:00
|
|
|
holder.binding.textRoom.text = currentItem.room
|
2023-04-10 20:54:15 +02:00
|
|
|
holder.binding.textTimeslot.text = currentItem.timeslot()
|
2023-04-08 17:30:05 +02:00
|
|
|
|
2023-04-12 10:49:30 +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
|
|
|
}
|