From 1bf55f9071c00e3d4103b94f45a186a1e7ee87db Mon Sep 17 00:00:00 2001 From: sowjanyakch Date: Tue, 29 Oct 2024 17:24:31 +0100 Subject: [PATCH] add const val for error code Signed-off-by: sowjanyakch --- .../conversationinfo/ConversationInfoActivity.kt | 12 ++++++++++-- .../nextcloud/talk/jobs/LeaveConversationWorker.kt | 9 +++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt index ae0881640..0904a79ff 100644 --- a/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/conversationinfo/ConversationInfoActivity.kt @@ -658,9 +658,17 @@ class ConversationInfoActivity : WorkInfo.State.FAILED -> { val errorType = workInfo.outputData.getString("error_type") if (errorType == LeaveConversationWorker.ERROR_NO_OTHER_MODERATORS_OR_OWNERS_LEFT) { - Snackbar.make( binding.root, R.string.nc_last_moderator_leaving_room_warning, Snackbar.LENGTH_LONG ).show() + Snackbar.make( + binding.root, + R.string.nc_last_moderator_leaving_room_warning, + Snackbar.LENGTH_LONG + ).show() } else { - Snackbar.make( binding.root, R.string.nc_common_error_sorry, Snackbar.LENGTH_LONG ).show() + Snackbar.make( + binding.root, + R.string.nc_common_error_sorry, + Snackbar.LENGTH_LONG + ).show() } } else -> { diff --git a/app/src/main/java/com/nextcloud/talk/jobs/LeaveConversationWorker.kt b/app/src/main/java/com/nextcloud/talk/jobs/LeaveConversationWorker.kt index 55eeb897e..bf746199e 100644 --- a/app/src/main/java/com/nextcloud/talk/jobs/LeaveConversationWorker.kt +++ b/app/src/main/java/com/nextcloud/talk/jobs/LeaveConversationWorker.kt @@ -70,15 +70,15 @@ class LeaveConversationWorker(context: Context, workerParams: WorkerParameters) override fun onError(e: Throwable) { Log.e(TAG, "Failed to remove self from room", e) val httpException = e as? HttpException - val errorData = if (httpException?.code() == 400) { + val errorData = if (httpException?.code() == HTTP_ERROR_CODE_400) { Data.Builder() .putString("error_type", ERROR_NO_OTHER_MODERATORS_OR_OWNERS_LEFT) .build() - } - else { + } else { Data.Builder() .putString("error_type", ERROR_OTHER) - .build() } + .build() + } result.set(Result.failure(errorData)) } @@ -97,5 +97,6 @@ class LeaveConversationWorker(context: Context, workerParams: WorkerParameters) private const val TAG = "LeaveConversationWorker" const val ERROR_NO_OTHER_MODERATORS_OR_OWNERS_LEFT = "NO_OTHER_MODERATORS_OR_OWNERS_LEFT" const val ERROR_OTHER = "ERROR_OTHER" + const val HTTP_ERROR_CODE_400 = 400 } }