Archived
Button for switching an event's timestamps to show the academic quarter is now properly animated (I think)
This commit is contained in:
Generated
-1
@@ -1,4 +1,3 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||
|
||||
@@ -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 <br> tags with line breaks.
|
||||
*
|
||||
* @return formatted element text
|
||||
*/
|
||||
private fun Element.textWithBreaks(): String =
|
||||
this.text()//html()
|
||||
// .replace("<br>", "\n")
|
||||
// .replace(" ", " ")
|
||||
// .replace("<strong>", "")
|
||||
// .replace("</strong>", "")
|
||||
// .replace("<p>", "")
|
||||
// .replace("</p>", "")
|
||||
|
||||
// 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"
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -37,9 +37,6 @@
|
||||
app:iconPadding="0dp"
|
||||
android:layout_gravity="end|center_vertical"
|
||||
app:iconTint="?attr/colorOnSurfaceVariant"/>
|
||||
<!-- app:icon="@drawable/cross"-->
|
||||
<!-- app:strokeColor="?attr/colorOutlineVariant"-->
|
||||
<!-- android:text="@string/cancel"-->
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user