Reformat code to apply to project style guide

This commit is contained in:
Julian Raufelder 2021-03-26 16:49:58 +01:00 committed by Manuel Jenny
parent 483a831618
commit 9843e77c3f
No known key found for this signature in database
GPG Key ID: 1C80FE62B2BEAA18
9 changed files with 122 additions and 124 deletions

View File

@ -5,42 +5,97 @@ import java.util.HashSet;
public class PCloudApiError {
public static final HashSet<Integer> ignoreExistsSet = new HashSet<>( //
Arrays.asList( //
PCloudApiErrorCodes.COMPONENT_OF_PARENT_DIRECTORY_DOES_NOT_EXIST.getValue(), //
PCloudApiErrorCodes.FILE_NOT_FOUND.getValue(), //
PCloudApiErrorCodes.FILE_OR_FOLDER_NOT_FOUND.getValue(), //
PCloudApiErrorCodes.DIRECTORY_DOES_NOT_EXIST.getValue(), //
PCloudApiErrorCodes.INVALID_FILE_OR_FOLDER_NAME.getValue() //
));
public static final HashSet<Integer> ignoreMoveSet = new HashSet<>( //
Arrays.asList( //
PCloudApiErrorCodes.FILE_OR_FOLDER_ALREADY_EXISTS.getValue(), //
PCloudApiErrorCodes.COMPONENT_OF_PARENT_DIRECTORY_DOES_NOT_EXIST.getValue(), //
PCloudApiErrorCodes.FILE_NOT_FOUND.getValue(), //
PCloudApiErrorCodes.FILE_OR_FOLDER_NOT_FOUND.getValue(), //
PCloudApiErrorCodes.DIRECTORY_DOES_NOT_EXIST.getValue() //
) //
);
public static boolean isCloudNodeAlreadyExistsException(int errorCode) {
return errorCode == PCloudApiErrorCodes.FILE_OR_FOLDER_ALREADY_EXISTS.getValue();
}
public static boolean isFatalBackendException(int errorCode) {
return errorCode == PCloudApiErrorCodes.INTERNAL_UPLOAD_ERROR.getValue() //
|| errorCode == PCloudApiErrorCodes.INTERNAL_UPLOAD_ERROR.getValue() //
|| errorCode == PCloudApiErrorCodes.UPLOAD_NOT_FOUND.getValue() //
|| errorCode == PCloudApiErrorCodes.TRANSFER_NOT_FOUND.getValue();
}
public static boolean isForbiddenException(int errorCode) {
return errorCode == PCloudApiErrorCodes.ACCESS_DENIED.getValue();
}
public static boolean isNetworkConnectionException(int errorCode) {
return errorCode == PCloudApiErrorCodes.CONNECTION_BROKE.getValue();
}
public static boolean isNoSuchCloudFileException(int errorCode) {
return errorCode == PCloudApiErrorCodes.COMPONENT_OF_PARENT_DIRECTORY_DOES_NOT_EXIST.getValue() //
|| errorCode == PCloudApiErrorCodes.FILE_NOT_FOUND.getValue() //
|| errorCode == PCloudApiErrorCodes.FILE_OR_FOLDER_NOT_FOUND.getValue() //
|| errorCode == PCloudApiErrorCodes.DIRECTORY_DOES_NOT_EXIST.getValue();
}
public static boolean isWrongCredentialsException(int errorCode) {
return errorCode == PCloudApiErrorCodes.INVALID_ACCESS_TOKEN.getValue() //
|| errorCode == PCloudApiErrorCodes.ACCESS_TOKEN_REVOKED.getValue();
}
public static boolean isUnauthorizedException(int errorCode) {
return errorCode == PCloudApiErrorCodes.LOGIN_FAILED.getValue() //
|| errorCode == PCloudApiErrorCodes.LOGIN_REQUIRED.getValue() //
|| errorCode == PCloudApiErrorCodes.TOO_MANY_LOGIN_TRIES_FROM_IP.getValue();
}
public enum PCloudApiErrorCodes {
LOGIN_REQUIRED(1000),
NO_FULL_PATH_OR_NAME_FOLDER_ID_PROVIDED(1001),
NO_FULL_PATH_OR_FOLDER_ID_PROVIDED(1002),
NO_FILE_ID_OR_PATH_PROVIDED(1004),
INVALID_DATE_TIME_FORMAT(1013),
NO_DESTINATION_PROVIDED(1016),
INVALID_FOLDER_ID(1017),
INVALID_DESTINATION(1037),
PROVIDE_URL(1040),
UPLOAD_NOT_FOUND(1900),
TRANSFER_NOT_FOUND(1902),
LOGIN_FAILED(2000),
INVALID_FILE_OR_FOLDER_NAME(2001),
COMPONENT_OF_PARENT_DIRECTORY_DOES_NOT_EXIST(2002),
ACCESS_DENIED(2003),
FILE_OR_FOLDER_ALREADY_EXISTS(2004),
DIRECTORY_DOES_NOT_EXIST(2005),
FOLDER_NOT_EMPTY(2006),
CANNOT_DELETE_ROOT_FOLDER(2007),
USER_OVER_QUOTA(2008),
FILE_NOT_FOUND(2009),
INVALID_PATH(2010),
SHARED_FOLDER_IN_SHARED_FOLDER(2023),
ACTIVE_SHARES_OR_SHAREREQUESTS_PRESENT(2028),
CONNECTION_BROKE(2041),
CANNOT_RENAME_ROOT_FOLDER(2042),
CANNOT_MOVE_FOLDER_INTO_SUBFOLDER_OF_ITSELF(2043),
FILE_OR_FOLDER_NOT_FOUND(2055),
NO_FILE_UPLOAD_DETECTED(2088),
INVALID_ACCESS_TOKEN(2094),
ACCESS_TOKEN_REVOKED(2095),
TRANSFER_OVER_QUOTA(2097),
TARGET_FOLDER_DOES_NOT_EXIST(2208),
TOO_MANY_LOGIN_TRIES_FROM_IP(4000),
INTERNAL_ERROR(5000),
LOGIN_REQUIRED(1000), //
NO_FULL_PATH_OR_NAME_FOLDER_ID_PROVIDED(1001), //
NO_FULL_PATH_OR_FOLDER_ID_PROVIDED(1002), //
NO_FILE_ID_OR_PATH_PROVIDED(1004), //
INVALID_DATE_TIME_FORMAT(1013), //
NO_DESTINATION_PROVIDED(1016), //
INVALID_FOLDER_ID(1017), //
INVALID_DESTINATION(1037), //
PROVIDE_URL(1040), //
UPLOAD_NOT_FOUND(1900), //
TRANSFER_NOT_FOUND(1902), //
LOGIN_FAILED(2000), //
INVALID_FILE_OR_FOLDER_NAME(2001), //
COMPONENT_OF_PARENT_DIRECTORY_DOES_NOT_EXIST(2002), //
ACCESS_DENIED(2003), //
FILE_OR_FOLDER_ALREADY_EXISTS(2004), //
DIRECTORY_DOES_NOT_EXIST(2005), //
FOLDER_NOT_EMPTY(2006), //
CANNOT_DELETE_ROOT_FOLDER(2007), //
USER_OVER_QUOTA(2008), //
FILE_NOT_FOUND(2009), //
INVALID_PATH(2010), //
SHARED_FOLDER_IN_SHARED_FOLDER(2023), //
ACTIVE_SHARES_OR_SHAREREQUESTS_PRESENT(2028), //
CONNECTION_BROKE(2041), //
CANNOT_RENAME_ROOT_FOLDER(2042), //
CANNOT_MOVE_FOLDER_INTO_SUBFOLDER_OF_ITSELF(2043), //
FILE_OR_FOLDER_NOT_FOUND(2055), //
NO_FILE_UPLOAD_DETECTED(2088), //
INVALID_ACCESS_TOKEN(2094), //
ACCESS_TOKEN_REVOKED(2095), //
TRANSFER_OVER_QUOTA(2097), //
TARGET_FOLDER_DOES_NOT_EXIST(2208), //
TOO_MANY_LOGIN_TRIES_FROM_IP(4000), //
INTERNAL_ERROR(5000), //
INTERNAL_UPLOAD_ERROR(5001);
private final int value;
@ -54,61 +109,4 @@ public class PCloudApiError {
}
}
public static final HashSet<Integer> ignoreExistsSet = new HashSet<>(
Arrays.asList(
PCloudApiErrorCodes.COMPONENT_OF_PARENT_DIRECTORY_DOES_NOT_EXIST.getValue(),
PCloudApiErrorCodes.FILE_NOT_FOUND.getValue(),
PCloudApiErrorCodes.FILE_OR_FOLDER_NOT_FOUND.getValue(),
PCloudApiErrorCodes.DIRECTORY_DOES_NOT_EXIST.getValue(),
PCloudApiErrorCodes.INVALID_FILE_OR_FOLDER_NAME.getValue()
)
);
public static final HashSet<Integer> ignoreMoveSet = new HashSet<>(
Arrays.asList(
PCloudApiErrorCodes.FILE_OR_FOLDER_ALREADY_EXISTS.getValue(),
PCloudApiErrorCodes.COMPONENT_OF_PARENT_DIRECTORY_DOES_NOT_EXIST.getValue(),
PCloudApiErrorCodes.FILE_NOT_FOUND.getValue(),
PCloudApiErrorCodes.FILE_OR_FOLDER_NOT_FOUND.getValue(),
PCloudApiErrorCodes.DIRECTORY_DOES_NOT_EXIST.getValue()
)
);
public static boolean isCloudNodeAlreadyExistsException(int errorCode) {
return errorCode == PCloudApiErrorCodes.FILE_OR_FOLDER_ALREADY_EXISTS.getValue();
}
public static boolean isFatalBackendException(int errorCode) {
return errorCode == PCloudApiErrorCodes.INTERNAL_UPLOAD_ERROR.getValue()
|| errorCode == PCloudApiErrorCodes.INTERNAL_UPLOAD_ERROR.getValue()
|| errorCode == PCloudApiErrorCodes.UPLOAD_NOT_FOUND.getValue()
|| errorCode == PCloudApiErrorCodes.TRANSFER_NOT_FOUND.getValue();
}
public static boolean isForbiddenException(int errorCode) {
return errorCode == PCloudApiErrorCodes.ACCESS_DENIED.getValue();
}
public static boolean isNetworkConnectionException(int errorCode) {
return errorCode == PCloudApiErrorCodes.CONNECTION_BROKE.getValue();
}
public static boolean isNoSuchCloudFileException(int errorCode) {
return errorCode == PCloudApiErrorCodes.COMPONENT_OF_PARENT_DIRECTORY_DOES_NOT_EXIST.getValue()
|| errorCode == PCloudApiErrorCodes.FILE_NOT_FOUND.getValue()
|| errorCode == PCloudApiErrorCodes.FILE_OR_FOLDER_NOT_FOUND.getValue()
|| errorCode == PCloudApiErrorCodes.DIRECTORY_DOES_NOT_EXIST.getValue();
}
public static boolean isWrongCredentialsException(int errorCode) {
return errorCode == PCloudApiErrorCodes.INVALID_ACCESS_TOKEN.getValue()
|| errorCode == PCloudApiErrorCodes.ACCESS_TOKEN_REVOKED.getValue();
}
public static boolean isUnauthorizedException(int errorCode) {
return errorCode == PCloudApiErrorCodes.LOGIN_FAILED.getValue()
|| errorCode == PCloudApiErrorCodes.LOGIN_REQUIRED.getValue()
|| errorCode == PCloudApiErrorCodes.TOO_MANY_LOGIN_TRIES_FROM_IP.getValue();
}
}
}

View File

@ -47,8 +47,8 @@ class PCloudContentRepository extends InterceptingCloudContentRepository<PCloud,
private void throwWrongCredentialsExceptionIfRequired(Exception e) {
if (e instanceof ApiError) {
int errorCode = ((ApiError)e).errorCode();
if (errorCode == PCloudApiError.PCloudApiErrorCodes.INVALID_ACCESS_TOKEN.getValue()
int errorCode = ((ApiError) e).errorCode();
if (errorCode == PCloudApiError.PCloudApiErrorCodes.INVALID_ACCESS_TOKEN.getValue() //
|| errorCode == PCloudApiError.PCloudApiErrorCodes.ACCESS_TOKEN_REVOKED.getValue()) {
throw new WrongCredentialsException(cloud);
}
@ -71,7 +71,7 @@ class PCloudContentRepository extends InterceptingCloudContentRepository<PCloud,
public PCloudFolder resolve(PCloud cloud, String path) throws BackendException {
try {
return this.cloud.resolve(path);
} catch(IOException ex) {
} catch (IOException ex) {
throw new FatalBackendException(ex);
}
}
@ -80,7 +80,7 @@ class PCloudContentRepository extends InterceptingCloudContentRepository<PCloud,
public PCloudFile file(PCloudFolder parent, String name) throws BackendException {
try {
return cloud.file(parent, name);
} catch(IOException ex) {
} catch (IOException ex) {
throw new FatalBackendException(ex);
}
}
@ -89,7 +89,7 @@ class PCloudContentRepository extends InterceptingCloudContentRepository<PCloud,
public PCloudFile file(PCloudFolder parent, String name, Optional<Long> size) throws BackendException {
try {
return cloud.file(parent, name, size);
} catch(IOException ex) {
} catch (IOException ex) {
throw new FatalBackendException(ex);
}
}
@ -98,7 +98,7 @@ class PCloudContentRepository extends InterceptingCloudContentRepository<PCloud,
public PCloudFolder folder(PCloudFolder parent, String name) throws BackendException {
try {
return cloud.folder(parent, name);
} catch(IOException ex) {
} catch (IOException ex) {
throw new FatalBackendException(ex);
}
}

View File

@ -40,7 +40,6 @@ import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@ -132,13 +131,13 @@ class PCloudImpl {
result.add(PCloudNodeFactory.from(folder, metadata));
}
return result;
} catch(ApiError ex) {
} catch (ApiError ex) {
handleApiError(ex, folder.getName());
throw new FatalBackendException(ex);
}
}
public PCloudFolder create(PCloudFolder folder) throws IOException, BackendException {
public PCloudFolder create(PCloudFolder folder) throws IOException, BackendException {
if (!exists(folder.getParent())) {
folder = new PCloudFolder( //
create(folder.getParent()), //
@ -168,7 +167,7 @@ class PCloudImpl {
} else {
return PCloudNodeFactory.from(target.getParent(), client().moveFile(source.getPath(), target.getPath()).execute());
}
} catch(ApiError ex) {
} catch (ApiError ex) {
if (PCloudApiError.isCloudNodeAlreadyExistsException(ex.errorCode())) {
throw new CloudNodeAlreadyExistsException(target.getName());
} else if (PCloudApiError.isNoSuchCloudFileException(ex.errorCode())) {
@ -180,8 +179,7 @@ class PCloudImpl {
}
}
public PCloudFile write(PCloudFile file, DataSource data, final ProgressAware<UploadState> progressAware, boolean replace, long size)
throws IOException, BackendException {
public PCloudFile write(PCloudFile file, DataSource data, final ProgressAware<UploadState> progressAware, boolean replace, long size) throws IOException, BackendException {
if (!replace && exists(file)) {
throw new CloudNodeAlreadyExistsException("CloudNode already exists and replace is false");
}
@ -202,11 +200,11 @@ class PCloudImpl {
private RemoteFile uploadFile(final PCloudFile file, DataSource data, final ProgressAware<UploadState> progressAware, UploadOptions uploadOptions, final long size) //
throws IOException, BackendException {
ProgressListener listener = (done, total) -> progressAware.onProgress( //
progress(UploadState.upload(file)) //
.between(0) //
.and(size) //
.withValue(done));
ProgressListener listener = (done, total) -> progressAware.onProgress( //
progress(UploadState.upload(file)) //
.between(0) //
.and(size) //
.withValue(done));
com.pcloud.sdk.DataSource pCloudDataSource = new com.pcloud.sdk.DataSource() {
@Override
@ -244,7 +242,7 @@ class PCloudImpl {
try {
remoteFile = client().loadFile(file.getPath()).execute().asFile();
cacheKey = Optional.of(remoteFile.fileId() + remoteFile.hash());
} catch(ApiError ex) {
} catch (ApiError ex) {
handleApiError(ex, file.getName());
}
@ -288,7 +286,7 @@ class PCloudImpl {
};
client().download(fileLink, sink, listener).execute();
} catch(ApiError ex) {
} catch (ApiError ex) {
handleApiError(ex, file.getName());
}
@ -311,7 +309,7 @@ class PCloudImpl {
client() //
.deleteFile(node.getPath()).execute();
}
} catch(ApiError ex) {
} catch (ApiError ex) {
handleApiError(ex, node.getName());
}
}
@ -322,7 +320,7 @@ class PCloudImpl {
.getUserInfo() //
.execute();
return currentAccount.email();
} catch(ApiError ex) {
} catch (ApiError ex) {
handleApiError(ex);
throw new FatalBackendException(ex);
}
@ -350,11 +348,11 @@ class PCloudImpl {
}
private void handleApiError(ApiError ex, Set<Integer> errorCodes, String name) throws BackendException {
if (errorCodes == null || !errorCodes.contains(ex.errorCode())) {
if (errorCodes == null || !errorCodes.contains(ex.errorCode())) {
int errorCode = ex.errorCode();
if (PCloudApiError.isCloudNodeAlreadyExistsException(errorCode)) {
throw new CloudNodeAlreadyExistsException(name);
} else if (PCloudApiError.isForbiddenException(errorCode)){
} else if (PCloudApiError.isForbiddenException(errorCode)) {
throw new ForbiddenException();
} else if (PCloudApiError.isNetworkConnectionException(errorCode)) {
throw new NetworkConnectionException(ex);

View File

@ -17,7 +17,7 @@ internal class Upgrade2To3 @Inject constructor(private val context: Context) : D
.columns(listOf("ACCESS_TOKEN"))
.where("TYPE", Sql.eq("DROPBOX"))
.executeOn(db).use {
if(it.moveToFirst()) {
if (it.moveToFirst()) {
Sql.update("CLOUD_ENTITY")
.set("ACCESS_TOKEN", Sql.toString(encrypt(it.getString(it.getColumnIndex("ACCESS_TOKEN")))))
.where("TYPE", Sql.eq("DROPBOX"));

View File

@ -182,7 +182,9 @@ public class VaultEntity extends DatabaseEntity {
this.position = position;
}
/** called by internal mechanisms, do not call yourself. */
/**
* called by internal mechanisms, do not call yourself.
*/
@Generated(hash = 674742652)
public void __setDaoSession(DaoSession daoSession) {
this.daoSession = daoSession;

View File

@ -4,10 +4,10 @@ import org.cryptomator.data.db.entities.CloudEntity;
import org.cryptomator.domain.Cloud;
import org.cryptomator.domain.CloudType;
import org.cryptomator.domain.DropboxCloud;
import org.cryptomator.domain.PCloud;
import org.cryptomator.domain.GoogleDriveCloud;
import org.cryptomator.domain.LocalStorageCloud;
import org.cryptomator.domain.OnedriveCloud;
import org.cryptomator.domain.PCloud;
import org.cryptomator.domain.WebDavCloud;
import javax.inject.Inject;

View File

@ -4,7 +4,6 @@ import android.content.ActivityNotFoundException
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.util.Log
import android.widget.Toast
import androidx.annotation.RequiresApi
import com.pcloud.sdk.AuthorizationActivity
@ -228,7 +227,8 @@ class CloudConnectionListPresenter @Inject constructor( //
override fun onSuccess(clouds: List<Cloud>) {
clouds.firstOrNull {
(it as PCloud).username() == cloud.username()
}?.let { it as PCloud
}?.let {
it as PCloud
saveCloud(PCloud.aCopyOf(it) //
.withUrl(cloud.url())
.withAccessToken(cloud.accessToken())

View File

@ -207,7 +207,7 @@ class ImagePreviewActivity : BaseActivity(), ImagePreviewView, ConfirmDeleteClou
presenter.pageIndexes.size.let {
when {
it == 0 -> {
showMessage(getString(R.string.dialog_no_more_images_to_display ))
showMessage(getString(R.string.dialog_no_more_images_to_display))
finish()
}
it > index -> updateTitle(index)

View File

@ -74,8 +74,8 @@ internal constructor(context: Context) : RecyclerViewBaseAdapter<CloudModel, Clo
}
private fun bindPCloudModel(cloudModel: PCloudModel) {
itemView.cloudText.text = cloudModel.username()
itemView.cloudSubText.visibility = View.GONE
itemView.cloudText.text = cloudModel.username()
itemView.cloudSubText.visibility = View.GONE
}
private fun bindLocalStorageCloudModel(cloudModel: LocalStorageModel) {