Implemented button to change dates for an event to reflect the academic quarter

This commit is contained in:
denizk0461
2023-04-27 08:20:56 +02:00
parent 540a2a7b9a
commit a6a1309bce
12 changed files with 119 additions and 42 deletions
@@ -7,6 +7,7 @@ import android.util.Base64
import android.view.View
import android.widget.Toast
import com.denizk0461.studip.R
import com.denizk0461.studip.data.showToast
import com.denizk0461.studip.data.viewBinding
import com.denizk0461.studip.databinding.SheetDevCodeBinding
import java.nio.charset.StandardCharsets
@@ -60,43 +61,34 @@ class DevCodeSheet(
"QkJVT0s/".d() -> launchLink("aHR0cHM6Ly95b3V0dS5iZS90Rm1PMm1TY0tHNA==".d())
"NEVENT" -> { // nuke events
nukeEvents()
showToast("Nuked all events")
showToast(context, "Nuked all events")
}
"NCANTE" -> { // nuke canteens
nukeOfferCanteens()
showToast("Nuked all canteens")
showToast(context, "Nuked all canteens")
}
"NDATES" -> { // nuke dates
nukeOfferDates()
showToast("Nuked all dates")
showToast(context, "Nuked all dates")
}
"NCATEG" -> { // nuke categories
nukeOfferCategories()
showToast("Nuked all categories")
showToast(context, "Nuked all categories")
}
"NITEMS" -> { // nuke items
nukeOfferItems()
showToast("Nuked all items")
showToast(context, "Nuked all items")
}
"NEVERY" -> { // nuke everything
nukeEverything()
showToast("Nuked everything")
showToast(context, "Nuked everything")
}
else -> showToast("code is invalid")
else -> showToast(context, "code is invalid")
}
dismiss()
}
}
/**
* Present the user with a toast.
*
* @param text text to display
*/
private fun showToast(text: String) {
Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
}
/**
* Launches a web link.
*
@@ -104,7 +96,7 @@ class DevCodeSheet(
*/
private fun launchLink(link: String) {
// Let the user know they accomplished something with their life
showToast("")
showToast(context, "")
// Give the user a slight dopamine boost
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link)))
@@ -1,11 +1,17 @@
package com.denizk0461.studip.sheet
import android.os.Bundle
import android.os.Handler
import android.util.Log
import android.view.View
import androidx.fragment.app.FragmentActivity
import androidx.transition.TransitionManager
import com.denizk0461.studip.R
import com.denizk0461.studip.data.parseToMinutes
import com.denizk0461.studip.data.showToast
import com.denizk0461.studip.data.timeslotsAcademicQuarter
import com.denizk0461.studip.data.timeslotsAcademicQuarterEnd
import com.denizk0461.studip.data.timeslotsAcademicQuarterStart
import com.denizk0461.studip.data.viewBinding
import com.denizk0461.studip.databinding.SheetScheduleUpdateBinding
import com.denizk0461.studip.dialog.TimePickerFragment
@@ -40,6 +46,34 @@ class ScheduleUpdateSheet(
binding.editTextLecturers.setText(event.lecturer)
binding.editTextRoom.setText(event.room)
// Show academic quarter suggestion if it is applicable
binding.buttonAcademicQuarter.visibility = if (
timeslotsAcademicQuarter.contains(timeslotStart) &&
timeslotsAcademicQuarter.contains(timeslotEnd)
) {
binding.buttonAcademicQuarter.setOnClickListener {
try {
val newStart = timeslotsAcademicQuarterStart[timeslotStart]
?: throw NullPointerException()
val newEnd = timeslotsAcademicQuarterEnd[timeslotEnd]
?: throw NullPointerException()
timeslotStart = newStart
binding.buttonTimeStart.text = newStart
timeslotEnd = newEnd
binding.buttonTimeEnd.text = newEnd
TransitionManager.beginDelayedTransition(binding.sheet)
binding.buttonAcademicQuarter.visibility = View.GONE
} catch (e: NullPointerException) {
showToast(context, getString(R.string.sheet_schedule_update_hint_quarter_error))
}
}
View.VISIBLE
} else {
View.GONE
}
// Prepare timestamp buttons
binding.buttonTimeStart.text = timeslotStart
binding.buttonTimeStart.setOnClickListener {