remove check for older version (<11)

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2018-02-15 07:24:22 +01:00 committed by AndyScherzinger
parent 699af02257
commit a3e59c4352
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
16 changed files with 354 additions and 446 deletions

View file

@ -208,9 +208,9 @@ dependencies {
// dependencies for app building
implementation 'com.android.support:multidex:1.0.3'
// implementation project('nextcloud-android-library')
genericImplementation "com.github.nextcloud:android-library:master-SNAPSHOT"
gplayImplementation "com.github.nextcloud:android-library:master-SNAPSHOT"
versionDevImplementation 'com.github.nextcloud:android-library:master-SNAPSHOT' // use always latest master
genericImplementation "com.github.nextcloud:android-library:removeCheckForOlderVersions-SNAPSHOT"
gplayImplementation "com.github.nextcloud:android-library:removeCheckForOlderVersions-SNAPSHOT"
versionDevImplementation 'com.github.nextcloud:android-library:removeCheckForOlderVersions-SNAPSHOT' // use always latest master
implementation "com.android.support:support-v4:${supportLibraryVersion}"
implementation "com.android.support:design:${supportLibraryVersion}"
implementation 'com.jakewharton:disklrucache:2.0.2'

View file

@ -1,221 +1,221 @@
/*
* 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 hasSearchUsersSupport(Account account) {
return getServerVersion(account).isSearchUsersSupported();
}
public static boolean hasSearchSupport(Account account) {
return getServerVersion(account).isSearchSupported();
}
}

View file

@ -22,6 +22,7 @@
package com.owncloud.android.datamodel;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
@ -286,45 +287,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 +543,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
@ -565,10 +560,10 @@ public class ThumbnailsCacheManager {
getMethod = new GetMethod(uri);
getMethod.setRequestHeader("Cookie",
"nc_sameSiteCookielax=true;nc_sameSiteCookiestrict=true");
getMethod.setRequestHeader(RemoteOperation.OCS_API_HEADER,
RemoteOperation.OCS_API_HEADER_VALUE);
int status = mClient.executeMethod(getMethod);
if (status == HttpStatus.SC_OK) {
InputStream inputStream = getMethod.getResponseBodyAsStream();
@ -577,7 +572,7 @@ public class ThumbnailsCacheManager {
} else {
mClient.exhaustResponse(getMethod.getResponseBodyAsStream());
}
// Handle PNG
if (file.getMimeType().equalsIgnoreCase(PNG_MIMETYPE)) {
thumbnail = handlePNG(thumbnail, pxW, pxH);
@ -588,9 +583,6 @@ public class ThumbnailsCacheManager {
if (getMethod != null) {
getMethod.releaseConnection();
}
}
} else {
Log_OC.d(TAG, "Server too old");
}
}
@ -865,58 +857,56 @@ 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)
// 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);
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();
// 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);
}
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);
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;
// 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;
case HttpStatus.SC_NOT_MODIFIED:
// old avatar
avatar = getBitmapFromDiskCache(avatarKey);
mClient.exhaustResponse(get.getResponseBodyAsStream());
break;
default:
// everything else
mClient.exhaustResponse(get.getResponseBodyAsStream());
break;
default:
// everything else
mClient.exhaustResponse(get.getResponseBodyAsStream());
break;
}
} catch (Exception e) {

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,7 @@ public class FileUploader extends Service
account,
files[i],
ocUpload,
chunked,
true,
forceOverwrite,
localAction,
this,
@ -692,7 +691,7 @@ public class FileUploader extends Service
account,
null,
upload,
chunked,
true,
upload.isForceOverwrite(), // TODO should be read from DB?
upload.getLocalAction(), // TODO should be read from DB?
this,

View file

@ -237,14 +237,10 @@ public class RefreshFolderOperation extends RemoteOperation {
UpdateOCVersionOperation update = new UpdateOCVersionOperation(mAccount, mContext);
RemoteOperationResult result = update.execute(client);
if (result.isSuccess()) {
mIsShareSupported = update.getOCVersion().isSharedSupported();
mIsShareSupported = true;
// Update Capabilities for this account
if (update.getOCVersion().isVersionWithCapabilitiesAPI()) {
updateCapabilities();
} else {
Log_OC.d(TAG, "Capabilities API disabled");
}
updateCapabilities();
}
}

View file

@ -239,7 +239,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
if (!result.isSuccess()) {
mLastFailedResult = result;
} else {
mIsShareSupported = update.getOCVersion().isSharedSupported();
mIsShareSupported = true;
}
}

View file

@ -2201,7 +2201,7 @@ public class FileDisplayActivity extends HookActivity
RemoteOperation synchFolderOp = new RefreshFolderOperation(folder,
currentSyncTime,
false,
getFileOperationsHelper().isSharedSupported(),
true,
ignoreETag,
getStorageManager(),
getAccount(),

View file

@ -250,7 +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(),
true, ignoreETag, getStorageManager(), getAccount(),
getApplicationContext());
refreshFolderOperation.execute(getAccount(), this, null, null);

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

@ -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

@ -85,7 +85,6 @@ import com.owncloud.android.ui.activity.FolderPickerActivity;
import com.owncloud.android.ui.activity.OnEnforceableRefreshListener;
import com.owncloud.android.ui.activity.ToolbarActivity;
import com.owncloud.android.ui.activity.UploadFilesActivity;
import com.owncloud.android.ui.adapter.OCFileListAdapter;
import com.owncloud.android.ui.dialog.ConfirmationDialogFragment;
import com.owncloud.android.ui.dialog.CreateFolderDialogFragment;
import com.owncloud.android.ui.dialog.RemoveFilesDialogFragment;
@ -1079,13 +1078,14 @@ public class OCFileListFragment extends ExtendedListFragment implements
}
private void updateLayout() {
// decide grid vs list view
if (AccountUtils.getServerVersion(((FileActivity) mContainerActivity).getAccount())
.supportsRemoteThumbnails() && isGridViewPreferred(mFile)) {
switchToGridView();
} else {
switchToListView();
if (!mJustFolders) {
updateFooter();
// decide grid vs list view
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,7 +226,7 @@ public class ShareFileFragment extends Fragment implements ShareUserListAdapter.
addUserGroupButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean shareWithUsersEnable = AccountUtils.hasSearchUsersSupport(mAccount);
boolean shareWithUsersEnable = true;
if (shareWithUsersEnable) {
// Show Search Fragment
mListener.showSearchUsersAndGroups();

View file

@ -356,47 +356,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");
}
}
@ -492,19 +481,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 +642,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 +935,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.d(TAG, e.getMessage(), e);
}
}
return null;