Archived
Fixed a bug that would cause the canteen plan to crash after refreshing while trying to layout the TabMediatorLayout. I don't know why that happened.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.denizk0461.studip.data
|
||||
|
||||
import android.util.Log
|
||||
import com.denizk0461.studip.db.EventRepository
|
||||
import com.denizk0461.studip.model.*
|
||||
import org.jsoup.Jsoup
|
||||
@@ -38,6 +39,7 @@ class StwParser {
|
||||
// TODO implement onRefresh(Int)
|
||||
parseFromPage(link, Dependencies.repo)
|
||||
}
|
||||
onFinish()
|
||||
}
|
||||
|
||||
private fun parseFromPage(url: String, repo: EventRepository): List<CanteenOffer> {
|
||||
@@ -58,7 +60,9 @@ class StwParser {
|
||||
|
||||
date = "${rawDate[0]}${rawDate[1].monthToNumber()}."
|
||||
|
||||
repo.insert(OfferDate(dateId, date))
|
||||
val d = OfferDate(dateId, date)
|
||||
Log.d("eek!8", d.toString())
|
||||
repo.insert(d)
|
||||
|
||||
// STEP: get each category in a day
|
||||
dayPlan.getElementsByClass("food-category").forEach { category ->
|
||||
|
||||
@@ -66,7 +66,7 @@ interface EventDAO {
|
||||
@get:Query("SELECT id FROM offer_date")
|
||||
val updateObserver: LiveData<List<Int>>
|
||||
|
||||
@Query("SELECT * FROM offer_date")
|
||||
@Query("SELECT * FROM offer_date ORDER BY id")
|
||||
fun getDates(): List<OfferDate>
|
||||
|
||||
@Query("DELETE FROM offer_date")
|
||||
|
||||
@@ -72,21 +72,20 @@ class CanteenFragment : Fragment() {
|
||||
viewPagerAdapter = CanteenOfferPageAdapter(listOf(), 0, getPrefRegex())
|
||||
binding.viewPager.adapter = viewPagerAdapter
|
||||
|
||||
createTabLayoutMediator(listOf())
|
||||
createTabLayoutMediator()
|
||||
|
||||
liveData = viewModel.allOffers
|
||||
liveData.observe(viewLifecycleOwner) { offers ->
|
||||
viewModel.allOffers.observe(viewLifecycleOwner) { offers ->
|
||||
elements = offers
|
||||
|
||||
val groupedElements = offers.groupElements().distinct()
|
||||
|
||||
// dates = groupedElements.map { it.date }.distinct()
|
||||
val newDates = viewModel.getDates()
|
||||
createTabLayoutMediator(newDates)
|
||||
val newDates = groupedElements.map { it.date }.distinct()//.map { item -> OfferDate(item.) }
|
||||
// val newDates = viewModel.getDates()
|
||||
|
||||
dateSize = newDates.size
|
||||
|
||||
viewPagerAdapter.setNewItems(groupedElements, dateSize)
|
||||
// createTabLayoutMediator(newDates)
|
||||
|
||||
// TODO this must be changed. if an exception is raised, then this will not fire
|
||||
binding.swipeRefreshLayout.isRefreshing = false
|
||||
@@ -97,13 +96,17 @@ class CanteenFragment : Fragment() {
|
||||
// TODO refresh updates
|
||||
}, onFinish = {
|
||||
// binding.swipeRefreshLayout.isRefreshing = false
|
||||
createTabLayoutMediator()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private fun createTabLayoutMediator(dates: List<OfferDate>) {
|
||||
private fun createTabLayoutMediator(){//List<OfferDate>) {
|
||||
val dates = viewModel.getDates()
|
||||
if (dates.isNotEmpty()) {
|
||||
Log.d("eek!7", "dates: ${dates}, viewpager pages: ${binding.viewPager.adapter?.itemCount}")
|
||||
TabLayoutMediator(binding.dayTabLayout, binding.viewPager) { tab, position ->
|
||||
Log.d("eek!9", position.toString())
|
||||
tab.text = dates[position].date
|
||||
}.attach()
|
||||
}
|
||||
|
||||
@@ -13,36 +13,38 @@ data class DietaryPrefObject(
|
||||
val isGame: Boolean,
|
||||
) {
|
||||
companion object {
|
||||
private const val C_TRUE = 't'
|
||||
private const val C_FALSE = '.'
|
||||
/* assume that the values must be parsed as follows:
|
||||
* "xxxxxxxxxx"
|
||||
* t = true, . = false
|
||||
*/
|
||||
fun construct(values: String) = DietaryPrefObject(
|
||||
isFair = values[0] == 't',
|
||||
isFish = values[1] == 't',
|
||||
isPoultry = values[2] == 't',
|
||||
isLamb = values[3] == 't',
|
||||
isVital = values[4] == 't',
|
||||
isBeef = values[5] == 't',
|
||||
isPork = values[6] == 't',
|
||||
isVegan = values[7] == 't',
|
||||
isVegetarian = values[8] == 't',
|
||||
isGame = values[9] == 't',
|
||||
isFair = values[0] == C_TRUE,
|
||||
isFish = values[1] == C_TRUE,
|
||||
isPoultry = values[2] == C_TRUE,
|
||||
isLamb = values[3] == C_TRUE,
|
||||
isVital = values[4] == C_TRUE,
|
||||
isBeef = values[5] == C_TRUE,
|
||||
isPork = values[6] == C_TRUE,
|
||||
isVegan = values[7] == C_TRUE,
|
||||
isVegetarian = values[8] == C_TRUE,
|
||||
isGame = values[9] == C_TRUE,
|
||||
)
|
||||
}
|
||||
|
||||
fun deconstruct() = String(
|
||||
charArrayOf(
|
||||
if (this.isFair) 't' else 'f',
|
||||
if (this.isFish) 't' else 'f',
|
||||
if (this.isPoultry) 't' else 'f',
|
||||
if (this.isLamb) 't' else 'f',
|
||||
if (this.isVital) 't' else 'f',
|
||||
if (this.isBeef) 't' else 'f',
|
||||
if (this.isPork) 't' else 'f',
|
||||
if (this.isVegan) 't' else 'f',
|
||||
if (this.isVegetarian) 't' else 'f',
|
||||
if (this.isGame) 't' else 'f',
|
||||
if (this.isFair) C_TRUE else C_FALSE,
|
||||
if (this.isFish) C_TRUE else C_FALSE,
|
||||
if (this.isPoultry) C_TRUE else C_FALSE,
|
||||
if (this.isLamb) C_TRUE else C_FALSE,
|
||||
if (this.isVital) C_TRUE else C_FALSE,
|
||||
if (this.isBeef) C_TRUE else C_FALSE,
|
||||
if (this.isPork) C_TRUE else C_FALSE,
|
||||
if (this.isVegan) C_TRUE else C_FALSE,
|
||||
if (this.isVegetarian) C_TRUE else C_FALSE,
|
||||
if (this.isGame) C_TRUE else C_FALSE,
|
||||
)
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user