Archived
Days (Monday thru Friday) are now shown on the canteen screen
This commit is contained in:
@@ -254,6 +254,9 @@ class StwParser(application: Application) {
|
||||
* @return date object
|
||||
*/
|
||||
private fun Document.getDateByIndex(index: Int): OfferDate {
|
||||
val day = getElementsByClass("tabs")[0]
|
||||
.getElementsByClass("tab-title")[index].text()
|
||||
|
||||
/*
|
||||
* Fetch the date for a given day. It will be in the following format:
|
||||
* 24. Apr
|
||||
@@ -272,7 +275,7 @@ class StwParser(application: Application) {
|
||||
val date = "${rawDate[0]}${rawDate[1].monthToNumber()}."
|
||||
|
||||
// Save the date to its list
|
||||
return OfferDate(dateId, date)
|
||||
return OfferDate(dateId, day, date)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -438,7 +441,8 @@ class StwParser(application: Application) {
|
||||
* Cleans up a HTML source by doing the following:
|
||||
* - replace non-breaking spaces ' ' with a regular space character ' ',
|
||||
* - replace closing paragraph tags '</p>' with a line break '\n', and
|
||||
* - remove any other tag.
|
||||
* - remove any other tag that does not start with 'a' or 'b' – this is a hacky way to preserve
|
||||
* <a> and <br> tags.
|
||||
* This is used to format the opening hours of the canteens.
|
||||
*
|
||||
* @receiver Element to parse the text of
|
||||
|
||||
@@ -22,7 +22,7 @@ import com.denizk0461.weserplaner.model.*
|
||||
OfferItem::class,
|
||||
EventTask::class,
|
||||
],
|
||||
version = 22,
|
||||
version = 23,
|
||||
exportSchema = true,
|
||||
autoMigrations = [
|
||||
AutoMigration(from = 20, to = 21),
|
||||
@@ -61,6 +61,7 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
).addMigrations(
|
||||
migrationAddNewsToOfferCanteen_19_20,
|
||||
migration_21_22,
|
||||
migration_22_23,
|
||||
// migrationAddTimetableId_20_21,
|
||||
// migrationAddEventTask_20_21,
|
||||
)
|
||||
@@ -125,5 +126,13 @@ abstract class AppDatabase : RoomDatabase() {
|
||||
database.execSQL("ALTER TABLE studip_events_temp RENAME TO studip_events")
|
||||
}
|
||||
}
|
||||
|
||||
private val migration_22_23 = object : Migration(22, 23) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("""
|
||||
ALTER TABLE offer_date ADD COLUMN day TEXT NOT NULL DEFAULT '?'
|
||||
""")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ class CanteenFragment : AppFragment<FragmentCanteenBinding>() {
|
||||
/**
|
||||
* Locally stored dates to populate the TabLayout with.
|
||||
*/
|
||||
private var dates: List<String> = listOf()
|
||||
private var dates: List<OfferDate> = listOf()
|
||||
|
||||
// Instantiate the view binding
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
@@ -219,7 +219,7 @@ class CanteenFragment : AppFragment<FragmentCanteenBinding>() {
|
||||
viewModel.getDates().observe(viewLifecycleOwner) { newDates ->
|
||||
|
||||
// Retrieve the dates individually and store them for the tab mediator to use
|
||||
dates = newDates.map { it.date }
|
||||
dates = newDates
|
||||
|
||||
// Let the adapter know of the new amount of dates (pages) to display
|
||||
viewPagerAdapter.itemCount = dates.size
|
||||
@@ -230,7 +230,7 @@ class CanteenFragment : AppFragment<FragmentCanteenBinding>() {
|
||||
|
||||
// Set up TabLayoutMediator to populate tabs
|
||||
TabLayoutMediator(binding.dayTabLayout, binding.viewPager) { tab, position ->
|
||||
tab.text = dates[position]
|
||||
tab.text = dates[position].run { "$day, $date" }
|
||||
}.attach()
|
||||
|
||||
// Set extended FAB to extend when the page is changed
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.room.PrimaryKey
|
||||
* Entity for binding several canteen items to a specific date. Registered in the app database.
|
||||
*
|
||||
* @param id primary key that uniquely identifies the item
|
||||
* @param day the day. that's it. pretty self-explanatory, eh?
|
||||
* @param date date formatted as dd.MM.
|
||||
*/
|
||||
@Entity(
|
||||
@@ -14,5 +15,6 @@ import androidx.room.PrimaryKey
|
||||
)
|
||||
data class OfferDate(
|
||||
@PrimaryKey val id: Int,
|
||||
val day: String,
|
||||
val date: String,
|
||||
)
|
||||
|
||||
@@ -88,5 +88,10 @@ enum class SettingsPreferences(val key: String) {
|
||||
* Which timetable the user has selected.
|
||||
*/
|
||||
SELECTED_TIMETABLE("selected_timetable"),
|
||||
|
||||
/**
|
||||
* How the dates should be shown on the canteen screen.
|
||||
*/
|
||||
CANTEEN_DATE_PREFERENCE("date_canteen_preference")
|
||||
;
|
||||
}
|
||||
Reference in New Issue
Block a user