From 00c14377f7ea46a63361d63527ac02f7c29e6f5f Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Mon, 9 Aug 2021 08:50:01 +0200 Subject: [PATCH] catch AccountNotFoundException from createNextcloudClient Signed-off-by: tobiasKaminsky --- src/main/java/com/nextcloud/ui/ClearStatusTask.kt | 12 ++++++++++-- .../nextcloud/ui/SetPredefinedCustomStatusTask.kt | 12 ++++++++++-- src/main/java/com/nextcloud/ui/SetStatusTask.kt | 12 ++++++++++-- .../nextcloud/ui/SetUserDefinedCustomStatusTask.kt | 12 ++++++++++-- 4 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/nextcloud/ui/ClearStatusTask.kt b/src/main/java/com/nextcloud/ui/ClearStatusTask.kt index 5da74065b0..25fcf45714 100644 --- a/src/main/java/com/nextcloud/ui/ClearStatusTask.kt +++ b/src/main/java/com/nextcloud/ui/ClearStatusTask.kt @@ -25,12 +25,20 @@ package com.nextcloud.ui import android.accounts.Account import android.content.Context import com.owncloud.android.lib.common.OwnCloudClientFactory +import com.owncloud.android.lib.common.accounts.AccountUtils +import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.users.ClearStatusMessageRemoteOperation public class ClearStatusTask(val account: Account?, val context: Context?) : Function0 { override fun invoke(): Boolean { - val client = OwnCloudClientFactory.createNextcloudClient(account, context) + return try { + val client = OwnCloudClientFactory.createNextcloudClient(account, context) - return ClearStatusMessageRemoteOperation().execute(client).isSuccess + ClearStatusMessageRemoteOperation().execute(client).isSuccess + } catch (e: AccountUtils.AccountNotFoundException) { + Log_OC.e(this, "Error clearing status", e) + + false + } } } diff --git a/src/main/java/com/nextcloud/ui/SetPredefinedCustomStatusTask.kt b/src/main/java/com/nextcloud/ui/SetPredefinedCustomStatusTask.kt index c6d2ddf8cc..b7498184f4 100644 --- a/src/main/java/com/nextcloud/ui/SetPredefinedCustomStatusTask.kt +++ b/src/main/java/com/nextcloud/ui/SetPredefinedCustomStatusTask.kt @@ -25,6 +25,8 @@ package com.nextcloud.ui import android.accounts.Account import android.content.Context import com.owncloud.android.lib.common.OwnCloudClientFactory +import com.owncloud.android.lib.common.accounts.AccountUtils +import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.users.SetPredefinedCustomStatusMessageRemoteOperation public class SetPredefinedCustomStatusTask( @@ -34,8 +36,14 @@ public class SetPredefinedCustomStatusTask( val context: Context? ) : Function0 { override fun invoke(): Boolean { - val client = OwnCloudClientFactory.createNextcloudClient(account, context) + return try { + val client = OwnCloudClientFactory.createNextcloudClient(account, context) - return SetPredefinedCustomStatusMessageRemoteOperation(messageId, clearAt).execute(client).isSuccess + SetPredefinedCustomStatusMessageRemoteOperation(messageId, clearAt).execute(client).isSuccess + } catch (e: AccountUtils.AccountNotFoundException) { + Log_OC.e(this, "Error setting predefined status", e) + + false + } } } diff --git a/src/main/java/com/nextcloud/ui/SetStatusTask.kt b/src/main/java/com/nextcloud/ui/SetStatusTask.kt index b5f4598c22..abe2070ea4 100644 --- a/src/main/java/com/nextcloud/ui/SetStatusTask.kt +++ b/src/main/java/com/nextcloud/ui/SetStatusTask.kt @@ -25,6 +25,8 @@ package com.nextcloud.ui import android.accounts.Account import android.content.Context import com.owncloud.android.lib.common.OwnCloudClientFactory +import com.owncloud.android.lib.common.accounts.AccountUtils +import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.users.SetStatusRemoteOperation import com.owncloud.android.lib.resources.users.StatusType @@ -34,8 +36,14 @@ class SetStatusTask( val context: Context? ) : Function0 { override fun invoke(): Boolean { - val client = OwnCloudClientFactory.createNextcloudClient(account, context) + return try { + val client = OwnCloudClientFactory.createNextcloudClient(account, context) - return SetStatusRemoteOperation(statusType).execute(client).isSuccess + SetStatusRemoteOperation(statusType).execute(client).isSuccess + } catch (e: AccountUtils.AccountNotFoundException) { + Log_OC.e(this, "Error setting status", e) + + false + } } } diff --git a/src/main/java/com/nextcloud/ui/SetUserDefinedCustomStatusTask.kt b/src/main/java/com/nextcloud/ui/SetUserDefinedCustomStatusTask.kt index 43167a56f6..db3ae58dd3 100644 --- a/src/main/java/com/nextcloud/ui/SetUserDefinedCustomStatusTask.kt +++ b/src/main/java/com/nextcloud/ui/SetUserDefinedCustomStatusTask.kt @@ -25,6 +25,8 @@ package com.nextcloud.ui import android.accounts.Account import android.content.Context import com.owncloud.android.lib.common.OwnCloudClientFactory +import com.owncloud.android.lib.common.accounts.AccountUtils +import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.users.SetUserDefinedCustomStatusMessageRemoteOperation public class SetUserDefinedCustomStatusTask( @@ -35,8 +37,14 @@ public class SetUserDefinedCustomStatusTask( val context: Context? ) : Function0 { override fun invoke(): Boolean { - val client = OwnCloudClientFactory.createNextcloudClient(account, context) + return try { + val client = OwnCloudClientFactory.createNextcloudClient(account, context) - return SetUserDefinedCustomStatusMessageRemoteOperation(message, icon, clearAt).execute(client).isSuccess + return SetUserDefinedCustomStatusMessageRemoteOperation(message, icon, clearAt).execute(client).isSuccess + } catch (e: AccountUtils.AccountNotFoundException) { + Log_OC.e(this, "Error setting user defined custom status", e) + + false + } } }