Merge pull request #2178 from nextcloud/removeCheckForOlderVersions

Remove check for older version (<11)
This commit is contained in:
Andy Scherzinger 2018-07-03 19:26:40 +02:00 committed by GitHub
commit 4803f9f55d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 404 additions and 575 deletions

View file

@ -27,7 +27,6 @@ public class UploadIT extends AbstractIT {
null,
ocUpload,
false,
false,
FileUploader.LOCAL_BEHAVIOUR_COPY,
context,
false,
@ -52,7 +51,6 @@ public class UploadIT extends AbstractIT {
null,
ocUpload,
false,
false,
FileUploader.LOCAL_BEHAVIOUR_COPY,
context,
false,

View file

@ -35,6 +35,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.StrictMode;
import android.support.annotation.RequiresApi;
import android.support.annotation.StringRes;
import android.support.multidex.MultiDexApplication;
import android.support.v4.util.Pair;
@ -341,6 +342,7 @@ public class MainApp extends MultiDexApplication {
}
}
@RequiresApi(api = Build.VERSION_CODES.N)
private static void createChannel(NotificationManager notificationManager,
String channelId, int channelName,
int channelDescription, Context context) {

View file

@ -1,221 +1,217 @@
/*
* ownCloud Android client application
*
* Copyright (C) 2012 Bartek Przybylski
* Copyright (C) 2016 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.owncloud.android.authentication;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.owncloud.android.MainApp;
import com.owncloud.android.datamodel.ArbitraryDataProvider;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.operations.GetCapabilitiesOperarion;
import com.owncloud.android.ui.activity.ManageAccountsActivity;
public class AccountUtils {
private static final String TAG = AccountUtils.class.getSimpleName();
private static final String PREF_SELECT_OC_ACCOUNT = "select_oc_account";
public static final int ACCOUNT_VERSION = 1;
public static final int ACCOUNT_VERSION_WITH_PROPER_ID = 2;
public static final String ACCOUNT_USES_STANDARD_PASSWORD = "ACCOUNT_USES_STANDARD_PASSWORD";
private AccountUtils() {
// Required empty constructor
}
/**
* Can be used to get the currently selected ownCloud {@link Account} in the
* application preferences.
*
* @param context The current application {@link Context}
* @return The ownCloud {@link Account} currently saved in preferences, or the first
* {@link Account} available, if valid (still registered in the system as ownCloud
* account). If none is available and valid, returns null.
*/
public static @Nullable Account getCurrentOwnCloudAccount(Context context) {
Account[] ocAccounts = getAccounts(context);
Account defaultAccount = null;
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver());
SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(context);
String accountName = appPreferences.getString(PREF_SELECT_OC_ACCOUNT, null);
// account validation: the saved account MUST be in the list of ownCloud Accounts known by the AccountManager
if (accountName != null) {
for (Account account : ocAccounts) {
if (account.name.equals(accountName)) {
defaultAccount = account;
break;
}
}
}
if (defaultAccount == null && ocAccounts.length > 0) {
// take first which is not pending for removal account as fallback
for (Account account: ocAccounts) {
boolean pendingForRemoval = arbitraryDataProvider.getBooleanValue(account,
ManageAccountsActivity.PENDING_FOR_REMOVAL);
if (!pendingForRemoval) {
defaultAccount = account;
break;
}
}
}
return defaultAccount;
}
public static Account[] getAccounts(Context context) {
AccountManager accountManager = AccountManager.get(context);
return accountManager.getAccountsByType(MainApp.getAccountType(context));
}
public static boolean exists(Account account, Context context) {
Account[] ocAccounts = getAccounts(context);
if (account != null && account.name != null) {
int lastAtPos = account.name.lastIndexOf('@');
String hostAndPort = account.name.substring(lastAtPos + 1);
String username = account.name.substring(0, lastAtPos);
String otherHostAndPort;
String otherUsername;
for (Account otherAccount : ocAccounts) {
lastAtPos = otherAccount.name.lastIndexOf('@');
otherHostAndPort = otherAccount.name.substring(lastAtPos + 1);
otherUsername = otherAccount.name.substring(0, lastAtPos);
if (otherHostAndPort.equals(hostAndPort) &&
otherUsername.equalsIgnoreCase(username)) {
return true;
}
}
}
return false;
}
/**
* returns the user's name based on the account name.
*
* @param accountName the account name
* @return the user's name
*/
public static String getAccountUsername(String accountName) {
if (accountName != null) {
return accountName.substring(0, accountName.lastIndexOf('@'));
} else {
return null;
}
}
/**
* Returns owncloud account identified by accountName or null if it does not exist.
* @param context the context
* @param accountName name of account to be returned
* @return owncloud account named accountName
*/
public static Account getOwnCloudAccountByName(Context context, String accountName) {
Account[] ocAccounts = AccountManager.get(context).getAccountsByType(MainApp.getAccountType(context));
for (Account account : ocAccounts) {
if(account.name.equals(accountName)) {
return account;
}
}
return null;
}
public static boolean setCurrentOwnCloudAccount(final Context context, String accountName) {
boolean result = false;
if (accountName != null) {
boolean found;
for (final Account account : getAccounts(context)) {
found = (account.name.equals(accountName));
if (found) {
SharedPreferences.Editor appPrefs = PreferenceManager.getDefaultSharedPreferences(context).edit();
appPrefs.putString(PREF_SELECT_OC_ACCOUNT, accountName);
// update credentials
Thread t = new Thread(() -> {
FileDataStorageManager storageManager = new FileDataStorageManager(account,
context.getContentResolver());
GetCapabilitiesOperarion getCapabilities = new GetCapabilitiesOperarion();
RemoteOperationResult updateResult = getCapabilities.execute(storageManager, context);
Log_OC.w(TAG, "Update Capabilities: " + updateResult.isSuccess());
});
t.start();
appPrefs.apply();
result = true;
break;
}
}
}
return result;
}
public static void resetOwnCloudAccount(Context context) {
SharedPreferences.Editor appPrefs = PreferenceManager.getDefaultSharedPreferences(context).edit();
appPrefs.putString(PREF_SELECT_OC_ACCOUNT, null);
appPrefs.apply();
}
/**
* Access the version of the OC server corresponding to an account SAVED IN THE ACCOUNTMANAGER
*
* @param account ownCloud account
* @return Version of the OC server corresponding to account, according to the data saved
* in the system AccountManager
*/
public static @NonNull
OwnCloudVersion getServerVersion(Account account) {
OwnCloudVersion serverVersion = OwnCloudVersion.nextcloud_10;
if (account != null) {
AccountManager accountMgr = AccountManager.get(MainApp.getAppContext());
String serverVersionStr = accountMgr.getUserData(account, Constants.KEY_OC_VERSION);
if (serverVersionStr != null) {
serverVersion = new OwnCloudVersion(serverVersionStr);
}
}
return serverVersion;
}
public static boolean hasSearchUsersSupport(Account account) {
return getServerVersion(account).isSearchUsersSupported();
}
public static boolean hasSearchSupport(Account account) {
return getServerVersion(account).isSearchSupported();
}
}
/*
* ownCloud Android client application
*
* Copyright (C) 2012 Bartek Przybylski
* Copyright (C) 2016 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
package com.owncloud.android.authentication;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.owncloud.android.MainApp;
import com.owncloud.android.datamodel.ArbitraryDataProvider;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.operations.GetCapabilitiesOperarion;
import com.owncloud.android.ui.activity.ManageAccountsActivity;
public class AccountUtils {
private static final String TAG = AccountUtils.class.getSimpleName();
private static final String PREF_SELECT_OC_ACCOUNT = "select_oc_account";
public static final int ACCOUNT_VERSION = 1;
public static final int ACCOUNT_VERSION_WITH_PROPER_ID = 2;
public static final String ACCOUNT_USES_STANDARD_PASSWORD = "ACCOUNT_USES_STANDARD_PASSWORD";
private AccountUtils() {
// Required empty constructor
}
/**
* Can be used to get the currently selected ownCloud {@link Account} in the
* application preferences.
*
* @param context The current application {@link Context}
* @return The ownCloud {@link Account} currently saved in preferences, or the first
* {@link Account} available, if valid (still registered in the system as ownCloud
* account). If none is available and valid, returns null.
*/
public static @Nullable Account getCurrentOwnCloudAccount(Context context) {
Account[] ocAccounts = getAccounts(context);
Account defaultAccount = null;
ArbitraryDataProvider arbitraryDataProvider = new ArbitraryDataProvider(context.getContentResolver());
SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(context);
String accountName = appPreferences.getString(PREF_SELECT_OC_ACCOUNT, null);
// account validation: the saved account MUST be in the list of ownCloud Accounts known by the AccountManager
if (accountName != null) {
for (Account account : ocAccounts) {
if (account.name.equals(accountName)) {
defaultAccount = account;
break;
}
}
}
if (defaultAccount == null && ocAccounts.length > 0) {
// take first which is not pending for removal account as fallback
for (Account account: ocAccounts) {
boolean pendingForRemoval = arbitraryDataProvider.getBooleanValue(account,
ManageAccountsActivity.PENDING_FOR_REMOVAL);
if (!pendingForRemoval) {
defaultAccount = account;
break;
}
}
}
return defaultAccount;
}
public static Account[] getAccounts(Context context) {
AccountManager accountManager = AccountManager.get(context);
return accountManager.getAccountsByType(MainApp.getAccountType(context));
}
public static boolean exists(Account account, Context context) {
Account[] ocAccounts = getAccounts(context);
if (account != null && account.name != null) {
int lastAtPos = account.name.lastIndexOf('@');
String hostAndPort = account.name.substring(lastAtPos + 1);
String username = account.name.substring(0, lastAtPos);
String otherHostAndPort;
String otherUsername;
for (Account otherAccount : ocAccounts) {
lastAtPos = otherAccount.name.lastIndexOf('@');
otherHostAndPort = otherAccount.name.substring(lastAtPos + 1);
otherUsername = otherAccount.name.substring(0, lastAtPos);
if (otherHostAndPort.equals(hostAndPort) &&
otherUsername.equalsIgnoreCase(username)) {
return true;
}
}
}
return false;
}
/**
* returns the user's name based on the account name.
*
* @param accountName the account name
* @return the user's name
*/
public static String getAccountUsername(String accountName) {
if (accountName != null) {
return accountName.substring(0, accountName.lastIndexOf('@'));
} else {
return null;
}
}
/**
* Returns owncloud account identified by accountName or null if it does not exist.
* @param context the context
* @param accountName name of account to be returned
* @return owncloud account named accountName
*/
public static Account getOwnCloudAccountByName(Context context, String accountName) {
Account[] ocAccounts = AccountManager.get(context).getAccountsByType(MainApp.getAccountType(context));
for (Account account : ocAccounts) {
if(account.name.equals(accountName)) {
return account;
}
}
return null;
}
public static boolean setCurrentOwnCloudAccount(final Context context, String accountName) {
boolean result = false;
if (accountName != null) {
boolean found;
for (final Account account : getAccounts(context)) {
found = (account.name.equals(accountName));
if (found) {
SharedPreferences.Editor appPrefs = PreferenceManager.getDefaultSharedPreferences(context).edit();
appPrefs.putString(PREF_SELECT_OC_ACCOUNT, accountName);
// update credentials
Thread t = new Thread(() -> {
FileDataStorageManager storageManager = new FileDataStorageManager(account,
context.getContentResolver());
GetCapabilitiesOperarion getCapabilities = new GetCapabilitiesOperarion();
RemoteOperationResult updateResult = getCapabilities.execute(storageManager, context);
Log_OC.w(TAG, "Update Capabilities: " + updateResult.isSuccess());
});
t.start();
appPrefs.apply();
result = true;
break;
}
}
}
return result;
}
public static void resetOwnCloudAccount(Context context) {
SharedPreferences.Editor appPrefs = PreferenceManager.getDefaultSharedPreferences(context).edit();
appPrefs.putString(PREF_SELECT_OC_ACCOUNT, null);
appPrefs.apply();
}
/**
* Access the version of the OC server corresponding to an account SAVED IN THE ACCOUNTMANAGER
*
* @param account ownCloud account
* @return Version of the OC server corresponding to account, according to the data saved
* in the system AccountManager
*/
public static @NonNull
OwnCloudVersion getServerVersion(Account account) {
OwnCloudVersion serverVersion = OwnCloudVersion.nextcloud_10;
if (account != null) {
AccountManager accountMgr = AccountManager.get(MainApp.getAppContext());
String serverVersionStr = accountMgr.getUserData(account, Constants.KEY_OC_VERSION);
if (serverVersionStr != null) {
serverVersion = new OwnCloudVersion(serverVersionStr);
}
}
return serverVersion;
}
public static boolean hasSearchSupport(Account account) {
return getServerVersion(account).isSearchSupported();
}
}

View file

@ -46,7 +46,6 @@ import android.widget.ImageView;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.lib.common.OwnCloudAccount;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
@ -54,7 +53,6 @@ import com.owncloud.android.lib.common.operations.RemoteOperation;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.files.ServerFileInterface;
import com.owncloud.android.lib.resources.files.TrashbinFile;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.ui.TextDrawable;
import com.owncloud.android.ui.adapter.DiskLruImageCache;
import com.owncloud.android.ui.fragment.FileFragment;
@ -286,45 +284,39 @@ public class ThumbnailsCacheManager {
} else {
// Download thumbnail from server
OwnCloudVersion serverOCVersion = AccountUtils.getServerVersion(account);
if (mClient != null) {
if (serverOCVersion.supportsRemoteThumbnails()) {
GetMethod getMethod = null;
try {
String uri = mClient.getBaseUri() + "/index.php/core/preview.png?file="
+ URLEncoder.encode(file.getRemotePath())
+ "&x=" + pxW + "&y=" + pxH + "&a=1&mode=cover&forceIcon=0";
getMethod = new GetMethod(uri);
GetMethod getMethod = null;
try {
String uri = mClient.getBaseUri() + "/index.php/core/preview.png?file="
+ URLEncoder.encode(file.getRemotePath())
+ "&x=" + pxW + "&y=" + pxH + "&a=1&mode=cover&forceIcon=0";
getMethod = new GetMethod(uri);
int status = mClient.executeMethod(getMethod);
if (status == HttpStatus.SC_OK) {
InputStream inputStream = getMethod.getResponseBodyAsStream();
thumbnail = BitmapFactory.decodeStream(inputStream);
} else {
mClient.exhaustResponse(getMethod.getResponseBodyAsStream());
}
int status = mClient.executeMethod(getMethod);
if (status == HttpStatus.SC_OK) {
InputStream inputStream = getMethod.getResponseBodyAsStream();
thumbnail = BitmapFactory.decodeStream(inputStream);
} else {
mClient.exhaustResponse(getMethod.getResponseBodyAsStream());
}
// Handle PNG
if (thumbnail != null && file.getMimeType().equalsIgnoreCase(PNG_MIMETYPE)) {
thumbnail = handlePNG(thumbnail, thumbnail.getWidth(), thumbnail.getHeight());
}
// Add thumbnail to cache
if (thumbnail != null) {
Log_OC.d(TAG, "add thumbnail to cache: " + file.getFileName());
addBitmapToCache(imageKey, thumbnail);
}
} catch (Exception e) {
Log_OC.d(TAG, e.getMessage(), e);
} finally {
if (getMethod != null) {
getMethod.releaseConnection();
}
// Add thumbnail to cache
if (thumbnail != null) {
Log_OC.d(TAG, "add thumbnail to cache: " + file.getFileName());
addBitmapToCache(imageKey, thumbnail);
}
} catch (Exception e) {
Log_OC.d(TAG, e.getMessage(), e);
} finally {
if (getMethod != null) {
getMethod.releaseConnection();
}
} else {
Log_OC.d(TAG, "Server too old");
}
}
}
@ -548,7 +540,7 @@ public class ThumbnailsCacheManager {
thumbnail = ThumbnailUtils.extractThumbnail(resizedImage, pxW, pxH);
} else {
// Download thumbnail from server
if (mClient != null && AccountUtils.getServerVersion(mAccount).supportsRemoteThumbnails()) {
if (mClient != null) {
getMethod = null;
try {
// thumbnail
@ -589,8 +581,6 @@ public class ThumbnailsCacheManager {
getMethod.releaseConnection();
}
}
} else {
Log_OC.d(TAG, "Server too old");
}
}
@ -603,7 +593,6 @@ public class ThumbnailsCacheManager {
}
return thumbnail;
}
/**
@ -820,9 +809,9 @@ public class ThumbnailsCacheManager {
thumbnail = doAvatarInBackground();
} catch(OutOfMemoryError oome) {
} catch (OutOfMemoryError oome) {
Log_OC.e(TAG, "Out of memory");
} catch(Throwable t){
} catch (Throwable t) {
// the app should never break due to a problem with avatars
Log_OC.e(TAG, "Generation of avatar for " + mUserId + " failed", t);
}
@ -843,6 +832,7 @@ public class ThumbnailsCacheManager {
/**
* Converts size of file icon from dp to pixel
*
* @return int
*/
private int getAvatarDimension() {
@ -865,81 +855,77 @@ public class ThumbnailsCacheManager {
int px = getAvatarDimension();
// Download avatar from server
OwnCloudVersion serverOCVersion = AccountUtils.getServerVersion(mAccount);
if (mClient != null) {
if (serverOCVersion.supportsRemoteThumbnails()) {
GetMethod get = null;
try {
String uri = mClient.getBaseUri() + "/index.php/avatar/" + Uri.encode(mUserId) + "/" + px;
Log_OC.d("Avatar", "URI: " + uri);
get = new GetMethod(uri);
GetMethod get = null;
try {
String uri = mClient.getBaseUri() + "/index.php/avatar/" + Uri.encode(mUserId) + "/" + px;
Log_OC.d("Avatar", "URI: " + uri);
get = new GetMethod(uri);
// only use eTag if available and corresponding avatar is still there
// (might be deleted from cache)
if (!eTag.isEmpty() && getBitmapFromDiskCache(avatarKey) != null) {
get.setRequestHeader("If-None-Match", eTag);
}
int status = mClient.executeMethod(get);
// we are using eTag to download a new avatar only if it changed
switch (status) {
case HttpStatus.SC_OK:
// new avatar
InputStream inputStream = get.getResponseBodyAsStream();
String newETag = null;
if (get.getResponseHeader(ETAG) != null) {
newETag = get.getResponseHeader(ETAG).getValue().replace("\"", "");
arbitraryDataProvider.storeOrUpdateKeyValue(accountName, AVATAR, newETag);
}
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
avatar = ThumbnailUtils.extractThumbnail(bitmap, px, px);
// Add avatar to cache
if (avatar != null && !TextUtils.isEmpty(newETag)) {
avatar = handlePNG(avatar, px, px);
String newImageKey = "a_" + mUserId + "_" + mServerName + "_" + newETag;
addBitmapToCache(newImageKey, avatar);
} else {
return TextDrawable.createAvatar(mAccount.name, mAvatarRadius);
}
break;
case HttpStatus.SC_NOT_MODIFIED:
// old avatar
avatar = getBitmapFromDiskCache(avatarKey);
mClient.exhaustResponse(get.getResponseBodyAsStream());
break;
default:
// everything else
mClient.exhaustResponse(get.getResponseBodyAsStream());
break;
}
} catch (Exception e) {
try {
return TextDrawable.createAvatar(mAccount.name, mAvatarRadius);
} catch (Exception e1) {
Log_OC.e(TAG, "Error generating fallback avatar");
}
} finally {
if (get != null) {
get.releaseConnection();
}
// only use eTag if available and corresponding avatar is still there
// (might be deleted from cache)
if (!eTag.isEmpty() && getBitmapFromDiskCache(avatarKey) != null) {
get.setRequestHeader("If-None-Match", eTag);
}
} else {
Log_OC.d(TAG, "Server too old");
int status = mClient.executeMethod(get);
// we are using eTag to download a new avatar only if it changed
switch (status) {
case HttpStatus.SC_OK:
// new avatar
InputStream inputStream = get.getResponseBodyAsStream();
String newETag = null;
if (get.getResponseHeader(ETAG) != null) {
newETag = get.getResponseHeader(ETAG).getValue().replace("\"", "");
arbitraryDataProvider.storeOrUpdateKeyValue(accountName, AVATAR, newETag);
}
Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
avatar = ThumbnailUtils.extractThumbnail(bitmap, px, px);
// Add avatar to cache
if (avatar != null && !TextUtils.isEmpty(newETag)) {
avatar = handlePNG(avatar, px, px);
String newImageKey = "a_" + mUserId + "_" + mServerName + "_" + newETag;
addBitmapToCache(newImageKey, avatar);
} else {
return TextDrawable.createAvatar(mAccount.name, mAvatarRadius);
}
break;
case HttpStatus.SC_NOT_MODIFIED:
// old avatar
avatar = getBitmapFromDiskCache(avatarKey);
mClient.exhaustResponse(get.getResponseBodyAsStream());
break;
default:
// everything else
mClient.exhaustResponse(get.getResponseBodyAsStream());
break;
}
} catch (Exception e) {
try {
return TextDrawable.createAvatar(mAccount.name, mAvatarRadius);
} catch (Exception e) {
} catch (Exception e1) {
Log_OC.e(TAG, "Error generating fallback avatar");
}
} finally {
if (get != null) {
get.releaseConnection();
}
}
try {
return TextDrawable.createAvatar(mAccount.name, mAvatarRadius);
} catch (Exception e) {
Log_OC.e(TAG, "Error generating fallback avatar");
}
}
return BitmapUtils.bitmapToCircularBitmapDrawable(mResources, avatar);
}
}
@ -1095,6 +1081,7 @@ public class ThumbnailsCacheManager {
return null;
}
public static class AsyncThumbnailDrawable extends BitmapDrawable {
private final WeakReference<ThumbnailGenerationTask> bitmapWorkerTaskReference;

View file

@ -545,7 +545,6 @@ public class FileUploader extends Service
boolean retry = intent.getBooleanExtra(KEY_RETRY, false);
AbstractList<String> requestedUploads = new Vector<>();
boolean chunked = AccountUtils.getServerVersion(account).isChunkedUploadSupported();
boolean onWifiOnly = intent.getBooleanExtra(KEY_WHILE_ON_WIFI_ONLY, false);
boolean whileChargingOnly = intent.getBooleanExtra(KEY_WHILE_CHARGING_ONLY, false);
@ -633,7 +632,6 @@ public class FileUploader extends Service
account,
files[i],
ocUpload,
chunked,
forceOverwrite,
localAction,
this,
@ -692,7 +690,6 @@ public class FileUploader extends Service
account,
null,
upload,
chunked,
upload.isForceOverwrite(), // TODO should be read from DB?
upload.getLocalAction(), // TODO should be read from DB?
this,

View file

@ -79,7 +79,7 @@ public class CommentFileOperation extends SyncOperation {
RemoteOperationResult result;
try {
String url = client.getNewWebdavUri(false) + "/comments/files/" + fileId;
String url = client.getNewWebdavUri() + "/comments/files/" + fileId;
PostMethod postMethod = new PostMethod(url);
postMethod.addRequestHeader("Content-type", "application/json");

View file

@ -63,7 +63,7 @@ public class EmptyTrashbinFileOperation extends SyncOperation {
RemoteOperationResult result;
try {
DeleteMethod delete = new DeleteMethod(client.getNewWebdavUri(false) + "/trashbin/" + userId + "/trash");
DeleteMethod delete = new DeleteMethod(client.getNewWebdavUri() + "/trashbin/" + userId + "/trash");
int status = client.executeMethod(delete, RESTORE_READ_TIMEOUT, RESTORE_CONNECTION_TIMEOUT);
result = new RemoteOperationResult(isSuccess(status), delete);

View file

@ -106,9 +106,6 @@ public class RefreshFolderOperation extends RemoteOperation {
*/
private boolean mSyncFullAccount;
/** 'True' means that Share resources bound to the files into should be refreshed also */
private boolean mIsShareSupported;
/** 'True' means that the remote folder changed and should be fetched */
private boolean mRemoteFolderChanged;
@ -126,7 +123,6 @@ public class RefreshFolderOperation extends RemoteOperation {
* @param currentSyncTime Time stamp for the synchronization process in progress.
* @param syncFullAccount 'True' means that this operation is part of a full account
* synchronization.
* @param isShareSupported 'True' means that the server supports the sharing API.
* @param ignoreETag 'True' means that the content of the remote folder should
* be fetched and updated even though the 'eTag' did not
* change.
@ -137,7 +133,6 @@ public class RefreshFolderOperation extends RemoteOperation {
public RefreshFolderOperation(OCFile folder,
long currentSyncTime,
boolean syncFullAccount,
boolean isShareSupported,
boolean ignoreETag,
FileDataStorageManager dataStorageManager,
Account account,
@ -145,7 +140,6 @@ public class RefreshFolderOperation extends RemoteOperation {
mLocalFolder = folder;
mCurrentSyncTime = currentSyncTime;
mSyncFullAccount = syncFullAccount;
mIsShareSupported = isShareSupported;
mStorageManager = dataStorageManager;
mAccount = account;
mContext = context;
@ -219,7 +213,7 @@ public class RefreshFolderOperation extends RemoteOperation {
);
}
if (result.isSuccess() && mIsShareSupported && !mSyncFullAccount) {
if (result.isSuccess() && !mSyncFullAccount) {
refreshSharesForFolder(client); // share result is ignored
}
@ -237,14 +231,8 @@ public class RefreshFolderOperation extends RemoteOperation {
UpdateOCVersionOperation update = new UpdateOCVersionOperation(mAccount, mContext);
RemoteOperationResult result = update.execute(client);
if (result.isSuccess()) {
mIsShareSupported = update.getOCVersion().isSharedSupported();
// Update Capabilities for this account
if (update.getOCVersion().isVersionWithCapabilitiesAPI()) {
updateCapabilities();
} else {
Log_OC.d(TAG, "Capabilities API disabled");
}
updateCapabilities();
}
}

View file

@ -69,8 +69,8 @@ public class RestoreFileVersionOperation extends SyncOperation {
RemoteOperationResult result;
try {
String source = client.getNewWebdavUri(false) + "/versions/" + userId + "/versions/" + fileId + "/" + fileName;
String target = client.getNewWebdavUri(false) + "/versions/" + userId + "/restore/" + fileId;
String source = client.getNewWebdavUri() + "/versions/" + userId + "/versions/" + fileId + "/" + fileName;
String target = client.getNewWebdavUri() + "/versions/" + userId + "/restore/" + fileId;
MoveMethod move = new MoveMethod(source, target, true);
int status = client.executeMethod(move, RESTORE_READ_TIMEOUT, RESTORE_CONNECTION_TIMEOUT);

View file

@ -70,8 +70,8 @@ public class RestoreTrashbinFileOperation extends SyncOperation {
RemoteOperationResult result;
try {
String source = client.getNewWebdavUri(false) + WebdavUtils.encodePath(sourcePath);
String target = client.getNewWebdavUri(false) + "/trashbin/" + userId + "/restore/" + fileName;
String source = client.getNewWebdavUri() + WebdavUtils.encodePath(sourcePath);
String target = client.getNewWebdavUri() + "/trashbin/" + userId + "/restore/" + fileName;
MoveMethod move = new MoveMethod(source, target, true);
int status = client.executeMethod(move, RESTORE_READ_TIMEOUT, RESTORE_CONNECTION_TIMEOUT);

View file

@ -113,7 +113,6 @@ public class UploadFileOperation extends SyncOperation {
private OCFile mOldFile;
private String mRemotePath = null;
private String mFolderUnlockToken;
private boolean mChunked = false;
private boolean mRemoteFolderToBeCreated = false;
private boolean mForceOverwrite = false;
private int mLocalBehaviour = FileUploader.LOCAL_BEHAVIOUR_COPY;
@ -175,7 +174,6 @@ public class UploadFileOperation extends SyncOperation {
public UploadFileOperation(Account account,
OCFile file,
OCUpload upload,
boolean chunked,
boolean forceOverwrite,
int localBehaviour,
Context context,
@ -208,7 +206,6 @@ public class UploadFileOperation extends SyncOperation {
mOnWifiOnly = onWifiOnly;
mWhileChargingOnly = whileChargingOnly;
mRemotePath = upload.getRemotePath();
mChunked = chunked;
mForceOverwrite = forceOverwrite;
mLocalBehaviour = localBehaviour;
mOriginalStoragePath = mFile.getStoragePath();
@ -342,10 +339,6 @@ public class UploadFileOperation extends SyncOperation {
mRenameUploadListener = listener;
}
public boolean isChunkedUploadSupported() {
return mChunked;
}
public Context getContext() {
return mContext;
}
@ -579,7 +572,7 @@ public class UploadFileOperation extends SyncOperation {
}
/// perform the upload
if (mChunked && (size > ChunkedUploadRemoteFileOperation.CHUNK_SIZE)) {
if (size > ChunkedUploadRemoteFileOperation.CHUNK_SIZE) {
mUploadOperation = new ChunkedUploadRemoteFileOperation(mContext, encryptedTempFile.getAbsolutePath(),
mFile.getParentRemotePath() + encryptedFileName, mFile.getMimeType(),
mFile.getEtagInConflict(), timeStamp);
@ -820,7 +813,7 @@ public class UploadFileOperation extends SyncOperation {
}
// perform the upload
if (mChunked && (size > ChunkedUploadRemoteFileOperation.CHUNK_SIZE)) {
if (size > ChunkedUploadRemoteFileOperation.CHUNK_SIZE) {
mUploadOperation = new ChunkedUploadRemoteFileOperation(mContext, mFile.getStoragePath(),
mFile.getRemotePath(), mFile.getMimeType(), mFile.getEtagInConflict(), timeStamp);
} else {

View file

@ -112,10 +112,6 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
/** {@link SyncResult} instance to return to the system when the synchronization finish */
private SyncResult mSyncResult;
/** 'True' means that the server supports the share API */
private boolean mIsShareSupported;
/**
* Creates a {@link FileSyncAdapter}
*
@ -238,8 +234,6 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
RemoteOperationResult result = update.execute(getClient());
if (!result.isSuccess()) {
mLastFailedResult = result;
} else {
mIsShareSupported = update.getOCVersion().isSharedSupported();
}
}
@ -265,7 +259,6 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
RefreshFolderOperation synchFolderOp = new RefreshFolderOperation( folder,
mCurrentSyncTime,
true,
mIsShareSupported,
false,
getStorageManager(),
getAccount(),

View file

@ -235,8 +235,7 @@ public class ActivitiesActivity extends FileActivity implements ActivityListInte
@Override
public void onActivityClicked(RichObject richObject) {
String path = FileUtils.PATH_SEPARATOR + richObject.getPath();
mActionListener.openActivity(path, this,
getFileOperationsHelper().isSharedSupported());
mActionListener.openActivity(path, this);
}
@Override

View file

@ -39,7 +39,8 @@ public interface ActivitiesContract {
interface ActionListener {
void loadActivities(String pageUrl);
void openActivity(String fileUrl, BaseActivity baseActivity, boolean isSharingSupported);
void openActivity(String fileUrl, BaseActivity baseActivity);
void stopLoadingActivity();
}

View file

@ -71,10 +71,9 @@ public class ActivitiesPresenter implements ActivitiesContract.ActionListener {
}
@Override
public void openActivity(String fileUrl, BaseActivity baseActivity, boolean isSharingSupported) {
public void openActivity(String fileUrl, BaseActivity baseActivity) {
activitiesView.setProgressIndicatorState(true);
filesRepository.readRemoteFile(fileUrl, baseActivity, isSharingSupported,
new FilesRepository.ReadRemoteFileCallback() {
filesRepository.readRemoteFile(fileUrl, baseActivity, new FilesRepository.ReadRemoteFileCallback() {
@Override
public void onFileLoaded(@Nullable OCFile ocFile) {
activitiesView.setProgressIndicatorState(false);

View file

@ -33,6 +33,5 @@ public interface FilesRepository {
void onFileLoadError(String error);
}
void readRemoteFile(String path, BaseActivity activity, boolean isSharingSupported,
@NonNull ReadRemoteFileCallback callback);
void readRemoteFile(String path, BaseActivity activity, @NonNull ReadRemoteFileCallback callback);
}

View file

@ -32,6 +32,5 @@ public interface FilesServiceApi {
void onError(String error);
}
void readRemoteFile(String fileUrl, BaseActivity activity, boolean isSharingSupported,
FilesServiceApi.FilesServiceCallback<OCFile> callback);
void readRemoteFile(String fileUrl, BaseActivity activity, FilesServiceApi.FilesServiceCallback<OCFile> callback);
}

View file

@ -49,10 +49,8 @@ public class FilesServiceApiImpl implements FilesServiceApi {
private static final String TAG = FilesServiceApiImpl.class.getSimpleName();
@Override
public void readRemoteFile(String fileUrl, BaseActivity activity,
boolean isSharingSupported, FilesServiceCallback<OCFile> callback) {
ReadRemoteFileTask readRemoteFileTask = new ReadRemoteFileTask(fileUrl, activity,
isSharingSupported, callback);
public void readRemoteFile(String fileUrl, BaseActivity activity, FilesServiceCallback<OCFile> callback) {
ReadRemoteFileTask readRemoteFileTask = new ReadRemoteFileTask(fileUrl, activity, callback);
readRemoteFileTask.execute();
}
@ -62,15 +60,11 @@ public class FilesServiceApiImpl implements FilesServiceApi {
private String errorMessage;
// TODO: Figure out a better way to do this than passing a BaseActivity reference.
private final BaseActivity baseActivity;
private final boolean isSharingSupported;
private final String fileUrl;
private ReadRemoteFileTask(String fileUrl, BaseActivity baseActivity,
boolean isSharingSupported,
FilesServiceCallback<OCFile> callback) {
private ReadRemoteFileTask(String fileUrl, BaseActivity baseActivity, FilesServiceCallback<OCFile> callback) {
this.callback = callback;
this.baseActivity = baseActivity;
this.isSharingSupported = isSharingSupported;
this.fileUrl = fileUrl;
}
@ -97,7 +91,6 @@ public class FilesServiceApiImpl implements FilesServiceApi {
RemoteOperation synchFolderOp = new RefreshFolderOperation(remoteOcFile,
System.currentTimeMillis(),
false,
isSharingSupported,
true,
baseActivity.getStorageManager(),
baseActivity.getAccount(),

View file

@ -33,9 +33,8 @@ class RemoteFilesRepository implements FilesRepository {
@Override
public void readRemoteFile(String path, BaseActivity activity, boolean isSharingSupported, @NonNull ReadRemoteFileCallback callback) {
filesServiceApi.readRemoteFile(path, activity, isSharingSupported,
new FilesServiceApi.FilesServiceCallback<OCFile>() {
public void readRemoteFile(String path, BaseActivity activity, @NonNull ReadRemoteFileCallback callback) {
filesServiceApi.readRemoteFile(path, activity, new FilesServiceApi.FilesServiceCallback<OCFile>() {
@Override
public void onLoaded(OCFile ocFile) {
callback.onFileLoaded(ocFile);

View file

@ -581,14 +581,8 @@ public class FileDisplayActivity extends HookActivity
return OCShare.READ_PERMISSION_FLAG; // minimum permissions
} else if (isFederated) {
if (com.owncloud.android.authentication.AccountUtils
.getServerVersion(getAccount()).isNotReshareableFederatedSupported()) {
return (getFile().isFolder() ? OCShare.FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9 :
OCShare.FEDERATED_PERMISSIONS_FOR_FILE_AFTER_OC9);
} else {
return (getFile().isFolder() ? OCShare.FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 :
OCShare.FEDERATED_PERMISSIONS_FOR_FILE_UP_TO_OC9);
}
return (getFile().isFolder() ? OCShare.FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9 :
OCShare.FEDERATED_PERMISSIONS_FOR_FILE_AFTER_OC9);
} else {
return (getFile().isFolder() ? OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER :
OCShare.MAXIMUM_PERMISSIONS_FOR_FILE);
@ -2201,7 +2195,6 @@ public class FileDisplayActivity extends HookActivity
RemoteOperation synchFolderOp = new RefreshFolderOperation(folder,
currentSyncTime,
false,
getFileOperationsHelper().isSharedSupported(),
ignoreETag,
getStorageManager(),
getAccount(),

View file

@ -250,8 +250,7 @@ public class FolderPickerActivity extends FileActivity implements FileFragment.C
// perform folder synchronization
RemoteOperation refreshFolderOperation = new RefreshFolderOperation(folder, currentSyncTime, false,
getFileOperationsHelper().isSharedSupported(), ignoreETag, getStorageManager(), getAccount(),
getApplicationContext());
ignoreETag, getStorageManager(), getAccount(), getApplicationContext());
refreshFolderOperation.execute(getAccount(), this, null, null);
setIndeterminate(true);

View file

@ -835,7 +835,6 @@ public class ReceiveExternalFilesActivity extends FileActivity
currentSyncTime,
false,
false,
false,
getStorageManager(),
getAccount(),
getApplicationContext()

View file

@ -148,14 +148,8 @@ public class ShareActivity extends FileActivity implements ShareFragmentListener
return OCShare.READ_PERMISSION_FLAG; // minimum permissions
} else if (isFederated) {
if (com.owncloud.android.authentication.AccountUtils
.getServerVersion(getAccount()).isNotReshareableFederatedSupported()) {
return (getFile().isFolder() ? OCShare.FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9 :
OCShare.FEDERATED_PERMISSIONS_FOR_FILE_AFTER_OC9);
} else {
return (getFile().isFolder() ? OCShare.FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9 :
OCShare.FEDERATED_PERMISSIONS_FOR_FILE_UP_TO_OC9);
}
} else {
return (getFile().isFolder() ? OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER :
OCShare.MAXIMUM_PERMISSIONS_FOR_FILE);

View file

@ -30,6 +30,7 @@ import android.graphics.Bitmap;
import android.graphics.Color;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
@ -89,7 +90,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
private List<OCFile> mFiles = new ArrayList<>();
private List<OCFile> mFilesAll = new ArrayList<>();
private boolean mHideItemOptions;
private boolean gridView = false;
private boolean gridView;
private boolean multiSelect = false;
private HashSet<OCFile> checkedFiles;
@ -218,8 +219,9 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
return mFiles.size() + 1;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
switch (viewType) {
default:
case VIEWTYPE_ITEM:
@ -247,7 +249,7 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if (holder instanceof OCFileListFooterViewHolder) {
((OCFileListFooterViewHolder) holder).footerText.setText(getFooterText());
} else {
@ -632,9 +634,8 @@ public class OCFileListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
// also sync folder content
if (ocFile.isFolder()) {
long currentSyncTime = System.currentTimeMillis();
boolean shareSupported = AccountUtils.getServerVersion(mAccount).isSharedSupported();
RemoteOperation refreshFolderOperation = new RefreshFolderOperation(ocFile, currentSyncTime, false,
shareSupported, false, mStorageManager, mAccount, mContext);
false, mStorageManager, mAccount, mContext);
refreshFolderOperation.execute(mAccount, mContext);
}

View file

@ -38,7 +38,6 @@ import android.widget.PopupMenu;
import android.widget.TextView;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.resources.shares.OCShare;
@ -236,8 +235,7 @@ public class UserListAdapter extends RecyclerView.Adapter<UserListAdapter.UserVi
}
private boolean isEditOptionsAvailable(OCShare share) {
return !ShareType.FEDERATED.equals(share.getShareType())
|| AccountUtils.getServerVersion(account).isNotReshareableFederatedSupported();
return !ShareType.FEDERATED.equals(share.getShareType());
}
private boolean isReshareForbidden(OCShare share) {

View file

@ -127,24 +127,15 @@ public class CreateFolderDialogFragment
DisplayUtils.showSnackMessage(getActivity(), R.string.filename_empty);
return;
}
boolean serverWithForbiddenChars = ((ComponentsGetter)getActivity()).
getFileOperationsHelper().isVersionWithForbiddenCharacters();
if (!FileUtils.isValidName(newFolderName, serverWithForbiddenChars)) {
if (serverWithForbiddenChars) {
DisplayUtils.showSnackMessage(getActivity(), R.string.filename_forbidden_charaters_from_server);
} else {
DisplayUtils.showSnackMessage(getActivity(), R.string.filename_forbidden_characters);
}
if (!FileUtils.isValidName(newFolderName)) {
DisplayUtils.showSnackMessage(getActivity(), R.string.filename_forbidden_charaters_from_server);
return;
}
String path = mParentFolder.getRemotePath();
path += newFolderName + OCFile.PATH_SEPARATOR;
((ComponentsGetter)getActivity()).
getFileOperationsHelper().createFolder(path, false);
String path = mParentFolder.getRemotePath() + newFolderName + OCFile.PATH_SEPARATOR;
((ComponentsGetter) getActivity()).getFileOperationsHelper().createFolder(path, false);
}
}
}

View file

@ -142,23 +142,13 @@ public class RenameFileDialogFragment
return;
}
boolean serverWithForbiddenChars = ((ComponentsGetter)getActivity()).
getFileOperationsHelper().isVersionWithForbiddenCharacters();
if (!FileUtils.isValidName(newFileName, serverWithForbiddenChars)) {
if (serverWithForbiddenChars) {
DisplayUtils.showSnackMessage(getActivity(), R.string.filename_forbidden_charaters_from_server);
} else {
DisplayUtils.showSnackMessage(getActivity(), R.string.filename_forbidden_characters);
}
if (!FileUtils.isValidName(newFileName)) {
DisplayUtils.showSnackMessage(getActivity(), R.string.filename_forbidden_charaters_from_server);
return;
}
((ComponentsGetter)getActivity()).getFileOperationsHelper().
renameFile(mTargetFile, newFileName);
((ComponentsGetter) getActivity()).getFileOperationsHelper().renameFile(mTargetFile, newFileName);
}
}
}

View file

@ -35,7 +35,6 @@ import android.widget.CompoundButton;
import android.widget.TextView;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
@ -44,7 +43,6 @@ import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.SharePermissionsBuilder;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.status.OCCapability;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.ui.activity.FileActivity;
import com.owncloud.android.utils.ThemeUtils;
@ -176,8 +174,6 @@ public class EditShareFragment extends Fragment {
int sharePermissions = mShare.getPermissions();
boolean isFederated = ShareType.FEDERATED.equals(mShare.getShareType());
OwnCloudVersion serverVersion = AccountUtils.getServerVersion(mAccount);
boolean isNotReshareableFederatedSupported = serverVersion.isNotReshareableFederatedSupported();
int accentColor = ThemeUtils.primaryAccentColor(getContext());
@ -199,7 +195,7 @@ public class EditShareFragment extends Fragment {
boolean canEdit = (sharePermissions & anyUpdatePermission) > 0;
switchCompat.setChecked(canEdit);
boolean areEditOptionsAvailable = !isFederated || isNotReshareableFederatedSupported;
boolean areEditOptionsAvailable = !isFederated;
if (mFile.isFolder() && areEditOptionsAvailable) {
/// TODO change areEditOptionsAvailable in order to delete !isFederated

View file

@ -1080,12 +1080,10 @@ public class OCFileListFragment extends ExtendedListFragment implements
private void updateLayout() {
// decide grid vs list view
if (AccountUtils.getServerVersion(((FileActivity) mContainerActivity).getAccount())
.supportsRemoteThumbnails() && isGridViewPreferred(mFile)) {
if (isGridViewPreferred(mFile)) {
switchToGridView();
} else {
switchToListView();
}
invalidateActionMode();

View file

@ -47,7 +47,6 @@ import android.widget.ScrollView;
import android.widget.TextView;
import com.owncloud.android.R;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.datamodel.ThumbnailsCacheManager;
import com.owncloud.android.lib.common.utils.Log_OC;
@ -227,17 +226,8 @@ public class ShareFileFragment extends Fragment implements ShareUserListAdapter.
addUserGroupButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean shareWithUsersEnable = AccountUtils.hasSearchUsersSupport(mAccount);
if (shareWithUsersEnable) {
// Show Search Fragment
mListener.showSearchUsersAndGroups();
} else {
Snackbar.make(
getActivity().findViewById(android.R.id.content),
getString(R.string.share_sharee_unavailable),
Snackbar.LENGTH_LONG
).show();
}
// Show Search Fragment
mListener.showSearchUsersAndGroups();
}
});

View file

@ -225,7 +225,7 @@ public class ContactsBackupFragment extends FileFragment implements DatePickerDi
if (folder != null) {
RefreshFolderOperation operation = new RefreshFolderOperation(folder, System.currentTimeMillis(),
false, false, false, storageManager, account, getContext());
false, false, storageManager, account, getContext());
RemoteOperationResult result = operation.execute(account, getContext());
return result.isSuccess();

View file

@ -57,7 +57,6 @@ import com.owncloud.android.lib.resources.files.FileVersion;
import com.owncloud.android.lib.resources.shares.OCShare;
import com.owncloud.android.lib.resources.shares.ShareType;
import com.owncloud.android.lib.resources.status.OCCapability;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
import com.owncloud.android.operations.SynchronizeFileOperation;
import com.owncloud.android.services.OperationsService;
import com.owncloud.android.ui.activity.ConflictsResolveActivity;
@ -356,47 +355,36 @@ public class FileOperationsHelper {
* @param password Optional password to protect the public share.
*/
public void shareFileViaLink(OCFile file, String password) {
if (isSharedSupported()) {
if (file != null) {
mFileActivity.showLoadingDialog(mFileActivity.getString(R.string.wait_a_moment));
Intent service = new Intent(mFileActivity, OperationsService.class);
service.setAction(OperationsService.ACTION_CREATE_SHARE_VIA_LINK);
service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
if (password != null && password.length() > 0) {
service.putExtra(OperationsService.EXTRA_SHARE_PASSWORD, password);
}
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
} else {
Log_OC.e(TAG, "Trying to share a NULL OCFile");
// TODO user-level error?
if (file != null) {
mFileActivity.showLoadingDialog(mFileActivity.getString(R.string.wait_a_moment));
Intent service = new Intent(mFileActivity, OperationsService.class);
service.setAction(OperationsService.ACTION_CREATE_SHARE_VIA_LINK);
service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
if (password != null && password.length() > 0) {
service.putExtra(OperationsService.EXTRA_SHARE_PASSWORD, password);
}
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
} else {
// Show a Message
DisplayUtils.showSnackMessage(mFileActivity, R.string.share_link_no_support_share_api);
Log_OC.e(TAG, "Trying to share a NULL OCFile");
// TODO user-level error?
}
}
public void getFileWithLink(OCFile file) {
if (isSharedSupported()) {
if (file != null) {
mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
getString(R.string.wait_a_moment));
if (file != null) {
mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
getString(R.string.wait_a_moment));
Intent service = new Intent(mFileActivity, OperationsService.class);
service.setAction(OperationsService.ACTION_CREATE_SHARE_VIA_LINK);
service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
Intent service = new Intent(mFileActivity, OperationsService.class);
service.setAction(OperationsService.ACTION_CREATE_SHARE_VIA_LINK);
service.putExtra(OperationsService.EXTRA_ACCOUNT, mFileActivity.getAccount());
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());
mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(service);
} else {
Log_OC.e(TAG, "Trying to share a NULL OCFile");
}
} else {
// Show a Message
DisplayUtils.showSnackMessage(mFileActivity, R.string.share_link_no_support_share_api);
Log_OC.e(TAG, "Trying to share a NULL OCFile");
}
}
@ -450,16 +438,6 @@ public class FileOperationsHelper {
}
}
/**
* @return 'True' if the server supports the Share API
*/
public boolean isSharedSupported() {
return mFileActivity.getAccount() != null &&
AccountUtils.getServerVersion(mFileActivity.getAccount()).isSharedSupported();
}
/**
* Helper method to unshare a file publicly shared via link.
* Starts a request to do it in {@link OperationsService}
@ -492,19 +470,11 @@ public class FileOperationsHelper {
queueShareIntent(unshareService);
}
private void queueShareIntent(Intent shareIntent) {
if (isSharedSupported()) {
// Unshare the file
mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(shareIntent);
// Unshare the file
mWaitingForOpId = mFileActivity.getOperationsServiceBinder().queueNewOperation(shareIntent);
mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().
getString(R.string.wait_a_moment));
} else {
// Show a Message
DisplayUtils.showSnackMessage(mFileActivity, R.string.share_link_no_support_share_api);
}
mFileActivity.showLoadingDialog(mFileActivity.getApplicationContext().getString(R.string.wait_a_moment));
}
/**
@ -661,29 +631,13 @@ public class FileOperationsHelper {
if (hideFileListing) {
updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_PERMISSIONS, OCShare.CREATE_PERMISSION_FLAG);
} else {
if (AccountUtils.getServerVersion(mFileActivity.getAccount()).isNotReshareableFederatedSupported()) {
updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_PERMISSIONS,
OCShare.FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9);
} else {
updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_PERMISSIONS,
OCShare.FEDERATED_PERMISSIONS_FOR_FOLDER_UP_TO_OC9);
}
updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_PERMISSIONS,
OCShare.FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9);
}
queueShareIntent(updateShareIntent);
}
/**
* @return 'True' if the server supports the Search Users API
*/
public boolean isSearchUserSupportedSupported() {
if (mFileActivity.getAccount() != null) {
OwnCloudVersion serverVersion = AccountUtils.getServerVersion(mFileActivity.getAccount());
return serverVersion.isSearchUsersSupported();
}
return false;
}
public void sendShareFile(OCFile file, boolean hideNcSharingOptions) {
// Show dialog
FragmentManager fm = mFileActivity.getSupportFragmentManager();
@ -970,14 +924,6 @@ public class FileOperationsHelper {
mWaitingForOpId = waitingForOpId;
}
/**
* @return 'True' if the server doesn't need to check forbidden characters
*/
public boolean isVersionWithForbiddenCharacters() {
return mFileActivity.getAccount() != null &&
AccountUtils.getServerVersion(mFileActivity.getAccount()).isVersionWithForbiddenCharacters();
}
/**
* Starts a check of the currently stored credentials for the given account.
*

View file

@ -59,23 +59,19 @@ public class HttpStreamFetcher implements DataFetcher<InputStream> {
getClientFor(ocAccount, MainApp.getAppContext());
if (mClient != null) {
if (AccountUtils.getServerVersion(mAccount).supportsRemoteThumbnails()) {
GetMethod get = null;
try {
get = new GetMethod(mURL);
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);
if (status == HttpStatus.SC_OK) {
return get.getResponseBodyAsStream();
} else {
mClient.exhaustResponse(get.getResponseBodyAsStream());
}
} catch (Exception e) {
Log_OC.d(TAG, e.getMessage(), e);
GetMethod get;
try {
get = new GetMethod(mURL);
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);
if (status == HttpStatus.SC_OK) {
return get.getResponseBodyAsStream();
} else {
mClient.exhaustResponse(get.getResponseBodyAsStream());
}
} else {
Log_OC.d(TAG, "Server too old");
} catch (Exception e) {
Log_OC.e(TAG, e.getMessage(), e);
}
}
return null;

View file

@ -359,7 +359,6 @@
<string name="prefs_instant_upload_path_use_subfolders_title">Use subfolders</string>
<string name="prefs_instant_upload_path_use_subfolders_summary">Store in subfolders based on year and month</string>
<string name="share_link_no_support_share_api">Sharing is not enabled on your server. Please contact your admin</string>
<string name="share_link_file_no_exist">Unable to share. Please check whether the file exists</string>
<string name="share_link_file_error">An error occurred while trying to share this file or folder</string>
<string name="unshare_link_file_no_exist">Unable to unshare. Please check whether the file exists</string>

View file

@ -1,4 +1,4 @@
/**
/*
* Nextcloud Android client application
*
* Copyright (C) 2018 Edvard Holst
@ -114,11 +114,11 @@ public class ActivitiesPresenterTest {
@Test
public void loadRemoteFileFromRepositoryShowDetailUI() {
// When retrieving remote file from repository...
mPresenter.openActivity("null", mBaseActivity, true);
mPresenter.openActivity("null", mBaseActivity);
// Progress indicator is shown in view
verify(mView).setProgressIndicatorState(eq(true));
// Repository retrieves remote file
verify(mFileRepository).readRemoteFile(eq("null"), eq(mBaseActivity), eq(true),
verify(mFileRepository).readRemoteFile(eq("null"), eq(mBaseActivity),
mReadRemoteFilleCallbackCaptor.capture());
// Repository returns valid file object
mReadRemoteFilleCallbackCaptor.getValue().onFileLoaded(mOCFile);
@ -131,11 +131,11 @@ public class ActivitiesPresenterTest {
@Test
public void loadRemoteFileFromRepositoryShowEmptyFile() {
// When retrieving remote file from repository...
mPresenter.openActivity("null", mBaseActivity, true);
mPresenter.openActivity("null", mBaseActivity);
// Progress indicator is shown in view
verify(mView).setProgressIndicatorState(eq(true));
// Repository retrieves remote file
verify(mFileRepository).readRemoteFile(eq("null"), eq(mBaseActivity), eq(true),
verify(mFileRepository).readRemoteFile(eq("null"), eq(mBaseActivity),
mReadRemoteFilleCallbackCaptor.capture());
// Repository returns an valid but Null value file object.
mReadRemoteFilleCallbackCaptor.getValue().onFileLoaded(null);
@ -148,11 +148,11 @@ public class ActivitiesPresenterTest {
@Test
public void loadRemoteFileFromRepositoryShowError() {
// When retrieving remote file from repository...
mPresenter.openActivity("null", mBaseActivity, true);
mPresenter.openActivity("null", mBaseActivity);
// Progress indicator is shown in view
verify(mView).setProgressIndicatorState(eq(true));
// Repository retrieves remote file
verify(mFileRepository).readRemoteFile(eq("null"), eq(mBaseActivity), eq(true),
verify(mFileRepository).readRemoteFile(eq("null"), eq(mBaseActivity),
mReadRemoteFilleCallbackCaptor.capture());
// Repository returns valid file object
mReadRemoteFilleCallbackCaptor.getValue().onFileLoadError("error");

View file

@ -1,4 +1,4 @@
/**
/*
* Nextcloud Android client application
*
* Copyright (C) 2018 Edvard Holst
@ -57,20 +57,16 @@ public class RemoteFilesRepositoryTest {
@Test
public void readRemoteFileReturnSuccess() {
mFilesRepository.readRemoteFile("path", baseActivity, true,
mockedReadRemoteFileCallback);
verify(serviceApi).readRemoteFile(eq("path"), eq(baseActivity), eq(true),
filesServiceCallbackCaptor.capture());
mFilesRepository.readRemoteFile("path", baseActivity, mockedReadRemoteFileCallback);
verify(serviceApi).readRemoteFile(eq("path"), eq(baseActivity), filesServiceCallbackCaptor.capture());
filesServiceCallbackCaptor.getValue().onLoaded(mOCFile);
verify(mockedReadRemoteFileCallback).onFileLoaded(eq(mOCFile));
}
@Test
public void readRemoteFileReturnError() {
mFilesRepository.readRemoteFile("path", baseActivity, true,
mockedReadRemoteFileCallback);
verify(serviceApi).readRemoteFile(eq("path"), eq(baseActivity), eq(true),
filesServiceCallbackCaptor.capture());
mFilesRepository.readRemoteFile("path", baseActivity, mockedReadRemoteFileCallback);
verify(serviceApi).readRemoteFile(eq("path"), eq(baseActivity), filesServiceCallbackCaptor.capture());
filesServiceCallbackCaptor.getValue().onError("error");
verify(mockedReadRemoteFileCallback).onFileLoadError(eq("error"));
}