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
@@ -1,7 +1,9 @@
package com.denizk0461.studip.data
import android.content.Context
import android.content.res.Resources
import android.util.TypedValue
import android.widget.Toast
import androidx.annotation.AttrRes
import com.denizk0461.studip.R
@@ -30,24 +32,52 @@ fun Resources.Theme.getThemedColor(@AttrRes id: Int): Int = TypedValue().also {
resolveAttribute(id, value, true)
}.data
object Misc {
// private val timeslotAcademicQuarter = mapOf(
// "6:00" to "6:15",
// "8:00" to "7:45",
// "8:00" to "8:15",
// "10:00" to "9:45",
// "10:00" to "10:15",
// "12:00" to "11:45",
// "12:00" to "12:15",
// "14:00" to "13:45",
// "14:00" to "14:15",
// "16:00" to "15:45",
// "16:00" to "16:15",
// "18:00" to "17:45",
// "18:00" to "18:15",
// "20:00" to "19:45",
// "20:00" to "20:15",
// "22:00" to "21:45",
// )
/**
* Present the user with a toast.
*
* @param text text to display
*/
fun showToast(context: Context, text: String) {
Toast.makeText(context, text, Toast.LENGTH_SHORT).show()
}
/**
* Provides a conversion method between a timestamp ending in a full hour, and one with an academic
* quarter applied.
*/
val timeslotsAcademicQuarter = listOf(
"4:00",
"6:00",
"8:00",
"10:00",
"12:00",
"14:00",
"16:00",
"18:00",
"20:00",
"22:00",
)
val timeslotsAcademicQuarterStart = mapOf(
"4:00" to "4:15",
"6:00" to "6:15",
"8:00" to "8:15",
"10:00" to "10:15",
"12:00" to "12:15",
"14:00" to "14:15",
"16:00" to "16:15",
"18:00" to "18:15",
"20:00" to "20:15",
)
val timeslotsAcademicQuarterEnd = mapOf(
"6:00" to "5:45",
"8:00" to "7:45",
"10:00" to "9:45",
"12:00" to "11:45",
"14:00" to "13:45",
"16:00" to "15:45",
"18:00" to "17:45",
"20:00" to "19:45",
"22:00" to "21:45",
)
@@ -197,7 +197,8 @@ class AppRepository(app: Application) {
* @param pref preference to retrieve
* @return whether the user set this preference
*/
fun getBooleanPreference(pref: SettingsPreferences): Boolean = prefs.getBoolean(pref.key, false)
fun getBooleanPreference(pref: SettingsPreferences, defaultValue: Boolean = false): Boolean =
prefs.getBoolean(pref.key, defaultValue)
/**
* Retrieves ta user-set integer preference.
@@ -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 {
@@ -70,7 +70,7 @@ class CanteenViewModel(app: Application) : AppViewModel(app) {
* This value determines whether the user wants to have allergens marked.
*/
val preferenceAllergen: Boolean
get() = repo.getBooleanPreference(SettingsPreferences.ALLERGEN)
get() = repo.getBooleanPreference(SettingsPreferences.ALLERGEN, defaultValue = true)
var preferenceCanteen: Int
get() = repo.getIntPreference(SettingsPreferences.CANTEEN)
@@ -60,7 +60,7 @@ class SettingsViewModel(app: Application) : AppViewModel(app) {
* This value determines whether the user wants to have allergens marked.
*/
var preferenceAllergen: Boolean
get() = repo.getBooleanPreference(SettingsPreferences.ALLERGEN)
get() = repo.getBooleanPreference(SettingsPreferences.ALLERGEN, defaultValue = true)
set(newValue) { repo.setPreference(SettingsPreferences.ALLERGEN, newValue) }
/**
+5
View File
@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M9,21c0,0.5 0.4,1 1,1h4c0.6,0 1,-0.5 1,-1v-1L9,20v1zM12,2C8.1,2 5,5.1 5,9c0,2.4 1.2,4.5 3,5.7L8,17c0,0.5 0.4,1 1,1h6c0.6,0 1,-0.5 1,-1v-2.3c1.8,-1.3 3,-3.4 3,-5.7 0,-3.9 -3.1,-7 -7,-7z"/>
</vector>
Binary file not shown.
+1 -1
View File
@@ -35,7 +35,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:fontFamily="serif-monospace"
android:fontFamily="@font/ibm_regular"
android:inputType="textNoSuggestions"
android:textSize="24sp"/>
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sheet"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
@@ -115,6 +116,15 @@
</androidx.appcompat.widget.LinearLayoutCompat>
<com.google.android.material.button.MaterialButton
android:id="@+id/button_academic_quarter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
app:icon="@drawable/lightbulb"
android:text="@string/sheet_schedule_update_hint_quarter"
android:layout_gravity="end"/>
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
@@ -149,7 +159,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="end">
android:gravity="end"
android:layout_marginBottom="8dp">
<com.google.android.material.button.MaterialButton
android:id="@+id/button_delete"
+2
View File
@@ -19,6 +19,8 @@
<string name="sheet_schedule_update_title_hint">Veranstaltungstitel</string>
<string name="sheet_schedule_update_lecturers_hint">Dozierende(r)</string>
<string name="sheet_schedule_update_room_hint">Raum</string>
<string name="sheet_schedule_update_hint_quarter">Auf akademisches Viertel umstellen</string>
<string name="sheet_schedule_update_hint_quarter_error">Sorry, ein Fehler ist aufgetreten!</string>
<string name="canteen_no_offer_header">Kein Angebot</string>
<string name="canteen_no_offer_desc">Für diesen Tag sind keine Angebote vorhanden</string>
+2
View File
@@ -20,6 +20,8 @@
<string name="sheet_schedule_update_lecturers_hint">Lecturer(s)</string>
<string name="sheet_schedule_update_room_hint">Room</string>
<string name="sheet_schedule_update_timeslot_middle" translatable="false"></string>
<string name="sheet_schedule_update_hint_quarter">Change to academic quarter</string>
<string name="sheet_schedule_update_hint_quarter_error">Sorry, an error occurred!</string>
<string name="canteen_no_offer_header">No offers</string>
<string name="canteen_no_offer_desc">There are no offers available for this day</string>