Upcoming/current course of the current day will now be highlighted with a thicker border

This commit is contained in:
denizk0461
2023-04-14 13:09:40 +02:00
parent a3489d06b3
commit f07c41079a
8 changed files with 83 additions and 18 deletions
@@ -1,17 +1,25 @@
package com.denizk0461.studip.adapter package com.denizk0461.studip.adapter
import android.content.res.ColorStateList
import android.util.AttributeSet
import android.util.Log
import android.util.TypedValue
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
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
import java.util.*
class StudIPEventAdapter( class StudIPEventAdapter(
events: List<StudIPEvent>, private val currentDay: Int, private val onClickListener: OnClickListener events: List<StudIPEvent>, private val currentDay: Int, private val onClickListener: OnClickListener
) : RecyclerView.Adapter<StudIPEventAdapter.EventViewHolder>() { ) : RecyclerView.Adapter<StudIPEventAdapter.EventViewHolder>() {
private val filteredEvents: List<StudIPEvent> = events.filter { it.day == currentDay } private val filteredEvents: List<StudIPEvent> = events.filter { it.day == currentDay }
private val currentCalendar = Calendar.getInstance()
private var isAnyCourseHighlighted = false
class EventViewHolder(val binding: ItemEventBinding) : RecyclerView.ViewHolder(binding.root) class EventViewHolder(val binding: ItemEventBinding) : RecyclerView.ViewHolder(binding.root)
@@ -35,10 +43,25 @@ class StudIPEventAdapter(
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 val colorPrimary = TypedValue()
val colorTextHint = TypedValue()
val theme = holder.binding.root.context.theme
theme.resolveAttribute(R.attr.colorPrimary, colorPrimary, true)
theme.resolveAttribute(R.attr.colorTextHintLighter, colorTextHint, true)
// Log.d("eek!", holder.binding.cardBackground.strokeWidth.toString())
if (!isAnyCourseHighlighted && currentItem.isCurrentCourse(currentCalendar)) { // highlight
isAnyCourseHighlighted = true
// holder.binding.textTitle.setTextColor(colorHighlight.data)
holder.binding.cardBackground.strokeColor = colorPrimary.data
holder.binding.cardBackground.strokeWidth = 6
// holder.binding.cardBackground.cardForegroundColor = holder.binding.root.context.getColorStateList( // holder.binding.cardBackground.cardForegroundColor = holder.binding.root.context.getColorStateList(
// R.color.list_card_selected) // R.color.list_card_selected)
} else { // un-highlight } else { // un-highlight
// holder.binding.textTitle.setTextColor(colorUnhighlight.data)
holder.binding.cardBackground.strokeColor = colorTextHint.data
holder.binding.cardBackground.strokeWidth = 3
// holder.binding.cardBackground.cardForegroundColor = Color.TRANSPARENT // holder.binding.cardBackground.cardForegroundColor = Color.TRANSPARENT
} }
@@ -54,6 +77,32 @@ class StudIPEventAdapter(
} }
private fun StudIPEvent.isCurrentCourse(calendar: Calendar): Boolean {
// if (calendar.get(Calendar.DAY_OF_WEEK) == this.day.toCalendarDay()) {
if (Calendar.THURSDAY == this.day.toCalendarDay()) {
if ((calendar.get(Calendar.MINUTE) + calendar.get(Calendar.HOUR_OF_DAY) * 60) < this.timeslotEnd.parseToMinutes()) {
return true
}
}
return false
}
// Converts day as defined in StudIPEvent.kt to day from Calendar
private fun Int.toCalendarDay(): Int = when (this) {
1 -> Calendar.TUESDAY
2 -> Calendar.WEDNESDAY
3 -> Calendar.THURSDAY
4 -> Calendar.FRIDAY
5 -> Calendar.SATURDAY
6 -> Calendar.SUNDAY
else -> Calendar.MONDAY
}
private fun String.parseToMinutes(): Int {
val parts = split(":")
return (parts[0].toInt() * 60) + parts[1].toInt()
}
interface OnClickListener { interface OnClickListener {
fun onClick(event: StudIPEvent) fun onClick(event: StudIPEvent)
fun onLongClick(event: StudIPEvent) fun onLongClick(event: StudIPEvent)
+9 -9
View File
@@ -40,15 +40,6 @@
app:layout_constraintTop_toBottomOf="@+id/toolbar" app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:navGraph="@navigation/nav_graph"/> app:navGraph="@navigation/nav_graph"/>
<com.google.android.material.divider.MaterialDivider
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
app:layout_constraintTop_toBottomOf="@id/nav_host_fragment_content_main"
app:layout_constraintBottom_toTopOf="@id/nav_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<com.google.android.material.bottomnavigation.BottomNavigationView <com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view" android:id="@+id/nav_view"
android:layout_width="0dp" android:layout_width="0dp"
@@ -63,4 +54,13 @@
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
android:background="?attr/colorBackground"/> android:background="?attr/colorBackground"/>
<com.google.android.material.divider.MaterialDivider
style="@style/DividerTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@id/nav_view"/>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
@@ -37,6 +37,7 @@
android:layout_marginHorizontal="16dp"/> android:layout_marginHorizontal="16dp"/>
<com.google.android.material.divider.MaterialDivider <com.google.android.material.divider.MaterialDivider
style="@style/DividerTheme"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"/> android:layout_marginHorizontal="16dp"/>
+1
View File
@@ -28,6 +28,7 @@
android:fontFamily="@font/lato_bolditalic"/> android:fontFamily="@font/lato_bolditalic"/>
<com.google.android.material.divider.MaterialDivider <com.google.android.material.divider.MaterialDivider
style="@style/DividerTheme"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginVertical="4dp"/> android:layout_marginVertical="4dp"/>
+5
View File
@@ -9,6 +9,7 @@
<item name="colorText">@color/colorTextNight</item> <item name="colorText">@color/colorTextNight</item>
<item name="colorTextHint">@color/colorTextHintNight</item> <item name="colorTextHint">@color/colorTextHintNight</item>
<item name="colorTextHintLighter">@color/colorTextHintLighterNight</item>
<item name="colorBackground">@color/colorBackgroundNight</item> <item name="colorBackground">@color/colorBackgroundNight</item>
<item name="colorCardBackground">@color/colorCardBackgroundNight</item> <item name="colorCardBackground">@color/colorCardBackgroundNight</item>
@@ -27,4 +28,8 @@
<style name="SelectableItemTheme"> <style name="SelectableItemTheme">
<item name="colorControlHighlight">@color/primaryNight</item> <item name="colorControlHighlight">@color/primaryNight</item>
</style> </style>
<style name="DividerTheme" parent="Widget.Material3.MaterialDivider">
<item name="dividerColor">@color/colorTextHintLighterNight</item>
</style>
</resources> </resources>
+2
View File
@@ -2,9 +2,11 @@
<resources> <resources>
<attr name="colorNavHighlight" format="color" /> <attr name="colorNavHighlight" format="color" />
<attr name="colorPrimaryOnContrast" format="color" /> <attr name="colorPrimaryOnContrast" format="color" />
<attr name="colorPrimary" format="color" />
<attr name="colorOnPrimary" format="color" /> <attr name="colorOnPrimary" format="color" />
<attr name="colorText" format="color" /> <attr name="colorText" format="color" />
<attr name="colorTextHint" format="color" /> <attr name="colorTextHint" format="color" />
<attr name="colorTextHintLighter" format="color" />
<attr name="colorBackground" format="color" /> <attr name="colorBackground" format="color" />
<attr name="colorCardBackground" format="color" /> <attr name="colorCardBackground" format="color" />
<attr name="colorSwitchTrack" format="color" /> <attr name="colorSwitchTrack" format="color" />
+10 -8
View File
@@ -2,26 +2,28 @@
<resources> <resources>
<color name="black">#FF000000</color> <color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color> <color name="white">#FFFFFFFF</color>
<color name="brightfuckingpink">#FF46BB</color> <!-- for debug purposes -->
<!-- <color name="primaryLight">#0F4759</color>--> <!-- colours i defined -->
<!-- <color name="primaryDark">#62CCE4</color>--> <color name="primaryDay">#B2665A</color>
<color name="primaryDay">#B2665A</color> <!-- B82729 -->
<color name="primaryNight">#995348</color> <color name="primaryNight">#995348</color>
<color name="highlightDay">#871D1E</color> <color name="highlightDay">#871D1E</color>
<color name="highlightNight">#CB9890</color> <color name="highlightNight">#CB9890</color>
<color name="colorTextDay">#141414</color> // TODO <color name="colorTextDay">#141414</color>
<color name="colorTextNight">#CDCBCB</color> <color name="colorTextNight">#CDCBCB</color>
<color name="colorTextHintDay">#2A2828</color> // TODO <color name="colorTextHintDay">#2A2828</color>
<color name="colorTextHintNight">#B9B6B6</color> <color name="colorTextHintNight">#B9B6B6</color>
<color name="colorBackgroundDay">#EBEBEB</color> // TODO <color name="colorTextHintLighterDay">#3E3C3C</color>
<color name="colorTextHintLighterNight">#918D8D</color>
<color name="colorBackgroundDay">#EBEBEB</color>
<color name="colorBackgroundNight">#151414</color> <color name="colorBackgroundNight">#151414</color>
<color name="colorCardBackgroundDay">#E0E0E0</color> // TODO <color name="colorCardBackgroundDay">#E0E0E0</color>
<color name="colorCardBackgroundNight">#1F1E1E</color> <color name="colorCardBackgroundNight">#1F1E1E</color>
<color name="colorSwitchTrackDay">#D6D6D6</color> <color name="colorSwitchTrackDay">#D6D6D6</color>
+5
View File
@@ -10,6 +10,7 @@
<item name="colorText">@color/colorTextDay</item> <item name="colorText">@color/colorTextDay</item>
<item name="colorTextHint">@color/colorTextHintDay</item> <item name="colorTextHint">@color/colorTextHintDay</item>
<item name="colorTextHintLighter">@color/colorTextHintLighterDay</item>
<item name="colorBackground">@color/colorBackgroundDay</item> <item name="colorBackground">@color/colorBackgroundDay</item>
<item name="colorCardBackground">@color/colorCardBackgroundDay</item> <item name="colorCardBackground">@color/colorCardBackgroundDay</item>
@@ -36,4 +37,8 @@
<style name="SelectableItemTheme"> <style name="SelectableItemTheme">
<item name="colorControlHighlight">@color/primaryDay</item> <item name="colorControlHighlight">@color/primaryDay</item>
</style> </style>
<style name="DividerTheme" parent="Widget.Material3.MaterialDivider">
<item name="dividerColor">@color/colorTextHintLighterDay</item>
</style>
</resources> </resources>