mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 07:05:49 +03:00
Migrate simple cases of getCurrentAccount() to getUser()
Migrate trivially convertible uses of getCurrentAccount() to new user model - getUser(). Signed-off-by: Chris Narkiewicz <hello@ezaquarii.com>
This commit is contained in:
parent
c8eba1d5ad
commit
a7eb7148fa
43 changed files with 444 additions and 348 deletions
|
@ -46,6 +46,7 @@ internal class AnonymousUser(private val accountType: String) : User {
|
|||
|
||||
override val accountName: String = "anonymous"
|
||||
override val server = Server(URI.create(""), MainApp.MINIMUM_SUPPORTED_SERVER_VERSION)
|
||||
override val isAnonymous = true
|
||||
|
||||
override fun toPlatformAccount(): Account {
|
||||
return Account(accountName, accountType)
|
||||
|
|
|
@ -31,6 +31,7 @@ internal class RegisteredUser(
|
|||
private val ownCloudAccount: OwnCloudAccount,
|
||||
override val server: Server
|
||||
) : User {
|
||||
override val isAnonymous = false
|
||||
|
||||
override val accountName: String get() {
|
||||
return account.name
|
||||
|
|
|
@ -26,6 +26,7 @@ import com.owncloud.android.lib.common.OwnCloudAccount
|
|||
interface User {
|
||||
val accountName: String
|
||||
val server: Server
|
||||
val isAnonymous: Boolean
|
||||
|
||||
/**
|
||||
* This is temporary helper method created to facilitate incremental refactoring.
|
||||
|
|
|
@ -97,10 +97,24 @@ public interface UserAccountManager extends CurrentAccountProvider {
|
|||
* @return Version of the OC server corresponding to account, according to the data saved
|
||||
* in the system AccountManager
|
||||
*/
|
||||
@Deprecated
|
||||
@NonNull
|
||||
OwnCloudVersion getServerVersion(Account account);
|
||||
|
||||
@Deprecated
|
||||
boolean isSearchSupported(@Nullable Account account);
|
||||
|
||||
/**
|
||||
* Check if user's account supports media streaming. This is a property of server where user has his account.
|
||||
*
|
||||
* @deprecated Please use {@link OwnCloudVersion#isMediaStreamingSupported()} directly,
|
||||
* obtainable from {@link User#getServer()} and {@link Server#getVersion()}
|
||||
*
|
||||
* @param account Account used to perform {@link android.accounts.AccountManager} lookup.
|
||||
*
|
||||
* @return true is server supports media streaming, false otherwise
|
||||
*/
|
||||
@Deprecated
|
||||
boolean isMediaStreamingSupported(@Nullable Account account);
|
||||
|
||||
void resetOwnCloudAccount();
|
||||
|
|
|
@ -41,6 +41,7 @@ import com.nextcloud.client.logger.FileLogHandler;
|
|||
import com.nextcloud.client.logger.Logger;
|
||||
import com.nextcloud.client.logger.LoggerImpl;
|
||||
import com.nextcloud.client.logger.LogsRepository;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||
import com.owncloud.android.datamodel.UploadsStorageManager;
|
||||
import com.owncloud.android.ui.activities.data.activities.ActivitiesRepository;
|
||||
|
@ -106,8 +107,8 @@ class AppModule {
|
|||
}
|
||||
|
||||
@Provides
|
||||
FilesRepository filesRepository(UserAccountManager accountManager) {
|
||||
return new RemoteFilesRepository(new FilesServiceApiImpl(accountManager));
|
||||
FilesRepository filesRepository(UserAccountManager accountManager, ClientFactory clientFactory) {
|
||||
return new RemoteFilesRepository(new FilesServiceApiImpl(accountManager, clientFactory));
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -26,6 +26,7 @@ import android.accounts.OperationCanceledException;
|
|||
import android.app.Activity;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
|
||||
|
@ -35,10 +36,31 @@ import java.io.IOException;
|
|||
|
||||
public interface ClientFactory {
|
||||
|
||||
/**
|
||||
* This exception wraps all possible errors thrown by trigger-happy
|
||||
* OwnCloudClient constructor, making try-catch blocks manageable.
|
||||
*
|
||||
* This is a temporary refactoring measure, until a better
|
||||
* error handling method can be procured.
|
||||
*/
|
||||
@Deprecated
|
||||
class CreationException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
CreationException(Throwable t) {
|
||||
super(t);
|
||||
}
|
||||
}
|
||||
|
||||
OwnCloudClient create(User user) throws CreationException;
|
||||
|
||||
@Deprecated
|
||||
OwnCloudClient create(Account account)
|
||||
throws OperationCanceledException, AuthenticatorException, IOException,
|
||||
AccountUtils.AccountNotFoundException;
|
||||
|
||||
@Deprecated
|
||||
OwnCloudClient create(Account account, Activity currentActivity)
|
||||
throws OperationCanceledException, AuthenticatorException, IOException,
|
||||
AccountUtils.AccountNotFoundException;
|
||||
|
|
|
@ -27,6 +27,7 @@ import android.app.Activity;
|
|||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientFactory;
|
||||
import com.owncloud.android.lib.common.accounts.AccountUtils;
|
||||
|
@ -41,6 +42,18 @@ class ClientFactoryImpl implements ClientFactory {
|
|||
this.context = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OwnCloudClient create(User user) throws CreationException {
|
||||
try {
|
||||
return OwnCloudClientFactory.createOwnCloudClient(user.toPlatformAccount(), context);
|
||||
} catch (OperationCanceledException|
|
||||
AuthenticatorException|
|
||||
IOException|
|
||||
AccountUtils.AccountNotFoundException e) {
|
||||
throw new CreationException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OwnCloudClient create(Account account)
|
||||
throws OperationCanceledException, AuthenticatorException, IOException,
|
||||
|
|
|
@ -27,6 +27,7 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManagerImpl;
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
|
@ -282,7 +283,7 @@ public final class AppPreferencesImpl implements AppPreferences {
|
|||
@Override
|
||||
public String getFolderLayout(OCFile folder) {
|
||||
return getFolderPreference(context,
|
||||
currentAccountProvider.getCurrentAccount(),
|
||||
currentAccountProvider.getUser(),
|
||||
PREF__FOLDER_LAYOUT,
|
||||
folder,
|
||||
FOLDER_LAYOUT_LIST);
|
||||
|
@ -291,7 +292,7 @@ public final class AppPreferencesImpl implements AppPreferences {
|
|||
@Override
|
||||
public void setFolderLayout(OCFile folder, String layout_name) {
|
||||
setFolderPreference(context,
|
||||
currentAccountProvider.getCurrentAccount(),
|
||||
currentAccountProvider.getUser(),
|
||||
PREF__FOLDER_LAYOUT,
|
||||
folder,
|
||||
layout_name);
|
||||
|
@ -300,7 +301,7 @@ public final class AppPreferencesImpl implements AppPreferences {
|
|||
@Override
|
||||
public FileSortOrder getSortOrderByFolder(OCFile folder) {
|
||||
return FileSortOrder.sortOrders.get(getFolderPreference(context,
|
||||
currentAccountProvider.getCurrentAccount(),
|
||||
currentAccountProvider.getUser(),
|
||||
PREF__FOLDER_SORT_ORDER,
|
||||
folder,
|
||||
FileSortOrder.sort_a_to_z.name));
|
||||
|
@ -309,7 +310,7 @@ public final class AppPreferencesImpl implements AppPreferences {
|
|||
@Override
|
||||
public void setSortOrder(OCFile folder, FileSortOrder sortOrder) {
|
||||
setFolderPreference(context,
|
||||
currentAccountProvider.getCurrentAccount(),
|
||||
currentAccountProvider.getUser(),
|
||||
PREF__FOLDER_SORT_ORDER,
|
||||
folder,
|
||||
sortOrder.name);
|
||||
|
@ -322,28 +323,23 @@ public final class AppPreferencesImpl implements AppPreferences {
|
|||
|
||||
@Override
|
||||
public FileSortOrder getSortOrderByType(FileSortOrder.Type type, FileSortOrder defaultOrder) {
|
||||
Account account = currentAccountProvider.getCurrentAccount();
|
||||
if (account == null) {
|
||||
User user = currentAccountProvider.getUser();
|
||||
if (user.isAnonymous()) {
|
||||
return defaultOrder;
|
||||
}
|
||||
|
||||
ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver());
|
||||
|
||||
String value = dataProvider.getValue(account.name, PREF__FOLDER_SORT_ORDER + "_" + type);
|
||||
String value = dataProvider.getValue(user.getAccountName(), PREF__FOLDER_SORT_ORDER + "_" + type);
|
||||
|
||||
return value.isEmpty() ? defaultOrder : FileSortOrder.sortOrders.get(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSortOrder(FileSortOrder.Type type, FileSortOrder sortOrder) {
|
||||
Account account = currentAccountProvider.getCurrentAccount();
|
||||
|
||||
if (account == null) {
|
||||
throw new IllegalArgumentException("Account may not be null!");
|
||||
}
|
||||
|
||||
User user = currentAccountProvider.getUser();
|
||||
ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver());
|
||||
dataProvider.storeOrUpdateKeyValue(account.name, PREF__FOLDER_SORT_ORDER + "_" + type, sortOrder.name);
|
||||
dataProvider.storeOrUpdateKeyValue(user.getAccountName(), PREF__FOLDER_SORT_ORDER + "_" + type, sortOrder.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -576,22 +572,22 @@ public final class AppPreferencesImpl implements AppPreferences {
|
|||
* @return Preference value
|
||||
*/
|
||||
private static String getFolderPreference(final Context context,
|
||||
final Account account,
|
||||
final User user,
|
||||
final String preferenceName,
|
||||
final OCFile folder,
|
||||
final String defaultValue) {
|
||||
if (account == null) {
|
||||
if (user.isAnonymous()) {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver());
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(account, context.getContentResolver());
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(user.toPlatformAccount(), context.getContentResolver());
|
||||
|
||||
String value = dataProvider.getValue(account.name, getKeyFromFolder(preferenceName, folder));
|
||||
String value = dataProvider.getValue(user.getAccountName(), getKeyFromFolder(preferenceName, folder));
|
||||
OCFile prefFolder = folder;
|
||||
while (prefFolder != null && value.isEmpty()) {
|
||||
prefFolder = storageManager.getFileById(prefFolder.getParentId());
|
||||
value = dataProvider.getValue(account.name, getKeyFromFolder(preferenceName, prefFolder));
|
||||
value = dataProvider.getValue(user.getAccountName(), getKeyFromFolder(preferenceName, prefFolder));
|
||||
}
|
||||
return value.isEmpty() ? defaultValue : value;
|
||||
}
|
||||
|
@ -605,16 +601,12 @@ public final class AppPreferencesImpl implements AppPreferences {
|
|||
* @param value Preference value to set.
|
||||
*/
|
||||
private static void setFolderPreference(final Context context,
|
||||
final Account account,
|
||||
final User user,
|
||||
final String preferenceName,
|
||||
final OCFile folder,
|
||||
final String value) {
|
||||
if (account == null) {
|
||||
throw new IllegalArgumentException("Account may not be null!");
|
||||
}
|
||||
|
||||
ArbitraryDataProvider dataProvider = new ArbitraryDataProvider(context.getContentResolver());
|
||||
dataProvider.storeOrUpdateKeyValue(account.name, getKeyFromFolder(preferenceName, folder), value);
|
||||
dataProvider.storeOrUpdateKeyValue(user.getAccountName(), getKeyFromFolder(preferenceName, folder), value);
|
||||
}
|
||||
|
||||
private static String getKeyFromFolder(String preferenceName, OCFile folder) {
|
||||
|
|
|
@ -92,6 +92,7 @@ import android.widget.Toast;
|
|||
|
||||
import com.blikoon.qrcodescanner.QrCodeActivity;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.device.DeviceInfo;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
|
@ -1735,8 +1736,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
|
|||
}
|
||||
|
||||
/// add the new account as default in preferences, if there is none already
|
||||
Account defaultAccount = accountManager.getCurrentAccount();
|
||||
if (defaultAccount == null) {
|
||||
User defaultAccount = accountManager.getUser();
|
||||
if (defaultAccount.isAnonymous()) {
|
||||
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
|
||||
editor.putString("select_oc_account", accountName);
|
||||
editor.apply();
|
||||
|
|
|
@ -1259,8 +1259,8 @@ public class FileDataStorageManager {
|
|||
|
||||
private void resetShareFlagsInAllFiles() {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, false);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, false);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, Boolean.FALSE);
|
||||
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + "=?";
|
||||
String[] whereArgs = new String[]{account.name};
|
||||
|
@ -1279,8 +1279,8 @@ public class FileDataStorageManager {
|
|||
|
||||
private void resetShareFlagsInFolder(OCFile folder) {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, false);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, false);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, Boolean.FALSE);
|
||||
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PARENT + "=?";
|
||||
String[] whereArgs = new String[]{account.name, String.valueOf(folder.getFileId())};
|
||||
|
@ -1299,8 +1299,8 @@ public class FileDataStorageManager {
|
|||
|
||||
private void resetShareFlagInAFile(String filePath) {
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, false);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, false);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_VIA_LINK, Boolean.FALSE);
|
||||
cv.put(ProviderTableMeta.FILE_SHARED_WITH_SHAREE, Boolean.FALSE);
|
||||
cv.put(ProviderTableMeta.FILE_PUBLIC_LINK, "");
|
||||
String where = ProviderTableMeta.FILE_ACCOUNT_OWNER + AND + ProviderTableMeta.FILE_PATH + "=?";
|
||||
String[] whereArgs = new String[]{account.name, filePath};
|
||||
|
|
|
@ -31,6 +31,7 @@ import android.net.Uri;
|
|||
import android.os.ParcelFileDescriptor;
|
||||
import android.provider.OpenableColumns;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
|
@ -61,8 +62,8 @@ public class DiskLruImageCacheFileProvider extends ContentProvider {
|
|||
}
|
||||
|
||||
private OCFile getFile(Uri uri) {
|
||||
Account account = accountManager.getCurrentAccount();
|
||||
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(account,
|
||||
User user = accountManager.getUser();
|
||||
FileDataStorageManager fileDataStorageManager = new FileDataStorageManager(user.toPlatformAccount(),
|
||||
MainApp.getAppContext().getContentResolver());
|
||||
|
||||
return fileDataStorageManager.getFileByPath(uri.getPath());
|
||||
|
|
|
@ -34,6 +34,7 @@ import android.os.Looper;
|
|||
import android.provider.BaseColumns;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
|
@ -180,18 +181,14 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
|
|||
|
||||
// need to trust on the AccountUtils to get the current account since the query in the client side is not
|
||||
// directly started by our code, but from SearchView implementation
|
||||
Account account = accountManager.getCurrentAccount();
|
||||
|
||||
if (account == null) {
|
||||
throw new IllegalArgumentException("Account may not be null!");
|
||||
}
|
||||
User user = accountManager.getUser();
|
||||
|
||||
String userQuery = lastPathSegment.toLowerCase(Locale.ROOT);
|
||||
|
||||
// request to the OC server about users and groups matching userQuery
|
||||
GetShareesRemoteOperation searchRequest = new GetShareesRemoteOperation(userQuery, REQUESTED_PAGE,
|
||||
RESULTS_PER_PAGE);
|
||||
RemoteOperationResult result = searchRequest.execute(account, getContext());
|
||||
RemoteOperationResult result = searchRequest.execute(user.toPlatformAccount(), getContext());
|
||||
List<JSONObject> names = new ArrayList<>();
|
||||
|
||||
if (result.isSuccess()) {
|
||||
|
@ -217,8 +214,10 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
|
|||
Uri remoteBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_REMOTE).build();
|
||||
Uri emailBaseUri = new Uri.Builder().scheme(CONTENT).authority(DATA_EMAIL).build();
|
||||
|
||||
FileDataStorageManager manager = new FileDataStorageManager(account, getContext().getContentResolver());
|
||||
boolean federatedShareAllowed = manager.getCapability(account.name).getFilesSharingFederationOutgoing()
|
||||
FileDataStorageManager manager = new FileDataStorageManager(user.toPlatformAccount(),
|
||||
getContext().getContentResolver());
|
||||
boolean federatedShareAllowed = manager.getCapability(user.getAccountName())
|
||||
.getFilesSharingFederationOutgoing()
|
||||
.isTrue();
|
||||
|
||||
try {
|
||||
|
|
|
@ -169,7 +169,8 @@ public class ActivitiesActivity extends FileActivity implements ActivityListInte
|
|||
PorterDuff.Mode.SRC_IN);
|
||||
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(getAccount(), getContentResolver());
|
||||
adapter = new ActivityListAdapter(this, getUserAccountManager(), this, storageManager, getCapabilities(), false);
|
||||
adapter = new ActivityListAdapter(this, getUserAccountManager(), this, storageManager,
|
||||
getCapabilities(), false);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
||||
|
|
|
@ -28,6 +28,7 @@ import android.accounts.OperationCanceledException;
|
|||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
|
@ -58,8 +59,11 @@ public class ActivitiesServiceApiImpl implements ActivitiesServiceApi {
|
|||
|
||||
@Override
|
||||
public void getAllActivities(int lastGiven, ActivitiesServiceCallback<List<Object>> callback) {
|
||||
Account account = accountManager.getCurrentAccount();
|
||||
GetActivityListTask getActivityListTask = new GetActivityListTask(account, accountManager, lastGiven, callback);
|
||||
User user = accountManager.getUser();
|
||||
GetActivityListTask getActivityListTask = new GetActivityListTask(user.toPlatformAccount(),
|
||||
accountManager,
|
||||
lastGiven,
|
||||
callback);
|
||||
getActivityListTask.execute();
|
||||
}
|
||||
|
||||
|
|
|
@ -22,19 +22,16 @@
|
|||
*/
|
||||
package com.owncloud.android.ui.activities.data.files;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
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;
|
||||
|
@ -44,8 +41,6 @@ import com.owncloud.android.operations.RefreshFolderOperation;
|
|||
import com.owncloud.android.ui.activity.BaseActivity;
|
||||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Implementation of the Files service API that communicates with the NextCloud remote server.
|
||||
*/
|
||||
|
@ -54,15 +49,18 @@ public class FilesServiceApiImpl implements FilesServiceApi {
|
|||
private static final String TAG = FilesServiceApiImpl.class.getSimpleName();
|
||||
|
||||
private UserAccountManager accountManager;
|
||||
private ClientFactory clientFactory;
|
||||
|
||||
public FilesServiceApiImpl(UserAccountManager accountManager) {
|
||||
public FilesServiceApiImpl(UserAccountManager accountManager, ClientFactory clientFactory) {
|
||||
this.accountManager = accountManager;
|
||||
this.clientFactory = clientFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readRemoteFile(String fileUrl, BaseActivity activity, FilesServiceCallback<OCFile> callback) {
|
||||
ReadRemoteFileTask readRemoteFileTask = new ReadRemoteFileTask(
|
||||
accountManager,
|
||||
clientFactory,
|
||||
fileUrl,
|
||||
activity,
|
||||
callback
|
||||
|
@ -77,30 +75,29 @@ public class FilesServiceApiImpl implements FilesServiceApi {
|
|||
// TODO: Figure out a better way to do this than passing a BaseActivity reference.
|
||||
private final BaseActivity baseActivity;
|
||||
private final String fileUrl;
|
||||
private final Account account;
|
||||
private final User user;
|
||||
private final UserAccountManager accountManager;
|
||||
private final ClientFactory clientFactory;
|
||||
|
||||
private ReadRemoteFileTask(UserAccountManager accountManager,
|
||||
ClientFactory clientFactory,
|
||||
String fileUrl,
|
||||
BaseActivity baseActivity,
|
||||
FilesServiceCallback<OCFile> callback) {
|
||||
this.callback = callback;
|
||||
this.baseActivity = baseActivity;
|
||||
this.fileUrl = fileUrl;
|
||||
this.account = accountManager.getCurrentAccount();
|
||||
this.user = accountManager.getUser();
|
||||
this.accountManager = accountManager;
|
||||
this.clientFactory = clientFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
final Context context = MainApp.getAppContext();
|
||||
OwnCloudAccount ocAccount;
|
||||
OwnCloudClient ownCloudClient;
|
||||
try {
|
||||
ocAccount = new OwnCloudAccount(account, context);
|
||||
ownCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||
getClientFor(ocAccount, MainApp.getAppContext());
|
||||
ownCloudClient.setOwnCloudVersion(accountManager.getServerVersion(account));
|
||||
OwnCloudClient ownCloudClient = clientFactory.create(user);
|
||||
ownCloudClient.setOwnCloudVersion(user.getServer().getVersion());
|
||||
// always update file as it could be an old state saved in database
|
||||
RemoteOperationResult resultRemoteFileOp = new ReadFileRemoteOperation(fileUrl).execute(ownCloudClient);
|
||||
|
||||
|
@ -111,28 +108,19 @@ public class FilesServiceApiImpl implements FilesServiceApi {
|
|||
if (remoteOcFile.isFolder()) {
|
||||
// perform folder synchronization
|
||||
RemoteOperation synchFolderOp = new RefreshFolderOperation(remoteOcFile,
|
||||
System.currentTimeMillis(),
|
||||
false,
|
||||
true,
|
||||
baseActivity.getStorageManager(),
|
||||
baseActivity.getAccount(),
|
||||
context);
|
||||
System.currentTimeMillis(),
|
||||
false,
|
||||
true,
|
||||
baseActivity.getStorageManager(),
|
||||
baseActivity.getAccount(),
|
||||
context);
|
||||
synchFolderOp.execute(ownCloudClient);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
|
||||
} catch (ClientFactory.CreationException e) {
|
||||
Log_OC.e(TAG, "Account not found", e);
|
||||
errorMessage = baseActivity.getString(R.string.account_not_found);
|
||||
} catch (IOException e) {
|
||||
Log_OC.e(TAG, "IO error", e);
|
||||
errorMessage = baseActivity.getString(R.string.io_error);
|
||||
} catch (OperationCanceledException e) {
|
||||
Log_OC.e(TAG, "Operation has been canceled", e);
|
||||
errorMessage = baseActivity.getString(R.string.operation_canceled);
|
||||
} catch (AuthenticatorException e) {
|
||||
Log_OC.e(TAG, "Authentication Exception", e);
|
||||
errorMessage = baseActivity.getString(R.string.authentication_exception);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
|
@ -6,17 +6,16 @@ import android.accounts.AccountManagerCallback;
|
|||
import android.accounts.AccountManagerFuture;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.PersistableBundle;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.nextcloud.client.preferences.AppPreferencesImpl;
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
@ -161,6 +160,10 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
|||
}
|
||||
}
|
||||
|
||||
protected void setUser(User user) {
|
||||
setAccount(user.toPlatformAccount(), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to swap the current ownCloud {@link Account} for other valid and existing.
|
||||
*
|
||||
|
@ -215,6 +218,14 @@ public abstract class BaseActivity extends AppCompatActivity implements Injectab
|
|||
public Account getAccount() {
|
||||
return currentAccount;
|
||||
}
|
||||
|
||||
public Optional<User> getUser() {
|
||||
if (currentAccount != null) {
|
||||
return accountManager.getUser(currentAccount.name);
|
||||
} else {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
public FileDataStorageManager getStorageManager() {
|
||||
return storageManager;
|
||||
|
|
|
@ -56,8 +56,10 @@ import com.bumptech.glide.Glide;
|
|||
import com.bumptech.glide.request.animation.GlideAnimation;
|
||||
import com.bumptech.glide.request.target.SimpleTarget;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.nextcloud.client.onboarding.FirstRunActivity;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.owncloud.android.MainApp;
|
||||
|
@ -217,6 +219,9 @@ public abstract class DrawerActivity extends ToolbarActivity
|
|||
@Inject
|
||||
AppPreferences preferences;
|
||||
|
||||
@Inject
|
||||
ClientFactory clientFactory;
|
||||
|
||||
/**
|
||||
* Initializes the drawer, its content and highlights the menu item with the given id.
|
||||
* This method needs to be called after the content view has been set.
|
||||
|
@ -357,21 +362,19 @@ public abstract class DrawerActivity extends ToolbarActivity
|
|||
navigationView.getMenu().setGroupVisible(R.id.drawer_menu_accounts, false);
|
||||
}
|
||||
|
||||
Account account = accountManager.getCurrentAccount();
|
||||
User account = accountManager.getUser();
|
||||
filterDrawerMenu(navigationView.getMenu(), account);
|
||||
}
|
||||
|
||||
private void filterDrawerMenu(Menu menu, Account account) {
|
||||
OCCapability capability = null;
|
||||
if (account != null) {
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(account, getContentResolver());
|
||||
capability = storageManager.getCapability(account.name);
|
||||
}
|
||||
private void filterDrawerMenu(final Menu menu, @NonNull final User user) {
|
||||
FileDataStorageManager storageManager = new FileDataStorageManager(user.toPlatformAccount(),
|
||||
getContentResolver());
|
||||
OCCapability capability = storageManager.getCapability(user.getAccountName());
|
||||
|
||||
boolean hasSearchSupport = accountManager.getServerVersion(account).isSearchSupported();
|
||||
boolean hasSearchSupport = user.getServer().getVersion().isSearchSupported();
|
||||
|
||||
DrawerMenuUtil.filterSearchMenuItems(menu, account, getResources(), hasSearchSupport);
|
||||
DrawerMenuUtil.filterTrashbinMenuItem(menu, account, capability, accountManager);
|
||||
DrawerMenuUtil.filterSearchMenuItems(menu, user.toPlatformAccount(), getResources(), hasSearchSupport);
|
||||
DrawerMenuUtil.filterTrashbinMenuItem(menu, user.toPlatformAccount(), capability, accountManager);
|
||||
DrawerMenuUtil.filterActivityMenuItem(menu, capability);
|
||||
|
||||
DrawerMenuUtil.setupHomeMenuItem(menu, getResources());
|
||||
|
@ -685,7 +688,7 @@ public abstract class DrawerActivity extends ToolbarActivity
|
|||
if (mNavigationView != null && mDrawerLayout != null) {
|
||||
if (persistingAccounts.size() > 0) {
|
||||
repopulateAccountList(persistingAccounts);
|
||||
setAccountInDrawer(accountManager.getCurrentAccount());
|
||||
setAccountInDrawer(accountManager.getUser());
|
||||
populateDrawerOwnCloudAccounts();
|
||||
|
||||
// activate second/end account avatar
|
||||
|
@ -791,30 +794,25 @@ public abstract class DrawerActivity extends ToolbarActivity
|
|||
* sets the given account name in the drawer in case the drawer is available. The account name is shortened
|
||||
* beginning from the @-sign in the username.
|
||||
*
|
||||
* @param account the account to be set in the drawer
|
||||
* @param user the account to be set in the drawer
|
||||
*/
|
||||
protected void setAccountInDrawer(Account account) {
|
||||
if (mDrawerLayout != null && account != null) {
|
||||
protected void setAccountInDrawer(User user) {
|
||||
if (mDrawerLayout != null && user != null) {
|
||||
TextView username = (TextView) findNavigationViewChildById(R.id.drawer_username);
|
||||
TextView usernameFull = (TextView) findNavigationViewChildById(R.id.drawer_username_full);
|
||||
|
||||
usernameFull.setText(DisplayUtils.convertIdn(account.name.substring(account.name.lastIndexOf('@') + 1),
|
||||
String name = user.getAccountName();
|
||||
usernameFull.setText(DisplayUtils.convertIdn(name.substring(name.lastIndexOf('@') + 1),
|
||||
false));
|
||||
usernameFull.setTextColor(ThemeUtils.fontColor(this));
|
||||
|
||||
try {
|
||||
OwnCloudAccount oca = new OwnCloudAccount(account, this);
|
||||
username.setText(oca.getDisplayName());
|
||||
username.setTextColor(ThemeUtils.fontColor(this));
|
||||
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
|
||||
Log_OC.w(TAG, "Couldn't read display name of account fallback to account name");
|
||||
username.setText(UserAccountManager.getUsername(account));
|
||||
}
|
||||
username.setText(user.toOwnCloudAccount().getDisplayName());
|
||||
username.setTextColor(ThemeUtils.fontColor(this));
|
||||
|
||||
View currentAccountView = findNavigationViewChildById(R.id.drawer_current_account);
|
||||
currentAccountView.setTag(account.name);
|
||||
currentAccountView.setTag(name);
|
||||
|
||||
DisplayUtils.setAvatar(account, this, mCurrentAccountAvatarRadiusDimension, getResources(),
|
||||
DisplayUtils.setAvatar(user.toPlatformAccount(), this, mCurrentAccountAvatarRadiusDimension, getResources(),
|
||||
currentAccountView, this);
|
||||
|
||||
// check and show quota info if available
|
||||
|
@ -958,6 +956,7 @@ public abstract class DrawerActivity extends ToolbarActivity
|
|||
};
|
||||
|
||||
DisplayUtils.downloadIcon(getUserAccountManager(),
|
||||
clientFactory,
|
||||
this,
|
||||
firstQuota.iconUrl,
|
||||
target,
|
||||
|
@ -1024,14 +1023,14 @@ public abstract class DrawerActivity extends ToolbarActivity
|
|||
// set user space information
|
||||
Thread t = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
final Account currentAccount = accountManager.getCurrentAccount();
|
||||
final User user = accountManager.getUser();
|
||||
|
||||
if (currentAccount == null) {
|
||||
if (user.isAnonymous()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Context context = MainApp.getAppContext();
|
||||
RemoteOperationResult result = new GetUserInfoRemoteOperation().execute(currentAccount, context);
|
||||
RemoteOperationResult result = new GetUserInfoRemoteOperation().execute(user.toPlatformAccount(), context);
|
||||
|
||||
if (result.isSuccess() && result.getData() != null) {
|
||||
final UserInfo userInfo = (UserInfo) result.getData().get(0);
|
||||
|
@ -1101,6 +1100,7 @@ public abstract class DrawerActivity extends ToolbarActivity
|
|||
};
|
||||
|
||||
DisplayUtils.downloadIcon(getUserAccountManager(),
|
||||
clientFactory,
|
||||
this,
|
||||
link.iconUrl,
|
||||
target,
|
||||
|
@ -1375,12 +1375,11 @@ public abstract class DrawerActivity extends ToolbarActivity
|
|||
}
|
||||
}
|
||||
|
||||
Account currentAccount = accountManager.getCurrentAccount();
|
||||
|
||||
mAvatars[0] = currentAccount;
|
||||
User user = accountManager.getUser();
|
||||
mAvatars[0] = user.toPlatformAccount();
|
||||
int j = 0;
|
||||
for (int i = 1; i <= 2 && i < persistingAccounts.size() && j < persistingAccounts.size(); j++) {
|
||||
if (!currentAccount.equals(persistingAccounts.get(j))) {
|
||||
if (!user.equals(persistingAccounts.get(j))) {
|
||||
mAvatars[i] = persistingAccounts.get(j);
|
||||
i++;
|
||||
}
|
||||
|
@ -1462,11 +1461,10 @@ public abstract class DrawerActivity extends ToolbarActivity
|
|||
getCapabilities.execute(getStorageManager(), getBaseContext());
|
||||
}
|
||||
|
||||
Account account = accountManager.getCurrentAccount();
|
||||
|
||||
if (account != null && getStorageManager() != null &&
|
||||
getStorageManager().getCapability(account.name) != null &&
|
||||
getStorageManager().getCapability(account.name).getExternalLinks().isTrue()) {
|
||||
User user = accountManager.getUser();
|
||||
String name = user.getAccountName();
|
||||
if (getStorageManager() != null && getStorageManager().getCapability(name) != null &&
|
||||
getStorageManager().getCapability(name).getExternalLinks().isTrue()) {
|
||||
|
||||
int count = arbitraryDataProvider.getIntegerValue(FilesSyncHelper.GLOBAL,
|
||||
FileActivity.APP_OPENED_COUNT);
|
||||
|
@ -1481,7 +1479,7 @@ public abstract class DrawerActivity extends ToolbarActivity
|
|||
|
||||
Log_OC.d("ExternalLinks", "update via api");
|
||||
RemoteOperation getExternalLinksOperation = new ExternalLinksOperation();
|
||||
RemoteOperationResult result = getExternalLinksOperation.execute(account, this);
|
||||
RemoteOperationResult result = getExternalLinksOperation.execute(user.toPlatformAccount(), this);
|
||||
|
||||
if (result.isSuccess() && result.getData() != null) {
|
||||
externalLinksProvider.deleteAllExternalLinks();
|
||||
|
|
|
@ -54,11 +54,13 @@ import android.view.View;
|
|||
import android.view.ViewTreeObserver;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.appinfo.AppInfo;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.media.PlayerServiceConnection;
|
||||
import com.nextcloud.client.network.ConnectivityService;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
|
@ -2545,8 +2547,8 @@ public class FileDisplayActivity extends FileActivity
|
|||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
final Account account = getAccount();
|
||||
if (account != null) {
|
||||
Optional<User> optionalUser = getUser();
|
||||
if (optionalUser.isPresent()) {
|
||||
/// Check whether the 'main' OCFile handled by the Activity is contained in the
|
||||
// current Account
|
||||
OCFile file = getFile();
|
||||
|
@ -2572,10 +2574,12 @@ public class FileDisplayActivity extends FileActivity
|
|||
}
|
||||
setFile(file);
|
||||
|
||||
setAccountInDrawer(account);
|
||||
User user = optionalUser.get();
|
||||
setAccountInDrawer(user);
|
||||
setupDrawer();
|
||||
|
||||
final boolean accountChanged = !account.equals(mLastDisplayedAccount);
|
||||
final String lastDisplayedAccountName = mLastDisplayedAccount != null ? mLastDisplayedAccount.name : null;
|
||||
final boolean accountChanged = !user.getAccountName().equals(lastDisplayedAccountName);
|
||||
if (accountChanged) {
|
||||
Log_OC.d(TAG, "Initializing Fragments in onAccountChanged..");
|
||||
initFragmentsWithFile();
|
||||
|
@ -2587,7 +2591,11 @@ public class FileDisplayActivity extends FileActivity
|
|||
updateActionBarTitleAndHomeButton(file.isFolder() ? null : file);
|
||||
}
|
||||
}
|
||||
mLastDisplayedAccount = account;
|
||||
if (optionalUser.isPresent()) {
|
||||
mLastDisplayedAccount = optionalUser.get().toPlatformAccount();
|
||||
} else {
|
||||
mLastDisplayedAccount = null;
|
||||
}
|
||||
|
||||
EventBus.getDefault().post(new TokenPushEvent());
|
||||
checkForNewDevVersionNecessary(findViewById(R.id.root_layout), getApplicationContext());
|
||||
|
|
|
@ -38,6 +38,7 @@ import android.view.MenuItem;
|
|||
|
||||
import com.evernote.android.job.JobRequest;
|
||||
import com.evernote.android.job.util.support.PersistableBundleCompat;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.onboarding.FirstRunActivity;
|
||||
import com.owncloud.android.MainApp;
|
||||
|
@ -198,11 +199,11 @@ public class ManageAccountsActivity extends FileActivity implements AccountListA
|
|||
* @return true if account list has changed, false if not
|
||||
*/
|
||||
private boolean hasCurrentAccountChanged() {
|
||||
Account account = getUserAccountManager().getCurrentAccount();
|
||||
if (account == null) {
|
||||
User account = getUserAccountManager().getUser();
|
||||
if (account.isAnonymous()) {
|
||||
return true;
|
||||
} else {
|
||||
return !account.name.equals(originalCurrentAccount);
|
||||
return !account.getAccountName().equals(originalCurrentAccount);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -320,7 +321,8 @@ public class ManageAccountsActivity extends FileActivity implements AccountListA
|
|||
}
|
||||
}
|
||||
|
||||
if (getUserAccountManager().getCurrentAccount() == null) {
|
||||
User user = getUserAccountManager().getUser();
|
||||
if (user.isAnonymous()) {
|
||||
String accountName = "";
|
||||
Account[] accounts = AccountManager.get(this).getAccountsByType(MainApp.getAccountType(this));
|
||||
if (accounts.length != 0) {
|
||||
|
|
|
@ -24,9 +24,6 @@
|
|||
|
||||
package com.owncloud.android.ui.activity;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.content.Intent;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.os.Bundle;
|
||||
|
@ -39,13 +36,14 @@ import android.widget.ProgressBar;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||
import com.owncloud.android.jobs.NotificationJob;
|
||||
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;
|
||||
|
@ -58,9 +56,10 @@ import com.owncloud.android.utils.DisplayUtils;
|
|||
import com.owncloud.android.utils.PushUtils;
|
||||
import com.owncloud.android.utils.ThemeUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
@ -109,7 +108,9 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
|||
private NotificationListAdapter adapter;
|
||||
private Snackbar snackbar;
|
||||
private OwnCloudClient client;
|
||||
private Account currentAccount;
|
||||
private Optional<User> optionalUser;
|
||||
|
||||
@Inject ClientFactory clientFactory;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -119,16 +120,18 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
|||
setContentView(R.layout.notifications_layout);
|
||||
unbinder = ButterKnife.bind(this);
|
||||
|
||||
currentAccount = getAccount();
|
||||
optionalUser = getUser();
|
||||
|
||||
// use account from intent (opened via android notification can have a different account than current one)
|
||||
if (getIntent() != null && getIntent().getExtras() != null) {
|
||||
String account = getIntent().getExtras().getString(NotificationJob.KEY_NOTIFICATION_ACCOUNT);
|
||||
|
||||
if (account != null && (currentAccount == null || !account.equalsIgnoreCase(currentAccount.name))) {
|
||||
accountManager.setCurrentOwnCloudAccount(account);
|
||||
setAccount(getUserAccountManager().getCurrentAccount(), false);
|
||||
currentAccount = getAccount();
|
||||
String accountName = getIntent().getExtras().getString(NotificationJob.KEY_NOTIFICATION_ACCOUNT);
|
||||
if(accountName != null && optionalUser.isPresent()) {
|
||||
User user = optionalUser.get();
|
||||
if (user.getAccountName().equalsIgnoreCase(accountName)) {
|
||||
accountManager.setCurrentOwnCloudAccount(accountName);
|
||||
setUser(getUserAccountManager().getUser());
|
||||
optionalUser = getUser();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,7 +145,7 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
|||
setupDrawer(R.id.nav_notifications);
|
||||
ThemeUtils.setColoredTitle(getSupportActionBar(), getString(R.string.drawer_item_notifications), this);
|
||||
|
||||
if (currentAccount == null) {
|
||||
if (!optionalUser.isPresent()) {
|
||||
// show error
|
||||
runOnUiThread(() -> setEmptyContent(noResultsHeadline, getString(R.string.account_not_found)));
|
||||
return;
|
||||
|
@ -156,7 +159,6 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
|||
swipeEmptyListRefreshLayout.setOnRefreshListener(() -> {
|
||||
setLoadingMessage();
|
||||
fetchAndSetData();
|
||||
|
||||
});
|
||||
|
||||
setupPushWarning();
|
||||
|
@ -175,16 +177,16 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
|||
snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_not_implemented,
|
||||
Snackbar.LENGTH_INDEFINITE);
|
||||
} else {
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
|
||||
|
||||
boolean usesOldLogin = arbitraryDataProvider.getBooleanValue(currentAccount.name,
|
||||
final ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
|
||||
final String accountName = optionalUser.isPresent() ? optionalUser.get().getAccountName() : "";
|
||||
final boolean usesOldLogin = arbitraryDataProvider.getBooleanValue(accountName,
|
||||
UserAccountManager.ACCOUNT_USES_STANDARD_PASSWORD);
|
||||
|
||||
if (usesOldLogin) {
|
||||
snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_old_login,
|
||||
Snackbar.LENGTH_INDEFINITE);
|
||||
} else {
|
||||
String pushValue = arbitraryDataProvider.getValue(currentAccount.name, PushUtils.KEY_PUSH);
|
||||
String pushValue = arbitraryDataProvider.getValue(accountName, PushUtils.KEY_PUSH);
|
||||
|
||||
if (pushValue == null || pushValue.isEmpty()) {
|
||||
snackbar = Snackbar.make(emptyContentContainer, R.string.push_notifications_temp_error,
|
||||
|
@ -250,13 +252,12 @@ public class NotificationsActivity extends FileActivity implements Notifications
|
|||
|
||||
private void fetchAndSetData() {
|
||||
Thread t = new Thread(() -> {
|
||||
if (client == null) {
|
||||
if (client == null && optionalUser.isPresent()) {
|
||||
try {
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(currentAccount, this);
|
||||
client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, this);
|
||||
client.setOwnCloudVersion(accountManager.getServerVersion(currentAccount));
|
||||
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException |
|
||||
IOException | OperationCanceledException | AuthenticatorException e) {
|
||||
User user = optionalUser.get();
|
||||
client = clientFactory.create(user);
|
||||
client.setOwnCloudVersion(user.getServer().getVersion());
|
||||
} catch (ClientFactory.CreationException e) {
|
||||
Log_OC.e(TAG, "Error initializing client", e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,7 @@ import android.widget.Toast;
|
|||
import com.bumptech.glide.Glide;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
|
@ -155,7 +156,8 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
|||
break;
|
||||
}
|
||||
|
||||
Glide.with(this).using(new CustomGlideStreamLoader(currentAccountProvider)).load(template.getThumbnailLink())
|
||||
Glide.with(this).using(new CustomGlideStreamLoader(currentAccountProvider, clientFactory))
|
||||
.load(template.getThumbnailLink())
|
||||
.placeholder(placeholder)
|
||||
.error(placeholder)
|
||||
.into(thumbnail);
|
||||
|
@ -314,9 +316,9 @@ public class RichDocumentsWebView extends ExternalSiteWebView {
|
|||
OCFile file = data.getParcelableExtra(FolderPickerActivity.EXTRA_FILES);
|
||||
|
||||
new Thread(() -> {
|
||||
Account account = currentAccountProvider.getCurrentAccount();
|
||||
User user = currentAccountProvider.getUser();
|
||||
RichDocumentsCreateAssetOperation operation = new RichDocumentsCreateAssetOperation(file.getRemotePath());
|
||||
RemoteOperationResult result = operation.execute(account, this);
|
||||
RemoteOperationResult result = operation.execute(user.toPlatformAccount(), this);
|
||||
|
||||
if (result.isSuccess()) {
|
||||
String asset = (String) result.getSingleData();
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
*/
|
||||
package com.owncloud.android.ui.activity;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
|
@ -52,10 +51,12 @@ import android.view.ViewGroup;
|
|||
import android.view.Window;
|
||||
import android.webkit.URLUtil;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.etm.EtmActivity;
|
||||
import com.nextcloud.client.logger.ui.LogsActivity;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.nextcloud.client.preferences.AppPreferencesImpl;
|
||||
import com.owncloud.android.BuildConfig;
|
||||
|
@ -69,8 +70,6 @@ import com.owncloud.android.datastorage.DataStorageProvider;
|
|||
import com.owncloud.android.datastorage.StoragePoint;
|
||||
import com.owncloud.android.lib.common.ExternalLink;
|
||||
import com.owncloud.android.lib.common.ExternalLinkType;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.ui.asynctasks.LoadingVersionNumberTask;
|
||||
import com.owncloud.android.utils.DeviceCredentialUtils;
|
||||
|
@ -130,10 +129,11 @@ public class SettingsActivity extends ThemedPreferenceActivity
|
|||
private String storagePath;
|
||||
private String pendingLock;
|
||||
|
||||
private Account account;
|
||||
private User user;
|
||||
@Inject ArbitraryDataProvider arbitraryDataProvider;
|
||||
@Inject AppPreferences preferences;
|
||||
@Inject UserAccountManager accountManager;
|
||||
@Inject ClientFactory clientFactory;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
|
@ -156,7 +156,7 @@ public class SettingsActivity extends ThemedPreferenceActivity
|
|||
String appVersion = getAppVersion();
|
||||
PreferenceScreen preferenceScreen = (PreferenceScreen) findPreference("preference_screen");
|
||||
|
||||
account = accountManager.getCurrentAccount();
|
||||
user = accountManager.getUser();
|
||||
|
||||
// retrieve user's base uri
|
||||
setupBaseUri();
|
||||
|
@ -408,7 +408,7 @@ public class SettingsActivity extends ThemedPreferenceActivity
|
|||
}
|
||||
|
||||
private void setupE2EMnemonicPreference(PreferenceCategory preferenceCategoryMore) {
|
||||
String mnemonic = arbitraryDataProvider.getValue(account.name, EncryptionUtils.MNEMONIC);
|
||||
String mnemonic = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.MNEMONIC);
|
||||
|
||||
Preference pMnemonic = findPreference("mnemonic");
|
||||
if (pMnemonic != null) {
|
||||
|
@ -603,11 +603,11 @@ public class SettingsActivity extends ThemedPreferenceActivity
|
|||
|
||||
final SwitchPreference pUploadOnWifiCheckbox = (SwitchPreference) findPreference("synced_folder_on_wifi");
|
||||
pUploadOnWifiCheckbox.setChecked(
|
||||
arbitraryDataProvider.getBooleanValue(account, SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI));
|
||||
arbitraryDataProvider.getBooleanValue(user.toPlatformAccount(), SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI));
|
||||
|
||||
pUploadOnWifiCheckbox.setOnPreferenceClickListener(preference -> {
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue(account.name, SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI,
|
||||
String.valueOf(pUploadOnWifiCheckbox.isChecked()));
|
||||
arbitraryDataProvider.storeOrUpdateKeyValue(user.getAccountName(), SYNCED_FOLDER_LIGHT_UPLOAD_ON_WIFI,
|
||||
String.valueOf(pUploadOnWifiCheckbox.isChecked()));
|
||||
|
||||
return true;
|
||||
});
|
||||
|
@ -764,7 +764,7 @@ public class SettingsActivity extends ThemedPreferenceActivity
|
|||
davDroidLoginIntent.setData(Uri.parse(serverBaseUri.toString() + AuthenticatorActivity.WEB_LOGIN));
|
||||
davDroidLoginIntent.putExtra("davPath", DAV_PATH);
|
||||
}
|
||||
davDroidLoginIntent.putExtra("username", UserAccountManager.getUsername(account));
|
||||
davDroidLoginIntent.putExtra("username", UserAccountManager.getUsername(user.toPlatformAccount()));
|
||||
|
||||
startActivityForResult(davDroidLoginIntent, ACTION_REQUEST_CODE_DAVDROID_SETUP);
|
||||
} else {
|
||||
|
@ -789,9 +789,7 @@ public class SettingsActivity extends ThemedPreferenceActivity
|
|||
// retrieve and set user's base URI
|
||||
Thread t = new Thread(() -> {
|
||||
try {
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(account, MainApp.getAppContext());
|
||||
serverBaseUri = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount,
|
||||
getApplicationContext()).getBaseUri();
|
||||
serverBaseUri = clientFactory.create(user).getBaseUri();
|
||||
} catch (Exception e) {
|
||||
Log_OC.e(TAG, "Error retrieving user's base URI", e);
|
||||
}
|
||||
|
@ -857,7 +855,7 @@ public class SettingsActivity extends ThemedPreferenceActivity
|
|||
RequestCredentialsActivity.KEY_CHECK_RESULT_TRUE) {
|
||||
|
||||
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(getContentResolver());
|
||||
String mnemonic = arbitraryDataProvider.getValue(account.name, EncryptionUtils.MNEMONIC);
|
||||
String mnemonic = arbitraryDataProvider.getValue(user.getAccountName(), EncryptionUtils.MNEMONIC);
|
||||
|
||||
int accentColor = ThemeUtils.primaryAccentColor(this);
|
||||
|
||||
|
|
|
@ -41,10 +41,12 @@ import android.view.View;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.core.Clock;
|
||||
import com.nextcloud.client.device.PowerManagementService;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.BuildConfig;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
|
@ -125,15 +127,15 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
|||
|
||||
setContentView(R.layout.synced_folders_layout);
|
||||
|
||||
String account;
|
||||
Account currentAccount;
|
||||
if (getIntent() != null && getIntent().getExtras() != null) {
|
||||
account = getIntent().getExtras().getString(NotificationJob.KEY_NOTIFICATION_ACCOUNT);
|
||||
currentAccount = getAccount();
|
||||
|
||||
if (account != null && currentAccount != null && !account.equalsIgnoreCase(currentAccount.name)) {
|
||||
accountManager.setCurrentOwnCloudAccount(account);
|
||||
setAccount(getUserAccountManager().getCurrentAccount(), false);
|
||||
final String accountName = getIntent().getExtras().getString(NotificationJob.KEY_NOTIFICATION_ACCOUNT);
|
||||
Optional<User> optionalUser = getUser();
|
||||
if (optionalUser.isPresent() && accountName != null) {
|
||||
User user = optionalUser.get();
|
||||
if (!accountName.equalsIgnoreCase(user.getAccountName())) {
|
||||
accountManager.setCurrentOwnCloudAccount(accountName);
|
||||
setUser(getUserAccountManager().getUser());
|
||||
}
|
||||
}
|
||||
|
||||
path = getIntent().getStringExtra(MediaFoldersDetectionJob.KEY_MEDIA_FOLDER_PATH);
|
||||
|
@ -254,10 +256,9 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA
|
|||
|
||||
List<SyncedFolder> syncedFolderArrayList = mSyncedFolderProvider.getSyncedFolders();
|
||||
List<SyncedFolder> currentAccountSyncedFoldersList = new ArrayList<>();
|
||||
Account currentAccount = getUserAccountManager().getCurrentAccount();
|
||||
User user = getUserAccountManager().getUser();
|
||||
for (SyncedFolder syncedFolder : syncedFolderArrayList) {
|
||||
if (currentAccount != null && syncedFolder.getAccount().equals(currentAccount.name)) {
|
||||
|
||||
if (syncedFolder.getAccount().equals(user.getAccountName())) {
|
||||
// delete non-existing & disabled synced folders
|
||||
if (!new File(syncedFolder.getLocalPath()).exists() && !syncedFolder.isEnabled()) {
|
||||
mSyncedFolderProvider.deleteSyncedFolder(syncedFolder.getId());
|
||||
|
|
|
@ -43,9 +43,11 @@ import com.evernote.android.job.Job;
|
|||
import com.evernote.android.job.JobManager;
|
||||
import com.evernote.android.job.JobRequest;
|
||||
import com.evernote.android.job.util.support.PersistableBundleCompat;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.device.PowerManagementService;
|
||||
import com.nextcloud.client.network.ConnectivityService;
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.UploadsStorageManager;
|
||||
import com.owncloud.android.files.services.FileUploader;
|
||||
|
@ -230,9 +232,9 @@ public class UploadListActivity extends FileActivity {
|
|||
protected void onStart() {
|
||||
super.onStart();
|
||||
ThemeUtils.setColoredTitle(getSupportActionBar(), R.string.uploads_view_title, this);
|
||||
final Account account = getAccount();
|
||||
if (account != null) {
|
||||
setAccountInDrawer(account);
|
||||
final Optional<User> optionalUser = getUser();
|
||||
if (optionalUser.isPresent()) {
|
||||
setAccountInDrawer(optionalUser.get());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@ import com.bumptech.glide.load.model.StreamEncoder;
|
|||
import com.bumptech.glide.load.resource.file.FileToStreamDecoder;
|
||||
import com.caverock.androidsvg.SVG;
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
|
@ -94,6 +95,7 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
|
||||
protected Context context;
|
||||
private CurrentAccountProvider currentAccountProvider;
|
||||
private ClientFactory clientFactory;
|
||||
private FileDataStorageManager storageManager;
|
||||
private OCCapability capability;
|
||||
protected List<Object> values;
|
||||
|
@ -246,8 +248,11 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
|
||||
if (MimeTypeUtil.isImageOrVideo(previewObject.getMimeType())) {
|
||||
int placeholder = R.drawable.file;
|
||||
Glide.with(context).using(new CustomGlideStreamLoader(currentAccountProvider)).load(previewObject.getSource()).
|
||||
placeholder(placeholder).error(placeholder).into(imageView);
|
||||
Glide.with(context).using(new CustomGlideStreamLoader(currentAccountProvider, clientFactory))
|
||||
.load(previewObject.getSource())
|
||||
.placeholder(placeholder)
|
||||
.error(placeholder)
|
||||
.into(imageView);
|
||||
} else {
|
||||
if (MimeTypeUtil.isFolder(previewObject.getMimeType())) {
|
||||
imageView.setImageDrawable(
|
||||
|
@ -297,8 +302,10 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
String uri = client.getBaseUri() + "/index.php/apps/files/api/v1/thumbnail/" + px + "/" + px +
|
||||
Uri.encode(file.getRemotePath(), "/");
|
||||
|
||||
Glide.with(context).using(new CustomGlideStreamLoader(currentAccountProvider)).load(uri).placeholder(placeholder)
|
||||
.error(placeholder).into(fileIcon); // using custom fetcher
|
||||
Glide.with(context).using(new CustomGlideStreamLoader(currentAccountProvider, clientFactory))
|
||||
.load(uri).placeholder(placeholder)
|
||||
.error(placeholder)
|
||||
.into(fileIcon); // using custom fetcher
|
||||
|
||||
} else {
|
||||
if (isDetailView) {
|
||||
|
|
|
@ -33,6 +33,7 @@ import android.widget.TextView;
|
|||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.Template;
|
||||
import com.owncloud.android.ui.dialog.ChooseTemplateDialogFragment;
|
||||
|
@ -56,17 +57,20 @@ public class TemplateAdapter extends RecyclerView.Adapter<TemplateAdapter.ViewHo
|
|||
private Context context;
|
||||
private ChooseTemplateDialogFragment.Type type;
|
||||
private CurrentAccountProvider currentAccountProvider;
|
||||
private ClientFactory clientFactory;
|
||||
|
||||
public TemplateAdapter(
|
||||
ChooseTemplateDialogFragment.Type type,
|
||||
ClickListener clickListener,
|
||||
Context context,
|
||||
CurrentAccountProvider currentAccountProvider
|
||||
CurrentAccountProvider currentAccountProvider,
|
||||
ClientFactory clientFactory
|
||||
) {
|
||||
this.clickListener = clickListener;
|
||||
this.type = type;
|
||||
this.context = context;
|
||||
this.currentAccountProvider = currentAccountProvider;
|
||||
this.clientFactory = clientFactory;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -135,7 +139,8 @@ public class TemplateAdapter extends RecyclerView.Adapter<TemplateAdapter.ViewHo
|
|||
break;
|
||||
}
|
||||
|
||||
Glide.with(context).using(new CustomGlideStreamLoader(currentAccountProvider)).load(template.getThumbnailLink())
|
||||
Glide.with(context).using(new CustomGlideStreamLoader(currentAccountProvider, clientFactory))
|
||||
.load(template.getThumbnailLink())
|
||||
.placeholder(placeholder)
|
||||
.error(placeholder)
|
||||
.into(thumbnail);
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
*/
|
||||
package com.owncloud.android.ui.adapter;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
|
@ -31,6 +30,7 @@ import android.widget.ImageView;
|
|||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
|
@ -65,7 +65,7 @@ public class TrashbinListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
private final TrashbinActivityInterface trashbinActivityInterface;
|
||||
private List<TrashbinFile> files;
|
||||
private final Context context;
|
||||
private final Account account;
|
||||
private final User user;
|
||||
private final FileDataStorageManager storageManager;
|
||||
private final AppPreferences preferences;
|
||||
|
||||
|
@ -76,11 +76,11 @@ public class TrashbinListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
FileDataStorageManager storageManager,
|
||||
AppPreferences preferences,
|
||||
Context context,
|
||||
Account account
|
||||
User user
|
||||
) {
|
||||
this.files = new ArrayList<>();
|
||||
this.trashbinActivityInterface = trashbinActivityInterface;
|
||||
this.account = account;
|
||||
this.user = user;
|
||||
this.storageManager = storageManager;
|
||||
this.preferences = preferences;
|
||||
this.context = context;
|
||||
|
@ -237,7 +237,7 @@ public class TrashbinListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
try {
|
||||
final ThumbnailsCacheManager.ThumbnailGenerationTask task =
|
||||
new ThumbnailsCacheManager.ThumbnailGenerationTask(thumbnailView, storageManager,
|
||||
account, asyncTasks);
|
||||
user.toPlatformAccount(), asyncTasks);
|
||||
|
||||
final ThumbnailsCacheManager.AsyncThumbnailDrawable asyncDrawable =
|
||||
new ThumbnailsCacheManager.AsyncThumbnailDrawable(context.getResources(),
|
||||
|
@ -257,7 +257,7 @@ public class TrashbinListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
}
|
||||
} else {
|
||||
thumbnailView.setImageDrawable(MimeTypeUtil.getFileTypeIcon(file.getMimeType(), file.getFileName(),
|
||||
account, context));
|
||||
user.toPlatformAccount(), context));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,9 +21,9 @@
|
|||
|
||||
package com.owncloud.android.ui.asynctasks;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
|
@ -38,18 +38,18 @@ import java.lang.ref.WeakReference;
|
|||
public class PhotoSearchTask extends AsyncTask<Void, Void, RemoteOperationResult> {
|
||||
|
||||
private int columnCount;
|
||||
private Account account;
|
||||
private User user;
|
||||
private WeakReference<PhotoFragment> photoFragmentWeakReference;
|
||||
private SearchRemoteOperation searchRemoteOperation;
|
||||
private FileDataStorageManager storageManager;
|
||||
|
||||
public PhotoSearchTask(int columnsCount,
|
||||
PhotoFragment photoFragment,
|
||||
Account account,
|
||||
User user,
|
||||
SearchRemoteOperation searchRemoteOperation,
|
||||
FileDataStorageManager storageManager) {
|
||||
this.columnCount = columnsCount;
|
||||
this.account = account;
|
||||
this.user = user;
|
||||
this.photoFragmentWeakReference = new WeakReference<>(photoFragment);
|
||||
this.searchRemoteOperation = searchRemoteOperation;
|
||||
this.storageManager = storageManager;
|
||||
|
@ -88,7 +88,7 @@ public class PhotoSearchTask extends AsyncTask<Void, Void, RemoteOperationResult
|
|||
searchRemoteOperation.setTimestamp(timestamp);
|
||||
|
||||
if (photoFragment.getContext() != null) {
|
||||
return searchRemoteOperation.execute(account, photoFragment.getContext());
|
||||
return searchRemoteOperation.execute(user.toPlatformAccount(), photoFragment.getContext());
|
||||
} else {
|
||||
return new RemoteOperationResult(new IllegalStateException("No context available"));
|
||||
}
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
|
||||
package com.owncloud.android.ui.dialog;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
|
@ -40,16 +39,16 @@ import android.view.WindowManager.LayoutParams;
|
|||
import android.widget.EditText;
|
||||
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
import com.owncloud.android.datamodel.Template;
|
||||
import com.owncloud.android.files.CreateFileFromTemplateOperation;
|
||||
import com.owncloud.android.files.FetchTemplateOperation;
|
||||
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.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.ui.activity.ExternalSiteWebView;
|
||||
|
@ -88,7 +87,8 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements Dial
|
|||
private TemplateAdapter adapter;
|
||||
private OCFile parentFolder;
|
||||
private OwnCloudClient client;
|
||||
@Inject CurrentAccountProvider currentAccount;
|
||||
@Inject CurrentAccountProvider currentUser;
|
||||
@Inject ClientFactory clientFactory;
|
||||
|
||||
public enum Type {
|
||||
DOCUMENT,
|
||||
|
@ -151,9 +151,8 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements Dial
|
|||
fileName.getBackground().setColorFilter(accentColor, PorterDuff.Mode.SRC_ATOP);
|
||||
|
||||
try {
|
||||
Account account = currentAccount.getCurrentAccount();
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(account, activity);
|
||||
client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(ocAccount, getContext());
|
||||
User user = currentUser.getUser();
|
||||
client = clientFactory.create(user);
|
||||
|
||||
new FetchTemplateTask(this, client).execute(type);
|
||||
} catch (Exception e) {
|
||||
|
@ -162,7 +161,7 @@ public class ChooseTemplateDialogFragment extends DialogFragment implements Dial
|
|||
|
||||
listView.setHasFixedSize(true);
|
||||
listView.setLayoutManager(new GridLayoutManager(activity, 2));
|
||||
adapter = new TemplateAdapter(type, this, getContext(), currentAccount);
|
||||
adapter = new TemplateAdapter(type, this, getContext(), currentUser, clientFactory);
|
||||
listView.setAdapter(adapter);
|
||||
|
||||
// Build the dialog
|
||||
|
|
|
@ -53,6 +53,7 @@ import android.widget.ProgressBar;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
|
@ -304,7 +305,8 @@ public class ExtendedListFragment extends Fragment implements
|
|||
handler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (accountManager.isSearchSupported(accountManager.getCurrentAccount())) {
|
||||
User user = accountManager.getUser();
|
||||
if (user.getServer().getVersion().isSearchSupported()) {
|
||||
EventBus.getDefault().post(new SearchEvent(query,
|
||||
SearchRemoteOperation.SearchType.FILE_SEARCH, SearchEvent.UnsetType.NO_UNSET));
|
||||
} else {
|
||||
|
|
|
@ -24,9 +24,6 @@
|
|||
package com.owncloud.android.ui.fragment;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.content.Context;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
|
@ -41,15 +38,14 @@ import android.widget.TextView;
|
|||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
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.RemoteOperationResult;
|
||||
import com.owncloud.android.lib.common.utils.Log_OC;
|
||||
import com.owncloud.android.lib.resources.activities.GetActivitiesRemoteOperation;
|
||||
|
@ -72,7 +68,6 @@ import com.owncloud.android.utils.ThemeUtils;
|
|||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -149,6 +144,7 @@ public class FileDetailActivitiesFragment extends Fragment implements
|
|||
private VersionListInterface.CommentCallback callback;
|
||||
|
||||
@Inject UserAccountManager accountManager;
|
||||
@Inject ClientFactory clientFactory;
|
||||
|
||||
public static FileDetailActivitiesFragment newInstance(OCFile file, Account account) {
|
||||
FileDetailActivitiesFragment fragment = new FileDetailActivitiesFragment();
|
||||
|
@ -258,7 +254,9 @@ public class FileDetailActivitiesFragment extends Fragment implements
|
|||
PorterDuff.Mode.SRC_IN);
|
||||
emptyContentIcon.setImageDrawable(getResources().getDrawable(R.drawable.ic_activity_light_grey));
|
||||
|
||||
adapter = new ActivityAndVersionListAdapter(getContext(), accountManager, this, this, storageManager, capability);
|
||||
adapter = new ActivityAndVersionListAdapter(getContext(), accountManager, this, this,
|
||||
storageManager,
|
||||
capability);
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
|
||||
|
@ -301,9 +299,9 @@ public class FileDetailActivitiesFragment extends Fragment implements
|
|||
|
||||
final SwipeRefreshLayout empty = swipeEmptyListRefreshLayout;
|
||||
final SwipeRefreshLayout list = swipeListRefreshLayout;
|
||||
final Account currentAccount = accountManager.getCurrentAccount();
|
||||
final User user = accountManager.getUser();
|
||||
|
||||
if (currentAccount == null) {
|
||||
if (user.isAnonymous()) {
|
||||
activity.runOnUiThread(() -> {
|
||||
setEmptyContent(getString(R.string.common_error), getString(R.string.file_detail_activity_error));
|
||||
list.setVisibility(View.GONE);
|
||||
|
@ -312,15 +310,10 @@ public class FileDetailActivitiesFragment extends Fragment implements
|
|||
return;
|
||||
}
|
||||
|
||||
final Context context = MainApp.getAppContext();
|
||||
|
||||
Thread t = new Thread(() -> {
|
||||
OwnCloudAccount ocAccount;
|
||||
try {
|
||||
ocAccount = new OwnCloudAccount(currentAccount, context);
|
||||
ownCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||
getClientFor(ocAccount, MainApp.getAppContext());
|
||||
ownCloudClient.setOwnCloudVersion(accountManager.getServerVersion(currentAccount));
|
||||
ownCloudClient = clientFactory.create(user);
|
||||
ownCloudClient.setOwnCloudVersion(user.getServer().getVersion());
|
||||
isLoadingActivities = true;
|
||||
|
||||
GetActivitiesRemoteOperation getRemoteNotificationOperation;
|
||||
|
@ -385,8 +378,7 @@ public class FileDetailActivitiesFragment extends Fragment implements
|
|||
}
|
||||
|
||||
hideRefreshLayoutLoader(activity);
|
||||
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException | IOException |
|
||||
OperationCanceledException | AuthenticatorException | NullPointerException e) {
|
||||
} catch (ClientFactory.CreationException e) {
|
||||
Log_OC.e(TAG, "Error fetching file details activities", e);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -47,9 +47,11 @@ import android.widget.AbsListView;
|
|||
import android.widget.PopupMenu;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.device.DeviceInfo;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
|
@ -169,6 +171,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|||
|
||||
@Inject AppPreferences preferences;
|
||||
@Inject UserAccountManager accountManager;
|
||||
@Inject ClientFactory clientFactory;
|
||||
protected FileFragment.ContainerActivity mContainerActivity;
|
||||
|
||||
protected OCFile mFile;
|
||||
|
@ -942,10 +945,11 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|||
mContainerActivity.getFileOperationsHelper().openFile(file);
|
||||
}
|
||||
} else {
|
||||
Account account = accountManager.getCurrentAccount();
|
||||
OCCapability capability = mContainerActivity.getStorageManager().getCapability(account.name);
|
||||
User account = accountManager.getUser();
|
||||
OCCapability capability = mContainerActivity.getStorageManager()
|
||||
.getCapability(account.getAccountName());
|
||||
|
||||
if (PreviewMediaFragment.canBePreviewed(file) && accountManager.getServerVersion(account)
|
||||
if (PreviewMediaFragment.canBePreviewed(file) && account.getServer().getVersion()
|
||||
.isMediaStreamingSupported()) {
|
||||
// stream media preview on >= NC14
|
||||
((FileDisplayActivity) mContainerActivity).startMediaPreview(file, 0, true, true, true);
|
||||
|
@ -1430,26 +1434,19 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|||
|
||||
@Subscribe(threadMode = ThreadMode.BACKGROUND)
|
||||
public void onMessageEvent(FavoriteEvent event) {
|
||||
Account currentAccount = accountManager.getCurrentAccount();
|
||||
|
||||
OwnCloudAccount ocAccount;
|
||||
|
||||
try {
|
||||
ocAccount = new OwnCloudAccount(currentAccount, MainApp.getAppContext());
|
||||
|
||||
OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||
getClientFor(ocAccount, MainApp.getAppContext());
|
||||
User user = accountManager.getUser();
|
||||
OwnCloudClient client = clientFactory.create(user);
|
||||
|
||||
ToggleFavoriteRemoteOperation toggleFavoriteOperation = new ToggleFavoriteRemoteOperation(
|
||||
event.shouldFavorite, event.remotePath);
|
||||
RemoteOperationResult remoteOperationResult = toggleFavoriteOperation.execute(mClient);
|
||||
RemoteOperationResult remoteOperationResult = toggleFavoriteOperation.execute(client);
|
||||
|
||||
if (remoteOperationResult.isSuccess()) {
|
||||
mAdapter.setFavoriteAttributeForItemID(event.remoteId, event.shouldFavorite);
|
||||
}
|
||||
|
||||
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException | AuthenticatorException
|
||||
| IOException | OperationCanceledException e) {
|
||||
} catch (ClientFactory.CreationException e) {
|
||||
Log_OC.e(TAG, "Error processing event", e);
|
||||
}
|
||||
}
|
||||
|
@ -1483,7 +1480,7 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|||
|
||||
new Handler(Looper.getMainLooper()).post(switchViewsRunnable);
|
||||
|
||||
final Account currentAccount = accountManager.getCurrentAccount();
|
||||
final User currentAccount = accountManager.getUser();
|
||||
|
||||
final RemoteOperation remoteOperation;
|
||||
if (currentSearchType != SearchType.SHARED_FILTER) {
|
||||
|
@ -1503,7 +1500,8 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|||
protected Object doInBackground(Object[] params) {
|
||||
setTitle();
|
||||
if (getContext() != null && !isCancelled()) {
|
||||
RemoteOperationResult remoteOperationResult = remoteOperation.execute(currentAccount, getContext());
|
||||
RemoteOperationResult remoteOperationResult = remoteOperation.execute(
|
||||
currentAccount.toPlatformAccount(), getContext());
|
||||
|
||||
FileDataStorageManager storageManager = null;
|
||||
if (mContainerActivity != null && mContainerActivity.getStorageManager() != null) {
|
||||
|
@ -1555,18 +1553,12 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|||
|
||||
@Subscribe(threadMode = ThreadMode.BACKGROUND)
|
||||
public void onMessageEvent(EncryptionEvent event) {
|
||||
Account currentAccount = accountManager.getCurrentAccount();
|
||||
|
||||
OwnCloudAccount ocAccount;
|
||||
try {
|
||||
ocAccount = new OwnCloudAccount(currentAccount, MainApp.getAppContext());
|
||||
|
||||
OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||
getClientFor(ocAccount, MainApp.getAppContext());
|
||||
|
||||
ToggleEncryptionRemoteOperation toggleEncryptionOperation = new ToggleEncryptionRemoteOperation(
|
||||
final User user = accountManager.getUser();
|
||||
final OwnCloudClient client = clientFactory.create(user);
|
||||
final ToggleEncryptionRemoteOperation toggleEncryptionOperation = new ToggleEncryptionRemoteOperation(
|
||||
event.localId, event.remotePath, event.shouldBeEncrypted);
|
||||
RemoteOperationResult remoteOperationResult = toggleEncryptionOperation.execute(mClient);
|
||||
final RemoteOperationResult remoteOperationResult = toggleEncryptionOperation.execute(client);
|
||||
|
||||
if (remoteOperationResult.isSuccess()) {
|
||||
mAdapter.setEncryptionAttributeForItemID(event.remoteId, event.shouldBeEncrypted);
|
||||
|
@ -1576,14 +1568,8 @@ public class OCFileListFragment extends ExtendedListFragment implements
|
|||
Snackbar.make(getRecyclerView(), R.string.common_error_unknown, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
} catch (com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
|
||||
Log_OC.e(TAG, "Account not found", e);
|
||||
} catch (AuthenticatorException e) {
|
||||
Log_OC.e(TAG, "Authentication failed", e);
|
||||
} catch (IOException e) {
|
||||
Log_OC.e(TAG, "IO error", e);
|
||||
} catch (OperationCanceledException e) {
|
||||
Log_OC.e(TAG, "Operation has been canceled", e);
|
||||
} catch (ClientFactory.CreationException e) {
|
||||
Log_OC.e(TAG, "Cannot create client", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -161,7 +161,7 @@ public class PhotoFragment extends OCFileListFragment {
|
|||
if (!photoSearchQueryRunning && !photoSearchNoNew) {
|
||||
photoSearchTask = new PhotoSearchTask(getColumnsCount(),
|
||||
this,
|
||||
accountManager.getCurrentAccount(),
|
||||
accountManager.getUser(),
|
||||
searchRemoteOperation,
|
||||
mContainerActivity.getStorageManager())
|
||||
.execute();
|
||||
|
|
|
@ -61,6 +61,7 @@ import com.evernote.android.job.util.support.PersistableBundleCompat;
|
|||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.nextcloud.client.account.UserAccountManager;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.FileDataStorageManager;
|
||||
import com.owncloud.android.datamodel.OCFile;
|
||||
|
@ -149,6 +150,7 @@ public class ContactListFragment extends FileFragment implements Injectable {
|
|||
private List<VCard> vCards = new ArrayList<>();
|
||||
private OCFile ocFile;
|
||||
@Inject UserAccountManager accountManager;
|
||||
@Inject ClientFactory clientFactory;
|
||||
|
||||
public static ContactListFragment newInstance(OCFile file, Account account) {
|
||||
ContactListFragment frag = new ContactListFragment();
|
||||
|
@ -191,7 +193,7 @@ public class ContactListFragment extends FileFragment implements Injectable {
|
|||
recyclerView = view.findViewById(R.id.contactlist_recyclerview);
|
||||
|
||||
if (savedInstanceState == null) {
|
||||
contactListAdapter = new ContactListAdapter(accountManager, getContext(), vCards);
|
||||
contactListAdapter = new ContactListAdapter(accountManager, clientFactory, getContext(), vCards);
|
||||
} else {
|
||||
Set<Integer> checkedItems = new HashSet<>();
|
||||
int[] itemsArray = savedInstanceState.getIntArray(CHECKED_ITEMS_ARRAY_KEY);
|
||||
|
@ -589,12 +591,15 @@ class ContactListAdapter extends RecyclerView.Adapter<ContactListFragment.Contac
|
|||
private Context context;
|
||||
|
||||
private UserAccountManager accountManager;
|
||||
private ClientFactory clientFactory;
|
||||
|
||||
ContactListAdapter(UserAccountManager accountManager, Context context, List<VCard> vCards) {
|
||||
ContactListAdapter(UserAccountManager accountManager, ClientFactory clientFactory, Context context,
|
||||
List<VCard> vCards) {
|
||||
this.vCards = vCards;
|
||||
this.context = context;
|
||||
this.checkedVCards = new HashSet<>();
|
||||
this.accountManager = accountManager;
|
||||
this.clientFactory = clientFactory;
|
||||
}
|
||||
|
||||
ContactListAdapter(UserAccountManager accountManager,
|
||||
|
@ -699,6 +704,7 @@ class ContactListAdapter extends RecyclerView.Adapter<ContactListFragment.Contac
|
|||
}
|
||||
};
|
||||
DisplayUtils.downloadIcon(accountManager,
|
||||
clientFactory,
|
||||
context,
|
||||
url,
|
||||
target,
|
||||
|
|
|
@ -46,6 +46,7 @@ import android.webkit.MimeTypeMap;
|
|||
|
||||
import com.evernote.android.job.JobRequest;
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.network.ConnectivityService;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
|
@ -291,14 +292,14 @@ public class FileOperationsHelper {
|
|||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Account account = currentAccount.getCurrentAccount();
|
||||
User user = currentAccount.getUser();
|
||||
FileDataStorageManager storageManager =
|
||||
new FileDataStorageManager(account, fileActivity.getContentResolver());
|
||||
new FileDataStorageManager(user.toPlatformAccount(), fileActivity.getContentResolver());
|
||||
// a fresh object is needed; many things could have occurred to the file
|
||||
// since it was registered to observe again, assuming that local files
|
||||
// are linked to a remote file AT MOST, SOMETHING TO BE DONE;
|
||||
SynchronizeFileOperation sfo =
|
||||
new SynchronizeFileOperation(file, null, account, true, fileActivity);
|
||||
new SynchronizeFileOperation(file, null, user.toPlatformAccount(), true, fileActivity);
|
||||
RemoteOperationResult result = sfo.execute(storageManager, fileActivity);
|
||||
fileActivity.dismissLoadingDialog();
|
||||
if (result.getCode() == RemoteOperationResult.ResultCode.SYNC_CONFLICT) {
|
||||
|
@ -307,7 +308,7 @@ public class FileOperationsHelper {
|
|||
Intent i = new Intent(fileActivity, ConflictsResolveActivity.class);
|
||||
i.setFlags(i.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
i.putExtra(ConflictsResolveActivity.EXTRA_FILE, file);
|
||||
i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, account);
|
||||
i.putExtra(ConflictsResolveActivity.EXTRA_ACCOUNT, user.toPlatformAccount());
|
||||
fileActivity.startActivity(i);
|
||||
} else {
|
||||
if (!launchables.isEmpty()) {
|
||||
|
@ -397,10 +398,10 @@ public class FileOperationsHelper {
|
|||
|
||||
public void streamMediaFile(OCFile file) {
|
||||
fileActivity.showLoadingDialog(fileActivity.getString(R.string.wait_a_moment));
|
||||
final Account account = currentAccount.getCurrentAccount();
|
||||
final User user = currentAccount.getUser();
|
||||
new Thread(() -> {
|
||||
StreamMediaFileOperation sfo = new StreamMediaFileOperation(file.getLocalId());
|
||||
RemoteOperationResult result = sfo.execute(account, fileActivity);
|
||||
RemoteOperationResult result = sfo.execute(user.toPlatformAccount(), fileActivity);
|
||||
|
||||
fileActivity.dismissLoadingDialog();
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.owncloud.android.MainApp;
|
||||
|
@ -385,11 +386,11 @@ public class PreviewImageActivity extends FileActivity implements
|
|||
@SuppressFBWarnings("DLS")
|
||||
@Override
|
||||
public void showDetails(OCFile file) {
|
||||
final Account currentAccount = getUserAccountManager().getCurrentAccount();
|
||||
final User currentUser = getUserAccountManager().getUser();
|
||||
final Intent showDetailsIntent = new Intent(this, FileDisplayActivity.class);
|
||||
showDetailsIntent.setAction(FileDisplayActivity.ACTION_DETAILS);
|
||||
showDetailsIntent.putExtra(FileActivity.EXTRA_FILE, file);
|
||||
showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, currentAccount);
|
||||
showDetailsIntent.putExtra(FileActivity.EXTRA_ACCOUNT, currentUser.toPlatformAccount());
|
||||
showDetailsIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
startActivity(showDetailsIntent);
|
||||
finish();
|
||||
|
|
|
@ -27,6 +27,8 @@ import android.accounts.Account;
|
|||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
|
@ -47,39 +49,46 @@ public class RemoteTrashbinRepository implements TrashbinRepository {
|
|||
|
||||
private static final String TAG = RemoteTrashbinRepository.class.getSimpleName();
|
||||
|
||||
private OwnCloudClient client;
|
||||
private final User user;
|
||||
private final ClientFactory clientFactory;
|
||||
|
||||
RemoteTrashbinRepository(final Context context, final Account account) {
|
||||
try {
|
||||
OwnCloudAccount nextcloudAccount = new OwnCloudAccount(account, context);
|
||||
client = OwnCloudClientManagerFactory.getDefaultSingleton().getClientFor(nextcloudAccount, context);
|
||||
} catch (Exception e) {
|
||||
Log_OC.e(TAG, e.getMessage());
|
||||
}
|
||||
RemoteTrashbinRepository(User user, ClientFactory clientFactory) {
|
||||
this.user = user;
|
||||
this.clientFactory = clientFactory;
|
||||
}
|
||||
|
||||
public void removeTrashbinFile(TrashbinFile file, OperationCallback callback) {
|
||||
new RemoveTrashbinFileTask(client, file, callback).execute();
|
||||
new RemoveTrashbinFileTask(user, clientFactory, file, callback).execute();
|
||||
}
|
||||
|
||||
private static class RemoveTrashbinFileTask extends AsyncTask<Void, Void, Boolean> {
|
||||
|
||||
private OwnCloudClient client;
|
||||
private User user;
|
||||
private ClientFactory clientFactory;
|
||||
private TrashbinFile file;
|
||||
private OperationCallback callback;
|
||||
|
||||
private RemoveTrashbinFileTask(OwnCloudClient client, TrashbinFile file, OperationCallback callback) {
|
||||
this.client = client;
|
||||
private RemoveTrashbinFileTask(User user,
|
||||
ClientFactory clientFactory,
|
||||
TrashbinFile file,
|
||||
OperationCallback callback) {
|
||||
this.user = user;
|
||||
this.clientFactory = clientFactory;
|
||||
this.file = file;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
RemoteOperationResult result = new RemoveTrashbinFileRemoteOperation(file.getFullRemotePath())
|
||||
.execute(client);
|
||||
|
||||
return result.isSuccess();
|
||||
try {
|
||||
OwnCloudClient client = clientFactory.create(user);
|
||||
RemoteOperationResult result = new RemoveTrashbinFileRemoteOperation(file.getFullRemotePath())
|
||||
.execute(client);
|
||||
return result.isSuccess();
|
||||
} catch (ClientFactory.CreationException e) {
|
||||
Log_OC.e(this, "Cannot create client", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -91,25 +100,32 @@ public class RemoteTrashbinRepository implements TrashbinRepository {
|
|||
}
|
||||
|
||||
public void emptyTrashbin(OperationCallback callback) {
|
||||
new EmptyTrashbinTask(client, callback).execute();
|
||||
new EmptyTrashbinTask(user, clientFactory, callback).execute();
|
||||
}
|
||||
|
||||
private static class EmptyTrashbinTask extends AsyncTask<Void, Void, Boolean> {
|
||||
|
||||
private OwnCloudClient client;
|
||||
private User user;
|
||||
private ClientFactory clientFactory;
|
||||
private OperationCallback callback;
|
||||
|
||||
private EmptyTrashbinTask(OwnCloudClient client, OperationCallback callback) {
|
||||
this.client = client;
|
||||
private EmptyTrashbinTask(User user, ClientFactory clientFactory, OperationCallback callback) {
|
||||
this.user = user;
|
||||
this.clientFactory = clientFactory;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
EmptyTrashbinRemoteOperation emptyTrashbinFileOperation = new EmptyTrashbinRemoteOperation();
|
||||
RemoteOperationResult result = emptyTrashbinFileOperation.execute(client);
|
||||
|
||||
return result.isSuccess();
|
||||
try {
|
||||
OwnCloudClient client = clientFactory.create(user);
|
||||
EmptyTrashbinRemoteOperation emptyTrashbinFileOperation = new EmptyTrashbinRemoteOperation();
|
||||
RemoteOperationResult result = emptyTrashbinFileOperation.execute(client);
|
||||
return result.isSuccess();
|
||||
} catch (ClientFactory.CreationException e) {
|
||||
Log_OC.e(this, "Cannot create client", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -122,28 +138,36 @@ public class RemoteTrashbinRepository implements TrashbinRepository {
|
|||
|
||||
@Override
|
||||
public void restoreFile(TrashbinFile file, OperationCallback callback) {
|
||||
new RestoreTrashbinFileTask(file, client, callback).execute();
|
||||
new RestoreTrashbinFileTask(file, user, clientFactory, callback).execute();
|
||||
}
|
||||
|
||||
private static class RestoreTrashbinFileTask extends AsyncTask<Void, Void, Boolean> {
|
||||
|
||||
private TrashbinFile file;
|
||||
private OwnCloudClient client;
|
||||
private User user;
|
||||
private ClientFactory clientFactory;
|
||||
private TrashbinRepository.OperationCallback callback;
|
||||
|
||||
private RestoreTrashbinFileTask(TrashbinFile file, OwnCloudClient client,
|
||||
private RestoreTrashbinFileTask(TrashbinFile file, User user, ClientFactory clientFactory,
|
||||
TrashbinRepository.OperationCallback callback) {
|
||||
this.file = file;
|
||||
this.client = client;
|
||||
this.user = user;
|
||||
this.clientFactory = clientFactory;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
RemoteOperationResult result = new RestoreTrashbinFileRemoteOperation(file.getFullRemotePath(),
|
||||
file.getFileName()).execute(client);
|
||||
try {
|
||||
OwnCloudClient client = clientFactory.create(user);
|
||||
RemoteOperationResult result = new RestoreTrashbinFileRemoteOperation(file.getFullRemotePath(),
|
||||
file.getFileName()).execute(client);
|
||||
|
||||
return result.isSuccess();
|
||||
return result.isSuccess();
|
||||
} catch (ClientFactory.CreationException e) {
|
||||
Log_OC.e(this, "Cannot create client", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -156,30 +180,37 @@ public class RemoteTrashbinRepository implements TrashbinRepository {
|
|||
|
||||
@Override
|
||||
public void getFolder(String remotePath, @NonNull LoadFolderCallback callback) {
|
||||
new ReadRemoteTrashbinFolderTask(remotePath, client, callback).execute();
|
||||
new ReadRemoteTrashbinFolderTask(remotePath, user, clientFactory, callback).execute();
|
||||
}
|
||||
|
||||
private static class ReadRemoteTrashbinFolderTask extends AsyncTask<Void, Void, Boolean> {
|
||||
|
||||
private String remotePath;
|
||||
private OwnCloudClient client;
|
||||
private User user;
|
||||
private ClientFactory clientFactory;
|
||||
private List<Object> trashbinFiles;
|
||||
private LoadFolderCallback callback;
|
||||
|
||||
private ReadRemoteTrashbinFolderTask(String remotePath, OwnCloudClient client, LoadFolderCallback callback) {
|
||||
private ReadRemoteTrashbinFolderTask(String remotePath, User user, ClientFactory clientFactory,
|
||||
LoadFolderCallback callback) {
|
||||
this.remotePath = remotePath;
|
||||
this.client = client;
|
||||
this.user = user;
|
||||
this.clientFactory = clientFactory;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... voids) {
|
||||
RemoteOperationResult result = new ReadTrashbinFolderRemoteOperation(remotePath).execute(client);
|
||||
|
||||
if (result.isSuccess()) {
|
||||
trashbinFiles = result.getData();
|
||||
return true;
|
||||
} else {
|
||||
try {
|
||||
OwnCloudClient client = clientFactory.create(user);
|
||||
RemoteOperationResult result = new ReadTrashbinFolderRemoteOperation(remotePath).execute(client);
|
||||
if (result.isSuccess()) {
|
||||
trashbinFiles = result.getData();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} catch (ClientFactory.CreationException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
*/
|
||||
package com.owncloud.android.ui.trashbin;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
|
@ -34,7 +33,10 @@ import android.widget.PopupMenu;
|
|||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.lib.resources.trashbin.model.TrashbinFile;
|
||||
|
@ -92,6 +94,8 @@ public class TrashbinActivity extends FileActivity implements
|
|||
public String noResultsMessage;
|
||||
|
||||
@Inject AppPreferences preferences;
|
||||
@Inject CurrentAccountProvider accountProvider;
|
||||
@Inject ClientFactory clientFactory;
|
||||
private Unbinder unbinder;
|
||||
private TrashbinListAdapter trashbinListAdapter;
|
||||
private TrashbinPresenter trashbinPresenter;
|
||||
|
@ -101,29 +105,20 @@ public class TrashbinActivity extends FileActivity implements
|
|||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
final Account currentAccount = getUserAccountManager().getCurrentAccount();
|
||||
final RemoteTrashbinRepository trashRepository = new RemoteTrashbinRepository(this, currentAccount);
|
||||
final User user = accountProvider.getUser();
|
||||
final RemoteTrashbinRepository trashRepository = new RemoteTrashbinRepository(user, clientFactory);
|
||||
trashbinPresenter = new TrashbinPresenter(trashRepository, this);
|
||||
|
||||
setContentView(R.layout.trashbin_activity);
|
||||
unbinder = ButterKnife.bind(this);
|
||||
|
||||
// setup toolbar
|
||||
setupToolbar();
|
||||
|
||||
// setup drawer
|
||||
setupDrawer(R.id.nav_trashbin);
|
||||
|
||||
ThemeUtils.setColoredTitle(getSupportActionBar(), R.string.trashbin_activity_title, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
active = true;
|
||||
|
||||
setupContent();
|
||||
}
|
||||
|
||||
|
@ -142,7 +137,7 @@ public class TrashbinActivity extends FileActivity implements
|
|||
getStorageManager(),
|
||||
preferences,
|
||||
this,
|
||||
getUserAccountManager().getCurrentAccount()
|
||||
getUserAccountManager().getUser()
|
||||
);
|
||||
recyclerView.setAdapter(trashbinListAdapter);
|
||||
recyclerView.setHasFixedSize(true);
|
||||
|
|
|
@ -55,6 +55,7 @@ import com.bumptech.glide.request.target.Target;
|
|||
import com.caverock.androidsvg.SVG;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.datamodel.ArbitraryDataProvider;
|
||||
|
@ -515,6 +516,7 @@ public final class DisplayUtils {
|
|||
}
|
||||
|
||||
public static void downloadIcon(CurrentAccountProvider currentAccountProvider,
|
||||
ClientFactory clientFactory,
|
||||
Context context,
|
||||
String iconUrl,
|
||||
SimpleTarget imageView,
|
||||
|
@ -523,7 +525,8 @@ public final class DisplayUtils {
|
|||
int height) {
|
||||
try {
|
||||
if (iconUrl.endsWith(".svg")) {
|
||||
downloadSVGIcon(currentAccountProvider, context, iconUrl, imageView, placeholder, width, height);
|
||||
downloadSVGIcon(currentAccountProvider, clientFactory, context, iconUrl, imageView, placeholder, width,
|
||||
height);
|
||||
} else {
|
||||
downloadPNGIcon(context, iconUrl, imageView, placeholder);
|
||||
}
|
||||
|
@ -544,6 +547,7 @@ public final class DisplayUtils {
|
|||
}
|
||||
|
||||
private static void downloadSVGIcon(CurrentAccountProvider currentAccountProvider,
|
||||
ClientFactory clientFactory,
|
||||
Context context,
|
||||
String iconUrl,
|
||||
SimpleTarget imageView,
|
||||
|
@ -551,7 +555,7 @@ public final class DisplayUtils {
|
|||
int width,
|
||||
int height) {
|
||||
GenericRequestBuilder<Uri, InputStream, SVG, PictureDrawable> requestBuilder = Glide.with(context)
|
||||
.using(new CustomGlideUriLoader(currentAccountProvider), InputStream.class)
|
||||
.using(new CustomGlideUriLoader(currentAccountProvider, clientFactory), InputStream.class)
|
||||
.from(Uri.class)
|
||||
.as(SVG.class)
|
||||
.transcode(new SvgDrawableTranscoder(), PictureDrawable.class)
|
||||
|
|
|
@ -25,6 +25,7 @@ package com.owncloud.android.utils.glide;
|
|||
import com.bumptech.glide.load.data.DataFetcher;
|
||||
import com.bumptech.glide.load.model.stream.StreamModelLoader;
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
|
@ -34,13 +35,15 @@ import java.io.InputStream;
|
|||
public class CustomGlideStreamLoader implements StreamModelLoader<String> {
|
||||
|
||||
private final CurrentAccountProvider currentAccount;
|
||||
private final ClientFactory clientFactory;
|
||||
|
||||
public CustomGlideStreamLoader(CurrentAccountProvider currentAccount) {
|
||||
public CustomGlideStreamLoader(CurrentAccountProvider currentAccount, ClientFactory clientFactory) {
|
||||
this.currentAccount = currentAccount;
|
||||
this.clientFactory = clientFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFetcher<InputStream> getResourceFetcher(String url, int width, int height) {
|
||||
return new HttpStreamFetcher(currentAccount, url);
|
||||
return new HttpStreamFetcher(currentAccount, clientFactory, url);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import android.net.Uri;
|
|||
import com.bumptech.glide.load.data.DataFetcher;
|
||||
import com.bumptech.glide.load.model.stream.StreamModelLoader;
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
|
@ -34,13 +35,15 @@ import java.io.InputStream;
|
|||
public class CustomGlideUriLoader implements StreamModelLoader<Uri> {
|
||||
|
||||
private final CurrentAccountProvider currentAccount;
|
||||
private final ClientFactory clientFactory;
|
||||
|
||||
public CustomGlideUriLoader(CurrentAccountProvider currentAccount) {
|
||||
public CustomGlideUriLoader(CurrentAccountProvider currentAccount, ClientFactory clientFactory) {
|
||||
this.currentAccount = currentAccount;
|
||||
this.clientFactory = clientFactory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataFetcher<InputStream> getResourceFetcher(Uri url, int width, int height) {
|
||||
return new HttpStreamFetcher(currentAccount, url.toString());
|
||||
return new HttpStreamFetcher(currentAccount, clientFactory, url.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@ import android.accounts.Account;
|
|||
import com.bumptech.glide.Priority;
|
||||
import com.bumptech.glide.load.data.DataFetcher;
|
||||
import com.nextcloud.client.account.CurrentAccountProvider;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.network.ClientFactory;
|
||||
import com.owncloud.android.MainApp;
|
||||
import com.owncloud.android.lib.common.OwnCloudAccount;
|
||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
||||
|
@ -47,30 +49,30 @@ public class HttpStreamFetcher implements DataFetcher<InputStream> {
|
|||
private static final String TAG = HttpStreamFetcher.class.getName();
|
||||
private final String url;
|
||||
private final CurrentAccountProvider currentAccount;
|
||||
private final ClientFactory clientFactory;
|
||||
|
||||
HttpStreamFetcher(final CurrentAccountProvider currentAccount, final String url) {
|
||||
HttpStreamFetcher(final CurrentAccountProvider currentAccount, ClientFactory clientFactory, final String url) {
|
||||
this.currentAccount = currentAccount;
|
||||
this.clientFactory = clientFactory;
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream loadData(Priority priority) throws Exception {
|
||||
Account account = currentAccount.getCurrentAccount();
|
||||
OwnCloudAccount ocAccount = new OwnCloudAccount(account, MainApp.getAppContext());
|
||||
OwnCloudClient mClient = OwnCloudClientManagerFactory.getDefaultSingleton().
|
||||
getClientFor(ocAccount, MainApp.getAppContext());
|
||||
User user = currentAccount.getUser();
|
||||
OwnCloudClient client = clientFactory.create(user);
|
||||
|
||||
if (mClient != null) {
|
||||
if (client != null) {
|
||||
GetMethod get;
|
||||
try {
|
||||
get = new GetMethod(url);
|
||||
get.setRequestHeader("Cookie", "nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true");
|
||||
get.setRequestHeader(RemoteOperation.OCS_API_HEADER, RemoteOperation.OCS_API_HEADER_VALUE);
|
||||
int status = mClient.executeMethod(get);
|
||||
int status = client.executeMethod(get);
|
||||
if (status == HttpStatus.SC_OK) {
|
||||
return get.getResponseBodyAsStream();
|
||||
} else {
|
||||
mClient.exhaustResponse(get.getResponseBodyAsStream());
|
||||
client.exhaustResponse(get.getResponseBodyAsStream());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log_OC.e(TAG, e.getMessage(), e);
|
||||
|
|
|
@ -868,9 +868,6 @@
|
|||
<string name="storage_music">Music</string>
|
||||
<string name="storage_documents">Documents</string>
|
||||
<string name="storage_downloads">Downloads</string>
|
||||
<string name="io_error">IO error</string>
|
||||
<string name="operation_canceled">Operation has been canceled</string>
|
||||
<string name="authentication_exception">Authentication Exception</string>
|
||||
<string name="shared_avatar_desc">Avatar from shared user</string>
|
||||
<string name="shared_with_you_by">Shared with you by %1$s</string>
|
||||
<string name="reshare_not_allowed">Resharing is not allowed</string>
|
||||
|
|
Loading…
Reference in a new issue