Archived
Big change successful; main view now uses RecyclerView for both horizontal and vertical scrolling, as using LinearLayout caused a duplication glitch on the first and last page
This commit is contained in:
@@ -10,37 +10,38 @@ import com.denizk0461.studip.databinding.ItemEventPageBinding
|
||||
|
||||
class StudIPEventAdapter(private val events: List<StudIPEvent>) : RecyclerView.Adapter<StudIPEventAdapter.EventViewHolder>() {
|
||||
|
||||
class EventViewHolder(val binding: ItemEventPageBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
class EventViewHolder(val binding: ItemEventBinding) : RecyclerView.ViewHolder(binding.root)
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EventViewHolder = EventViewHolder(
|
||||
ItemEventPageBinding.inflate(
|
||||
ItemEventBinding.inflate(
|
||||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
)
|
||||
)
|
||||
|
||||
override fun getItemCount(): Int = 5
|
||||
override fun getItemCount(): Int = events.size
|
||||
|
||||
override fun onBindViewHolder(holder: EventViewHolder, position: Int) {
|
||||
var itemCount = 0
|
||||
events.filter { it.day == position }.forEach { event ->
|
||||
val newView = ItemEventBinding.inflate(
|
||||
LayoutInflater.from(holder.binding.root.context),
|
||||
holder.binding.root,
|
||||
false
|
||||
).also { item ->
|
||||
Log.d("HELLO", "generating ${event.title}...2")
|
||||
itemCount += 1
|
||||
item.textTitle.text = event.title
|
||||
item.textLecturers.text = event.lecturer.joinToString(", ")
|
||||
item.textRoom.text = event.room
|
||||
item.textTimeslot.text = event.timeslot
|
||||
}
|
||||
holder.binding.pageLayout.addView(newView.root)
|
||||
}
|
||||
if (itemCount == 0) {
|
||||
// TODO inflate view saying "no events!" or sth
|
||||
}
|
||||
val currentItem = events[position]
|
||||
// var itemCount = 0
|
||||
// events.filter { it.day == position }.forEach { event ->
|
||||
// val newView = ItemEventBinding.inflate(
|
||||
// LayoutInflater.from(holder.binding.root.context),
|
||||
// holder.binding.root,
|
||||
// false
|
||||
// ).also { item ->
|
||||
// Log.d("HELLO", "generating ${event.title}...2")
|
||||
// itemCount += 1
|
||||
holder.binding.textTitle.text = currentItem.title
|
||||
holder.binding.textLecturers.text = currentItem.lecturer.joinToString(", ")
|
||||
holder.binding.textRoom.text = currentItem.room
|
||||
holder.binding.textTimeslot.text = currentItem.timeslot
|
||||
// }
|
||||
// holder.binding.pageLayout.addView(newView.root)
|
||||
// }
|
||||
// if (itemCount == 0) {
|
||||
// // TODO inflate view saying "no events!" or sth
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ package com.denizk0461.studip.adapter
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.denizk0461.studip.data.StudIPEvent
|
||||
import com.denizk0461.studip.databinding.ItemEventBinding
|
||||
@@ -23,24 +25,30 @@ class StudIPEventPageAdapter(private val events: List<StudIPEvent>) : RecyclerVi
|
||||
override fun getItemCount(): Int = 5
|
||||
|
||||
override fun onBindViewHolder(holder: EventPageViewHolder, position: Int) {
|
||||
var itemCount = 0
|
||||
events.filter { it.day == position }.forEach { event ->
|
||||
val newView = ItemEventBinding.inflate(
|
||||
LayoutInflater.from(holder.binding.root.context),
|
||||
holder.binding.root,
|
||||
false
|
||||
).also { item ->
|
||||
Log.d("HELLO", "generating ${event.title}...2")
|
||||
itemCount += 1
|
||||
item.textTitle.text = event.title
|
||||
item.textLecturers.text = event.lecturer.joinToString(", ")
|
||||
item.textRoom.text = event.room
|
||||
item.textTimeslot.text = event.timeslot
|
||||
}
|
||||
holder.binding.pageLayout.addView(newView.root)
|
||||
}
|
||||
if (itemCount == 0) {
|
||||
// TODO inflate view saying "no events!" or sth
|
||||
|
||||
holder.binding.pageRecyclerView.apply {
|
||||
layoutManager = LinearLayoutManager(holder.binding.root.context, LinearLayoutManager.VERTICAL, false)
|
||||
adapter = StudIPEventAdapter(events.filter { it.day == position }) // TODO check if empty
|
||||
}
|
||||
|
||||
// var itemCount = 0
|
||||
// events.filter { it.day == position }.forEach { event ->
|
||||
// val newView = ItemEventBinding.inflate(
|
||||
// LayoutInflater.from(holder.binding.root.context),
|
||||
// holder.binding.root,
|
||||
// false
|
||||
// ).also { item ->
|
||||
// Log.d("HELLO", "generating ${event.title}...2")
|
||||
// itemCount += 1
|
||||
// item.textTitle.text = event.title
|
||||
// item.textLecturers.text = event.lecturer.joinToString(", ")
|
||||
// item.textRoom.text = event.room
|
||||
// item.textTimeslot.text = event.timeslot
|
||||
// }
|
||||
// holder.binding.pageLayout.addView(newView.root)
|
||||
// }
|
||||
// if (itemCount == 0) {
|
||||
// // TODO inflate view saying "no events!" or sth
|
||||
// }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user