From 1aef1e203b6ab31e27b585d6f8b36d33b28962e1 Mon Sep 17 00:00:00 2001 From: Jonas Sulzer Date: Thu, 30 May 2024 22:25:11 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20branch=20event=20deletion?= =?UTF-8?q?=20button=20on=20repository?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jonas Sulzer --- .../github/swent/echo/compose/event/EventScreen.kt | 3 +-- .../swent/echo/viewmodels/event/EventViewModel.kt | 12 ++++++++++++ app/src/main/res/values/strings.xml | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/swent/echo/compose/event/EventScreen.kt b/app/src/main/java/com/github/swent/echo/compose/event/EventScreen.kt index 8cfa45f30..611727417 100644 --- a/app/src/main/java/com/github/swent/echo/compose/event/EventScreen.kt +++ b/app/src/main/java/com/github/swent/echo/compose/event/EventScreen.kt @@ -94,8 +94,7 @@ fun EventScreen( ) { if (canDelete) { DeleteEventButton(enabled = isOnline) { - // TODO: delete the event in the repository - onEventDeleted() + eventViewModel.deleteEvent(onEventDeleted) } } OutlinedButton( diff --git a/app/src/main/java/com/github/swent/echo/viewmodels/event/EventViewModel.kt b/app/src/main/java/com/github/swent/echo/viewmodels/event/EventViewModel.kt index 1d7b8e179..48ce9118e 100644 --- a/app/src/main/java/com/github/swent/echo/viewmodels/event/EventViewModel.kt +++ b/app/src/main/java/com/github/swent/echo/viewmodels/event/EventViewModel.kt @@ -148,6 +148,18 @@ constructor( } } + // delete the current event in the repository + fun deleteEvent(onEventDeleted: () -> Unit) { + viewModelScope.launch { + try { + repository.deleteEvent(event.value) + onEventDeleted() + } catch (e: RepositoryStoreWhileNoInternetException) { + _status.value = EventStatus.Error(R.string.event_creation_error_network_failure) + } + } + } + /** change event status from error to modified */ fun dismissError() { if (_status.value is EventStatus.Error) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0b6b8a515..959d04446 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -49,7 +49,7 @@ The end date is before the start date The title is empty The maximum number of participants is too low - Network problem while saving event. Please retry. + Network problem while saving or deleting event. Please retry. EPFL Section Class