Archived
Implemented snackbar telling the user that an error has occurred when fetching their schedule through FetcherActivity.kt. Also made some slight additions to the documentation
This commit is contained in:
@@ -2,7 +2,6 @@ package com.denizk0461.studip.sheet
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.TimePicker
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
import com.denizk0461.studip.R
|
||||
import com.denizk0461.studip.data.parseToMinutes
|
||||
@@ -11,6 +10,13 @@ import com.denizk0461.studip.databinding.SheetScheduleUpdateBinding
|
||||
import com.denizk0461.studip.dialog.TimePickerFragment
|
||||
import com.denizk0461.studip.model.StudIPEvent
|
||||
|
||||
/**
|
||||
* Update sheet to allow the user to edit attributes for a specific schedule event.
|
||||
*
|
||||
* @param event event to be updated
|
||||
* @param onUpdate action to execute to update the event
|
||||
* @param onDelete action to execute to delete the event
|
||||
*/
|
||||
class ScheduleUpdateSheet(
|
||||
private val event: StudIPEvent,
|
||||
private val onUpdate: (event: StudIPEvent) -> Unit,
|
||||
@@ -28,24 +34,37 @@ class ScheduleUpdateSheet(
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
// Set editable text fields
|
||||
binding.editTextTitle.setText(event.title)
|
||||
binding.editTextLecturers.setText(event.lecturer)
|
||||
binding.editTextRoom.setText(event.room)
|
||||
|
||||
// Prepare timestamp buttons
|
||||
binding.buttonTimeStart.text = timeslotStart
|
||||
binding.buttonTimeStart.setOnClickListener {
|
||||
TimePickerFragment(binding.buttonTimeStart.text.toString(), this, true).show((context as FragmentActivity).supportFragmentManager, "timePicker")
|
||||
TimePickerFragment(
|
||||
binding.buttonTimeStart.text.toString(),
|
||||
this,
|
||||
true,
|
||||
).show((context as FragmentActivity).supportFragmentManager, "timePicker")
|
||||
}
|
||||
binding.buttonTimeEnd.text = timeslotEnd
|
||||
binding.buttonTimeEnd.setOnClickListener {
|
||||
TimePickerFragment(binding.buttonTimeEnd.text.toString(), this, false).show((context as FragmentActivity).supportFragmentManager, "timePicker")
|
||||
TimePickerFragment(
|
||||
binding.buttonTimeEnd.text.toString(),
|
||||
this,
|
||||
false,
|
||||
).show((context as FragmentActivity).supportFragmentManager, "timePicker")
|
||||
}
|
||||
|
||||
// Prepare delete button
|
||||
binding.buttonDelete.setOnClickListener {
|
||||
onDelete(event)
|
||||
// Dismiss the sheet upon deletion
|
||||
dismiss()
|
||||
}
|
||||
|
||||
// Prepare update/save button
|
||||
binding.buttonSave.setOnClickListener {
|
||||
onUpdate(
|
||||
StudIPEvent(
|
||||
@@ -60,22 +79,28 @@ class ScheduleUpdateSheet(
|
||||
colour = colour,
|
||||
)
|
||||
)
|
||||
// Dismiss the sheet upon update
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks and stores a new timestamp after the user picks one through [TimePickerFragment].
|
||||
*
|
||||
* @param hours newly set hour
|
||||
* @param minutes newly set minute
|
||||
* @param isEventStart whether this timestamp is for the start of the course
|
||||
*/
|
||||
override fun onTimeSet(hours: Int, minutes: Int, isEventStart: Boolean) {
|
||||
|
||||
// Parse the separate ints into a timestamp string
|
||||
val newTimestamp = "$hours:$minutes"
|
||||
|
||||
// If start > end, show an error
|
||||
if ((isEventStart && newTimestamp.parseToMinutes() > timeslotEnd.parseToMinutes()) ||
|
||||
(!isEventStart && newTimestamp.parseToMinutes() < timeslotStart.parseToMinutes())) {
|
||||
// tell user that the timestamp must be set earlier/later
|
||||
} else {
|
||||
|
||||
// If the new timestamp is valid, save it
|
||||
if (isEventStart) {
|
||||
timeslotStart = newTimestamp
|
||||
binding.buttonTimeStart.text = newTimestamp
|
||||
|
||||
Reference in New Issue
Block a user