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">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||||
|
|||||||
@@ -102,9 +102,33 @@ class StwParser {
|
|||||||
* TODO this formatting sucks
|
* TODO this formatting sucks
|
||||||
*/
|
*/
|
||||||
var openingHours = ""
|
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
|
// Save the canteen to persistent storage
|
||||||
repo.insert(
|
repo.insert(
|
||||||
@@ -340,6 +364,20 @@ class StwParser {
|
|||||||
else -> "00" // shouldn't occur
|
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
|
// 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 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"
|
private val imageLinkPrefFish = "https://www.stw-bremen.de/sites/default/files/images/pictograms/fisch.png"
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
package com.denizk0461.studip.sheet
|
package com.denizk0461.studip.sheet
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
|
||||||
import android.util.Log
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import androidx.transition.TransitionManager
|
import androidx.transition.TransitionManager
|
||||||
import com.denizk0461.studip.R
|
import com.denizk0461.studip.R
|
||||||
@@ -46,37 +45,56 @@ class ScheduleUpdateSheet(
|
|||||||
binding.editTextLecturers.setText(event.lecturer)
|
binding.editTextLecturers.setText(event.lecturer)
|
||||||
binding.editTextRoom.setText(event.room)
|
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 (
|
binding.buttonAcademicQuarter.visibility = if (
|
||||||
timeslotsAcademicQuarter.contains(timeslotStart) &&
|
timeslotsAcademicQuarter.contains(timeslotStart) &&
|
||||||
timeslotsAcademicQuarter.contains(timeslotEnd)
|
timeslotsAcademicQuarter.contains(timeslotEnd)
|
||||||
) {
|
) {
|
||||||
binding.buttonAcademicQuarter.setOnClickListener {
|
binding.buttonAcademicQuarter.setOnClickListener {
|
||||||
try {
|
try {
|
||||||
|
// Retrieve new timestamps with the academic quarter applied, or throw a tantrum
|
||||||
val newStart = timeslotsAcademicQuarterStart[timeslotStart]
|
val newStart = timeslotsAcademicQuarterStart[timeslotStart]
|
||||||
?: throw NullPointerException()
|
?: throw NullPointerException()
|
||||||
val newEnd = timeslotsAcademicQuarterEnd[timeslotEnd]
|
val newEnd = timeslotsAcademicQuarterEnd[timeslotEnd]
|
||||||
?: throw NullPointerException()
|
?: throw NullPointerException()
|
||||||
|
|
||||||
|
// Set the buttons to the new timesatmps
|
||||||
timeslotStart = newStart
|
timeslotStart = newStart
|
||||||
binding.buttonTimeStart.text = newStart
|
binding.buttonTimeStart.text = newStart
|
||||||
timeslotEnd = newEnd
|
timeslotEnd = newEnd
|
||||||
binding.buttonTimeEnd.text = 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
|
binding.buttonAcademicQuarter.visibility = View.GONE
|
||||||
|
|
||||||
|
// Catch if a timeslot couldn't be found in the list, and tell the user
|
||||||
} catch (e: NullPointerException) {
|
} catch (e: NullPointerException) {
|
||||||
showToast(context, getString(R.string.sheet_schedule_update_hint_quarter_error))
|
showToast(context, getString(R.string.sheet_schedule_update_hint_quarter_error))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the pattern applies, show the button to the user
|
||||||
View.VISIBLE
|
View.VISIBLE
|
||||||
} else {
|
} else {
|
||||||
|
// Hide the button if the action is not necessary or applicable
|
||||||
View.GONE
|
View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare timestamp buttons
|
// Prepare timestamp buttons
|
||||||
binding.buttonTimeStart.text = timeslotStart
|
binding.buttonTimeStart.text = timeslotStart
|
||||||
binding.buttonTimeStart.setOnClickListener {
|
binding.buttonTimeStart.setOnClickListener {
|
||||||
|
// Launch a time picker dialogue to pick a new start timestamp
|
||||||
TimePickerFragment(
|
TimePickerFragment(
|
||||||
binding.buttonTimeStart.text.toString(),
|
binding.buttonTimeStart.text.toString(),
|
||||||
this,
|
this,
|
||||||
@@ -85,6 +103,7 @@ class ScheduleUpdateSheet(
|
|||||||
}
|
}
|
||||||
binding.buttonTimeEnd.text = timeslotEnd
|
binding.buttonTimeEnd.text = timeslotEnd
|
||||||
binding.buttonTimeEnd.setOnClickListener {
|
binding.buttonTimeEnd.setOnClickListener {
|
||||||
|
// Launch a time picker dialogue to pick a new end timestamp
|
||||||
TimePickerFragment(
|
TimePickerFragment(
|
||||||
binding.buttonTimeEnd.text.toString(),
|
binding.buttonTimeEnd.text.toString(),
|
||||||
this,
|
this,
|
||||||
|
|||||||
@@ -37,9 +37,6 @@
|
|||||||
app:iconPadding="0dp"
|
app:iconPadding="0dp"
|
||||||
android:layout_gravity="end|center_vertical"
|
android:layout_gravity="end|center_vertical"
|
||||||
app:iconTint="?attr/colorOnSurfaceVariant"/>
|
app:iconTint="?attr/colorOnSurfaceVariant"/>
|
||||||
<!-- app:icon="@drawable/cross"-->
|
|
||||||
<!-- app:strokeColor="?attr/colorOutlineVariant"-->
|
|
||||||
<!-- android:text="@string/cancel"-->
|
|
||||||
|
|
||||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user