Implemented page view for courses

This commit is contained in:
denizk0461
2023-04-08 13:43:26 +02:00
parent 73ea48626d
commit 9c0e67b396
8 changed files with 108 additions and 24 deletions
+9 -9
View File
@@ -37,14 +37,14 @@ android {
dependencies { dependencies {
implementation 'androidx.core:core-ktx:1.7.0' implementation 'androidx.core:core-ktx:1.10.0'
implementation 'androidx.appcompat:appcompat:1.4.1' implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.5.0' implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3' implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.4.1' implementation 'androidx.navigation:navigation-fragment-ktx:2.5.3'
implementation 'androidx.navigation:navigation-ui-ktx:2.4.1' implementation 'androidx.navigation:navigation-ui-ktx:2.5.3'
implementation 'androidx.core:core-ktx:+' implementation 'androidx.core:core-ktx:1.10.0'
testImplementation 'junit:junit:4.13.2' testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
} }
@@ -0,0 +1,45 @@
package com.denizk0461.studip.adapter
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.denizk0461.studip.data.StudIPEvent
import com.denizk0461.studip.databinding.ItemEventBinding
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)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EventViewHolder = EventViewHolder(
ItemEventPageBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
)
override fun getItemCount(): Int = 5
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 ->
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
}
}
}
@@ -3,6 +3,11 @@ package com.denizk0461.studip.data
object DummyData { object DummyData {
val events: Array<StudIPEvent> = arrayOf( val events: Array<StudIPEvent> = arrayOf(
StudIPEvent("Literatures", arrayOf("Nittel"), "MZH 1380/1400", 0, 3, 1),
StudIPEvent("Linguistics", arrayOf("Du Bois"), "SFG 1020", 1, 1, 1),
StudIPEvent("System Erde", arrayOf("Zolitschka", "Labuhn-Deroubaix"), "GW2 B1410", 1, 3, 1),
StudIPEvent("Key Moments", arrayOf("Esders-Angermund"), "GW2 B2890", 2, 2, 1),
StudIPEvent("ULS-1", arrayOf("Herrmann"), "GW2 B2890", 2, 3, 1),
StudIPEvent("Gesellschaft und Raum", arrayOf("Lossau", "Mossig"), "GW2 B1820", 3, 1, 1),
) )
} }
@@ -4,9 +4,17 @@ data class StudIPEvent(
val title: String, // the name of the event val title: String, // the name of the event
val lecturer: Array<String>, // the lecturer(s) val lecturer: Array<String>, // the lecturer(s)
val room: String, // the room the event takes place in; assumes that the room doesn't change val room: String, // the room the event takes place in; assumes that the room doesn't change
val timeStart: Int, // 1 = 08:15, 2 = 10:15, 3 = 12:15, 4 = 14:15, 5 = 16:15, 6 = 18:15 val day: Int, // 0 = Monday, 1 = Tuesday, 2 = Wednesday, 3 = Thursday, 4 = Friday
val timeLength: Int, // the amount of hours the course takes place over val timeslotStart: Int, // 0 = 08:15, 1 = 10:15, 2 = 12:15, 3 = 14:15, 4 = 16:15, 5 = 18:15
val timeslots: Int, // the amount of timeslots the course takes place over (1 timeslot = 90min)
) { ) {
private val timeSlotStartTimes: List<String> = listOf("08:15", "10:15", "12:15", "14:15", "16:15", "18:15")
private val timeSlotEndTimes: List<String> = listOf("09:45", "11:45", "13:45", "15:45", "17:45", "19:45")
val timeslot: String =
"${timeSlotStartTimes[timeslotStart]} ${timeSlotEndTimes[timeslots - 1]}"
override fun equals(other: Any?): Boolean { override fun equals(other: Any?): Boolean {
if (this === other) return true if (this === other) return true
if (javaClass != other?.javaClass) return false if (javaClass != other?.javaClass) return false
@@ -6,6 +6,12 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.LinearSnapHelper
import androidx.recyclerview.widget.PagerSnapHelper
import com.denizk0461.studip.adapter.StudIPEventAdapter
import com.denizk0461.studip.data.DummyData
import com.denizk0461.studip.databinding.FragmentFirstBinding import com.denizk0461.studip.databinding.FragmentFirstBinding
/** /**
@@ -18,16 +24,23 @@ class FirstFragment : Fragment() {
// This property is only valid between onCreateView and // This property is only valid between onCreateView and
// onDestroyView. // onDestroyView.
private val binding get() = _binding!! private val binding get() = _binding!!
private lateinit var recyclerViewAdapter: StudIPEventAdapter
private lateinit var recyclerViewLayoutManager: LinearLayoutManager
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
_binding = FragmentFirstBinding.inflate(inflater, container, false) _binding = FragmentFirstBinding.inflate(inflater, container, false)
return binding.root return binding.root
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
recyclerViewAdapter = StudIPEventAdapter(DummyData.events.toList())
binding.recyclerView.adapter = recyclerViewAdapter
recyclerViewLayoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
binding.recyclerView.layoutManager = recyclerViewLayoutManager
PagerSnapHelper().attachToRecyclerView(binding.recyclerView)
// binding.buttonFirst.setOnClickListener { // binding.buttonFirst.setOnClickListener {
// findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment) // findNavController().navigate(R.id.action_FirstFragment_to_SecondFragment)
// } // }
+7 -10
View File
@@ -1,18 +1,15 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".fragment.FirstFragment"> tools:context=".fragment.FirstFragment">
<androidx.constraintlayout.widget.ConstraintLayout <androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent" android:id="@+id/recycler_view"
android:layout_height="match_parent" android:layout_width="match_parent"
android:padding="16dp"> android:layout_height="match_parent"
android:scrollbars="horizontal"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" <androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical">
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/page_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.core.widget.NestedScrollView>