From: David A. Velasco Date: Fri, 19 Jun 2015 13:36:11 +0000 (+0200) Subject: Refactored extractions of server version from AccountManager through X-Git-Tag: oc-android-1.7.2~1^2~5^2^2~3 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/51a04aa54111ce3c7b45c5ab6f073a25b3b4d985?ds=inline;hp=-c Refactored extractions of server version from AccountManager through AccountUtils; fixed line lengths and some warnings --- 51a04aa54111ce3c7b45c5ab6f073a25b3b4d985 diff --git a/src/com/owncloud/android/authentication/AccountUtils.java b/src/com/owncloud/android/authentication/AccountUtils.java index b535fc90..87766b54 100644 --- a/src/com/owncloud/android/authentication/AccountUtils.java +++ b/src/com/owncloud/android/authentication/AccountUtils.java @@ -23,7 +23,6 @@ package com.owncloud.android.authentication; import java.util.Locale; import com.owncloud.android.MainApp; -import com.owncloud.android.lib.common.OwnCloudAccount; import com.owncloud.android.lib.common.accounts.AccountTypeUtils; import com.owncloud.android.lib.common.accounts.AccountUtils.Constants; import com.owncloud.android.lib.common.utils.Log_OC; @@ -115,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) { @@ -221,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 @@ -243,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) + ); } } @@ -276,12 +278,15 @@ public class AccountUtils { * 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); - return new OwnCloudVersion(serverVersionStr); + if (serverVersionStr != null) { + serverVersion = new OwnCloudVersion(serverVersionStr); + } } - return null; + 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/fragment/FileDetailFragment.java b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java index bff9cea4..fa78039c 100644 --- a/src/com/owncloud/android/ui/fragment/FileDetailFragment.java +++ b/src/com/owncloud/android/ui/fragment/FileDetailFragment.java @@ -73,7 +73,8 @@ public class FileDetailFragment extends FileFragment implements OnClickListener /** * 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(); @@ -118,9 +119,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 +127,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 +336,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,8 +386,8 @@ 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); @@ -416,20 +412,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 +474,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 +529,6 @@ public class FileDetailFragment extends FileFragment implements OnClickListener mLastPercent = percent; } - }; + } }