diff --git a/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt b/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt index 63b9573cb7..471390356e 100644 --- a/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt +++ b/app/src/main/java/com/owncloud/android/ui/activity/NotificationsActivity.kt @@ -19,11 +19,11 @@ import com.nextcloud.client.account.User import com.nextcloud.client.account.UserAccountManager import com.nextcloud.client.jobs.NotificationWork import com.nextcloud.client.network.ClientFactory.CreationException +import com.nextcloud.common.NextcloudClient import com.owncloud.android.R import com.owncloud.android.databinding.NotificationsLayoutBinding import com.owncloud.android.datamodel.ArbitraryDataProvider import com.owncloud.android.datamodel.ArbitraryDataProviderImpl -import com.owncloud.android.lib.common.OwnCloudClient import com.owncloud.android.lib.common.utils.Log_OC import com.owncloud.android.lib.resources.notifications.GetNotificationsRemoteOperation import com.owncloud.android.lib.resources.notifications.models.Notification @@ -44,7 +44,7 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View { private var adapter: NotificationListAdapter? = null private var snackbar: Snackbar? = null - private var client: OwnCloudClient? = null + private var client: NextcloudClient? = null private var optionalUser: Optional? = null override fun onCreate(savedInstanceState: Bundle?) { @@ -213,16 +213,16 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View { val t = Thread { initializeAdapter() val getRemoteNotificationOperation = GetNotificationsRemoteOperation() - val result = getRemoteNotificationOperation.execute(client) - if (result.isSuccess && result.resultData != null) { + val result = client?.let { getRemoteNotificationOperation.execute(it) } + if (result?.isSuccess == true && result.resultData != null) { runOnUiThread { populateList(result.resultData) } } else { - Log_OC.d(TAG, result.logMessage) + Log_OC.d(TAG, result?.logMessage) // show error runOnUiThread { setEmptyContent( getString(R.string.notifications_no_results_headline), - result.logMessage + result?.logMessage ) } } @@ -235,7 +235,7 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View { if (client == null && optionalUser?.isPresent == true) { try { val user = optionalUser?.get() - client = clientFactory.create(user) + client = clientFactory.createNextcloudClient(user) } catch (e: CreationException) { Log_OC.e(TAG, "Error initializing client", e) } diff --git a/app/src/main/java/com/owncloud/android/ui/adapter/NotificationListAdapter.java b/app/src/main/java/com/owncloud/android/ui/adapter/NotificationListAdapter.java index 99cf32ab66..0894dd98ac 100644 --- a/app/src/main/java/com/owncloud/android/ui/adapter/NotificationListAdapter.java +++ b/app/src/main/java/com/owncloud/android/ui/adapter/NotificationListAdapter.java @@ -36,9 +36,9 @@ import com.bumptech.glide.load.resource.file.FileToStreamDecoder; import com.caverock.androidsvg.SVG; import com.google.android.material.button.MaterialButton; import com.nextcloud.android.common.ui.theme.utils.ColorRole; +import com.nextcloud.common.NextcloudClient; import com.owncloud.android.R; import com.owncloud.android.databinding.NotificationListItemBinding; -import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.resources.notifications.models.Action; import com.owncloud.android.lib.resources.notifications.models.Notification; import com.owncloud.android.lib.resources.notifications.models.RichObject; @@ -71,11 +71,11 @@ public class NotificationListAdapter extends RecyclerView.Adapter notificationsList; - private final OwnCloudClient client; + private final NextcloudClient client; private final NotificationsActivity notificationsActivity; private final ViewThemeUtils viewThemeUtils; - public NotificationListAdapter(OwnCloudClient client, + public NotificationListAdapter(NextcloudClient client, NotificationsActivity notificationsActivity, ViewThemeUtils viewThemeUtils) { this.notificationsList = new ArrayList<>(); diff --git a/app/src/main/java/com/owncloud/android/ui/asynctasks/DeleteAllNotificationsTask.java b/app/src/main/java/com/owncloud/android/ui/asynctasks/DeleteAllNotificationsTask.java index 3afbc89a12..26165a2aae 100644 --- a/app/src/main/java/com/owncloud/android/ui/asynctasks/DeleteAllNotificationsTask.java +++ b/app/src/main/java/com/owncloud/android/ui/asynctasks/DeleteAllNotificationsTask.java @@ -9,7 +9,7 @@ package com.owncloud.android.ui.asynctasks; import android.os.AsyncTask; -import com.owncloud.android.lib.common.OwnCloudClient; +import com.nextcloud.common.NextcloudClient; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.notifications.DeleteAllNotificationsRemoteOperation; import com.owncloud.android.lib.resources.notifications.models.Action; @@ -17,10 +17,10 @@ import com.owncloud.android.ui.activity.NotificationsActivity; import com.owncloud.android.ui.notifications.NotificationsContract; public class DeleteAllNotificationsTask extends AsyncTask { - private OwnCloudClient client; - private NotificationsContract.View notificationsActivity; + private NextcloudClient client; + private final NotificationsContract.View notificationsActivity; - public DeleteAllNotificationsTask(OwnCloudClient client, NotificationsActivity notificationsActivity) { + public DeleteAllNotificationsTask(NextcloudClient client, NotificationsActivity notificationsActivity) { this.client = client; this.notificationsActivity = notificationsActivity; } diff --git a/app/src/main/java/com/owncloud/android/ui/asynctasks/DeleteNotificationTask.java b/app/src/main/java/com/owncloud/android/ui/asynctasks/DeleteNotificationTask.java index 2e414e005d..458e642b49 100644 --- a/app/src/main/java/com/owncloud/android/ui/asynctasks/DeleteNotificationTask.java +++ b/app/src/main/java/com/owncloud/android/ui/asynctasks/DeleteNotificationTask.java @@ -9,7 +9,7 @@ package com.owncloud.android.ui.asynctasks; import android.os.AsyncTask; -import com.owncloud.android.lib.common.OwnCloudClient; +import com.nextcloud.common.NextcloudClient; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.resources.notifications.DeleteNotificationRemoteOperation; import com.owncloud.android.lib.resources.notifications.models.Action; @@ -21,10 +21,10 @@ import com.owncloud.android.ui.notifications.NotificationsContract; public class DeleteNotificationTask extends AsyncTask { private Notification notification; private NotificationListAdapter.NotificationViewHolder holder; - private OwnCloudClient client; + private NextcloudClient client; private NotificationsContract.View notificationsActivity; - public DeleteNotificationTask(OwnCloudClient client, Notification notification, + public DeleteNotificationTask(NextcloudClient client, Notification notification, NotificationListAdapter.NotificationViewHolder holder, NotificationsActivity notificationsActivity) { this.client = client; diff --git a/app/src/main/java/com/owncloud/android/ui/asynctasks/NotificationExecuteActionTask.java b/app/src/main/java/com/owncloud/android/ui/asynctasks/NotificationExecuteActionTask.java index 47b6e8ba9f..79a3669294 100644 --- a/app/src/main/java/com/owncloud/android/ui/asynctasks/NotificationExecuteActionTask.java +++ b/app/src/main/java/com/owncloud/android/ui/asynctasks/NotificationExecuteActionTask.java @@ -8,7 +8,12 @@ package com.owncloud.android.ui.asynctasks; import android.os.AsyncTask; -import com.owncloud.android.lib.common.OwnCloudClient; +import com.nextcloud.common.NextcloudClient; +import com.nextcloud.common.OkHttpMethodBase; +import com.nextcloud.operations.DeleteMethod; +import com.nextcloud.operations.GetMethod; +import com.nextcloud.operations.PostMethod; +import com.nextcloud.operations.PutMethod; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.notifications.models.Action; @@ -16,23 +21,18 @@ import com.owncloud.android.lib.resources.notifications.models.Notification; import com.owncloud.android.ui.activity.NotificationsActivity; import com.owncloud.android.ui.adapter.NotificationListAdapter; -import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.httpclient.methods.DeleteMethod; -import org.apache.commons.httpclient.methods.GetMethod; -import org.apache.commons.httpclient.methods.PutMethod; -import org.apache.commons.httpclient.methods.Utf8PostMethod; import java.io.IOException; public class NotificationExecuteActionTask extends AsyncTask { - private NotificationListAdapter.NotificationViewHolder holder; - private OwnCloudClient client; - private Notification notification; - private NotificationsActivity notificationsActivity; + private final NotificationListAdapter.NotificationViewHolder holder; + private final NextcloudClient client; + private final Notification notification; + private final NotificationsActivity notificationsActivity; - public NotificationExecuteActionTask(OwnCloudClient client, + public NotificationExecuteActionTask(NextcloudClient client, NotificationListAdapter.NotificationViewHolder holder, Notification notification, NotificationsActivity notificationsActivity) { @@ -44,39 +44,28 @@ public class NotificationExecuteActionTask extends AsyncTask method = new GetMethod(action.link, true); + case "POST" -> method = new PostMethod(action.link, true, null); + case "DELETE" -> method = new DeleteMethod(action.link, true); + case "PUT" -> method = new PutMethod(action.link, true, null); + default -> { // do nothing - return Boolean.FALSE; + return false; + } } - method.setRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE); + method.addRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE); int status; try { - status = client.executeMethod(method); + status = client.execute(method); } catch (IOException e) { Log_OC.e(this, "Execution of notification action failed: " + e); - return Boolean.FALSE; + return false; } finally { method.releaseConnection(); }