Merge pull request #3916 from jmue/cleanup/string_compare

unify empty string compare
This commit is contained in:
Andy Scherzinger 2019-04-30 18:14:58 +02:00 committed by GitHub
commit 0f500884cf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 138 additions and 147 deletions

View file

@ -212,7 +212,7 @@ android {
android.applicationVariants.all { variant ->
String variantName = variant.name
String capVariantName = variantName.substring(0, 1).toUpperCase() + variantName.substring(1);
String capVariantName = variantName.substring(0, 1).toUpperCase() + variantName.substring(1)
tasks.register("spotbugs${capVariantName}", SpotBugsTask) {
ignoreFailures = false
effort = "max"
@ -273,7 +273,6 @@ dependencies {
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15'
implementation 'com.github.tobiaskaminsky:qrcodescanner:0.1.2.2' // 'com.github.blikoon:QRCodeScanner:0.1.2'
implementation 'com.google.android:flexbox:1.1.0'
implementation 'org.parceler:parceler-api:1.1.12'
annotationProcessor 'org.parceler:parceler:1.1.12'
implementation('com.github.bumptech.glide:glide:3.7.0') {
@ -282,6 +281,19 @@ dependencies {
implementation 'com.caverock:androidsvg:1.3'
implementation 'androidx.annotation:annotation:1.0.2'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'org.jetbrains:annotations:17.0.0'
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.9.0'
spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.3'
implementation 'com.google.dagger:dagger:2.22.1'
implementation 'com.google.dagger:dagger-android:2.22.1'
implementation 'com.google.dagger:dagger-android-support:2.22.1'
annotationProcessor 'com.google.dagger:dagger-compiler:2.22.1'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.22.1'
compileOnly "org.projectlombok:lombok:1.18.6"
annotationProcessor "org.projectlombok:lombok:1.18.6"
// dependencies for local unit tests
testImplementation 'junit:junit:4.12'
@ -302,26 +314,13 @@ dependencies {
// Espresso core
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.1.1'
androidTestImplementation 'org.mockito:mockito-core:2.27.0'
// UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
// androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
// fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
//androidTestImplementation "com.android.support:support-annotations:${supportLibraryVersion}"
implementation 'org.jetbrains:annotations:17.0.0'
compileOnly "org.projectlombok:lombok:1.18.6"
annotationProcessor "org.projectlombok:lombok:1.18.6"
androidTestImplementation 'tools.fastlane:screengrab:1.2.0'
spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.9.0'
spotbugsPlugins 'com.mebigfatguy.fb-contrib:fb-contrib:7.4.3'
implementation 'com.google.dagger:dagger:2.22.1'
implementation 'com.google.dagger:dagger-android:2.22.1'
implementation 'com.google.dagger:dagger-android-support:2.22.1'
annotationProcessor 'com.google.dagger:dagger-compiler:2.22.1'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.22.1'
// jacocoAnt "org.jacoco:org.jacoco.ant:${jacocoVersion}"
// jacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"
// androidJacocoAgent "org.jacoco:org.jacoco.agent:${jacocoVersion}"

View file

@ -0,0 +1,59 @@
/*
* ownCloud Android client application
*
* @author David A. Velasco
* 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.util;
import android.accounts.Account;
import android.content.res.Resources;
import com.owncloud.android.MainApp;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.operations.RemoveFileOperation;
import com.owncloud.android.utils.ErrorMessageAdapter;
import org.junit.Test;
import org.junit.runner.RunWith;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import static junit.framework.TestCase.assertEquals;
@RunWith(AndroidJUnit4.class)
public class ErrorMessageAdapterIT {
private final static String PATH_TO_DELETE = "/path/to/a.file";
private final static String EXPECTED_ERROR_MESSAGE = "You are not permitted to delete this file";
private final static String ACCOUNT_TYPE = "nextcloud";
@Test
public void getErrorCauseMessageForForbiddenRemoval() {
Resources resources = InstrumentationRegistry.getInstrumentation().getTargetContext().getResources();
Account account = new Account("name", ACCOUNT_TYPE);
String errorMessage = ErrorMessageAdapter.getErrorCauseMessage(
new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN),
new RemoveFileOperation(PATH_TO_DELETE, false, account, false, MainApp.getAppContext()),
resources
);
assertEquals(EXPECTED_ERROR_MESSAGE, errorMessage);
}
}

View file

@ -1,4 +1,4 @@
package com.owncloud.android.utils;
package com.owncloud.android.util;
import com.owncloud.android.datamodel.OCFile;

View file

@ -1091,9 +1091,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
public void onOkClick() {
// this check should be unnecessary
if (mServerInfo.mVersion == null ||
!mServerInfo.mVersion.isVersionValid() ||
mServerInfo.mBaseUrl == null ||
mServerInfo.mBaseUrl.length() == 0) {
!mServerInfo.mVersion.isVersionValid() ||
TextUtils.isEmpty(mServerInfo.mBaseUrl)) {
mServerStatusIcon = R.drawable.ic_alert;
mServerStatusText = getResources().getString(R.string.auth_wtf_reenter_URL);
showServerStatus();
@ -1898,8 +1897,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
mOperationsServiceBinder.dispatchResultIfFinished((int) mWaitingForOpId, this);
}
if (!webViewLoginMethod && mHostUrlInput.getText() != null && mHostUrlInput.getText().length() > 0
&& !mServerIsChecked) {
if (!webViewLoginMethod && !TextUtils.isEmpty(mHostUrlInput.getText()) && !mServerIsChecked) {
checkOcServer();
}
}

View file

@ -22,6 +22,7 @@
package com.owncloud.android.authentication;
import android.content.Context;
import android.text.TextUtils;
import com.owncloud.android.lib.resources.status.OwnCloudVersion;
@ -64,7 +65,7 @@ public final class AuthenticatorUrlUtils {
public static String normalizeUrl(String url, boolean sslWhenUnprefixed) {
String normalizedUrl = url;
if (normalizedUrl != null && normalizedUrl.length() > 0) {
if (!TextUtils.isEmpty(normalizedUrl)) {
normalizedUrl = normalizedUrl.trim();
if (!normalizedUrl.toLowerCase(Locale.ROOT).startsWith(HTTP_PROTOCOL) &&

View file

@ -28,6 +28,8 @@ import android.content.Context;
import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.core.content.FileProvider;
import com.owncloud.android.R;
@ -115,7 +117,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
public OCFile(String path) {
resetData();
needsUpdatingWhileSaving = false;
if (path == null || path.length() <= 0 || !path.startsWith(PATH_SEPARATOR)) {
if (TextUtils.isEmpty(path) || !path.startsWith(PATH_SEPARATOR)) {
throw new IllegalArgumentException("Trying to create a OCFile with a non valid remote path: " + path);
}
remotePath = path;
@ -262,7 +264,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
* @return true if it is
*/
public boolean existsOnDevice() {
if (localPath != null && localPath.length() > 0) {
if (!TextUtils.isEmpty(localPath)) {
return new File(localPath).exists();
}
return false;
@ -283,7 +285,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
* @return A URI to the local copy of the file, or NULL if not stored in the device
*/
public Uri getStorageUri() {
if (localPath == null || localPath.length() == 0) {
if (TextUtils.isEmpty(localPath)) {
return null;
}
if (localUri == null) {
@ -297,7 +299,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
public Uri getLegacyExposedFileUri() {
if (localPath == null || localPath.length() == 0) {
if (TextUtils.isEmpty(localPath)) {
return null;
}
@ -312,7 +314,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
Partly disabled because not all apps understand paths that we get via this method for now
*/
public Uri getExposedFileUri(Context context) {
if (localPath == null || localPath.length() == 0) {
if (TextUtils.isEmpty(localPath)) {
return null;
}
if (exposedFileUri == null) {
@ -360,8 +362,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
*/
public void setFileName(String name) {
Log_OC.d(TAG, "OCFile name changing from " + remotePath);
if (name != null && name.length() > 0 && !name.contains(PATH_SEPARATOR) &&
!ROOT_PATH.equals(remotePath)) {
if (!TextUtils.isEmpty(name) && !name.contains(PATH_SEPARATOR) && !ROOT_PATH.equals(remotePath)) {
String parent = new File(this.getRemotePath()).getParent();
parent = parent.endsWith(PATH_SEPARATOR) ? parent : parent + PATH_SEPARATOR;
remotePath = parent + name;
@ -468,7 +469,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
}
public long getLocalModificationTimestamp() {
if (localPath != null && localPath.length() > 0) {
if (!TextUtils.isEmpty(localPath)) {
File f = new File(localPath);
return f.lastModified();
}
@ -479,7 +480,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
* @return 'True' if the file is hidden
*/
public boolean isHidden() {
return getFileName().length() > 0 && getFileName().charAt(0) == '.';
return !TextUtils.isEmpty(getFileName()) && getFileName().charAt(0) == '.';
}
/**
@ -492,7 +493,7 @@ public class OCFile implements Parcelable, Comparable<OCFile>, ServerFileInterfa
}
public boolean isInConflict() {
return etagInConflict != null && !"".equals(etagInConflict);
return !TextUtils.isEmpty(etagInConflict);
}
public boolean isSharedWithMe() {

View file

@ -22,6 +22,7 @@ package com.owncloud.android.operations;
import android.content.Context;
import android.net.Uri;
import android.text.TextUtils;
import com.owncloud.android.lib.common.OwnCloudClient;
import com.owncloud.android.lib.common.operations.RemoteOperation;
@ -89,8 +90,7 @@ public class DetectAuthenticationMethodOperation extends RemoteOperation {
// try to access the root folder, following redirections but not SAML SSO redirections
result = operation.execute(client);
String redirectedLocation = result.getRedirectedLocation();
while (redirectedLocation != null && redirectedLocation.length() > 0 &&
!result.isIdPRedirection()) {
while (!TextUtils.isEmpty(redirectedLocation) && !result.isIdPRedirection()) {
client.setBaseUri(Uri.parse(result.getRedirectedLocation()));
result = operation.execute(client);
redirectedLocation = result.getRedirectedLocation();

View file

@ -23,6 +23,7 @@ package com.owncloud.android.operations;
import android.accounts.Account;
import android.content.Context;
import android.text.TextUtils;
import android.webkit.MimeTypeMap;
import com.owncloud.android.datamodel.DecryptedFolderMetadata;
@ -110,7 +111,7 @@ public class DownloadFileOperation extends RemoteOperation {
public String getMimeType() {
String mimeType = file.getMimeType();
if (mimeType == null || mimeType.length() <= 0) {
if (TextUtils.isEmpty(mimeType)) {
try {
mimeType = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(

View file

@ -21,6 +21,8 @@
package com.owncloud.android.operations;
import android.text.TextUtils;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.lib.common.OwnCloudClient;
@ -157,7 +159,7 @@ public class RenameFileOperation extends SyncOperation {
*/
private boolean isValidNewName() throws IOException {
// check tricky names
if (newName == null || newName.length() <= 0 || newName.contains(File.separator)) {
if (TextUtils.isEmpty(newName) || newName.contains(File.separator)) {
return false;
}
// create a test file

View file

@ -24,6 +24,7 @@ package com.owncloud.android.operations;
import android.accounts.Account;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.files.services.FileDownloader;
@ -204,7 +205,7 @@ public class SynchronizeFileOperation extends SyncOperation {
if (mServerFile != null) {
/// check changes in server and local file
boolean serverChanged;
if (mLocalFile.getEtag() == null || mLocalFile.getEtag().length() == 0) {
if (TextUtils.isEmpty(mLocalFile.getEtag())) {
// file uploaded (null) or downloaded ("") before upgrade to version 1.8.0; check the old condition
serverChanged = mServerFile.getModificationTimestamp() !=
mLocalFile.getModificationTimestampAtLastSyncForData();

View file

@ -23,6 +23,7 @@ package com.owncloud.android.operations;
import android.accounts.Account;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import com.owncloud.android.datamodel.FileDataStorageManager;
@ -482,7 +483,7 @@ public class SynchronizeFolderOperation extends SyncOperation {
public String getFolderPath() {
String path = mLocalFolder.getStoragePath();
if (path != null && path.length() > 0) {
if (!TextUtils.isEmpty(path)) {
return path;
}
return FileStorageUtils.getDefaultSavePathFor(mAccount.name, mLocalFolder);

View file

@ -27,6 +27,7 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
import com.evernote.android.job.JobRequest;
@ -153,7 +154,7 @@ public class UploadFileOperation extends SyncOperation {
public static OCFile obtainNewOCFileToUpload(String remotePath, String localPath, String mimeType) {
// MIME type
if (mimeType == null || mimeType.length() <= 0) {
if (TextUtils.isEmpty(mimeType)) {
mimeType = MimeTypeUtil.getBestMimeTypeByFilename(localPath);
}
@ -163,7 +164,7 @@ public class UploadFileOperation extends SyncOperation {
newFile.setLastSyncDateForData(0);
// size
if (localPath != null && localPath.length() > 0) {
if (!TextUtils.isEmpty(localPath)) {
File localFile = new File(localPath);
newFile.setFileLength(localFile.length());
newFile.setLastSyncDateForData(localFile.lastModified());
@ -192,7 +193,7 @@ public class UploadFileOperation extends SyncOperation {
if (upload == null) {
throw new IllegalArgumentException("Illegal NULL file in UploadFileOperation creation");
}
if (upload.getLocalPath() == null || upload.getLocalPath().length() <= 0) {
if (TextUtils.isEmpty(upload.getLocalPath())) {
throw new IllegalArgumentException(
"Illegal file in UploadFileOperation; storage path invalid: "
+ upload.getLocalPath());

View file

@ -36,6 +36,7 @@ import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
import android.text.TextUtils;
import android.util.Pair;
import com.owncloud.android.MainApp;
@ -455,8 +456,7 @@ public class OperationsService extends Service {
);
} else {
OwnCloudCredentials credentials = null;
if (mLastTarget.mCookie != null &&
mLastTarget.mCookie.length() > 0) {
if (!TextUtils.isEmpty(mLastTarget.mCookie)) {
// just used for GetUserName
// TODO refactor to run GetUserName as AsyncTask in the context of
// AuthenticatorActivity
@ -558,7 +558,7 @@ public class OperationsService extends Service {
case ACTION_CREATE_SHARE_VIA_LINK:
remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
if (remotePath.length() > 0) {
if (!TextUtils.isEmpty(remotePath)) {
operation = new CreateShareViaLinkOperation(remotePath, password);
}
break;
@ -567,7 +567,7 @@ public class OperationsService extends Service {
remotePath = operationIntent.getStringExtra(EXTRA_REMOTE_PATH);
shareId = operationIntent.getLongExtra(EXTRA_SHARE_ID, -1);
if (remotePath != null && remotePath.length() > 0) {
if (!TextUtils.isEmpty(remotePath)) {
UpdateShareViaLinkOperation updateLinkOperation = new UpdateShareViaLinkOperation(remotePath);
password = operationIntent.getStringExtra(EXTRA_SHARE_PASSWORD);
@ -621,7 +621,7 @@ public class OperationsService extends Service {
String shareeName = operationIntent.getStringExtra(EXTRA_SHARE_WITH);
shareType = (ShareType) operationIntent.getSerializableExtra(EXTRA_SHARE_TYPE);
int permissions = operationIntent.getIntExtra(EXTRA_SHARE_PERMISSIONS, -1);
if (remotePath.length() > 0) {
if (!TextUtils.isEmpty(remotePath)) {
operation = new CreateShareWithShareeOperation(remotePath, shareeName, shareType,
permissions);
}
@ -632,7 +632,7 @@ public class OperationsService extends Service {
shareType = (ShareType) operationIntent.getSerializableExtra(EXTRA_SHARE_TYPE);
String shareWith = operationIntent.getStringExtra(EXTRA_SHARE_WITH);
if (remotePath.length() > 0) {
if (!TextUtils.isEmpty(remotePath)) {
operation = new UnshareOperation(remotePath, shareType, shareWith, this);
}
break;

View file

@ -1989,7 +1989,7 @@ public class FileDisplayActivity extends FileActivity
// Detect Failure (403) --> maybe needs password
String password = operation.getPassword();
if (result.getCode() == RemoteOperationResult.ResultCode.SHARE_FORBIDDEN &&
(password == null || password.length() == 0) &&
TextUtils.isEmpty(password) &&
getCapabilities().getFilesSharingPublicEnabled().isUnknown()) {
// Was tried without password, but not sure that it's optional.

View file

@ -26,6 +26,7 @@ import android.content.Intent;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
@ -204,7 +205,7 @@ public class PassCodeActivity extends AppCompatActivity implements Injectable {
private void onPassCodeEditTextFocusChange(final int passCodeIndex) {
for (int i = 0; i < passCodeIndex; i++) {
if ("".equals(mPassCodeEditTexts[i].getText().toString())) {
if (TextUtils.isEmpty(mPassCodeEditTexts[i].getText())) {
mPassCodeEditTexts[i].requestFocus();
break;
}

View file

@ -43,6 +43,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Parcelable;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.Menu;
@ -750,7 +751,7 @@ public class ReceiveExternalFilesActivity extends FileActivity
boolean notRoot = mParents.size() > 1;
if (actionBar != null) {
if ("".equals(current_dir)) {
if (TextUtils.isEmpty(current_dir)) {
ThemeUtils.setColoredTitle(actionBar, R.string.uploader_top_message, this);
} else {
ThemeUtils.setColoredTitle(actionBar, current_dir, this);

View file

@ -25,6 +25,7 @@ import android.app.SearchManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import com.google.android.material.snackbar.Snackbar;
import com.owncloud.android.R;
@ -348,7 +349,7 @@ public class ShareActivity extends FileActivity implements ShareFragmentListener
// Detect Failure (403) --> maybe needs password
String password = operation.getPassword();
if (result.getCode() == RemoteOperationResult.ResultCode.SHARE_FORBIDDEN &&
(password == null || password.length() == 0) &&
TextUtils.isEmpty(password) &&
getCapabilities().getFilesSharingPublicEnabled().isUnknown()) {
// Was tried without password, but not sure that it's optional.

View file

@ -24,6 +24,7 @@ import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
@ -124,7 +125,7 @@ public class CreateFolderDialogFragment
((TextView)(getDialog().findViewById(R.id.user_input)))
.getText().toString().trim();
if (newFolderName.length() <= 0) {
if (TextUtils.isEmpty(newFolderName)) {
DisplayUtils.showSnackMessage(getActivity(), R.string.filename_empty);
return;
}

View file

@ -30,6 +30,7 @@ import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
@ -139,7 +140,7 @@ public class RenameFileDialogFragment
((TextView)(getDialog().findViewById(R.id.user_input)))
.getText().toString().trim();
if (newFileName.length() <= 0) {
if (TextUtils.isEmpty(newFileName)) {
DisplayUtils.showSnackMessage(getActivity(), R.string.filename_empty);
return;
}

View file

@ -24,6 +24,7 @@ import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.PorterDuff;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -152,7 +153,7 @@ public class SharePasswordDialogFragment extends DialogFragment implements Dialo
if (which == AlertDialog.BUTTON_POSITIVE) {
String password = ((TextView) (getDialog().findViewById(R.id.share_password))).getText().toString();
if (password.length() <= 0) {
if (TextUtils.isEmpty(password)) {
DisplayUtils.showSnackMessage(
getActivity().findViewById(android.R.id.content),
R.string.share_link_empty_password

View file

@ -27,6 +27,7 @@ import android.content.Intent;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.view.LayoutInflater;
import android.view.View;
@ -203,7 +204,7 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
// Set values
setEnabled(mSyncedFolder.getEnabled());
if (mSyncedFolder.getLocalPath() != null && mSyncedFolder.getLocalPath().length() > 0) {
if (!TextUtils.isEmpty(mSyncedFolder.getLocalPath())) {
mLocalFolderPath.setText(
DisplayUtils.createTextWithSpan(
String.format(
@ -216,7 +217,7 @@ public class SyncedFolderPreferencesDialogFragment extends DialogFragment {
mLocalFolderSummary.setText(R.string.choose_local_folder);
}
if (mSyncedFolder.getLocalPath() != null && mSyncedFolder.getLocalPath().length() > 0) {
if (!TextUtils.isEmpty(mSyncedFolder.getLocalPath())) {
mRemoteFolderSummary.setText(mSyncedFolder.getRemotePath());
} else {
mRemoteFolderSummary.setText(R.string.choose_remote_folder);

View file

@ -39,6 +39,7 @@ import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.webkit.MimeTypeMap;
@ -431,7 +432,7 @@ public class FileOperationsHelper {
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) {
if (!TextUtils.isEmpty(password)) {
service.putExtra(OperationsService.EXTRA_SHARE_PASSWORD, password);
}
service.putExtra(OperationsService.EXTRA_REMOTE_PATH, file.getRemotePath());

View file

@ -32,6 +32,7 @@ import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.text.TextUtils;
import android.view.MenuItem;
import android.view.View;
@ -222,7 +223,7 @@ public class PreviewImageActivity extends FileActivity implements
// Detect Failure (403) --> maybe needs password
String password = op.getPassword();
if (result.getCode() == RemoteOperationResult.ResultCode.SHARE_FORBIDDEN &&
(password == null || password.length() == 0) &&
TextUtils.isEmpty(password) &&
getCapabilities().getFilesSharingPublicEnabled().isUnknown()) {
// Was tried without password, but not sure that it's optional.

View file

@ -24,6 +24,7 @@ import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;
import com.owncloud.android.R;
@ -43,7 +44,7 @@ public final class ClipboardUtil {
}
public static void copyToClipboard(Activity activity, String text, boolean showToast) {
if (text != null && text.length() > 0) {
if (!TextUtils.isEmpty(text)) {
try {
ClipData clip = ClipData.newPlainText(
activity.getString(

View file

@ -22,6 +22,7 @@
package com.owncloud.android.utils;
import android.content.res.Resources;
import android.text.TextUtils;
import com.owncloud.android.R;
import com.owncloud.android.lib.common.operations.RemoteOperation;
@ -77,11 +78,11 @@ public final class ErrorMessageAdapter {
) {
String message = getSpecificMessageForResultAndOperation(result, operation, res);
if (message == null || message.length() <= 0) {
if (TextUtils.isEmpty(message)) {
message = getCommonMessageForResult(result, res);
}
if (message == null || message.length() <= 0) {
if (TextUtils.isEmpty(message)) {
message = getGenericErrorMessageForOperation(operation, res);
}
@ -434,7 +435,7 @@ public final class ErrorMessageAdapter {
}
else if (result.getHttpPhrase() != null && result.getHttpPhrase().length() > 0) {
else if (!TextUtils.isEmpty(result.getHttpPhrase())) {
// last chance: error message from server
message = result.getHttpPhrase();
}

View file

@ -1,84 +0,0 @@
/*
* ownCloud Android client application
*
* @author David A. Velasco
* 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.utils;
import android.accounts.Account;
import android.content.res.Resources;
import com.owncloud.android.MainApp;
import com.owncloud.android.R;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.operations.RemoveFileOperation;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.when;
/**
* Local unit test, to be run out of Android emulator or device.
*
* At the moment, it's a sample to validate the automatic test environment, in the scope of local unit tests with
* mock Android dependencies.
*
* Don't take it as an example of completeness.
*
* See http://developer.android.com/intl/es/training/testing/unit-testing/local-unit-tests.html .
*/
@RunWith(MockitoJUnitRunner.class)
public class ErrorMessageAdapterUnitTest {
private final static String MOCK_FORBIDDEN_PERMISSIONS = "You do not have permission %s";
private final static String MOCK_TO_DELETE = "to delete this file";
private final static String PATH_TO_DELETE = "/path/to/a.file";
private final static String EXPECTED_ERROR_MESSAGE = "You do not have permission to delete this file";
private final static String ACCOUNT_TYPE = "nextcloud";
@Mock
private Resources mMockResources;
@Test
public void getErrorCauseMessageForForbiddenRemoval() {
// Given a mocked set of resources passed to the object under test...
when(mMockResources.getString(R.string.forbidden_permissions))
.thenReturn(MOCK_FORBIDDEN_PERMISSIONS);
when(mMockResources.getString(R.string.forbidden_permissions_delete))
.thenReturn(MOCK_TO_DELETE);
Account account = new Account("name", ACCOUNT_TYPE);
// ... when method under test is called ...
String errorMessage = ErrorMessageAdapter.getErrorCauseMessage(
new RemoteOperationResult(RemoteOperationResult.ResultCode.FORBIDDEN),
new RemoveFileOperation(PATH_TO_DELETE, false, account, false, MainApp.getAppContext()),
mMockResources
);
// ... then the result should be the expected one.
assertThat(errorMessage, is(EXPECTED_ERROR_MESSAGE));
}
}