From: masensio Date: Thu, 25 Jun 2015 11:29:50 +0000 (+0200) Subject: Merge pull request #1027 from owncloud/auto_grid_only_with_all_pictures X-Git-Tag: oc-android-1.7.2~1^2~5^2 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/51026a005868e4bd67df98a6b68e0236799b52b3?hp=b4c217b505b99d5a6053cb1d8a6b36153545e7e3 Merge pull request #1027 from owncloud/auto_grid_only_with_all_pictures Auto grid only in folders with only pictures and server with remote thumbnails support --- diff --git a/owncloud-android-library b/owncloud-android-library index 8f87ad78..f5fbca24 160000 --- a/owncloud-android-library +++ b/owncloud-android-library @@ -1 +1 @@ -Subproject commit 8f87ad78f752fd44c419d1595482247cae5d056b +Subproject commit f5fbca24becbb01660abe2a7013c1b536ea8a301 diff --git a/src/com/owncloud/android/authentication/AccountUtils.java b/src/com/owncloud/android/authentication/AccountUtils.java index 9afa819c..87766b54 100644 --- a/src/com/owncloud/android/authentication/AccountUtils.java +++ b/src/com/owncloud/android/authentication/AccountUtils.java @@ -114,7 +114,7 @@ public class AccountUtils { if (accountName != null) { Account[] ocAccounts = AccountManager.get(context).getAccountsByType( MainApp.getAccountType()); - boolean found = false; + boolean found; for (Account account : ocAccounts) { found = (account.name.equals(accountName)); if (found) { @@ -220,19 +220,20 @@ public class AccountUtils { if (isOAuth) { accountMgr.setUserData(newAccount, Constants.KEY_SUPPORTS_OAUTH2, "TRUE"); } - /* TODO - study if it's possible to run this method in a background thread to copy the authToken - if (isOAuth || isSaml) { - accountMgr.setAuthToken(newAccount, mAuthTokenType, mAuthToken); - } - */ + /* TODO - study if it's possible to run this method in a background thread to copy the authToken + if (isOAuth || isSaml) { + accountMgr.setAuthToken(newAccount, mAuthTokenType, mAuthToken); + } + */ // don't forget the account saved in preferences as the current one - if (currentAccount != null && currentAccount.name.equals(account.name)) { + if (currentAccount.name.equals(account.name)) { AccountUtils.setCurrentOwnCloudAccount(context, newAccountName); } // remove the old account - accountMgr.removeAccount(account, null, null); // will assume it succeeds, not a big deal otherwise + accountMgr.removeAccount(account, null, null); + // will assume it succeeds, not a big deal otherwise } else { // servers which base URL is in the root of their domain need no change @@ -242,7 +243,9 @@ public class AccountUtils { // at least, upgrade account version Log_OC.d(TAG, "Setting version " + ACCOUNT_VERSION + " to " + newAccountName); - accountMgr.setUserData(newAccount, Constants.KEY_OC_ACCOUNT_VERSION, Integer.toString(ACCOUNT_VERSION)); + accountMgr.setUserData( + newAccount, Constants.KEY_OC_ACCOUNT_VERSION, Integer.toString(ACCOUNT_VERSION) + ); } } @@ -267,4 +270,23 @@ public class AccountUtils { return url; } + /** + * 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 OwnCloudVersion getServerVersion(Account account) { + OwnCloudVersion serverVersion = null; + 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; + } + } diff --git a/src/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/com/owncloud/android/authentication/AuthenticatorActivity.java index e7b33979..e8f42d99 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -54,7 +54,6 @@ import android.view.MotionEvent; import android.view.View; import android.view.View.OnFocusChangeListener; import android.view.View.OnTouchListener; -import android.view.Window; import android.view.inputmethod.EditorInfo; import android.webkit.HttpAuthHandler; import android.webkit.SslErrorHandler; @@ -348,11 +347,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity if (mAccount != null) { mServerInfo.mBaseUrl = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_BASE_URL); // TODO do next in a setter for mBaseUrl - mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://"); - String ocVersion = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_VERSION); - if (ocVersion != null) { - mServerInfo.mVersion = new OwnCloudVersion(ocVersion); - } + mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://"); + mServerInfo.mVersion = AccountUtils.getServerVersion(mAccount); } else { mServerInfo.mBaseUrl = getString(R.string.server_url).trim(); mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://"); @@ -570,7 +566,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity * intended to defer the processing of the redirection caught in * {@link #onNewIntent(Intent)} until {@link #onResume()} * - * See {@link #onSaveInstanceState(Bundle)} + * See {@link super#onSaveInstanceState(Bundle)} */ @Override protected void onSaveInstanceState(Bundle outState) { @@ -1136,7 +1132,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity if(url.toLowerCase().endsWith(AccountUtils.WEBDAV_PATH_4_0_AND_LATER)){ url = url.substring(0, url.length() - AccountUtils.WEBDAV_PATH_4_0_AND_LATER.length()); } - return (url != null ? url : ""); + return url; } @@ -1717,7 +1713,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } - private void getRemoteUserNameOperation(String sessionCookie, boolean followRedirects) { + private void getRemoteUserNameOperation(String sessionCookie) { Intent getUserNameIntent = new Intent(); getUserNameIntent.setAction(OperationsService.ACTION_GET_USER_NAME); @@ -1735,7 +1731,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity if (sessionCookie != null && sessionCookie.length() > 0) { Log_OC.d(TAG, "Successful SSO - time to save the account"); mAuthToken = sessionCookie; - getRemoteUserNameOperation(sessionCookie, true); + getRemoteUserNameOperation(sessionCookie); Fragment fd = getSupportFragmentManager().findFragmentByTag(SAML_DIALOG_TAG); if (fd != null && fd instanceof DialogFragment) { Dialog d = ((DialogFragment)fd).getDialog(); @@ -1769,7 +1765,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity X509Certificate x509Certificate, SslError error, SslErrorHandler handler ) { // Show a dialog with the certificate info - SslUntrustedCertDialog dialog = null; + SslUntrustedCertDialog dialog; if (x509Certificate == null) { dialog = SslUntrustedCertDialog.newInstanceForEmptySslError(error, handler); } else { @@ -1861,8 +1857,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity doOnResumeAndBound(); - } else { - return; } } @@ -1881,8 +1875,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity /** * Create and show dialog for request authentication to the user - * @param webView - * @param handler + * @param webView Web view to emebd into the authentication dialog. + * @param handler Object responsible for catching and recovering HTTP authentication fails. */ public void createAuthenticationDialog(WebView webView, HttpAuthHandler handler) { diff --git a/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java b/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java index 7825b959..0e59a834 100644 --- a/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java +++ b/src/com/owncloud/android/datamodel/ThumbnailsCacheManager.java @@ -29,7 +29,6 @@ import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.methods.GetMethod; import android.accounts.Account; -import android.accounts.AccountManager; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Bitmap.CompressFormat; @@ -43,10 +42,10 @@ 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; -import com.owncloud.android.lib.common.accounts.AccountUtils.Constants; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.ui.adapter.DiskLruImageCache; @@ -61,8 +60,7 @@ public class ThumbnailsCacheManager { private static final String TAG = ThumbnailsCacheManager.class.getSimpleName(); private static final String CACHE_FOLDER = "thumbnailCache"; - private static final String MINOR_SERVER_VERSION_FOR_THUMBS = "7.8.0"; - + private static final Object mThumbnailsDiskCacheLock = new Object(); private static DiskLruImageCache mThumbnailCache = null; private static boolean mThumbnailCacheStarting = true; @@ -71,7 +69,6 @@ public class ThumbnailsCacheManager { private static final CompressFormat mCompressFormat = CompressFormat.JPEG; private static final int mCompressQuality = 70; private static OwnCloudClient mClient = null; - private static String mServerVersion = null; public static Bitmap mDefaultImg = BitmapFactory.decodeResource( @@ -130,10 +127,12 @@ public class ThumbnailsCacheManager { while (mThumbnailCacheStarting) { try { mThumbnailsDiskCacheLock.wait(); - } catch (InterruptedException e) {} + } catch (InterruptedException e) { + Log_OC.e(TAG, "Wait in mThumbnailsDiskCacheLock was interrupted", e); + } } if (mThumbnailCache != null) { - return (Bitmap) mThumbnailCache.getBitmap(key); + return mThumbnailCache.getBitmap(key); } } return null; @@ -167,9 +166,6 @@ public class ThumbnailsCacheManager { try { if (mAccount != null) { - AccountManager accountMgr = AccountManager.get(MainApp.getAppContext()); - - mServerVersion = accountMgr.getUserData(mAccount, Constants.KEY_OC_VERSION); OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, MainApp.getAppContext()); mClient = OwnCloudClientManagerFactory.getDefaultSingleton(). @@ -182,8 +178,7 @@ public class ThumbnailsCacheManager { thumbnail = doOCFileInBackground(); } else if (mFile instanceof File) { thumbnail = doFileInBackground(); - } else { - // do nothing + //} else { do nothing } }catch(Throwable t){ @@ -202,15 +197,15 @@ public class ThumbnailsCacheManager { bitmap = null; } - if (mImageViewReference != null && bitmap != null) { + if (bitmap != null) { final ImageView imageView = mImageViewReference.get(); final ThumbnailGenerationTask bitmapWorkerTask = getBitmapWorkerTask(imageView); - if (this == bitmapWorkerTask && imageView != null) { + if (this == bitmapWorkerTask) { String tagId = ""; if (mFile instanceof OCFile){ tagId = String.valueOf(((OCFile)mFile).getFileId()); } else if (mFile instanceof File){ - tagId = String.valueOf(((File)mFile).hashCode()); + tagId = String.valueOf(mFile.hashCode()); } if (String.valueOf(imageView.getTag()).equals(tagId)) { imageView.setImageBitmap(bitmap); @@ -247,17 +242,16 @@ public class ThumbnailsCacheManager { private int getThumbnailDimension(){ // Converts dp to pixel Resources r = MainApp.getAppContext().getResources(); - return (int) Math.round(r.getDimension(R.dimen.file_icon_size_grid)); + return Math.round(r.getDimension(R.dimen.file_icon_size_grid)); } private Bitmap doOCFileInBackground() { - Bitmap thumbnail = null; OCFile file = (OCFile)mFile; final String imageKey = String.valueOf(file.getRemoteId()); // Check disk cache in background thread - thumbnail = getBitmapFromDiskCache(imageKey); + Bitmap thumbnail = getBitmapFromDiskCache(imageKey); // Not found in disk cache if (thumbnail == null || file.needsUpdateThumbnail()) { @@ -277,19 +271,16 @@ public class ThumbnailsCacheManager { } else { // Download thumbnail from server - if (mClient != null && mServerVersion != null) { - OwnCloudVersion serverOCVersion = new OwnCloudVersion(mServerVersion); - if (serverOCVersion.compareTo( - new OwnCloudVersion(MINOR_SERVER_VERSION_FOR_THUMBS)) >= 0) { + OwnCloudVersion serverOCVersion = AccountUtils.getServerVersion(mAccount); + if (mClient != null && serverOCVersion != null) { + if (serverOCVersion.supportsRemoteThumbnails()) { try { - int status = -1; - String uri = mClient.getBaseUri() + "" + "/index.php/apps/files/api/v1/thumbnail/" + px + "/" + px + Uri.encode(file.getRemotePath(), "/"); Log_OC.d("Thumbnail", "URI: " + uri); GetMethod get = new GetMethod(uri); - status = mClient.executeMethod(get); + int status = mClient.executeMethod(get); if (status == HttpStatus.SC_OK) { // byte[] bytes = get.getResponseBody(); // Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, @@ -318,13 +309,12 @@ public class ThumbnailsCacheManager { } private Bitmap doFileInBackground() { - Bitmap thumbnail = null; File file = (File)mFile; final String imageKey = String.valueOf(file.hashCode()); // Check disk cache in background thread - thumbnail = getBitmapFromDiskCache(imageKey); + Bitmap thumbnail = getBitmapFromDiskCache(imageKey); // Not found in disk cache if (thumbnail == null) { diff --git a/src/com/owncloud/android/files/FileOperationsHelper.java b/src/com/owncloud/android/files/FileOperationsHelper.java index 5e6741bb..75fae370 100644 --- a/src/com/owncloud/android/files/FileOperationsHelper.java +++ b/src/com/owncloud/android/files/FileOperationsHelper.java @@ -24,7 +24,6 @@ package com.owncloud.android.files; import org.apache.http.protocol.HTTP; import android.accounts.Account; -import android.accounts.AccountManager; import android.content.Intent; import android.net.Uri; import android.support.v4.app.DialogFragment; @@ -32,11 +31,11 @@ import android.webkit.MimeTypeMap; import android.widget.Toast; import com.owncloud.android.R; +import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.datamodel.OCFile; import com.owncloud.android.files.services.FileDownloader.FileDownloaderBinder; import com.owncloud.android.files.services.FileUploader.FileUploaderBinder; -import com.owncloud.android.lib.common.accounts.AccountUtils.Constants; import com.owncloud.android.lib.common.network.WebdavUtils; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.status.OwnCloudVersion; @@ -70,19 +69,25 @@ public class FileOperationsHelper { Intent intentForSavedMimeType = new Intent(Intent.ACTION_VIEW); intentForSavedMimeType.setDataAndType(Uri.parse("file://"+ encodedStoragePath), file.getMimetype()); - intentForSavedMimeType.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + intentForSavedMimeType.setFlags( + Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ); Intent intentForGuessedMimeType = null; if (storagePath.lastIndexOf('.') >= 0) { - String guessedMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(storagePath.substring(storagePath.lastIndexOf('.') + 1)); + String guessedMimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension( + storagePath.substring(storagePath.lastIndexOf('.') + 1) + ); if (guessedMimeType != null && !guessedMimeType.equals(file.getMimetype())) { intentForGuessedMimeType = new Intent(Intent.ACTION_VIEW); intentForGuessedMimeType.setDataAndType(Uri.parse("file://"+ encodedStoragePath), guessedMimeType); - intentForGuessedMimeType.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION); + intentForGuessedMimeType.setFlags( + Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION + ); } } - Intent chooserIntent = null; + Intent chooserIntent; if (intentForGuessedMimeType != null) { chooserIntent = Intent.createChooser(intentForGuessedMimeType, mFileActivity.getString(R.string.actionbar_open_with)); } else { @@ -113,7 +118,9 @@ public class FileOperationsHelper { } else { // Show a Message - Toast t = Toast.makeText(mFileActivity, mFileActivity.getString(R.string.share_link_no_support_share_api), Toast.LENGTH_LONG); + Toast t = Toast.makeText( + mFileActivity, mFileActivity.getString(R.string.share_link_no_support_share_api), Toast.LENGTH_LONG + ); t.show(); } } @@ -151,10 +158,8 @@ public class FileOperationsHelper { */ public boolean isSharedSupported() { if (mFileActivity.getAccount() != null) { - AccountManager accountManager = AccountManager.get(mFileActivity); - - String version = accountManager.getUserData(mFileActivity.getAccount(), Constants.KEY_OC_VERSION); - return (new OwnCloudVersion(version)).isSharedSupported(); + OwnCloudVersion serverVersion = AccountUtils.getServerVersion(mFileActivity.getAccount()); + return (serverVersion != null && serverVersion.isSharedSupported()); } return false; } @@ -321,11 +326,8 @@ public class FileOperationsHelper { */ public boolean isVersionWithForbiddenCharacters() { if (mFileActivity.getAccount() != null) { - AccountManager accountManager = AccountManager.get(mFileActivity); - - String version = accountManager.getUserData(mFileActivity.getAccount(), - Constants.KEY_OC_VERSION); - return (new OwnCloudVersion(version)).isVersionWithForbiddenCharacters(); + OwnCloudVersion serverVersion = AccountUtils.getServerVersion(mFileActivity.getAccount()); + return (serverVersion != null && serverVersion.isVersionWithForbiddenCharacters()); } return false; } diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index 8beff92d..98ad87e2 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -48,7 +48,6 @@ import android.os.Process; import android.support.v4.app.NotificationCompat; import android.webkit.MimeTypeMap; -import com.owncloud.android.MainApp; import com.owncloud.android.R; import com.owncloud.android.authentication.AccountUtils; import com.owncloud.android.authentication.AuthenticatorActivity; @@ -58,7 +57,6 @@ import com.owncloud.android.db.DbHandler; import com.owncloud.android.lib.common.OwnCloudAccount; import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; -import com.owncloud.android.lib.common.accounts.AccountUtils.Constants; import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; @@ -118,7 +116,8 @@ public class FileUploader extends Service private Account mLastAccount = null; private FileDataStorageManager mStorageManager; - private ConcurrentMap mPendingUploads = new ConcurrentHashMap(); + private ConcurrentMap mPendingUploads = + new ConcurrentHashMap(); private UploadFileOperation mCurrentUpload = null; private NotificationManager mNotificationManager; @@ -130,7 +129,7 @@ public class FileUploader extends Service public static String getUploadFinishMessage() { - return FileUploader.class.getName().toString() + UPLOAD_FINISH_MESSAGE; + return FileUploader.class.getName() + UPLOAD_FINISH_MESSAGE; } /** @@ -230,7 +229,7 @@ public class FileUploader extends Service if (uploadType == UPLOAD_SINGLE_FILE) { if (intent.hasExtra(KEY_FILE)) { - files = new OCFile[] { (OCFile) intent.getParcelableExtra(KEY_FILE) }; + files = new OCFile[] { intent.getParcelableExtra(KEY_FILE) }; } else { localPaths = new String[] { intent.getStringExtra(KEY_LOCAL_FILE) }; @@ -283,7 +282,7 @@ public class FileUploader extends Service files = new OCFile[localPaths.length]; for (int i = 0; i < localPaths.length; i++) { files[i] = obtainNewOCFileToUpload(remotePaths[i], localPaths[i], - ((mimeTypes != null) ? mimeTypes[i] : (String) null), storageManager); + ((mimeTypes != null) ? mimeTypes[i] : null), storageManager); if (files[i] == null) { // TODO @andomaex add failure Notification return Service.START_NOT_STICKY; @@ -291,9 +290,7 @@ public class FileUploader extends Service } } - AccountManager aMgr = AccountManager.get(this); - String version = aMgr.getUserData(account, Constants.KEY_OC_VERSION); - OwnCloudVersion ocv = new OwnCloudVersion(version); + OwnCloudVersion ocv = AccountUtils.getServerVersion(account); boolean chunked = FileUploader.chunkedUploadIsSupported(ocv); AbstractList requestedUploads = new Vector(); @@ -383,7 +380,8 @@ public class FileUploader extends Service * Map of listeners that will be reported about progress of uploads from a * {@link FileUploaderBinder} instance */ - private Map mBoundListeners = new HashMap(); + private Map mBoundListeners = + new HashMap(); /** * Cancels a pending or current upload of a remote file. @@ -392,7 +390,7 @@ public class FileUploader extends Service * @param file A file in the queue of pending uploads */ public void cancel(Account account, OCFile file) { - UploadFileOperation upload = null; + UploadFileOperation upload; synchronized (mPendingUploads) { upload = mPendingUploads.remove(buildRemoteName(account, file)); } @@ -563,7 +561,7 @@ public class FileUploader extends Service notifyUploadStart(mCurrentUpload); - RemoteOperationResult uploadResult = null, grantResult = null; + RemoteOperationResult uploadResult = null, grantResult; try { /// prepare client object to send requests to the ownCloud server @@ -610,7 +608,7 @@ public class FileUploader extends Service mPendingUploads.remove(uploadKey); Log_OC.i(TAG, "Remove CurrentUploadItem from pending upload Item Map."); } - if (uploadResult.isException()) { + if (uploadResult != null && uploadResult.isException()) { // enforce the creation of a new client object for next uploads; // this grant that a new socket will be created in the future if // the current exception is due to an abrupt lose of network connection @@ -845,7 +843,7 @@ public class FileUploader extends Service int tickerId = (uploadResult.isSuccess()) ? R.string.uploader_upload_succeeded_ticker : R.string.uploader_upload_failed_ticker; - String content = null; + String content; // check credentials error boolean needsToUpdateCredentials = ( @@ -964,8 +962,8 @@ public class FileUploader extends Service /** * Checks if content provider, using the content:// scheme, returns a file with mime-type * 'application/pdf' but file has not extension - * @param localPath - * @param mimeType + * @param localPath Full path to a file in the local file system. + * @param mimeType MIME type of the file. * @return true if is needed to add the pdf file extension to the file */ private boolean isPdfFileFromContentProviderWithoutExtension(String localPath, @@ -977,7 +975,7 @@ public class FileUploader extends Service /** * Remove uploads of an account - * @param accountName + * @param accountName Name of an OC account */ private void cancelUploadForAccount(String accountName){ // this can be slow if there are many uploads :( diff --git a/src/com/owncloud/android/services/OperationsService.java b/src/com/owncloud/android/services/OperationsService.java index 82114140..7667e90a 100644 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@ -34,13 +34,13 @@ import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; import com.owncloud.android.lib.common.OwnCloudCredentials; import com.owncloud.android.lib.common.OwnCloudCredentialsFactory; -import com.owncloud.android.lib.common.accounts.AccountUtils; import com.owncloud.android.lib.common.accounts.AccountUtils.AccountNotFoundException; import com.owncloud.android.lib.common.operations.OnRemoteOperationListener; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.lib.resources.shares.ShareType; +import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.lib.resources.users.GetRemoteUserNameOperation; import com.owncloud.android.operations.common.SyncOperation; import com.owncloud.android.operations.CreateFolderOperation; @@ -354,12 +354,7 @@ public class OperationsService extends Service { return true; //Log_OC.wtf(TAG, "Sending callback later"); } else { - if (!mServiceHandler.mPendingOperations.isEmpty()) { - return true; - } else { - return false; - } - //Log_OC.wtf(TAG, "Not finished yet"); + return (!mServiceHandler.mPendingOperations.isEmpty()); } } @@ -445,9 +440,9 @@ public class OperationsService extends Service { mOwnCloudClient = OwnCloudClientManagerFactory.getDefaultSingleton(). getClientFor(ocAccount, mService); - AccountManager am = AccountManager.get(mService.getApplicationContext()); - String version = am.getUserData(mLastTarget.mAccount, - AccountUtils.Constants.KEY_OC_VERSION); + OwnCloudVersion version = com.owncloud.android.authentication.AccountUtils.getServerVersion( + mLastTarget.mAccount + ); mOwnCloudClient.setOwnCloudVersion(version); mStorageManager = new FileDataStorageManager( diff --git a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java index b1c0ffbe..7c3f6f50 100644 --- a/src/com/owncloud/android/ui/activity/FileDisplayActivity.java +++ b/src/com/owncloud/android/ui/activity/FileDisplayActivity.java @@ -49,7 +49,6 @@ import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; import android.support.v4.view.GravityCompat; -import android.support.v7.app.ActionBar; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -322,7 +321,7 @@ public class FileDisplayActivity extends HookActivity startPlaybackPosition, autoplay); } else { - secondFragment = new FileDetailFragment(file, getAccount()); + secondFragment = FileDetailFragment.newInstance(file, getAccount()); } } return secondFragment; @@ -621,10 +620,7 @@ public class FileDisplayActivity extends HookActivity String[] filePaths = data.getStringArrayExtra(UploadFilesActivity.EXTRA_CHOSEN_FILES); if (filePaths != null) { String[] remotePaths = new String[filePaths.length]; - String remotePathBase = ""; - - if (!remotePathBase.endsWith(OCFile.PATH_SEPARATOR)) - remotePathBase += OCFile.PATH_SEPARATOR; + String remotePathBase = getCurrentDir().getRemotePath(); for (int j = 0; j< remotePaths.length; j++) { remotePaths[j] = remotePathBase + (new File(filePaths[j])).getName(); } @@ -1149,7 +1145,7 @@ public class FileDisplayActivity extends HookActivity */ @Override public void showDetails(OCFile file) { - Fragment detailFragment = new FileDetailFragment(file, getAccount()); + Fragment detailFragment = FileDetailFragment.newInstance(file, getAccount()); setSecondFragment(detailFragment); updateFragmentsVisibility(true); updateActionBarTitleAndHomeButton(file); @@ -1641,7 +1637,7 @@ public class FileDisplayActivity extends HookActivity * @param file {@link OCFile} to download and preview. */ public void startDownloadForPreview(OCFile file) { - Fragment detailFragment = new FileDetailFragment(file, getAccount()); + Fragment detailFragment = FileDetailFragment.newInstance(file, getAccount()); setSecondFragment(detailFragment); mWaitingToPreview = file; requestForDownload(); diff --git a/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java b/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java index 2432380f..941654b2 100644 --- a/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java +++ b/src/com/owncloud/android/ui/fragment/ExtendedListFragment.java @@ -397,8 +397,8 @@ public class ExtendedListFragment extends Fragment mListFooterView.invalidate(); } else { -// mGridView.removeFooterView(mGridFooterView); -// mListView.removeFooterView(mListFooterView); + mGridView.removeFooterView(mGridFooterView); + mListView.removeFooterView(mListFooterView); } } diff --git a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index bff9cea4..4f099e49 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -68,12 +68,34 @@ public class FileDetailFragment extends FileFragment implements OnClickListener private static final String TAG = FileDetailFragment.class.getSimpleName(); public static final String FTAG_CONFIRMATION = "REMOVE_CONFIRMATION_FRAGMENT"; public static final String FTAG_RENAME_FILE = "RENAME_FILE_FRAGMENT"; - + + private static final String ARG_FILE = "FILE"; + private static final String ARG_ACCOUNT = "ACCOUNT"; + + + /** + * Public factory method to create new FileDetailFragment instances. + * + * When 'fileToDetail' or 'ocAccount' are null, creates a dummy layout (to use when a file wasn't tapped before). + * + * @param fileToDetail An {@link OCFile} to show in the fragment + * @param account An ownCloud account; needed to start downloads + * @return New fragment with arguments set + */ + public static FileDetailFragment newInstance(OCFile fileToDetail, Account account) { + FileDetailFragment frag = new FileDetailFragment(); + Bundle args = new Bundle(); + args.putParcelable(ARG_FILE, fileToDetail); + args.putParcelable(ARG_ACCOUNT, account); + frag.setArguments(args); + return frag; + } /** * Creates an empty details fragment. * - * It's necessary to keep a public constructor without parameters; the system uses it when tries to reinstantiate a fragment automatically. + * It's necessary to keep a public constructor without parameters; the system uses it when tries + * to reinstantiate a fragment automatically. */ public FileDetailFragment() { super(); @@ -82,22 +104,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener mProgressListener = null; } - /** - * Creates a details fragment. - * - * When 'fileToDetail' or 'ocAccount' are null, creates a dummy layout (to use when a file wasn't tapped before). - * - * @param fileToDetail An {@link OCFile} to show in the fragment - * @param ocAccount An ownCloud account; needed to start downloads - */ - public FileDetailFragment(OCFile fileToDetail, Account ocAccount) { - super(fileToDetail); - mAccount = ocAccount; - mLayout = R.layout.file_details_empty; - mProgressListener = null; - } - - + @Override public void onActivityCreated(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -108,7 +115,10 @@ public class FileDetailFragment extends FileFragment implements OnClickListener @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - + + setFile((OCFile) getArguments().getParcelable(ARG_FILE)); + mAccount = getArguments().getParcelable(ARG_ACCOUNT); + if (savedInstanceState != null) { setFile((OCFile)savedInstanceState.getParcelable(FileActivity.EXTRA_FILE)); mAccount = savedInstanceState.getParcelable(FileActivity.EXTRA_ACCOUNT); @@ -118,9 +128,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener mLayout = R.layout.file_details_fragment; } - View view = null; - view = inflater.inflate(mLayout, null); - mView = view; + mView = inflater.inflate(mLayout, null); if (mLayout == R.layout.file_details_fragment) { mView.findViewById(R.id.fdKeepInSync).setOnClickListener(this); @@ -128,9 +136,9 @@ public class FileDetailFragment extends FileFragment implements OnClickListener mProgressListener = new ProgressListener(progressBar); mView.findViewById(R.id.fdCancelBtn).setOnClickListener(this); } - + updateFileDetails(false, false); - return view; + return mView; } @Override @@ -337,10 +345,7 @@ public class FileDetailFragment extends FileFragment implements OnClickListener setFilename(file.getFileName()); setFiletype(file.getMimetype(), file.getFileName()); setFilesize(file.getFileLength()); - if(ocVersionSupportsTimeCreated()){ - setTimeCreated(file.getCreationTimestamp()); - } - + setTimeModified(file.getModificationTimestamp()); CheckBox cb = (CheckBox)getView().findViewById(R.id.fdKeepInSync); @@ -390,13 +395,13 @@ public class FileDetailFragment extends FileFragment implements OnClickListener /** * Updates the MIME type in view - * @param mimetype to set - * @param filename + * @param mimetype MIME type to set + * @param filename Name of the file, to deduce the icon to use in case the MIME type is not precise enough */ private void setFiletype(String mimetype, String filename) { TextView tv = (TextView) getView().findViewById(R.id.fdType); if (tv != null) { - String printableMimetype = DisplayUtils.convertMIMEtoPrettyPrint(mimetype);; + String printableMimetype = DisplayUtils.convertMIMEtoPrettyPrint(mimetype); tv.setText(printableMimetype); } ImageView iv = (ImageView) getView().findViewById(R.id.fdIcon); @@ -416,20 +421,6 @@ public class FileDetailFragment extends FileFragment implements OnClickListener } /** - * Updates the time that the file was created in view - * @param milliseconds Unix time to set - */ - private void setTimeCreated(long milliseconds){ - TextView tv = (TextView) getView().findViewById(R.id.fdCreated); - TextView tvLabel = (TextView) getView().findViewById(R.id.fdCreatedLabel); - if(tv != null){ - tv.setText(DisplayUtils.unixTimeToHumanReadable(milliseconds)); - tv.setVisibility(View.VISIBLE); - tvLabel.setVisibility(View.VISIBLE); - } - } - - /** * Updates the time that the file was last modified * @param milliseconds Unix time to set */ @@ -492,27 +483,6 @@ public class FileDetailFragment extends FileFragment implements OnClickListener } - /** - * In ownCloud 3.X.X and 4.X.X there is a bug that SabreDAV does not return - * the time that the file was created. There is a chance that this will - * be fixed in future versions. Use this method to check if this version of - * ownCloud has this fix. - * @return True, if ownCloud the ownCloud version is supporting creation time - */ - private boolean ocVersionSupportsTimeCreated(){ - /*if(mAccount != null){ - AccountManager accManager = (AccountManager) getActivity() - .getSystemService(Context.ACCOUNT_SERVICE); - OwnCloudVersion ocVersion = new OwnCloudVersion(accManager - .getUserData(mAccount, AccountAuthenticator.KEY_OC_VERSION)); - if(ocVersion.compareTo(new OwnCloudVersion(0x030000)) < 0) { - return true; - } - }*/ - return false; - } - - public void listenForTransferProgress() { if (mProgressListener != null) { if (mContainerActivity.getFileDownloaderBinder() != null) { @@ -568,6 +538,6 @@ public class FileDetailFragment extends FileFragment implements OnClickListener mLastPercent = percent; } - }; + } } diff --git a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java index dd8ed029..68deb031 100644 --- a/src/com/owncloud/android/ui/fragment/OCFileListFragment.java +++ b/src/com/owncloud/android/ui/fragment/OCFileListFragment.java @@ -36,10 +36,13 @@ import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; 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.files.FileMenuFilter; import com.owncloud.android.lib.common.utils.Log_OC; +import com.owncloud.android.lib.resources.status.OwnCloudVersion; +import com.owncloud.android.ui.activity.FileActivity; import com.owncloud.android.ui.activity.FileDisplayActivity; import com.owncloud.android.ui.activity.FolderPickerActivity; import com.owncloud.android.ui.activity.OnEnforceableRefreshListener; @@ -54,7 +57,7 @@ import com.owncloud.android.utils.FileStorageUtils; /** * A Fragment that lists all files and folders in a given path. * - * TODO refactorize to get rid of direct dependency on FileDisplayActivity + * TODO refactor to get rid of direct dependency on FileDisplayActivity */ public class OCFileListFragment extends ExtendedListFragment { @@ -68,8 +71,6 @@ public class OCFileListFragment extends ExtendedListFragment { private static final String KEY_FILE = MY_PACKAGE + ".extra.FILE"; - private final static Double THUMBNAIL_THRESHOLD = 0.5; - private FileFragment.ContainerActivity mContainerActivity; private OCFile mFile = null; @@ -429,7 +430,10 @@ public class OCFileListFragment extends ExtendedListFragment { setFooterText(generateFooterText(filesCount, foldersCount)); // decide grid vs list view - if (((double)imagesCount / (double)filesCount) >= THUMBNAIL_THRESHOLD) { + OwnCloudVersion version = AccountUtils.getServerVersion( + ((FileActivity)mContainerActivity).getAccount()); + if (version != null && version.supportsRemoteThumbnails() && + imagesCount > 0 && imagesCount == filesCount) { switchToGridView(); } else { switchToListView();