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 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(
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EventViewHolder = EventViewHolder(
|
||||||
ItemEventPageBinding.inflate(
|
ItemEventBinding.inflate(
|
||||||
LayoutInflater.from(parent.context),
|
LayoutInflater.from(parent.context),
|
||||||
parent,
|
parent,
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun getItemCount(): Int = 5
|
override fun getItemCount(): Int = events.size
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: EventViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: EventViewHolder, position: Int) {
|
||||||
var itemCount = 0
|
val currentItem = events[position]
|
||||||
events.filter { it.day == position }.forEach { event ->
|
// var itemCount = 0
|
||||||
val newView = ItemEventBinding.inflate(
|
// events.filter { it.day == position }.forEach { event ->
|
||||||
LayoutInflater.from(holder.binding.root.context),
|
// val newView = ItemEventBinding.inflate(
|
||||||
holder.binding.root,
|
// LayoutInflater.from(holder.binding.root.context),
|
||||||
false
|
// holder.binding.root,
|
||||||
).also { item ->
|
// false
|
||||||
Log.d("HELLO", "generating ${event.title}...2")
|
// ).also { item ->
|
||||||
itemCount += 1
|
// Log.d("HELLO", "generating ${event.title}...2")
|
||||||
item.textTitle.text = event.title
|
// itemCount += 1
|
||||||
item.textLecturers.text = event.lecturer.joinToString(", ")
|
holder.binding.textTitle.text = currentItem.title
|
||||||
item.textRoom.text = event.room
|
holder.binding.textLecturers.text = currentItem.lecturer.joinToString(", ")
|
||||||
item.textTimeslot.text = event.timeslot
|
holder.binding.textRoom.text = currentItem.room
|
||||||
}
|
holder.binding.textTimeslot.text = currentItem.timeslot
|
||||||
holder.binding.pageLayout.addView(newView.root)
|
// }
|
||||||
}
|
// holder.binding.pageLayout.addView(newView.root)
|
||||||
if (itemCount == 0) {
|
// }
|
||||||
// TODO inflate view saying "no events!" or sth
|
// 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.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.LinearLayout
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.denizk0461.studip.data.StudIPEvent
|
import com.denizk0461.studip.data.StudIPEvent
|
||||||
import com.denizk0461.studip.databinding.ItemEventBinding
|
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 getItemCount(): Int = 5
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: EventPageViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: EventPageViewHolder, position: Int) {
|
||||||
var itemCount = 0
|
|
||||||
events.filter { it.day == position }.forEach { event ->
|
holder.binding.pageRecyclerView.apply {
|
||||||
val newView = ItemEventBinding.inflate(
|
layoutManager = LinearLayoutManager(holder.binding.root.context, LinearLayoutManager.VERTICAL, false)
|
||||||
LayoutInflater.from(holder.binding.root.context),
|
adapter = StudIPEventAdapter(events.filter { it.day == position }) // TODO check if empty
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,12 +5,11 @@
|
|||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:scrollbars="vertical">
|
android:scrollbars="vertical">
|
||||||
|
|
||||||
<androidx.appcompat.widget.LinearLayoutCompat
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/page_layout"
|
android:id="@+id/page_recycler_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent">
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
</androidx.recyclerview.widget.RecyclerView>
|
||||||
|
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
||||||
Reference in New Issue
Block a user