Changed filter chip colour, but when pressed, the primary colour needs to be changed to a more desaturated tint

This commit is contained in:
denizk0461
2023-04-20 12:19:44 +02:00
parent de1b5f8005
commit b5f5e06b7f
7 changed files with 46 additions and 100 deletions
@@ -1,14 +1,11 @@
package com.denizk0461.studip.adapter
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.denizk0461.studip.databinding.ItemScrollablePageBinding
import com.denizk0461.studip.model.CanteenOffer
import com.denizk0461.studip.model.CanteenOfferGroup
import com.denizk0461.studip.model.CanteenOfferGroupElement
class CanteenOfferPageAdapter(private var offers: List<CanteenOfferGroup>, private var daysCovered: Int, private var prefsRegex: Regex) : RecyclerView.Adapter<CanteenOfferPageAdapter.CanteenOfferPageViewHolder>() {
@@ -31,15 +28,6 @@ class CanteenOfferPageAdapter(private var offers: List<CanteenOfferGroup>, priva
layoutManager = LinearLayoutManager(holder.binding.root.context, LinearLayoutManager.VERTICAL, false)
// TODO second filter needs to be worked on; it shouldn't filter out something if two options are selected and only one is met
// Log.d("eek!5", prefsRegex.toString())
// .filter { it.dietaryPreferences == prefs.deconstruct() }
// val filtered2 = filtered
// offers
adapter = CanteenOfferItemAdapter(offers.filter { it.dateId == position }) // TODO check if empty
scheduleLayoutAnimation()
}
@@ -50,12 +38,4 @@ class CanteenOfferPageAdapter(private var offers: List<CanteenOfferGroup>, priva
offers = items
notifyDataSetChanged()
}
fun refreshView(prefsRegex: Regex) {
this.prefsRegex = prefsRegex
notifyDataSetChanged()
}
// private fun constructRegex(pref: String): String =
// pref.replace('f', '.')
}
@@ -4,52 +4,23 @@ import com.denizk0461.studip.R
object Misc {
// val events: Array<StudIPEvent> = arrayOf(
// StudIPEvent(1, "Literatures", "Nittel", "MZH 1380/1400", 0, 3, 1),
// StudIPEvent(2, "Linguistics", "Du Bois", "SFG 1020", 1, 1, 1),
// StudIPEvent(3, "System Erde", "Zolitschka, Labuhn-Deroubaix", "GW2 B1410", 1, 3, 1),
// StudIPEvent(4, "Key Moments", "Esders-Angermund", "GW2 B2890", 2, 2, 1),
// StudIPEvent(5, "ULS-1", "Herrmann", "GW2 B2890", 2, 3, 1),
// StudIPEvent(6, "Gesellschaft und Raum", "Lossau, Mossig", "GW2 B1820", 3, 1, 1),
// StudIPEvent(7, "Gesellschaft und Raum2", "Lossau, Mossig", "GW2 B1820", 4, 4, 2),
// )
private val timeslotStartMap: Map<String, Int> = mapOf(
"6:00" to 0,
"6:15" to 0,
"8:00" to 1,
"8:15" to 1,
"10:00" to 2,
"10:15" to 2,
"12:00" to 3,
"12:15" to 3,
"14:00" to 4,
"14:15" to 4,
"16:00" to 5,
"16:15" to 5,
"18:00" to 6,
"18:15" to 6,
"20:00" to 7,
"20:15" to 7,
)
private val timeslotEndMap: Map<String, Int> = mapOf(
"8:00" to 0,
"7:45" to 0,
"10:00" to 1,
"9:45" to 1,
"12:00" to 2,
"11:45" to 2,
"14:00" to 3,
"13:45" to 3,
"16:00" to 4,
"15:45" to 4,
"18:00" to 5,
"17:45" to 5,
"20:00" to 6,
"19:45" to 6,
"22:00" to 7,
"21:45" to 7,
private val timeslotAcademicQuarter = mapOf(
"6:00" to "6:15",
"8:00" to "7:45",
"8:00" to "8:15",
"10:00" to "9:45",
"10:00" to "10:15",
"12:00" to "11:45",
"12:00" to "12:15",
"14:00" to "13:45",
"14:00" to "14:15",
"16:00" to "15:45",
"16:00" to "16:15",
"18:00" to "17:45",
"18:00" to "18:15",
"20:00" to "19:45",
"20:00" to "20:15",
"22:00" to "21:45",
)
val indexToDrawable: Map<Int, Int> = mapOf(
@@ -66,12 +37,5 @@ object Misc {
10 to R.drawable.circle,
)
fun parseTimeslot(time: String): Pair<Int, Int> {
val splitTime = time.split(" - ")
val start = timeslotStartMap[splitTime[0]] ?: 0
val length = (timeslotEndMap[splitTime[1]] ?: 0)
return Pair(start, length)
}
val mysteryLink = "https://www.youtube.com/watch?v=nhIQMCXJzLI"
const val mysteryLink = "https://www.youtube.com/watch?v=nhIQMCXJzLI"
}
@@ -88,7 +88,6 @@ class CanteenFragment : Fragment() {
dates = groupedElements.map { it.date }.distinct()
createTabLayoutMediator()
// this.groupedElements = groupedElements
this.dateSize = dates.size
viewPagerAdapter.setNewItems(groupedElements, dates.size)
@@ -121,15 +120,12 @@ class CanteenFragment : Fragment() {
private fun setPreference(pref: DietaryPreferences, newValue: Boolean) {
viewModel.setPreference(pref, newValue)
// viewPagerAdapter.refreshView(getPrefRegex())
viewPagerAdapter.setNewItems(elements.groupElements().distinct(), dateSize)
}
private fun getPreference(pref: DietaryPreferences): Boolean =
viewModel.getPreference(pref)
// private data class RegexF(val index: Int)
private fun getPrefRegex(): Regex {
val prefs = viewModel.getDietaryPrefs().deconstruct().replace('f', '.')
@@ -163,20 +159,10 @@ class CanteenFragment : Fragment() {
this
} else {
this.filter {
// Log.d("eek!5", "${it.title}: - ${prefsRegex} vs ${it.dietaryPreferences}")
prefsRegex.matches(it.dietaryPreferences)
}
}
// Log.d("eek!6", "preference: $prefsRegex, list: $filteredForPreferences")
// val a = filteredForPreferences.map {
// CanteenOfferGroupElement(
// it.title,
// it.price,
// it.dietaryPreferences,
// )
// }
val b = filteredForPreferences.map { offer ->
CanteenOfferGroup(
offer.date,
@@ -196,6 +182,4 @@ class CanteenFragment : Fragment() {
}
return b
}
// private fun Regex.matchesAny
}
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="?attr/colorPrimary" />
<item android:color="?attr/colorBackground" />
</selector>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@android:color/transparent" />
<item android:color="?attr/colorTextHintLighter" />
</selector>
+10 -10
View File
@@ -50,70 +50,70 @@
android:animateLayoutChanges="true">
<com.google.android.material.chip.Chip
style="@style/Widget.Material3.Chip.Filter"
style="@style/ChipStyle"
android:id="@+id/chip_pref_fair"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_fair"/>
<com.google.android.material.chip.Chip
style="@style/Widget.Material3.Chip.Filter"
style="@style/ChipStyle"
android:id="@+id/chip_pref_fish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_fish"/>
<com.google.android.material.chip.Chip
style="@style/Widget.Material3.Chip.Filter"
style="@style/ChipStyle"
android:id="@+id/chip_pref_poultry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_poultry"/>
<com.google.android.material.chip.Chip
style="@style/Widget.Material3.Chip.Filter"
style="@style/ChipStyle"
android:id="@+id/chip_pref_lamb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_lamb"/>
<com.google.android.material.chip.Chip
style="@style/Widget.Material3.Chip.Filter"
style="@style/ChipStyle"
android:id="@+id/chip_pref_vital"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_vital"/>
<com.google.android.material.chip.Chip
style="@style/Widget.Material3.Chip.Filter"
style="@style/ChipStyle"
android:id="@+id/chip_pref_beef"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_beef"/>
<com.google.android.material.chip.Chip
style="@style/Widget.Material3.Chip.Filter"
style="@style/ChipStyle"
android:id="@+id/chip_pref_pork"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_pork"/>
<com.google.android.material.chip.Chip
style="@style/Widget.Material3.Chip.Filter"
style="@style/ChipStyle"
android:id="@+id/chip_pref_vegetarian"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_vegetarian"/>
<com.google.android.material.chip.Chip
style="@style/Widget.Material3.Chip.Filter"
style="@style/ChipStyle"
android:id="@+id/chip_pref_vegan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pref_vegan"/>
<com.google.android.material.chip.Chip
style="@style/Widget.Material3.Chip.Filter"
style="@style/ChipStyle"
android:id="@+id/chip_pref_game"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+8
View File
@@ -41,4 +41,12 @@
<style name="DividerTheme" parent="Widget.Material3.MaterialDivider">
<item name="dividerColor">@color/colorTextHintLighterDay</item>
</style>
<style name="ChipStyle" parent="Widget.Material3.Chip.Filter">
<item name="chipStrokeColor">@color/item_chip_outline</item>
<item name="android:textColor">?attr/colorText</item>
<item name="rippleColor">?attr/colorPrimary</item>
<item name="chipBackgroundColor">@color/item_chip_background</item>
<item name="chipIconTint">?attr/colorText</item>
</style>
</resources>