Archived
Fixed a bug that would cause the tab for a day without canteen offers to not be shown, causing the offers for the next days to be shifted over, thus not showing the offers for the last day that's available online. I know I didn't explain that very well, but it's fixed now anyway, soo (: also made some minor visual adjustments to margins and colours
This commit is contained in:
@@ -45,24 +45,23 @@ class StudIPEventItemAdapter(
|
||||
val colorTextHintLighter = TypedValue()
|
||||
val theme = holder.binding.root.context.theme
|
||||
|
||||
theme.resolveAttribute(R.attr.colorPrimaryTranslucent, colorPrimaryTranslucent, true)
|
||||
theme.resolveAttribute(R.attr.colorCardBackground, colorCardBackground, true)
|
||||
theme.resolveAttribute(R.attr.colorTextHintLighter, colorTextHintLighter, true)
|
||||
theme.apply {
|
||||
resolveAttribute(R.attr.colorPrimaryTranslucent, colorPrimaryTranslucent, true)
|
||||
resolveAttribute(R.attr.colorCardBackground, colorCardBackground, true)
|
||||
resolveAttribute(R.attr.colorTextHintLighter, colorTextHintLighter, true)
|
||||
}
|
||||
|
||||
if (!isAnyCourseHighlighted && currentItem.isCurrentCourse(currentCalendar)) { // highlight
|
||||
isAnyCourseHighlighted = true
|
||||
holder.binding.cardBackground.apply {
|
||||
backgroundTintList = ColorStateList.valueOf(colorPrimaryTranslucent.data)//R.attr.colorPrimaryTranslucent)
|
||||
backgroundTintList = ColorStateList.valueOf(colorPrimaryTranslucent.data)
|
||||
strokeColor = context.getColor(android.R.color.transparent)
|
||||
}//colorPrimary.data
|
||||
// holder.binding.cardBackground.strokeWidth = 6 // TODO replace this with proper float -> dp conversion
|
||||
// R.color.list_card_selected)
|
||||
}
|
||||
} else { // un-highlight
|
||||
holder.binding.cardBackground.apply {
|
||||
backgroundTintList = ColorStateList.valueOf(colorCardBackground.data)//context.getColor(R.attr.colorCardBackground))
|
||||
backgroundTintList = ColorStateList.valueOf(colorCardBackground.data)
|
||||
strokeColor = colorTextHintLighter.data
|
||||
}
|
||||
// holder.binding.cardBackground.strokeWidth = 3 // this should (?) be 1dp
|
||||
}
|
||||
|
||||
holder.binding.cardBackground.setOnClickListener {
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.denizk0461.studip.data
|
||||
|
||||
import android.util.Log
|
||||
import com.denizk0461.studip.db.EventRepository
|
||||
import com.denizk0461.studip.model.*
|
||||
import org.jsoup.Jsoup
|
||||
@@ -89,8 +88,6 @@ class StwParser {
|
||||
isGame = prefs.isDietaryPreferenceMet(PREFERENCE_GAME),
|
||||
).deconstruct()
|
||||
|
||||
// Log.d("eek!4", "prefString = $prefString")
|
||||
|
||||
repo.insert(
|
||||
OfferItem(
|
||||
itemId,
|
||||
@@ -101,25 +98,6 @@ class StwParser {
|
||||
)
|
||||
)
|
||||
itemId += 1
|
||||
|
||||
// val newItem = CanteenOffer(
|
||||
// id = id,
|
||||
// date = date,
|
||||
// dateId = day,
|
||||
// category = categoryTitle,
|
||||
// title = tableRows[1].getFilteredText(),
|
||||
//// price = tableRows.getTextOrEmpty(2),
|
||||
// isFair = prefs.isDietaryPreferenceMet(PREFERENCE_FAIR),
|
||||
// isFish = prefs.isDietaryPreferenceMet(PREFERENCE_FISH),
|
||||
// isPoultry = prefs.isDietaryPreferenceMet(PREFERENCE_POULTRY),
|
||||
// isLamb = prefs.isDietaryPreferenceMet(PREFERENCE_LAMB),
|
||||
// isVital = prefs.isDietaryPreferenceMet(PREFERENCE_VITAL),
|
||||
// isBeef = prefs.isDietaryPreferenceMet(PREFERENCE_BEEF),
|
||||
// isPork = prefs.isDietaryPreferenceMet(PREFERENCE_PORK),
|
||||
// isVegan = prefs.isDietaryPreferenceMet(PREFERENCE_VEGAN),
|
||||
// isVegetarian = prefs.isDietaryPreferenceMet(PREFERENCE_VEGETARIAN),
|
||||
// isGame = prefs.isDietaryPreferenceMet(PREFERENCE_GAME),
|
||||
// )
|
||||
}
|
||||
categoryId += 1
|
||||
}
|
||||
|
||||
@@ -66,6 +66,9 @@ interface EventDAO {
|
||||
@get:Query("SELECT id FROM offer_date")
|
||||
val updateObserver: LiveData<List<Int>>
|
||||
|
||||
@Query("SELECT * FROM offer_date")
|
||||
fun getDates(): List<OfferDate>
|
||||
|
||||
@Query("DELETE FROM offer_date")
|
||||
fun nukeOfferDates()
|
||||
|
||||
|
||||
@@ -21,6 +21,8 @@ class EventRepository(app: Application) {
|
||||
|
||||
val allOffers: LiveData<List<CanteenOffer>> = dao.allOffers
|
||||
|
||||
fun getDates(): List<OfferDate> = dao.getDates()
|
||||
|
||||
fun getDietaryPrefs(): String {
|
||||
return prefs.getString(dietaryPrefString, "..........") ?: ".........."
|
||||
// return DietaryPrefObject(
|
||||
|
||||
@@ -10,10 +10,7 @@ import androidx.fragment.app.viewModels
|
||||
import androidx.lifecycle.LiveData
|
||||
import com.denizk0461.studip.adapter.CanteenOfferPageAdapter
|
||||
import com.denizk0461.studip.databinding.FragmentCanteenBinding
|
||||
import com.denizk0461.studip.model.CanteenOffer
|
||||
import com.denizk0461.studip.model.CanteenOfferGroup
|
||||
import com.denizk0461.studip.model.CanteenOfferGroupElement
|
||||
import com.denizk0461.studip.model.DietaryPreferences
|
||||
import com.denizk0461.studip.model.*
|
||||
import com.denizk0461.studip.viewmodel.CanteenViewModel
|
||||
import com.google.android.material.tabs.TabLayoutMediator
|
||||
|
||||
@@ -25,8 +22,6 @@ class CanteenFragment : Fragment() {
|
||||
// onDestroyView.
|
||||
private val binding get() = _binding!!
|
||||
|
||||
private var dates = listOf<String>()
|
||||
|
||||
private lateinit var liveData: LiveData<List<CanteenOffer>>
|
||||
|
||||
private lateinit var viewPagerAdapter: CanteenOfferPageAdapter
|
||||
@@ -77,7 +72,7 @@ class CanteenFragment : Fragment() {
|
||||
viewPagerAdapter = CanteenOfferPageAdapter(listOf(), 0, getPrefRegex())
|
||||
binding.viewPager.adapter = viewPagerAdapter
|
||||
|
||||
createTabLayoutMediator()
|
||||
createTabLayoutMediator(listOf())
|
||||
|
||||
liveData = viewModel.allOffers
|
||||
liveData.observe(viewLifecycleOwner) { offers ->
|
||||
@@ -85,12 +80,13 @@ class CanteenFragment : Fragment() {
|
||||
|
||||
val groupedElements = offers.groupElements().distinct()
|
||||
|
||||
dates = groupedElements.map { it.date }.distinct()
|
||||
createTabLayoutMediator()
|
||||
// dates = groupedElements.map { it.date }.distinct()
|
||||
val newDates = viewModel.getDates()
|
||||
createTabLayoutMediator(newDates)
|
||||
|
||||
this.dateSize = dates.size
|
||||
dateSize = newDates.size
|
||||
|
||||
viewPagerAdapter.setNewItems(groupedElements, dates.size)
|
||||
viewPagerAdapter.setNewItems(groupedElements, dateSize)
|
||||
|
||||
// TODO this must be changed. if an exception is raised, then this will not fire
|
||||
binding.swipeRefreshLayout.isRefreshing = false
|
||||
@@ -105,10 +101,10 @@ class CanteenFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun createTabLayoutMediator() {
|
||||
private fun createTabLayoutMediator(dates: List<OfferDate>) {
|
||||
if (dates.isNotEmpty()) {
|
||||
TabLayoutMediator(binding.dayTabLayout, binding.viewPager) { tab, position ->
|
||||
tab.text = dates[position]
|
||||
tab.text = dates[position].date
|
||||
}.attach()
|
||||
}
|
||||
}
|
||||
@@ -127,7 +123,7 @@ class CanteenFragment : Fragment() {
|
||||
viewModel.getPreference(pref)
|
||||
|
||||
private fun getPrefRegex(): Regex {
|
||||
val prefs = viewModel.getDietaryPrefs().deconstruct().replace('f', '.')
|
||||
val prefs = viewModel.getDietaryPrefs().deconstruct()//.replace('f', '.')
|
||||
|
||||
val template = ".........."
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.denizk0461.studip.data.StwParser
|
||||
import com.denizk0461.studip.model.CanteenOffer
|
||||
import com.denizk0461.studip.model.DietaryPrefObject
|
||||
import com.denizk0461.studip.model.DietaryPreferences
|
||||
import com.denizk0461.studip.model.OfferDate
|
||||
|
||||
class CanteenViewModel(app: Application) : TemplateViewModel(app) {
|
||||
|
||||
@@ -15,6 +16,8 @@ class CanteenViewModel(app: Application) : TemplateViewModel(app) {
|
||||
|
||||
fun getDietaryPrefs(): DietaryPrefObject = repo.getDietaryPrefsAsObj()
|
||||
|
||||
fun getDates(): List<OfferDate> = returnBlocking { repo.getDates() }
|
||||
|
||||
fun fetchOffers(onRefreshUpdate: (status: Int) -> Unit, onFinish: () -> Unit) { doAsync { parser.parse(onRefreshUpdate, onFinish) }}
|
||||
|
||||
fun setPreference(pref: DietaryPreferences, newValue: Boolean) { repo.setPreference(pref, newValue) }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
@@ -8,16 +8,22 @@
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/day_tab_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
app:tabMode="scrollable"
|
||||
android:background="@android:color/transparent"/>
|
||||
android:background="@android:color/transparent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"/>
|
||||
|
||||
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||
android:id="@+id/swipe_refresh_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/day_tab_layout"
|
||||
app:layout_constraintBottom_toTopOf="@+id/scroll_view_chip">
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="match_parent"
|
||||
@@ -27,26 +33,26 @@
|
||||
<androidx.viewpager2.widget.ViewPager2
|
||||
android:id="@+id/view_pager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"/>
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||
|
||||
<HorizontalScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:id="@+id/scroll_view_chip"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:scrollbars="none">
|
||||
android:scrollbars="none"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent">
|
||||
|
||||
<com.google.android.material.chip.ChipGroup
|
||||
android:id="@+id/chips_preference"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:backgroundTint="@android:color/transparent"
|
||||
android:background="@android:color/transparent"
|
||||
android:animateLayoutChanges="true">
|
||||
|
||||
<com.google.android.material.chip.Chip
|
||||
@@ -123,4 +129,4 @@
|
||||
|
||||
</HorizontalScrollView>
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -78,12 +78,14 @@
|
||||
android:paddingVertical="8dp">
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent">
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/switch_quarter"
|
||||
android:layout_marginEnd="8dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
@@ -120,12 +122,14 @@
|
||||
android:paddingVertical="8dp">
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent">
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/switch_highlight"
|
||||
android:layout_marginEnd="8dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
@@ -153,6 +157,33 @@
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<!-- Data handling -->
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:id="@+id/button_data_handling"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/layout_ripple"
|
||||
android:clickable="true"
|
||||
android:focusable="true"
|
||||
android:paddingHorizontal="16dp"
|
||||
android:paddingVertical="8dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:fontFamily="@font/lato_bolditalic"
|
||||
android:text="@string/settings_data_title"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="16sp"
|
||||
android:text="@string/settings_data_subtitle"/>
|
||||
|
||||
</androidx.appcompat.widget.LinearLayoutCompat>
|
||||
|
||||
<!-- App version -->
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:id="@+id/button_app_version"
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"/>
|
||||
@@ -24,6 +25,7 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/image_view_container"
|
||||
|
||||
@@ -49,6 +49,8 @@
|
||||
<string name="settings_quarter_subtitle">Wo es passt</string>
|
||||
<string name="settings_highlight_title">Markiere meinen nächsten Kurs</string>
|
||||
<string name="settings_highlight_subtitle">Funktioniert nur wenn Kurse sich nicht überschneiden!</string>
|
||||
<string name="settings_data_title">Was passiert mit meinen Daten?</string>
|
||||
<string name="settings_data_subtitle">Stiehlst du meinen Login?</string>
|
||||
<string name="settings_app_version">App-Verison</string>
|
||||
|
||||
<string name="with_love">mit ♡️ aus Bremen-Osterholz\von denizk0461 \\__*</string>
|
||||
|
||||
@@ -48,7 +48,9 @@
|
||||
<string name="settings_quarter_title">Use academic quarter</string>
|
||||
<string name="settings_quarter_subtitle">Where applicable</string>
|
||||
<string name="settings_highlight_title">Highlight next course</string>
|
||||
<string name="settings_highlight_subtitle">Only works if courses don\'t overlap!</string>
|
||||
<string name="settings_highlight_subtitle">Only works properly if courses don\'t overlap!</string>
|
||||
<string name="settings_data_title">What happens with my data?</string>
|
||||
<string name="settings_data_subtitle">Will you steal my login?</string>
|
||||
<string name="settings_app_version">App Version</string>
|
||||
|
||||
<string name="with_love">with ♡️ from Bremen-Osterholz\nmade by denizk0461 \\__*</string>
|
||||
|
||||
Reference in New Issue
Block a user