Skip to content

Commit

Permalink
unify empty string compare
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Mueller <tschenser@gmx.de>
  • Loading branch information
jmue committed Apr 18, 2019
1 parent 2f23a30 commit d8b9d10
Show file tree
Hide file tree
Showing 20 changed files with 58 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,8 @@ private void hidePassword() {
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();
Expand Down Expand Up @@ -1898,8 +1897,7 @@ private void doOnResumeAndBound() {
mOperationsServiceBinder.dispatchResultIfFinished((int) mWaitingForOpId, this);
}

if (!webViewLoginMethod && mHostUrlInput.getText() != null && mHostUrlInput.getText().length() > 0
&& !mServerIsChecked) {
if (!webViewLoginMethod && !TextUtils.isEmpty(mHostUrlInput.getText()) && !mServerIsChecked) {
checkOcServer();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -64,7 +65,7 @@ public static String normalizeUrlSuffix(String url) {
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) &&
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/com/owncloud/android/datamodel/OCFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -262,7 +264,7 @@ public boolean isDown() {
* @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;
Expand All @@ -283,7 +285,7 @@ public String getStoragePath() {
* @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) {
Expand All @@ -297,7 +299,7 @@ public Uri getStorageUri() {


public Uri getLegacyExposedFileUri() {
if (localPath == null || localPath.length() == 0) {
if (TextUtils.isEmpty(localPath)) {
return null;
}

Expand All @@ -312,7 +314,7 @@ public Uri getLegacyExposedFileUri() {
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) {
Expand Down Expand Up @@ -360,8 +362,7 @@ public String getFileName() {
*/
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;
Expand Down Expand Up @@ -468,7 +469,7 @@ public void setEtagOnServer(String etag) {
}

public long getLocalModificationTimestamp() {
if (localPath != null && localPath.length() > 0) {
if (!TextUtils.isEmpty(localPath)) {
File f = new File(localPath);
return f.lastModified();
}
Expand All @@ -479,7 +480,7 @@ public long getLocalModificationTimestamp() {
* @return 'True' if the file is hidden
*/
public boolean isHidden() {
return getFileName().length() > 0 && getFileName().charAt(0) == '.';
return !TextUtils.isEmpty(getFileName()) && getFileName().charAt(0) == '.';
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

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;
Expand Down Expand Up @@ -89,8 +90,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
// 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import android.accounts.Account;
import android.content.Context;
import android.text.TextUtils;
import android.webkit.MimeTypeMap;

import com.owncloud.android.datamodel.DecryptedFolderMetadata;
Expand Down Expand Up @@ -110,7 +111,7 @@ public String getRemotePath() {

public String getMimeType() {
String mimeType = file.getMimeType();
if (mimeType == null || mimeType.length() <= 0) {
if (TextUtils.isEmpty(mimeType)) {
try {
mimeType = MimeTypeMap.getSingleton()
.getMimeTypeFromExtension(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -157,7 +159,7 @@ private void saveLocalFile() {
*/
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -204,7 +205,7 @@ protected RemoteOperationResult run(OwnCloudClient client) {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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;
Expand Down Expand Up @@ -482,7 +483,7 @@ public void cancel() {

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -163,7 +164,7 @@ public static OCFile obtainNewOCFileToUpload(String remotePath, String localPath
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());
Expand Down Expand Up @@ -192,7 +193,7 @@ public UploadFileOperation(UploadsStorageManager uploadsStorageManager,
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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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;
Expand Down Expand Up @@ -455,8 +456,7 @@ private void nextOperation() {
);
} 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
Expand Down Expand Up @@ -558,7 +558,7 @@ private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
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;
Expand All @@ -567,7 +567,7 @@ private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
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);
Expand Down Expand Up @@ -616,7 +616,7 @@ private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
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);
}
Expand All @@ -627,7 +627,7 @@ private Pair<Target, RemoteOperation> newOperation(Intent operationIntent) {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1989,7 +1989,7 @@ private void onCreateShareViaLinkOperationFinish(CreateShareViaLinkOperation ope
// 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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
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;
Expand Down Expand Up @@ -348,7 +349,7 @@ private void onCreateShareViaLinkOperationFinish(CreateShareViaLinkOperation ope
// 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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -124,7 +125,7 @@ public void onClick(DialogInterface dialog, int which) {
((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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -139,7 +140,7 @@ public void onClick(DialogInterface dialog, int which) {
((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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -152,7 +153,7 @@ public void onClick(DialogInterface dialog, int which) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand Down Expand Up @@ -203,7 +204,7 @@ private void setupDialogElements(View view) {
// Set values
setEnabled(mSyncedFolder.getEnabled());

if (mSyncedFolder.getLocalPath() != null && mSyncedFolder.getLocalPath().length() > 0) {
if (!TextUtils.isEmpty(mSyncedFolder.getLocalPath())) {
mLocalFolderPath.setText(
DisplayUtils.createTextWithSpan(
String.format(
Expand All @@ -216,7 +217,7 @@ private void setupDialogElements(View view) {
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);
Expand Down
Loading

0 comments on commit d8b9d10

Please sign in to comment.