diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 15aa9363..cf36b13d 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -20,7 +20,7 @@ android { defaultConfig { applicationId = "com.joeloewi.croissant" - versionCode = 48 + versionCode = 49 versionName = "1.2.2" targetSdk = 34 diff --git a/app/src/main/kotlin/com/joeloewi/croissant/di/UtilModule.kt b/app/src/main/kotlin/com/joeloewi/croissant/di/UtilModule.kt index 50092a1c..9e4fabef 100644 --- a/app/src/main/kotlin/com/joeloewi/croissant/di/UtilModule.kt +++ b/app/src/main/kotlin/com/joeloewi/croissant/di/UtilModule.kt @@ -79,7 +79,7 @@ object UtilModule { this } } - .okHttpClient { okHttpClient } + .okHttpClient(okHttpClient) .placeholder(R.drawable.image_placeholder) .build() } diff --git a/app/src/main/kotlin/com/joeloewi/croissant/viewmodel/AttendanceDetailViewModel.kt b/app/src/main/kotlin/com/joeloewi/croissant/viewmodel/AttendanceDetailViewModel.kt index 4d1c2561..e6cf7d91 100644 --- a/app/src/main/kotlin/com/joeloewi/croissant/viewmodel/AttendanceDetailViewModel.kt +++ b/app/src/main/kotlin/com/joeloewi/croissant/viewmodel/AttendanceDetailViewModel.kt @@ -252,7 +252,21 @@ class AttendanceDetailViewModel @Inject constructor( viewModelScope.launch(Dispatchers.IO) { _deleteAttendanceState.value = ILCE.Loading _deleteAttendanceState.value = runCatching { - deleteAttendanceUseCase(getOneAttendanceUseCase(attendanceId).attendance) + val attendance = getOneAttendanceUseCase(attendanceId).attendance + + listOf( + attendance.checkSessionWorkerName, + attendance.attendCheckInEventWorkerName, + attendance.oneTimeAttendCheckInEventWorkerName + ).map { it.toString() }.map { uniqueWorkName -> + workManager.cancelUniqueWork(uniqueWorkName) + } + + workManager.cancelWorkById(attendance.checkSessionWorkerId) + + alarmScheduler.cancelCheckInAlarm(attendance.id) + + deleteAttendanceUseCase(attendance) Unit }.foldAsILCE() } diff --git a/app/src/main/kotlin/com/joeloewi/croissant/worker/CheckSessionWorker.kt b/app/src/main/kotlin/com/joeloewi/croissant/worker/CheckSessionWorker.kt index 46308c9b..9ed9b521 100644 --- a/app/src/main/kotlin/com/joeloewi/croissant/worker/CheckSessionWorker.kt +++ b/app/src/main/kotlin/com/joeloewi/croissant/worker/CheckSessionWorker.kt @@ -3,6 +3,7 @@ package com.joeloewi.croissant.worker import android.content.Context import androidx.hilt.work.HiltWorker import androidx.work.CoroutineWorker +import androidx.work.WorkManager import androidx.work.WorkerParameters import com.google.firebase.Firebase import com.google.firebase.crashlytics.crashlytics @@ -46,7 +47,14 @@ class CheckSessionWorker @AssistedInject constructor( _attendanceId.runCatching { takeIf { it != Long.MIN_VALUE }!! }.mapCatching { attendanceId -> - getOneAttendanceUseCase(attendanceId) + val attendance = runCatching { getOneAttendanceUseCase(attendanceId) }.getOrNull() + + if (attendance == null) { + WorkManager.getInstance(context).cancelWorkById(id) + return@withContext Result.failure() + } else { + attendance + } }.mapCatching { attendanceWithAllValues -> getUserFullInfoHoYoLABUseCase(attendanceWithAllValues.attendance.cookie).getOrThrow() }.fold(