Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate OwncloudClient - Notifications #12266

Merged
merged 12 commits into from
Jun 11, 2024
18 changes: 7 additions & 11 deletions app/src/gplay/java/com/owncloud/android/utils/PushUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@
import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.client.preferences.AppPreferences;
import com.nextcloud.client.preferences.AppPreferencesImpl;
import com.nextcloud.common.NextcloudClient;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.ArbitraryDataProvider;
import com.owncloud.android.datamodel.ArbitraryDataProviderImpl;
import com.owncloud.android.datamodel.PushConfigurationState;
import com.owncloud.android.datamodel.SignatureVerification;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.notifications.RegisterAccountDeviceForNotificationsOperation;
Expand Down Expand Up @@ -131,14 +130,11 @@ private static void deleteRegistrationForAccount(Account account) {

try {
ocAccount = new OwnCloudAccount(account, context);
OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, context);
NextcloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
getNextcloudClientFor(ocAccount, context);

RemoteOperation unregisterAccountDeviceForNotificationsOperation = new
UnregisterAccountDeviceForNotificationsOperation();

RemoteOperationResult remoteOperationResult = unregisterAccountDeviceForNotificationsOperation.
execute(mClient);
RemoteOperationResult<Void> remoteOperationResult =
new UnregisterAccountDeviceForNotificationsOperation().execute(mClient);

if (remoteOperationResult.getHttpCode() == HttpStatus.SC_ACCEPTED) {
String arbitraryValue;
Expand Down Expand Up @@ -201,8 +197,8 @@ public static void pushRegistrationToServer(final UserAccountManager accountMana
TextUtils.isEmpty(providerValue)) {
try {
OwnCloudAccount ocAccount = new OwnCloudAccount(account, context);
OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton().
getClientFor(ocAccount, context);
NextcloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton().
getNextcloudClientFor(ocAccount, context);

RemoteOperationResult<PushResponse> remoteOperationResult =
new RegisterAccountDeviceForNotificationsOperation(pushTokenHash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.nextcloud.client.integrations.deck.DeckApi
import com.owncloud.android.R
import com.owncloud.android.datamodel.DecryptedPushMessage
import com.owncloud.android.lib.common.OwnCloudClient
import com.owncloud.android.lib.common.OwnCloudClientFactory
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory
import com.owncloud.android.lib.common.operations.RemoteOperation
import com.owncloud.android.lib.common.utils.Log_OC
Expand Down Expand Up @@ -236,8 +237,7 @@ class NotificationWork constructor(
}
val user = optionalUser.get()
try {
val client = OwnCloudClientManagerFactory.getDefaultSingleton()
.getClientFor(user.toOwnCloudAccount(), context)
val client = OwnCloudClientFactory.createNextcloudClient(user, context)
val result = GetNotificationRemoteOperation(decryptedPushMessage.nid)
.execute(client)
if (result.isSuccess) {
Expand Down Expand Up @@ -287,14 +287,15 @@ class NotificationWork constructor(
val user = optionalUser.get()
val client = OwnCloudClientManagerFactory.getDefaultSingleton()
.getClientFor(user.toOwnCloudAccount(), context)
val nextcloudClient = OwnCloudClientFactory.createNextcloudClient(user, context)
val actionType = intent.getStringExtra(KEY_NOTIFICATION_ACTION_TYPE)
val actionLink = intent.getStringExtra(KEY_NOTIFICATION_ACTION_LINK)
val success: Boolean = if (!actionType.isNullOrEmpty() && !actionLink.isNullOrEmpty()) {
val resultCode = executeAction(actionType, actionLink, client)
resultCode == HttpStatus.SC_OK || resultCode == HttpStatus.SC_ACCEPTED
} else {
DeleteNotificationRemoteOperation(numericNotificationId)
.execute(client).isSuccess
.execute(nextcloudClient).isSuccess
}
if (success) {
if (oldNotification == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Nextcloud - Android Client
*
* SPDX-FileCopyrightText: 2023 ZetaTom
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH
* SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
*/

package com.nextcloud.utils.extensions

import android.content.Context
import com.nextcloud.common.NextcloudClient
import com.owncloud.android.lib.common.OwnCloudClient
import com.owncloud.android.lib.common.OwnCloudClientFactory

fun OwnCloudClient.toNextcloudClient(context: Context): NextcloudClient {
return OwnCloudClientFactory.createNextcloudClient(
baseUri,
userId,
credentials.toOkHttpCredentials(),
context,
isFollowRedirects
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import com.nextcloud.client.account.User;
import com.nextcloud.client.account.UserAccountManager;
import com.nextcloud.common.NextcloudClient;
import com.nextcloud.utils.extensions.IntentExtensionsKt;
import com.owncloud.android.MainApp;
import com.owncloud.android.datamodel.ArbitraryDataProvider;
Expand Down Expand Up @@ -260,7 +261,7 @@ public class OperationsServiceBinder extends Binder /* implements OnRemoteOperat
*/
private final ConcurrentMap<OnRemoteOperationListener, Handler> mBoundListeners = new ConcurrentHashMap<>();

private ServiceHandler mServiceHandler;
private final ServiceHandler mServiceHandler;

public OperationsServiceBinder(ServiceHandler serviceHandler) {
mServiceHandler = serviceHandler;
Expand Down Expand Up @@ -380,7 +381,7 @@ private static class ServiceHandler extends Handler {
OperationsService mService;


private ConcurrentLinkedQueue<Pair<Target, RemoteOperation>> mPendingOperations =
private final ConcurrentLinkedQueue<Pair<Target, RemoteOperation>> mPendingOperations =
new ConcurrentLinkedQueue<>();
private RemoteOperation mCurrentOperation;
private Target mLastTarget;
Expand Down Expand Up @@ -416,11 +417,12 @@ private void nextOperation() {
if (next != null) {
mCurrentOperation = next.second;
RemoteOperationResult result;
OwnCloudAccount ocAccount = null;

try {
/// prepare client object to send the request to the ownCloud server
if (mLastTarget == null || !mLastTarget.equals(next.first)) {
mLastTarget = next.first;
OwnCloudAccount ocAccount;
if (mLastTarget.mAccount != null) {
ocAccount = new OwnCloudAccount(mLastTarget.mAccount, mService);
} else {
Expand All @@ -430,19 +432,21 @@ private void nextOperation() {
getClientFor(ocAccount, mService);
}

/// perform the operation
result = mCurrentOperation.execute(mOwnCloudClient);
} catch (AccountsException e) {
if (mLastTarget.mAccount == null) {
Log_OC.e(TAG, "Error while trying to get authorization for a NULL account",
e);
} else {
Log_OC.e(TAG, "Error while trying to get authorization for " +
mLastTarget.mAccount.name, e);
}
result = new RemoteOperationResult(e);
// perform the operation
try {
result = mCurrentOperation.execute(mOwnCloudClient);
} catch (UnsupportedOperationException e) {
// TODO remove - added to aid in transition to NextcloudClient

if (ocAccount == null) {
throw e;
}

} catch (IOException e) {
NextcloudClient nextcloudClient = OwnCloudClientManagerFactory.getDefaultSingleton()
.getNextcloudClientFor(ocAccount, mService.getBaseContext());
result = mCurrentOperation.run(nextcloudClient);
}
} catch (AccountsException | IOException e) {
if (mLastTarget.mAccount == null) {
Log_OC.e(TAG, "Error while trying to get authorization for a NULL account",
e);
Expand All @@ -451,6 +455,7 @@ private void nextOperation() {
mLastTarget.mAccount.name, e);
}
result = new RemoteOperationResult(e);

} catch (Exception e) {
if (mLastTarget.mAccount == null) {
Log_OC.e(TAG, "Unexpected error for a NULL account", e);
Expand Down Expand Up @@ -537,10 +542,6 @@ private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
false);
updateLinkOperation.setHideFileDownload(hideFileDownload);

// if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_UPLOAD)) {
// updateLinkOperation.setPublicUpload(true);
// }

if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_LABEL)) {
updateLinkOperation.setLabel(operationIntent.getStringExtra(EXTRA_SHARE_PUBLIC_LABEL));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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?) {
Expand Down Expand Up @@ -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
)
}
}
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
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;
Expand Down Expand Up @@ -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<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@

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;
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

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;
Expand All @@ -21,10 +21,10 @@
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;
Expand Down
Loading
Loading