Deprecate OwncloudClient - Notifications

Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com>
This commit is contained in:
ZetaTom 2023-11-27 14:09:57 +01:00 committed by tobiasKaminsky
parent d6c3eb0196
commit 97e31644ce
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
5 changed files with 39 additions and 50 deletions

View file

@ -19,11 +19,11 @@ import com.nextcloud.client.account.User
import com.nextcloud.client.account.UserAccountManager import com.nextcloud.client.account.UserAccountManager
import com.nextcloud.client.jobs.NotificationWork import com.nextcloud.client.jobs.NotificationWork
import com.nextcloud.client.network.ClientFactory.CreationException import com.nextcloud.client.network.ClientFactory.CreationException
import com.nextcloud.common.NextcloudClient
import com.owncloud.android.R import com.owncloud.android.R
import com.owncloud.android.databinding.NotificationsLayoutBinding import com.owncloud.android.databinding.NotificationsLayoutBinding
import com.owncloud.android.datamodel.ArbitraryDataProvider import com.owncloud.android.datamodel.ArbitraryDataProvider
import com.owncloud.android.datamodel.ArbitraryDataProviderImpl 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.common.utils.Log_OC
import com.owncloud.android.lib.resources.notifications.GetNotificationsRemoteOperation import com.owncloud.android.lib.resources.notifications.GetNotificationsRemoteOperation
import com.owncloud.android.lib.resources.notifications.models.Notification 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 adapter: NotificationListAdapter? = null
private var snackbar: Snackbar? = null private var snackbar: Snackbar? = null
private var client: OwnCloudClient? = null private var client: NextcloudClient? = null
private var optionalUser: Optional<User>? = null private var optionalUser: Optional<User>? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
@ -213,16 +213,16 @@ class NotificationsActivity : DrawerActivity(), NotificationsContract.View {
val t = Thread { val t = Thread {
initializeAdapter() initializeAdapter()
val getRemoteNotificationOperation = GetNotificationsRemoteOperation() val getRemoteNotificationOperation = GetNotificationsRemoteOperation()
val result = getRemoteNotificationOperation.execute(client) val result = client?.let { getRemoteNotificationOperation.execute(it) }
if (result.isSuccess && result.resultData != null) { if (result?.isSuccess == true && result.resultData != null) {
runOnUiThread { populateList(result.resultData) } runOnUiThread { populateList(result.resultData) }
} else { } else {
Log_OC.d(TAG, result.logMessage) Log_OC.d(TAG, result?.logMessage)
// show error // show error
runOnUiThread { runOnUiThread {
setEmptyContent( setEmptyContent(
getString(R.string.notifications_no_results_headline), 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) { if (client == null && optionalUser?.isPresent == true) {
try { try {
val user = optionalUser?.get() val user = optionalUser?.get()
client = clientFactory.create(user) client = clientFactory.createNextcloudClient(user)
} catch (e: CreationException) { } catch (e: CreationException) {
Log_OC.e(TAG, "Error initializing client", e) Log_OC.e(TAG, "Error initializing client", e)
} }

View file

@ -36,9 +36,9 @@ import com.bumptech.glide.load.resource.file.FileToStreamDecoder;
import com.caverock.androidsvg.SVG; import com.caverock.androidsvg.SVG;
import com.google.android.material.button.MaterialButton; import com.google.android.material.button.MaterialButton;
import com.nextcloud.android.common.ui.theme.utils.ColorRole; import com.nextcloud.android.common.ui.theme.utils.ColorRole;
import com.nextcloud.common.NextcloudClient;
import com.owncloud.android.R; import com.owncloud.android.R;
import com.owncloud.android.databinding.NotificationListItemBinding; 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.Action;
import com.owncloud.android.lib.resources.notifications.models.Notification; import com.owncloud.android.lib.resources.notifications.models.Notification;
import com.owncloud.android.lib.resources.notifications.models.RichObject; import com.owncloud.android.lib.resources.notifications.models.RichObject;
@ -71,11 +71,11 @@ public class NotificationListAdapter extends RecyclerView.Adapter<NotificationLi
private final ForegroundColorSpan foregroundColorSpanBlack; private final ForegroundColorSpan foregroundColorSpanBlack;
private final List<Notification> notificationsList; private final List<Notification> notificationsList;
private final OwnCloudClient client; private final NextcloudClient client;
private final NotificationsActivity notificationsActivity; private final NotificationsActivity notificationsActivity;
private final ViewThemeUtils viewThemeUtils; private final ViewThemeUtils viewThemeUtils;
public NotificationListAdapter(OwnCloudClient client, public NotificationListAdapter(NextcloudClient client,
NotificationsActivity notificationsActivity, NotificationsActivity notificationsActivity,
ViewThemeUtils viewThemeUtils) { ViewThemeUtils viewThemeUtils) {
this.notificationsList = new ArrayList<>(); this.notificationsList = new ArrayList<>();

View file

@ -9,7 +9,7 @@ package com.owncloud.android.ui.asynctasks;
import android.os.AsyncTask; 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.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.notifications.DeleteAllNotificationsRemoteOperation; import com.owncloud.android.lib.resources.notifications.DeleteAllNotificationsRemoteOperation;
import com.owncloud.android.lib.resources.notifications.models.Action; 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; import com.owncloud.android.ui.notifications.NotificationsContract;
public class DeleteAllNotificationsTask extends AsyncTask<Action, Void, Boolean> { public class DeleteAllNotificationsTask extends AsyncTask<Action, Void, Boolean> {
private OwnCloudClient client; private NextcloudClient client;
private NotificationsContract.View notificationsActivity; private final NotificationsContract.View notificationsActivity;
public DeleteAllNotificationsTask(OwnCloudClient client, NotificationsActivity notificationsActivity) { public DeleteAllNotificationsTask(NextcloudClient client, NotificationsActivity notificationsActivity) {
this.client = client; this.client = client;
this.notificationsActivity = notificationsActivity; this.notificationsActivity = notificationsActivity;
} }

View file

@ -9,7 +9,7 @@ package com.owncloud.android.ui.asynctasks;
import android.os.AsyncTask; 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.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.notifications.DeleteNotificationRemoteOperation; import com.owncloud.android.lib.resources.notifications.DeleteNotificationRemoteOperation;
import com.owncloud.android.lib.resources.notifications.models.Action; 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<Action, Void, Boolean> { public class DeleteNotificationTask extends AsyncTask<Action, Void, Boolean> {
private Notification notification; private Notification notification;
private NotificationListAdapter.NotificationViewHolder holder; private NotificationListAdapter.NotificationViewHolder holder;
private OwnCloudClient client; private NextcloudClient client;
private NotificationsContract.View notificationsActivity; private NotificationsContract.View notificationsActivity;
public DeleteNotificationTask(OwnCloudClient client, Notification notification, public DeleteNotificationTask(NextcloudClient client, Notification notification,
NotificationListAdapter.NotificationViewHolder holder, NotificationListAdapter.NotificationViewHolder holder,
NotificationsActivity notificationsActivity) { NotificationsActivity notificationsActivity) {
this.client = client; this.client = client;

View file

@ -8,7 +8,12 @@ package com.owncloud.android.ui.asynctasks;
import android.os.AsyncTask; 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.operations.RemoteOperation;
import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.notifications.models.Action; 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.activity.NotificationsActivity;
import com.owncloud.android.ui.adapter.NotificationListAdapter; import com.owncloud.android.ui.adapter.NotificationListAdapter;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpStatus; 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; import java.io.IOException;
public class NotificationExecuteActionTask extends AsyncTask<Action, Void, Boolean> { public class NotificationExecuteActionTask extends AsyncTask<Action, Void, Boolean> {
private NotificationListAdapter.NotificationViewHolder holder; private final NotificationListAdapter.NotificationViewHolder holder;
private OwnCloudClient client; private final NextcloudClient client;
private Notification notification; private final Notification notification;
private NotificationsActivity notificationsActivity; private final NotificationsActivity notificationsActivity;
public NotificationExecuteActionTask(OwnCloudClient client, public NotificationExecuteActionTask(NextcloudClient client,
NotificationListAdapter.NotificationViewHolder holder, NotificationListAdapter.NotificationViewHolder holder,
Notification notification, Notification notification,
NotificationsActivity notificationsActivity) { NotificationsActivity notificationsActivity) {
@ -44,39 +44,28 @@ public class NotificationExecuteActionTask extends AsyncTask<Action, Void, Boole
@Override @Override
protected Boolean doInBackground(Action... actions) { protected Boolean doInBackground(Action... actions) {
HttpMethod method; OkHttpMethodBase method;
Action action = actions[0]; Action action = actions[0];
switch (action.type) { switch (action.type) {
case "GET": case "GET" -> method = new GetMethod(action.link, true);
method = new GetMethod(action.link); case "POST" -> method = new PostMethod(action.link, true, null);
break; case "DELETE" -> method = new DeleteMethod(action.link, true);
case "PUT" -> method = new PutMethod(action.link, true, null);
case "POST": default -> {
method = new Utf8PostMethod(action.link);
break;
case "DELETE":
method = new DeleteMethod(action.link);
break;
case "PUT":
method = new PutMethod(action.link);
break;
default:
// do nothing // 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; int status;
try { try {
status = client.executeMethod(method); status = client.execute(method);
} catch (IOException e) { } catch (IOException e) {
Log_OC.e(this, "Execution of notification action failed: " + e); Log_OC.e(this, "Execution of notification action failed: " + e);
return Boolean.FALSE; return false;
} finally { } finally {
method.releaseConnection(); method.releaseConnection();
} }