Archived
Fixed filtering behaviour, since it wouldn't recognise items with two preferences if only one had been selected; added icons for preferences
This commit is contained in:
@@ -2,8 +2,13 @@ package com.denizk0461.studip.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import androidx.core.widget.ImageViewCompat
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.denizk0461.studip.data.Misc
|
||||
import com.denizk0461.studip.databinding.ItemCanteenBinding
|
||||
import com.denizk0461.studip.databinding.ItemCanteenLineBinding
|
||||
import com.denizk0461.studip.databinding.ItemIconBinding
|
||||
import com.denizk0461.studip.model.CanteenOffer
|
||||
|
||||
class CanteenOfferItemAdapter(private val offers: List<CanteenOffer>) : RecyclerView.Adapter<CanteenOfferItemAdapter.OfferViewHolder>() {
|
||||
@@ -25,8 +30,32 @@ class CanteenOfferItemAdapter(private val offers: List<CanteenOffer>) : Recycler
|
||||
override fun onBindViewHolder(holder: OfferViewHolder, position: Int) {
|
||||
val currentItem = offers[position]
|
||||
|
||||
val line = ItemCanteenLineBinding.inflate(
|
||||
LayoutInflater.from(holder.binding.root.context),
|
||||
// holder.binding.root,
|
||||
// true,
|
||||
)
|
||||
holder.binding.textCategory.text = currentItem.category
|
||||
holder.binding.tempContent.text = "${currentItem.title} • ${currentItem.price}"
|
||||
line.content.text = currentItem.title
|
||||
val indices = arrayListOf<Int>()
|
||||
currentItem.dietaryPreferences.filterIndexed { index, char ->
|
||||
if (char == 't') {
|
||||
indices.add(index)
|
||||
true
|
||||
} else false
|
||||
}
|
||||
if (indices.isEmpty()) indices.add(10)
|
||||
indices.forEach { index ->
|
||||
val img = ItemIconBinding.inflate(LayoutInflater.from(holder.binding.root.context))
|
||||
// holder.binding.root.resources.getDrawable(Misc.indexToDrawable[index]!!, holder.binding.root.context.theme)
|
||||
img.imageView.setImageDrawable(holder.binding.root.context.getDrawable(Misc.indexToDrawable[index]!!))
|
||||
line.imageViewContainer.addView(img.root)
|
||||
}
|
||||
|
||||
holder.binding.lineContainer.addView(line.root)
|
||||
|
||||
// holder.binding.textCategory.text = currentItem.category
|
||||
// holder.binding.tempContent.text = "${currentItem.title} • ${currentItem.price}"
|
||||
|
||||
// TODO inflate view saying "no offers!" or sth
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ class CanteenOfferPageAdapter(private var offers: List<CanteenOffer>, private va
|
||||
filteredForDate
|
||||
} else {
|
||||
filteredForDate.filter {
|
||||
Log.d("eek!5", it.dietaryPreferences)
|
||||
Log.d("eek!5", "${it.title}: - ${prefsRegex} vs ${it.dietaryPreferences}")
|
||||
prefsRegex.matches(it.dietaryPreferences)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.denizk0461.studip.data
|
||||
|
||||
import com.denizk0461.studip.model.StudIPEvent
|
||||
import com.denizk0461.studip.R
|
||||
|
||||
object Misc {
|
||||
|
||||
@@ -52,6 +52,20 @@ object Misc {
|
||||
"21:45" to 7,
|
||||
)
|
||||
|
||||
val indexToDrawable: Map<Int, Int> = mapOf(
|
||||
0 to R.drawable.handshake,
|
||||
1 to R.drawable.fish,
|
||||
2 to R.drawable.chicken,
|
||||
3 to R.drawable.sheep,
|
||||
4 to R.drawable.yoga,
|
||||
5 to R.drawable.cow,
|
||||
6 to R.drawable.pig,
|
||||
7 to R.drawable.leaf,
|
||||
8 to R.drawable.carrot,
|
||||
9 to R.drawable.deer,
|
||||
10 to R.drawable.circle,
|
||||
)
|
||||
|
||||
fun parseTimeslot(time: String): Pair<Int, Int> {
|
||||
val splitTime = time.split(" - ")
|
||||
val start = timeslotStartMap[splitTime[0]] ?: 0
|
||||
|
||||
@@ -116,5 +116,6 @@ class CanteenFragment : Fragment() {
|
||||
viewModel.getPreference(pref)
|
||||
|
||||
private fun getPrefRegex(): Regex =
|
||||
Regex(viewModel.getDietaryPrefs().deconstruct().replace('t', '.'))
|
||||
// Regex(viewModel.getDietaryPrefs().deconstruct().replace('t', '.'))
|
||||
Regex(viewModel.getDietaryPrefs().deconstruct().replace('f', '.'))
|
||||
}
|
||||
Reference in New Issue
Block a user