All sheets now have a button to dismiss the sheet

This commit is contained in:
denizk0461
2023-05-03 21:49:18 +02:00
parent df1d127a17
commit 9e5277a5f6
15 changed files with 210 additions and 61 deletions
@@ -131,6 +131,12 @@ class SettingsFragment : AppFragment() {
true
}
val cheesyWisdoms: MutableList<String> = resources
.getStringArray(R.array.cheesy_wisdoms)
.toList()
.shuffled()
.toMutableList()
// Set click listener for the app version button
binding.buttonAppVersion.setOnClickListener {
when (appVersionClick) {
@@ -152,10 +158,30 @@ class SettingsFragment : AppFragment() {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(mysteryLink)))
}
238 -> { // after 222 has been reached, this loops every 16 clicks
showToast(context, resources.getStringArray(R.array.cheesy).random())
// Show the next cheesy wisdom
showToast(context, cheesyWisdoms[0])
// Remove the cheesy wisdom from the list
cheesyWisdoms.removeAt(0)
// Get new cheesy wisdoms if cheesy wisdoms have run out
if (cheesyWisdoms.isEmpty()) {
cheesyWisdoms.addAll(resources
.getStringArray(R.array.cheesy_wisdoms)
.toList()
.shuffled()
)
}
/*
* Reset to 222 to make the user click 16 times again before the next cheesy
* wisdom is shown.
*/
appVersionClick = 222
}
}
// Increment click counter
appVersionClick += 1
}
@@ -64,6 +64,12 @@ class AllergenConfigSheet : AppSheet(R.layout.sheet_allergen_config) {
binding.buttonSave.setOnClickListener {
saveAllergenPrefs()
}
// Set up close button
binding.buttonCancel.setOnClickListener {
// Do nothing and dismiss the sheet
dismiss()
}
}
/**
@@ -95,6 +95,12 @@ class AllergenSheet : AppSheet(R.layout.sheet_allergen) {
textPrice.text = offer.price
}
}
// Set up close button
binding.buttonCancel.setOnClickListener {
// Do nothing and dismiss the sheet
dismiss()
}
} catch (e: ParcelNotFoundException) {
// Tell the user that something went wrong when retrieving Parcelable
showToast(context, getString(R.string.canteen_page_allergen_sheet_error))
@@ -99,6 +99,12 @@ class DevCodeSheet : AppSheet(R.layout.sheet_dev_code) {
}
dismiss()
}
// Set up close button
binding.buttonCancel.setOnClickListener {
// Do nothing and dismiss the sheet
dismiss()
}
}
/**
@@ -114,13 +120,6 @@ class DevCodeSheet : AppSheet(R.layout.sheet_dev_code) {
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link)))
}
/**
* Encodes a string to Base64.
*
* @return the encoded string
*/
private val String.e64: String get() = Base64.encodeToString(this.toByteArray(), Base64.DEFAULT)
/**
* Decodes Base64 to a regular string.
@@ -203,8 +203,11 @@ class ScheduleUpdateSheet : AppSheet(R.layout.sheet_schedule_update), TimePicker
else -> Pair(0, R.string.monday) // assume Monday
}
// Store the new day
selectedDay = newDay
// Prepare layout animation
TransitionManager.beginDelayedTransition(binding.sheet.parent as ViewGroup)
// Set newly selected day to the button
binding.buttonDay.text = getString(newDayId)
@@ -277,7 +280,7 @@ class ScheduleUpdateSheet : AppSheet(R.layout.sheet_schedule_update), TimePicker
}.show((context as FragmentActivity).supportFragmentManager, "timePicker")
}
// Prepare cancel button
// Set up close button
binding.buttonCancel.setOnClickListener {
// Do nothing and dismiss the sheet
dismiss()
@@ -334,7 +337,7 @@ class ScheduleUpdateSheet : AppSheet(R.layout.sheet_schedule_update), TimePicker
// Check if the title field is blank
if (binding.editTextTitle.text.toString().isBlank()) {
// Set an error on the title field
binding.editTextTitle.error =
binding.textLayoutTitle.error =
getString(R.string.sheet_schedule_update_text_field_empty_error)
// Set that the action must not be executed
@@ -344,7 +347,7 @@ class ScheduleUpdateSheet : AppSheet(R.layout.sheet_schedule_update), TimePicker
// Check if the lecturer field is blank
if (binding.editTextLecturers.text.toString().isBlank()) {
// Set an error on the lecturer field
binding.editTextLecturers.error =
binding.textLayoutLecturers.error =
getString(R.string.sheet_schedule_update_text_field_empty_error)
// Set that the action must not be executed
@@ -354,7 +357,7 @@ class ScheduleUpdateSheet : AppSheet(R.layout.sheet_schedule_update), TimePicker
// Check if the room field is blank
if (binding.editTextRoom.text.toString().isBlank()) {
// Set an error on the room field
binding.editTextRoom.error =
binding.textLayoutRoom.error =
getString(R.string.sheet_schedule_update_text_field_empty_error)
// Set that the action must not be executed
@@ -28,5 +28,11 @@ class TextSheet : AppSheet(R.layout.sheet_text) {
textHeader.text = header
textContent.text = content
}
// Set up close button
binding.buttonCancel.setOnClickListener {
// Do nothing and dismiss the sheet
dismiss()
}
}
}