mirror of
https://github.com/nextcloud/android.git
synced 2024-11-29 18:59:18 +03:00
Deprecate OwncloudClient - Notifications
Signed-off-by: ZetaTom <70907959+ZetaTom@users.noreply.github.com>
This commit is contained in:
parent
d6c3eb0196
commit
97e31644ce
5 changed files with 39 additions and 50 deletions
|
@ -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<User>? = 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)
|
||||
}
|
||||
|
|
|
@ -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<NotificationLi
|
|||
private final ForegroundColorSpan foregroundColorSpanBlack;
|
||||
|
||||
private final List<Notification> 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<>();
|
||||
|
|
|
@ -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<Action, Void, Boolean> {
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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<Action, Void, Boolean> {
|
||||
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;
|
||||
|
|
|
@ -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<Action, Void, Boolean> {
|
||||
|
||||
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<Action, Void, Boole
|
|||
|
||||
@Override
|
||||
protected Boolean doInBackground(Action... actions) {
|
||||
HttpMethod method;
|
||||
OkHttpMethodBase method;
|
||||
Action action = actions[0];
|
||||
|
||||
switch (action.type) {
|
||||
case "GET":
|
||||
method = new GetMethod(action.link);
|
||||
break;
|
||||
|
||||
case "POST":
|
||||
method = new Utf8PostMethod(action.link);
|
||||
break;
|
||||
|
||||
case "DELETE":
|
||||
method = new DeleteMethod(action.link);
|
||||
break;
|
||||
|
||||
case "PUT":
|
||||
method = new PutMethod(action.link);
|
||||
break;
|
||||
|
||||
default:
|
||||
case "GET" -> 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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue