diff --git a/.idea/misc.xml b/.idea/misc.xml index 9f71c83..773fe0f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/app/src/main/java/com/denizk0461/studip/data/StwParser.kt b/app/src/main/java/com/denizk0461/studip/data/StwParser.kt index 338ca62..7948a83 100644 --- a/app/src/main/java/com/denizk0461/studip/data/StwParser.kt +++ b/app/src/main/java/com/denizk0461/studip/data/StwParser.kt @@ -102,10 +102,34 @@ class StwParser { * TODO this formatting sucks */ var openingHours = "" - doc.getElementsByClass("details-wrapper")[0].getElementsByTag("p").forEach { p -> - openingHours += "${p.text()}\n" + + // Iterate through all wrappers that could contain opening hours + doc.getElementsByClass("details-wrapper").forEach { + // Element is not for providing contact details + if (it.getElementsByClass("contact-person-name").size == 0) { + + /* + * Retrieve all opening hours. + * TODO this slows down the fetch SIGNIFICANTLY, but why? + */ + it.children().forEach { element -> + if (element.tag().toString() == "p") { + openingHours += element.textWithBreaks().trim() + "\n" // Uni-Mensa is not parsed properly + } else { + element.children().forEach { subElement -> + openingHours += subElement.textWithBreaks() + '\n' + } + } + } + } + + // Add an extra line break to separate elements + openingHours += "\n" } + // Trim off excess line breaks + openingHours = openingHours.trim() + // Save the canteen to persistent storage repo.insert( OfferCanteen( @@ -340,6 +364,20 @@ class StwParser { else -> "00" // shouldn't occur } + /** + * Retrieves a text and adds
tags with line breaks. + * + * @return formatted element text + */ + private fun Element.textWithBreaks(): String = + this.text()//html() +// .replace("
", "\n") +// .replace(" ", " ") +// .replace("", "") +// .replace("", "") +// .replace("

", "") +// .replace("

", "") + // Image links to all dietary preferences used for checking whether a preference is met private val imageLinkPrefFair = "https://www.stw-bremen.de/sites/default/files/images/pictograms/at_small.png" private val imageLinkPrefFish = "https://www.stw-bremen.de/sites/default/files/images/pictograms/fisch.png" diff --git a/app/src/main/java/com/denizk0461/studip/sheet/ScheduleUpdateSheet.kt b/app/src/main/java/com/denizk0461/studip/sheet/ScheduleUpdateSheet.kt index e459d64..6de8f7f 100644 --- a/app/src/main/java/com/denizk0461/studip/sheet/ScheduleUpdateSheet.kt +++ b/app/src/main/java/com/denizk0461/studip/sheet/ScheduleUpdateSheet.kt @@ -1,9 +1,8 @@ package com.denizk0461.studip.sheet import android.os.Bundle -import android.os.Handler -import android.util.Log import android.view.View +import android.view.ViewGroup import androidx.fragment.app.FragmentActivity import androidx.transition.TransitionManager import com.denizk0461.studip.R @@ -46,37 +45,56 @@ class ScheduleUpdateSheet( binding.editTextLecturers.setText(event.lecturer) binding.editTextRoom.setText(event.room) - // Show academic quarter suggestion if it is applicable + /* + * Show academic quarter suggestion if it is applicable. For this to be the case, both the + * start timestamp and the end timestamp must match up in a pattern that would make it + * likely for the course to use the academic quarter. Example: + * 14:00 - 16:00 -> likely 14:15 - 15:45 + * + * 13:00 - 15:30 -> likely no academic quarter intended + */ binding.buttonAcademicQuarter.visibility = if ( timeslotsAcademicQuarter.contains(timeslotStart) && timeslotsAcademicQuarter.contains(timeslotEnd) ) { binding.buttonAcademicQuarter.setOnClickListener { try { + // Retrieve new timestamps with the academic quarter applied, or throw a tantrum val newStart = timeslotsAcademicQuarterStart[timeslotStart] ?: throw NullPointerException() val newEnd = timeslotsAcademicQuarterEnd[timeslotEnd] ?: throw NullPointerException() + // Set the buttons to the new timesatmps timeslotStart = newStart binding.buttonTimeStart.text = newStart timeslotEnd = newEnd binding.buttonTimeEnd.text = newEnd - TransitionManager.beginDelayedTransition(binding.sheet) + /* + * Attempt to fix the issue of the bottom sheet jumping up when hiding the + * button. + */ + TransitionManager.beginDelayedTransition(binding.sheet.parent as ViewGroup) binding.buttonAcademicQuarter.visibility = View.GONE + + // Catch if a timeslot couldn't be found in the list, and tell the user } catch (e: NullPointerException) { showToast(context, getString(R.string.sheet_schedule_update_hint_quarter_error)) } } + + // If the pattern applies, show the button to the user View.VISIBLE } else { + // Hide the button if the action is not necessary or applicable View.GONE } // Prepare timestamp buttons binding.buttonTimeStart.text = timeslotStart binding.buttonTimeStart.setOnClickListener { + // Launch a time picker dialogue to pick a new start timestamp TimePickerFragment( binding.buttonTimeStart.text.toString(), this, @@ -85,6 +103,7 @@ class ScheduleUpdateSheet( } binding.buttonTimeEnd.text = timeslotEnd binding.buttonTimeEnd.setOnClickListener { + // Launch a time picker dialogue to pick a new end timestamp TimePickerFragment( binding.buttonTimeEnd.text.toString(), this, diff --git a/app/src/main/res/layout/sheet_schedule_update.xml b/app/src/main/res/layout/sheet_schedule_update.xml index 3d5b767..873ffbc 100644 --- a/app/src/main/res/layout/sheet_schedule_update.xml +++ b/app/src/main/res/layout/sheet_schedule_update.xml @@ -37,9 +37,6 @@ app:iconPadding="0dp" android:layout_gravity="end|center_vertical" app:iconTint="?attr/colorOnSurfaceVariant"/> - - -