Fixed ScheduleUpdateSheet.kt not updating and deleting events... somehow. Also implemented cheat codes hehe

This commit is contained in:
denizk0461
2023-04-26 18:36:32 +02:00
parent d80e85fdbe
commit 450ce92dca
10 changed files with 233 additions and 69 deletions
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="KotlinJpsPluginSettings">
<option name="version" value="1.8.20" />
</component>
</project>
@@ -135,12 +135,32 @@ class AppRepository(app: Application) {
* Deletes all canteen offers from the database. * Deletes all canteen offers from the database.
*/ */
fun nukeOffers() { fun nukeOffers() {
dao.nukeOfferItems() nukeOfferItems()
dao.nukeOfferCategories() nukeOfferCategories()
dao.nukeOfferCanteens() nukeOfferCanteens()
dao.nukeOfferDates() nukeOfferDates()
} }
/**
* Deletes all canteen items from the database.
*/
fun nukeOfferItems() { dao.nukeOfferItems() }
/**
* Deletes all canteen categories from the database.
*/
fun nukeOfferCategories() { dao.nukeOfferCategories() }
/**
* Deletes all canteens from the database.
*/
fun nukeOfferCanteens() { dao.nukeOfferCanteens() }
/**
* Deletes all canteen dates from the database.
*/
fun nukeOfferDates() { dao.nukeOfferDates() }
/** /**
* Inserts a date into the database. * Inserts a date into the database.
* *
@@ -107,7 +107,14 @@ class SettingsFragment : AppFragment() {
// Set long click listener for licences button to open dev code sheet // Set long click listener for licences button to open dev code sheet
binding.buttonLicences.setOnLongClickListener { binding.buttonLicences.setOnLongClickListener {
openBottomSheet(DevCodeSheet()) openBottomSheet(DevCodeSheet(
viewModel::nukeEvents,
viewModel::nukeOfferItems,
viewModel::nukeOfferCategories,
viewModel::nukeOfferCanteens,
viewModel::nukeOfferDates,
viewModel::nukeEverything,
))
true true
} }
@@ -1,10 +1,130 @@
package com.denizk0461.studip.sheet package com.denizk0461.studip.sheet
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.util.Base64
import android.view.View
import android.widget.Toast
import com.denizk0461.studip.R import com.denizk0461.studip.R
import com.denizk0461.studip.data.viewBinding
import com.denizk0461.studip.databinding.SheetDevCodeBinding
import java.nio.charset.StandardCharsets
/** /**
* Sheet that presents the user / developer with a text field to input developer codes / cheat * Sheet that presents the user / developer with a text field to input developer codes / cheat
* codes. * codes.
*
* @param nukeEvents deletes all events
* @param nukeOfferItems deletes all canteen items
* @param nukeOfferCategories deletes all canteen categories
* @param nukeOfferCanteens deletes all canteens
* @param nukeOfferDates deletes all canteen dates
* @param nukeEverything deletes everything
*/ */
class DevCodeSheet : AppSheet(R.layout.sheet_dev_code) { class DevCodeSheet(
private val nukeEvents: () -> Unit,
private val nukeOfferItems: () -> Unit,
private val nukeOfferCategories: () -> Unit,
private val nukeOfferCanteens: () -> Unit,
private val nukeOfferDates: () -> Unit,
private val nukeEverything: () -> Unit,
) : AppSheet(R.layout.sheet_dev_code) {
// View binding
private val binding: SheetDevCodeBinding by viewBinding(SheetDevCodeBinding::bind)
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// Execute an action based on the input
binding.buttonConfirm.setOnClickListener {
/*
* Codes are implemented here.
*
* About the inks; they are safe (which is suspicious of me to say), just encoded so
* people can't just look at the file and figure out all the codes! Of course, they're
* easily decoded, but who would go for that? You would have to be a pretty big nerd to
* do that. Then again, I was the one who encoded all of these links in the first place,
* so I suppose the joke's on me...
*
* If you're reading this why?
*/
when (binding.input.text.toString().uppercase()) {
"U1RST0JF".d() -> launchLink("aHR0cHM6Ly95b3V0dS5iZS90S2k5Wi1mNnFYNA==".d())
"U1BJUklU".d() -> launchLink("aHR0cHM6Ly95b3V0dS5iZS9XN25lMzlEU05TZw==".d())
"Q0xPVURT".d() -> launchLink("aHR0cHM6Ly95b3V0dS5iZS9rbUJ6YTRhNTB2dw==".d())
"NjQxODJL".d() -> launchLink("aHR0cHM6Ly95b3V0dS5iZS9EbTFyZ285UHBUcw==".d())
"U0FJTE9S".d() -> launchLink("aHR0cHM6Ly95b3V0dS5iZS9QUHlDYXZ6OG5NWQ==".d())
"SE9ORVNU".d() -> launchLink("aHR0cHM6Ly95b3V0dS5iZS9DSEg0OE5LUEFraw==".d())
"QkJVT0s/".d() -> launchLink("aHR0cHM6Ly95b3V0dS5iZS90Rm1PMm1TY0tHNA==".d())
"NEVENT" -> { // nuke events
nukeEvents()
showToast("Nuked all events")
}
"NCANTE" -> { // nuke canteens
nukeOfferCanteens()
showToast("Nuked all canteens")
}
"NDATES" -> { // nuke dates
nukeOfferDates()
showToast("Nuked all dates")
}
"NCATEG" -> { // nuke categories
nukeOfferCategories()
showToast("Nuked all categories")
}
"NITEMS" -> { // nuke items
nukeOfferItems()
showToast("Nuked all items")
}
"NEVERY" -> { // nuke everything
nukeEverything()
showToast("Nuked everything")
}
else -> showToast("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.
*
* @param link link to open
*/
private fun launchLink(link: String) {
// Let the user know they accomplished something with their life
showToast("")
// Give the user a slight dopamine boost
startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(link)))
}
/**
* Encodes a string to Base64.
*
* @return the encoded string
*/
private fun String.e(): String = Base64.encodeToString(this.toByteArray(), Base64.DEFAULT)
/**
* Decodes Base64 to a regular string.
*
* @return the decoded string
*/
private fun String.d(): String = String(
Base64.decode(this, Base64.DEFAULT),
StandardCharsets.UTF_8
)
} }
@@ -1,6 +1,7 @@
package com.denizk0461.studip.sheet package com.denizk0461.studip.sheet
import android.os.Bundle import android.os.Bundle
import android.util.Log
import android.view.View import android.view.View
import androidx.fragment.app.FragmentActivity import androidx.fragment.app.FragmentActivity
import com.denizk0461.studip.R import com.denizk0461.studip.R
@@ -104,8 +105,8 @@ class ScheduleUpdateSheet(
* @param isEventStart whether this timestamp is for the start of the course * @param isEventStart whether this timestamp is for the start of the course
*/ */
override fun onTimeSet(hours: Int, minutes: Int, isEventStart: Boolean) { override fun onTimeSet(hours: Int, minutes: Int, isEventStart: Boolean) {
// Parse the separate ints into a timestamp string // Parse the separate ints into a timestamp string. Add a leading zero if necessary.
val newTimestamp = "$hours:$minutes" val newTimestamp = "$hours:${String.format("%02d", minutes)}"
// If start > end, show an error // If start > end, show an error
if ((isEventStart && newTimestamp.parseToMinutes() > timeslotEnd.parseToMinutes()) || if ((isEventStart && newTimestamp.parseToMinutes() > timeslotEnd.parseToMinutes()) ||
@@ -10,6 +10,44 @@ import com.denizk0461.studip.model.SettingsPreferences
*/ */
class SettingsViewModel(app: Application) : AppViewModel(app) { class SettingsViewModel(app: Application) : AppViewModel(app) {
/**
* Deletes everything from the database.
*/
fun nukeEverything() {
nukeEvents()
nukeOfferItems()
nukeOfferCategories()
nukeOfferCanteens()
nukeOfferDates()
}
/**
* Deletes all Stud.IP events from the database.
*/
fun nukeEvents() { doAsync { repo.nukeEvents() } }
/**
* Deletes all canteen items from the database.
*/
fun nukeOfferItems() { doAsync { repo.nukeOfferItems() } }
/**
* Deletes all canteen categories from the database.
*/
fun nukeOfferCategories() { doAsync { repo.nukeOfferCategories() } }
/**
* Deletes all canteens from the database.
*/
fun nukeOfferCanteens() { doAsync { repo.nukeOfferCanteens() } }
/**
* Deletes all canteen dates from the database.
*/
fun nukeOfferDates() { doAsync { repo.nukeOfferDates() } }
/** /**
* This value determines whether the user wants to have the next course in their schedule * This value determines whether the user wants to have the next course in their schedule
* highlighted. * highlighted.
@@ -0,0 +1,9 @@
<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,15c-2.67,0 -8,1.34 -8,4v2h16v-2C17,16.34 11.67,15 9,15z"/>
<path android:fillColor="@android:color/white" android:pathData="M22.1,6.84c0.01,-0.11 0.02,-0.22 0.02,-0.34c0,-0.12 -0.01,-0.23 -0.03,-0.34l0.74,-0.58c0.07,-0.05 0.08,-0.15 0.04,-0.22l-0.7,-1.21c-0.04,-0.08 -0.14,-0.1 -0.21,-0.08L21.1,4.42c-0.18,-0.14 -0.38,-0.25 -0.59,-0.34l-0.13,-0.93C20.36,3.06 20.29,3 20.2,3h-1.4c-0.09,0 -0.16,0.06 -0.17,0.15L18.5,4.08c-0.21,0.09 -0.41,0.21 -0.59,0.34l-0.87,-0.35c-0.08,-0.03 -0.17,0 -0.21,0.08l-0.7,1.21c-0.04,0.08 -0.03,0.17 0.04,0.22l0.74,0.58c-0.02,0.11 -0.03,0.23 -0.03,0.34c0,0.11 0.01,0.23 0.03,0.34l-0.74,0.58c-0.07,0.05 -0.08,0.15 -0.04,0.22l0.7,1.21c0.04,0.08 0.14,0.1 0.21,0.08l0.87,-0.35c0.18,0.14 0.38,0.25 0.59,0.34l0.13,0.93C18.64,9.94 18.71,10 18.8,10h1.4c0.09,0 0.16,-0.06 0.17,-0.15l0.13,-0.93c0.21,-0.09 0.41,-0.21 0.59,-0.34l0.87,0.35c0.08,0.03 0.17,0 0.21,-0.08l0.7,-1.21c0.04,-0.08 0.03,-0.17 -0.04,-0.22L22.1,6.84zM19.5,7.75c-0.69,0 -1.25,-0.56 -1.25,-1.25s0.56,-1.25 1.25,-1.25s1.25,0.56 1.25,1.25S20.19,7.75 19.5,7.75z"/>
<path android:fillColor="@android:color/white" android:pathData="M19.92,11.68l-0.5,-0.87c-0.03,-0.06 -0.1,-0.08 -0.15,-0.06l-0.62,0.25c-0.13,-0.1 -0.27,-0.18 -0.42,-0.24l-0.09,-0.66C18.12,10.04 18.06,10 18,10h-1c-0.06,0 -0.11,0.04 -0.12,0.11l-0.09,0.66c-0.15,0.06 -0.29,0.15 -0.42,0.24l-0.62,-0.25c-0.06,-0.02 -0.12,0 -0.15,0.06l-0.5,0.87c-0.03,0.06 -0.02,0.12 0.03,0.16l0.53,0.41c-0.01,0.08 -0.02,0.16 -0.02,0.24c0,0.08 0.01,0.17 0.02,0.24l-0.53,0.41c-0.05,0.04 -0.06,0.11 -0.03,0.16l0.5,0.87c0.03,0.06 0.1,0.08 0.15,0.06l0.62,-0.25c0.13,0.1 0.27,0.18 0.42,0.24l0.09,0.66C16.89,14.96 16.94,15 17,15h1c0.06,0 0.12,-0.04 0.12,-0.11l0.09,-0.66c0.15,-0.06 0.29,-0.15 0.42,-0.24l0.62,0.25c0.06,0.02 0.12,0 0.15,-0.06l0.5,-0.87c0.03,-0.06 0.02,-0.12 -0.03,-0.16l-0.52,-0.41c0.01,-0.08 0.02,-0.16 0.02,-0.24c0,-0.08 -0.01,-0.17 -0.02,-0.24l0.53,-0.41C19.93,11.81 19.94,11.74 19.92,11.68zM17.5,13.33c-0.46,0 -0.83,-0.38 -0.83,-0.83c0,-0.46 0.38,-0.83 0.83,-0.83s0.83,0.38 0.83,0.83C18.33,12.96 17.96,13.33 17.5,13.33z"/>
<path android:fillColor="@android:color/white" android:pathData="M4.74,9h8.53c0.27,0 0.49,-0.22 0.49,-0.49V8.49c0,-0.27 -0.22,-0.49 -0.49,-0.49H13c0,-1.48 -0.81,-2.75 -2,-3.45V5.5C11,5.78 10.78,6 10.5,6S10,5.78 10,5.5V4.14C9.68,4.06 9.35,4 9,4S8.32,4.06 8,4.14V5.5C8,5.78 7.78,6 7.5,6S7,5.78 7,5.5V4.55C5.81,5.25 5,6.52 5,8H4.74C4.47,8 4.25,8.22 4.25,8.49v0.03C4.25,8.78 4.47,9 4.74,9z"/>
<path android:fillColor="@android:color/white" android:pathData="M9,13c1.86,0 3.41,-1.28 3.86,-3H5.14C5.59,11.72 7.14,13 9,13z"/>
</vector>
+21 -60
View File
@@ -21,75 +21,36 @@
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"
android:text="@string/sheet_cheat_header"/> android:text="@string/sheet_cheat_header"/>
<androidx.appcompat.widget.LinearLayoutCompat <com.google.android.material.textfield.TextInputLayout
style="@style/Widget.Material3.TextInputLayout.OutlinedBox"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:scrollbars="horizontal"> android:paddingHorizontal="24dp">
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
style="@style/Widget.Material3.TextInputEditText.OutlinedBox" style="@style/Widget.Material3.TextInputEditText.OutlinedBox"
android:maxLines="1" android:maxLines="1"
android:maxLength="1" android:maxLength="6"
android:id="@+id/input_0" android:id="@+id/input"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="2dp"/> android:gravity="center"
android:fontFamily="serif-monospace"
android:inputType="textNoSuggestions"
android:textSize="24sp"/>
<com.google.android.material.textfield.TextInputEditText </com.google.android.material.textfield.TextInputLayout>
style="@style/Widget.Material3.TextInputEditText.OutlinedBox"
android:maxLines="1"
android:maxLength="1"
android:id="@+id/input_1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:layout_marginEnd="2dp"/>
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.button.MaterialButton
style="@style/Widget.Material3.TextInputEditText.OutlinedBox" android:id="@+id/button_confirm"
android:maxLines="1" style="@style/Widget.Material3.Button.TonalButton"
android:maxLength="1" android:layout_width="wrap_content"
android:id="@+id/input_2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="2dp" android:text="@string/confirm"
android:layout_marginEnd="2dp"/> android:layout_gravity="end"
android:layout_marginTop="8dp"
<com.google.android.material.textfield.TextInputEditText android:layout_marginEnd="24dp"
style="@style/Widget.Material3.TextInputEditText.OutlinedBox" android:layout_marginBottom="8dp"
android:maxLines="1" app:icon="@drawable/engineering"/>
android:maxLength="1"
android:id="@+id/input_3"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:layout_marginEnd="2dp"/>
<com.google.android.material.textfield.TextInputEditText
style="@style/Widget.Material3.TextInputEditText.OutlinedBox"
android:maxLines="1"
android:maxLength="1"
android:id="@+id/input_4"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"
android:layout_marginEnd="2dp"/>
<com.google.android.material.textfield.TextInputEditText
style="@style/Widget.Material3.TextInputEditText.OutlinedBox"
android:maxLines="1"
android:maxLength="1"
android:id="@+id/input_5"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginStart="2dp"/>
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat> </androidx.appcompat.widget.LinearLayoutCompat>
+1
View File
@@ -14,6 +14,7 @@
<string name="save">Speichern</string> <string name="save">Speichern</string>
<string name="delete">Löschen</string> <string name="delete">Löschen</string>
<string name="cancel">Abbrechen</string> <string name="cancel">Abbrechen</string>
<string name="confirm">Bestätigen</string>
<string name="sheet_schedule_update_header">Veranstaltung bearbeiten</string> <string name="sheet_schedule_update_header">Veranstaltung bearbeiten</string>
<string name="sheet_schedule_update_title_hint">Veranstaltungstitel</string> <string name="sheet_schedule_update_title_hint">Veranstaltungstitel</string>
<string name="sheet_schedule_update_lecturers_hint">Dozierende(r)</string> <string name="sheet_schedule_update_lecturers_hint">Dozierende(r)</string>
+1
View File
@@ -14,6 +14,7 @@
<string name="save">Save</string> <string name="save">Save</string>
<string name="delete">Delete</string> <string name="delete">Delete</string>
<string name="cancel">Cancel</string> <string name="cancel">Cancel</string>
<string name="confirm">Confirm</string>
<string name="sheet_schedule_update_header">Edit Event</string> <string name="sheet_schedule_update_header">Edit Event</string>
<string name="sheet_schedule_update_title_hint">Event title</string> <string name="sheet_schedule_update_title_hint">Event title</string>
<string name="sheet_schedule_update_lecturers_hint">Lecturer(s)</string> <string name="sheet_schedule_update_lecturers_hint">Lecturer(s)</string>