Skip to content

Commit

Permalink
style: consistent braces on when statements
Browse files Browse the repository at this point in the history
  • Loading branch information
JuancaG05 committed Jan 28, 2025
1 parent 025440b commit 6b7df4e
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,11 @@ fun Throwable.parseError(
is CopyIntoDescendantException -> resources.getString(R.string.copy_file_invalid_into_descendent)
is CopyIntoSameFolderException -> resources.getString(R.string.copy_file_invalid_overwrite)
is FileAlreadyExistsException -> resources.getString(R.string.file_already_exists)
is FileNameException -> {
val stringId = when (this.type) {
is FileNameException -> resources.getString(when (this.type) {
FileNameException.FileNameExceptionType.FILE_NAME_EMPTY -> R.string.filename_empty
FileNameException.FileNameExceptionType.FILE_NAME_FORBIDDEN_CHARACTERS -> R.string.filename_forbidden_characters_from_server
FileNameException.FileNameExceptionType.FILE_NAME_TOO_LONG -> R.string.filename_too_long
}
resources.getString(stringId)
}
})
is FileNotFoundException -> resources.getString(R.string.common_not_found)
is ForbiddenException -> resources.getString(R.string.uploads_view_upload_status_failed_permission_error)
is IncorrectAddressException -> resources.getString(R.string.auth_incorrect_address_title)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,33 @@ class FileDetailsFragment : FileFragment() {
}

is UIResult.Loading -> {}
is UIResult.Success -> when (uiResult.data) {
SynchronizeFileUseCase.SyncType.AlreadySynchronized -> showMessageInSnackbar(getString(R.string.sync_file_nothing_to_do_msg))
is SynchronizeFileUseCase.SyncType.ConflictDetected -> {
val showConflictActivityIntent = Intent(requireActivity(), ConflictsResolveActivity::class.java)
showConflictActivityIntent.putExtra(ConflictsResolveActivity.EXTRA_FILE, file)
startActivity(showConflictActivityIntent)
}
is UIResult.Success -> {
when (uiResult.data) {
SynchronizeFileUseCase.SyncType.AlreadySynchronized -> {
showMessageInSnackbar(getString(R.string.sync_file_nothing_to_do_msg))
}
is SynchronizeFileUseCase.SyncType.ConflictDetected -> {
val showConflictActivityIntent = Intent(requireActivity(), ConflictsResolveActivity::class.java)
showConflictActivityIntent.putExtra(ConflictsResolveActivity.EXTRA_FILE, file)
startActivity(showConflictActivityIntent)
}

is SynchronizeFileUseCase.SyncType.DownloadEnqueued -> {
fileDetailsViewModel.startListeningToWorkInfo(uiResult.data.workerId)
}
is SynchronizeFileUseCase.SyncType.DownloadEnqueued -> {
fileDetailsViewModel.startListeningToWorkInfo(uiResult.data.workerId)
}

SynchronizeFileUseCase.SyncType.FileNotFound -> showMessageInSnackbar(getString(R.string.sync_file_not_found_msg))
SynchronizeFileUseCase.SyncType.FileNotFound -> {
showMessageInSnackbar(getString(R.string.sync_file_not_found_msg))
}

is SynchronizeFileUseCase.SyncType.UploadEnqueued -> fileDetailsViewModel.startListeningToWorkInfo(uiResult.data.workerId)
is SynchronizeFileUseCase.SyncType.UploadEnqueued -> {
fileDetailsViewModel.startListeningToWorkInfo(uiResult.data.workerId)
}

null -> showMessageInSnackbar(getString(R.string.common_error_unknown))
null -> {
showMessageInSnackbar(getString(R.string.common_error_unknown))
}
}
}
}
})
Expand Down Expand Up @@ -323,7 +333,9 @@ class FileDetailsFragment : FileFragment() {
true
}

else -> super.onOptionsItemSelected(item)
else -> {
super.onOptionsItemSelected(item)
}
}
}

Expand Down Expand Up @@ -579,7 +591,9 @@ class FileDetailsFragment : FileFragment() {
fileDisplayActivity.startTextPreview(fileWaitingToPreview)
}

else -> fileDisplayActivity.openOCFile(fileWaitingToPreview)
else -> {
fileDisplayActivity.openOCFile(fileWaitingToPreview)
}
}
fileOperationsViewModel.setLastUsageFile(fileWaitingToPreview)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,9 @@ class MainFileListFragment : Fragment(),
collectLatestLifecycleFlow(fileOperationsViewModel.checkIfFileIsLocalAndNotAvailableOfflineSharedFlow) {
val fileActivity = (requireActivity() as FileActivity)
when (it) {
is UIResult.Loading -> fileActivity.showLoadingDialog(R.string.common_loading)
is UIResult.Loading -> {
fileActivity.showLoadingDialog(R.string.common_loading)
}
is UIResult.Success -> {
fileActivity.dismissLoadingDialog()
it.data?.let { result -> onShowRemoveDialog(filesToRemove, result) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,9 @@ class PassCodeActivity : AppCompatActivity(), NumberKeyboardListener, EnableBiom
true
}

else -> super.onKeyUp(keyCode, event)
else -> {
super.onKeyUp(keyCode, event)
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ class ShareActivity : FileActivity(), ShareFragmentListener {
data?.authority
)
}
else -> Timber.e("Unexpected intent $intent")
else -> {
Timber.e("Unexpected intent $intent")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,13 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
"", whereArgs
)
}
ROOT_DIRECTORY ->
count = db.delete(ProviderTableMeta.FILE_TABLE_NAME, where, whereArgs)
SHARES -> count = db.delete(ProviderTableMeta.OCSHARES_TABLE_NAME, where, whereArgs)
CAPABILITIES -> count = db.delete(ProviderTableMeta.CAPABILITIES_TABLE_NAME, where, whereArgs)
UPLOADS -> count = db.delete(ProviderTableMeta.UPLOADS_TABLE_NAME, where, whereArgs)
CAMERA_UPLOADS_SYNC -> count = db.delete(ProviderTableMeta.CAMERA_UPLOADS_SYNC_TABLE_NAME, where, whereArgs)
QUOTAS -> count = db.delete(ProviderTableMeta.USER_QUOTAS_TABLE_NAME, where, whereArgs)
else -> throw IllegalArgumentException("Unknown uri: $uri")
ROOT_DIRECTORY -> { count = db.delete(ProviderTableMeta.FILE_TABLE_NAME, where, whereArgs) }
SHARES -> { count = db.delete(ProviderTableMeta.OCSHARES_TABLE_NAME, where, whereArgs) }
CAPABILITIES -> { count = db.delete(ProviderTableMeta.CAPABILITIES_TABLE_NAME, where, whereArgs) }
UPLOADS -> { count = db.delete(ProviderTableMeta.UPLOADS_TABLE_NAME, where, whereArgs) }
CAMERA_UPLOADS_SYNC -> { count = db.delete(ProviderTableMeta.CAMERA_UPLOADS_SYNC_TABLE_NAME, where, whereArgs) }
QUOTAS -> { count = db.delete(ProviderTableMeta.USER_QUOTAS_TABLE_NAME, where, whereArgs) }
else -> { throw IllegalArgumentException("Unknown uri: $uri") }
}
return count
}
Expand Down Expand Up @@ -267,7 +266,9 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
if (quotaId <= 0) throw SQLException("ERROR $uri")
ContentUris.withAppendedId(ProviderTableMeta.CONTENT_URI_QUOTAS, quotaId)
}
else -> throw IllegalArgumentException("Unknown uri id: $uri")
else -> {
throw IllegalArgumentException("Unknown uri id: $uri")
}
}

override fun onCreate(): Boolean {
Expand Down Expand Up @@ -315,7 +316,9 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
sqlQuery.tables = ProviderTableMeta.FILE_TABLE_NAME

when (uriMatcher.match(uri)) {
ROOT_DIRECTORY -> sqlQuery.projectionMap = fileProjectionMap
ROOT_DIRECTORY -> {
sqlQuery.projectionMap = fileProjectionMap
}
DIRECTORY -> {
val folderId = uri.pathSegments[1]
sqlQuery.appendWhere(
Expand Down Expand Up @@ -364,7 +367,9 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
}
sqlQuery.projectionMap = quotaProjectionMap
}
else -> throw IllegalArgumentException("Unknown uri id: $uri")
else -> {
throw IllegalArgumentException("Unknown uri id: $uri")
}
}

val order: String? = if (TextUtils.isEmpty(sortOrder)) {
Expand Down Expand Up @@ -413,19 +418,29 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
throw IllegalArgumentException("Selection not allowed, use parameterized queries")
}
return when (uriMatcher.match(uri)) {
DIRECTORY -> 0 //updateFolderSize(db, selectionArgs[0]);
SHARES -> db.update(ProviderTableMeta.OCSHARES_TABLE_NAME, values, selection, selectionArgs)
CAPABILITIES -> db.update(ProviderTableMeta.CAPABILITIES_TABLE_NAME, values, selection, selectionArgs)
DIRECTORY -> {
0 //updateFolderSize(db, selectionArgs[0]);
}
SHARES -> {
db.update(ProviderTableMeta.OCSHARES_TABLE_NAME, values, selection, selectionArgs)
}
CAPABILITIES -> {
db.update(ProviderTableMeta.CAPABILITIES_TABLE_NAME, values, selection, selectionArgs)
}
UPLOADS -> {
val ret = db.update(ProviderTableMeta.UPLOADS_TABLE_NAME, values, selection, selectionArgs)
trimSuccessfulUploads(db)
ret
}
CAMERA_UPLOADS_SYNC -> db.update(ProviderTableMeta.CAMERA_UPLOADS_SYNC_TABLE_NAME, values, selection, selectionArgs)
QUOTAS -> db.update(ProviderTableMeta.USER_QUOTAS_TABLE_NAME, values, selection, selectionArgs)
else -> db.update(
ProviderTableMeta.FILE_TABLE_NAME, values, selection, selectionArgs
)
CAMERA_UPLOADS_SYNC -> {
db.update(ProviderTableMeta.CAMERA_UPLOADS_SYNC_TABLE_NAME, values, selection, selectionArgs)
}
QUOTAS -> {
db.update(ProviderTableMeta.USER_QUOTAS_TABLE_NAME, values, selection, selectionArgs)
}
else -> {
db.update(ProviderTableMeta.FILE_TABLE_NAME, values, selection, selectionArgs)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ abstract class DrawerActivity : ToolbarActivity() {
val settingsIntent = Intent(applicationContext, SettingsActivity::class.java)
startActivity(settingsIntent)
}
R.id.drawer_menu_feedback -> openFeedback()
R.id.drawer_menu_help -> openHelp()
R.id.drawer_menu_privacy_policy -> openPrivacyPolicy()
else -> Timber.i("Unknown drawer menu item clicked: %s", menuItem.title)
R.id.drawer_menu_feedback -> { openFeedback() }
R.id.drawer_menu_help -> { openHelp() }
R.id.drawer_menu_privacy_policy -> { openPrivacyPolicy() }
else -> { Timber.i("Unknown drawer menu item clicked: %s", menuItem.title) }
}
true
}
Expand Down Expand Up @@ -316,8 +316,8 @@ abstract class DrawerActivity : ToolbarActivity() {
}
}
}
is UIResult.Loading -> getAccountQuotaText()?.text = getString(R.string.drawer_loading_quota)
is UIResult.Error -> getAccountQuotaText()?.text = getString(R.string.drawer_unavailable_used_storage)
is UIResult.Loading -> { getAccountQuotaText()?.text = getString(R.string.drawer_loading_quota) }
is UIResult.Error -> { getAccountQuotaText()?.text = getString(R.string.drawer_unavailable_used_storage) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,9 @@ class FileDisplayActivity : FileActivity(),
/** Nothing to do atm. If we are in details view, go back to file list */
}

is SynchronizeFileUseCase.SyncType.UploadEnqueued -> showSnackMessage(getString(R.string.upload_enqueued_msg))
is SynchronizeFileUseCase.SyncType.UploadEnqueued -> {
showSnackMessage(getString(R.string.upload_enqueued_msg))
}
null -> { /* Nothing to do */ }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,10 @@ class ErrorMessageAdapter {

if (throwable == null) {
return when (transferOperation) {
is Download -> {
formatter.format(
R.string.downloader_download_succeeded_content,
File(transferOperation.downloadPath).name
)
}
is Download -> formatter.format(
R.string.downloader_download_succeeded_content,
File(transferOperation.downloadPath).name
)
is TransferOperation.Upload -> formatter.format(
R.string.uploader_upload_succeeded_content_single,
transferOperation.fileName
Expand All @@ -96,9 +94,7 @@ class ErrorMessageAdapter {
R.string.downloader_download_failed_content,
File(transferOperation.downloadPath).name
)
is TransferOperation.Upload -> {
getMessageForFailedUpload(formatter, throwable, transferOperation)
}
is TransferOperation.Upload -> getMessageForFailedUpload(formatter, throwable, transferOperation)
}
return throwable.parseError(genericMessage, resources, true).toString()
}
Expand All @@ -118,23 +114,17 @@ class ErrorMessageAdapter {
R.string.error__upload__local_file_not_copied,
transferOperation.fileName, R.string.app_name
)
is ForbiddenException -> {
formatter.format(
R.string.forbidden_permissions,
R.string.uploader_upload_forbidden_permissions
)
}
is InvalidCharacterException -> {
formatter.format(
R.string.filename_forbidden_characters_from_server
)
}
is QuotaExceededException ->
formatter.format(R.string.failed_upload_quota_exceeded_text)
is FileNotFoundException -> {
formatter.format(R.string.uploads_view_upload_status_failed_folder_error)
}
else -> formatter.format(R.string.uploader_upload_failed_content_single, transferOperation.fileName)
is ForbiddenException -> formatter.format(
R.string.forbidden_permissions,
R.string.uploader_upload_forbidden_permissions
)
is InvalidCharacterException -> formatter.format(R.string.filename_forbidden_characters_from_server)
is QuotaExceededException -> formatter.format(R.string.failed_upload_quota_exceeded_text)
is FileNotFoundException -> formatter.format(R.string.uploads_view_upload_status_failed_folder_error)
else -> formatter.format(
R.string.uploader_upload_failed_content_single,
transferOperation.fileName
)

}

Expand All @@ -154,26 +144,22 @@ class ErrorMessageAdapter {
val formatter = Formatter(resources)

return when (result.code) {
ResultCode.FORBIDDEN -> {
formatter.format(
R.string.filename_forbidden_characters_from_server
)
}
ResultCode.FORBIDDEN ->
formatter.format(R.string.filename_forbidden_characters_from_server)
ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER ->
formatter.format(R.string.filename_forbidden_characters_from_server)
ResultCode.QUOTA_EXCEEDED ->
formatter.format(R.string.failed_upload_quota_exceeded_text)
ResultCode.FILE_NOT_FOUND -> {
ResultCode.FILE_NOT_FOUND ->
formatter.format(R.string.rename_local_fail_msg)
}
ResultCode.INVALID_LOCAL_FILE_NAME ->
formatter.format(R.string.rename_local_fail_msg)
ResultCode.INVALID_CHARACTER_IN_NAME ->
formatter.format(R.string.filename_forbidden_characters)
ResultCode.INVALID_OVERWRITE -> {
ResultCode.INVALID_OVERWRITE ->
formatter.format(R.string.move_file_error)
ResultCode.CONFLICT ->
formatter.format(R.string.move_file_error)
}
ResultCode.CONFLICT -> formatter.format(R.string.move_file_error)
ResultCode.INVALID_COPY_INTO_DESCENDANT ->
formatter.format(R.string.copy_file_invalid_into_descendent)
else -> getCommonMessageForResult(result, resources)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,9 @@ class PreviewAudioFragment : FileFragment() {
true
}

else -> super.onOptionsItemSelected(item)
else -> {
super.onOptionsItemSelected(item)
}
}

private fun seeDetails() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ class PreviewImageActivity : FileActivity(),
showErrorInSnackbar(R.string.remove_fail_msg, uiResult.getThrowableOrNull())
}

is UIResult.Loading -> showLoadingDialog(R.string.wait_a_moment)
is UIResult.Loading -> {
showLoadingDialog(R.string.wait_a_moment)
}
is UIResult.Success -> {

// Refresh the spaces and update the quota
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ class PreviewImageFragment : FileFragment() {
true
}

else -> super.onOptionsItemSelected(item)
else -> {
super.onOptionsItemSelected(item)
}
}

private fun seeDetails() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ class PreviewVideoActivity : FileActivity(), Player.Listener, OnPrepareVideoPlay
showErrorInSnackbar(R.string.remove_fail_msg, uiResult.getThrowableOrNull())
}

is UIResult.Loading -> showLoadingDialog(R.string.wait_a_moment)
is UIResult.Loading -> {
showLoadingDialog(R.string.wait_a_moment)
}
is UIResult.Success -> {

// Refresh the spaces and update the quota
Expand Down
Loading

0 comments on commit 6b7df4e

Please sign in to comment.