Added bottom navigation view (currently unpopulated) and changed logic for pages

This commit is contained in:
denizk0461
2023-04-12 10:49:30 +02:00
parent a37b6dfd0b
commit 7da43dc2b7
11 changed files with 113 additions and 53 deletions
@@ -1,33 +1,46 @@
package com.denizk0461.studip.adapter package com.denizk0461.studip.adapter
import android.graphics.Color
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewGroup import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.denizk0461.studip.R
import com.denizk0461.studip.model.StudIPEvent import com.denizk0461.studip.model.StudIPEvent
import com.denizk0461.studip.databinding.ItemEventBinding import com.denizk0461.studip.databinding.ItemEventBinding
class StudIPEventAdapter(private val events: List<StudIPEvent>) : RecyclerView.Adapter<StudIPEventAdapter.EventViewHolder>() { class StudIPEventAdapter(events: List<StudIPEvent>, private val currentDay: Int) : RecyclerView.Adapter<StudIPEventAdapter.EventViewHolder>() {
private val filteredEvents: List<StudIPEvent> = events.filter { it.day == currentDay }
class EventViewHolder(val binding: ItemEventBinding) : 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 {
return EventViewHolder(
ItemEventBinding.inflate( ItemEventBinding.inflate(
LayoutInflater.from(parent.context), LayoutInflater.from(parent.context),
parent, parent,
false false
) )
) )
}
override fun getItemCount(): Int = events.size override fun getItemCount(): Int = filteredEvents.size
override fun onBindViewHolder(holder: EventViewHolder, position: Int) { override fun onBindViewHolder(holder: EventViewHolder, position: Int) {
val currentItem = events[position] val currentItem = filteredEvents[position]
holder.binding.textTitle.text = currentItem.title holder.binding.textTitle.text = currentItem.title
holder.binding.textLecturers.text = currentItem.lecturer holder.binding.textLecturers.text = currentItem.lecturer
holder.binding.textRoom.text = currentItem.room holder.binding.textRoom.text = currentItem.room
holder.binding.textTimeslot.text = currentItem.timeslot() holder.binding.textTimeslot.text = currentItem.timeslot()
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
}
// TODO inflate view saying "no events!" or sth // TODO inflate view saying "no events!" or sth
} }
@@ -25,7 +25,7 @@ class StudIPEventPageAdapter(private val events: List<StudIPEvent>) : RecyclerVi
holder.binding.pageRecyclerView.apply { holder.binding.pageRecyclerView.apply {
layoutManager = LinearLayoutManager(holder.binding.root.context, LinearLayoutManager.VERTICAL, false) layoutManager = LinearLayoutManager(holder.binding.root.context, LinearLayoutManager.VERTICAL, false)
adapter = StudIPEventAdapter(events.filter { it.day == position }) // TODO check if empty adapter = StudIPEventAdapter(events, currentDay = position) // TODO check if empty
scheduleLayoutAnimation() scheduleLayoutAnimation()
} }
} }
@@ -67,8 +67,8 @@ class EventFragment : Fragment() {
binding.recyclerView.onFlingListener = null binding.recyclerView.onFlingListener = null
pagerSnapHelper.attachToRecyclerView(binding.recyclerView) pagerSnapHelper.attachToRecyclerView(binding.recyclerView)
// binding.recyclerView.scheduleLayoutAnimation() // binding.recyclerView.scheduleLayoutAnimation()
binding.recyclerView.scrollToPosition(dayOfWeek)
binding.dayTabs.getTabAt(dayOfWeek)?.select() switchToCurrentDayView()
} }
binding.fab.setOnClickListener { view -> binding.fab.setOnClickListener { view ->
@@ -107,12 +107,29 @@ class EventFragment : Fragment() {
// } // }
} }
override fun onResume() {
super.onResume()
switchToCurrentDayView()
}
override fun onDestroyView() { override fun onDestroyView() {
super.onDestroyView() super.onDestroyView()
_binding = null _binding = null
} }
private fun switchToCurrentDayView() {
binding.recyclerView.scrollToPosition(dayOfWeek)
binding.dayTabs.getTabAt(dayOfWeek)?.select()
}
private fun launchWebview() { private fun launchWebview() {
findNavController(this).navigate(R.id.action_FirstFragment_to_SecondFragment) findNavController(this).navigate(R.id.action_FirstFragment_to_SecondFragment)
} }
/**
* Highlights the current or next course.
*/
private fun highlightCurrentCourse() {
}
} }
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:color="@color/primaryLight" />
<item android:state_pressed="true"
android:state_enabled="false"
android:color="@android:color/transparent" />
<item android:state_enabled="false"
android:color="@android:color/transparent" />
</selector>
+9 -1
View File
@@ -7,6 +7,14 @@
android:fitsSystemWindows="true" android:fitsSystemWindows="true"
tools:context=".activity.MainActivity"> tools:context=".activity.MainActivity">
<include layout="@layout/content_main" /> <com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_gravity="bottom" />
<include layout="@layout/content_main"
android:layout_marginBottom="56dp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>
+12 -10
View File
@@ -11,22 +11,26 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:fitsSystemWindows="true"> android:fitsSystemWindows="true">
<com.google.android.material.appbar.CollapsingToolbarLayout <!-- <com.google.android.material.appbar.MaterialToolbar-->
android:layout_width="match_parent" <!-- android:id="@+id/toolbar"-->
android:layout_height="wrap_content"> <!-- android:layout_width="match_parent"-->
<!-- android:layout_height="?attr/actionBarSize"/>-->
<com.google.android.material.appbar.MaterialToolbar <TextView
android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="48dp"
app:title="title"/> android:text="@string/your_schedule"
android:textSize="32sp"
android:fontFamily="@font/lato_bolditalic"
android:layout_marginHorizontal="16dp"/>
<com.google.android.material.tabs.TabLayout <com.google.android.material.tabs.TabLayout
android:id="@+id/day_tabs" android:id="@+id/day_tabs"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:tabMode="scrollable" app:tabMode="scrollable"
android:layout_gravity="bottom"> android:layout_gravity="bottom"
android:background="@android:color/transparent">
<com.google.android.material.tabs.TabItem <com.google.android.material.tabs.TabItem
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -55,8 +59,6 @@
</com.google.android.material.tabs.TabLayout> </com.google.android.material.tabs.TabLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
+1
View File
@@ -7,6 +7,7 @@
android:orientation="vertical"> android:orientation="vertical">
<com.google.android.material.card.MaterialCardView <com.google.android.material.card.MaterialCardView
android:id="@+id/card_background"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
style="@style/Widget.Material3.CardView.Outlined"> style="@style/Widget.Material3.CardView.Outlined">
+3 -2
View File
@@ -1,7 +1,8 @@
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="Base.Theme.StudIPTimetable" parent="Theme.Material3.DayNight.NoActionBar"> <style name="Base.Theme.StudIPTimetable" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your dark theme here. -->
<!-- <item name="colorPrimary">@color/my_dark_primary</item> --> <!-- colour -->
<item name="colorPrimary">@color/primaryDark</item>
</style> </style>
</resources> </resources>
+3
View File
@@ -2,4 +2,7 @@
<resources> <resources>
<color name="black">#FF000000</color> <color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color> <color name="white">#FFFFFFFF</color>
<color name="primaryLight">#0F4759</color>
<color name="primaryDark">#62CCE4</color>
</resources> </resources>
+2
View File
@@ -13,6 +13,8 @@
<string name="thursday">THURSDAY</string> <string name="thursday">THURSDAY</string>
<string name="friday">FRIDAY</string> <string name="friday">FRIDAY</string>
<string name="your_schedule">Your Schedule</string>
<string name="lorem_ipsum"> <string name="lorem_ipsum">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam in scelerisque sem. Mauris Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam in scelerisque sem. Mauris
volutpat, dolor id interdum ullamcorper, risus dolor egestas lectus, sit amet mattis purus volutpat, dolor id interdum ullamcorper, risus dolor egestas lectus, sit amet mattis purus
+5 -2
View File
@@ -1,9 +1,12 @@
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="Base.Theme.StudIPTimetable" parent="Theme.Material3.DayNight.NoActionBar"> <style name="Base.Theme.StudIPTimetable" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> --> <!-- customisation -->
<item name="fontFamily">@font/lato_regular</item> <item name="fontFamily">@font/lato_regular</item>
<!-- colour -->
<item name="colorPrimary">@color/primaryLight</item>
</style> </style>
<style name="Theme.StudIPTimetable" parent="Base.Theme.StudIPTimetable" /> <style name="Theme.StudIPTimetable" parent="Base.Theme.StudIPTimetable" />