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
import android.graphics.Color
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.denizk0461.studip.R
import com.denizk0461.studip.model.StudIPEvent
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)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EventViewHolder = EventViewHolder(
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): EventViewHolder {
return EventViewHolder(
ItemEventBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
)
}
override fun getItemCount(): Int = events.size
override fun getItemCount(): Int = filteredEvents.size
override fun onBindViewHolder(holder: EventViewHolder, position: Int) {
val currentItem = events[position]
val currentItem = filteredEvents[position]
holder.binding.textTitle.text = currentItem.title
holder.binding.textLecturers.text = currentItem.lecturer
holder.binding.textRoom.text = currentItem.room
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
}
@@ -25,7 +25,7 @@ class StudIPEventPageAdapter(private val events: List<StudIPEvent>) : RecyclerVi
holder.binding.pageRecyclerView.apply {
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()
}
}
@@ -67,8 +67,8 @@ class EventFragment : Fragment() {
binding.recyclerView.onFlingListener = null
pagerSnapHelper.attachToRecyclerView(binding.recyclerView)
// binding.recyclerView.scheduleLayoutAnimation()
binding.recyclerView.scrollToPosition(dayOfWeek)
binding.dayTabs.getTabAt(dayOfWeek)?.select()
switchToCurrentDayView()
}
binding.fab.setOnClickListener { view ->
@@ -107,12 +107,29 @@ class EventFragment : Fragment() {
// }
}
override fun onResume() {
super.onResume()
switchToCurrentDayView()
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
private fun switchToCurrentDayView() {
binding.recyclerView.scrollToPosition(dayOfWeek)
binding.dayTabs.getTabAt(dayOfWeek)?.select()
}
private fun launchWebview() {
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"
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>
+12 -10
View File
@@ -11,22 +11,26 @@
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- <com.google.android.material.appbar.MaterialToolbar-->
<!-- android:id="@+id/toolbar"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="?attr/actionBarSize"/>-->
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
<TextView
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:title="title"/>
android:layout_height="48dp"
android:text="@string/your_schedule"
android:textSize="32sp"
android:fontFamily="@font/lato_bolditalic"
android:layout_marginHorizontal="16dp"/>
<com.google.android.material.tabs.TabLayout
android:id="@+id/day_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
android:layout_gravity="bottom">
android:layout_gravity="bottom"
android:background="@android:color/transparent">
<com.google.android.material.tabs.TabItem
android:layout_width="wrap_content"
@@ -55,8 +59,6 @@
</com.google.android.material.tabs.TabLayout>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
+1
View File
@@ -7,6 +7,7 @@
android:orientation="vertical">
<com.google.android.material.card.MaterialCardView
android:id="@+id/card_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.Material3.CardView.Outlined">
+3 -2
View File
@@ -1,7 +1,8 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<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>
</resources>
+3
View File
@@ -2,4 +2,7 @@
<resources>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="primaryLight">#0F4759</color>
<color name="primaryDark">#62CCE4</color>
</resources>
+2
View File
@@ -13,6 +13,8 @@
<string name="thursday">THURSDAY</string>
<string name="friday">FRIDAY</string>
<string name="your_schedule">Your Schedule</string>
<string name="lorem_ipsum">
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
+5 -2
View File
@@ -1,9 +1,12 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<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>
<!-- colour -->
<item name="colorPrimary">@color/primaryLight</item>
</style>
<style name="Theme.StudIPTimetable" parent="Base.Theme.StudIPTimetable" />