Skip to content

Commit

Permalink
style: changed functions with just return to expression body
Browse files Browse the repository at this point in the history
  • Loading branch information
joragua committed Jan 23, 2025
1 parent f62fb05 commit 57fd55b
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ class FileListAdapter(
}
}

private fun generateFooterText(filesCount: Int, foldersCount: Int): String {
return when {
private fun generateFooterText(filesCount: Int, foldersCount: Int): String =
when {
filesCount <= 0 -> {
when {
foldersCount <= 0 -> {
Expand Down Expand Up @@ -438,7 +438,6 @@ class FileListAdapter(
}
}
}
}

interface FileListAdapterListener {
fun onItemClick(ocFileWithSyncInfo: OCFileWithSyncInfo, position: Int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1303,8 +1303,8 @@ class MainFileListFragment : Fragment(),
}
}

private fun onCheckedFilesActionChosen(menuId: Int?, checkedFiles: ArrayList<OCFile>): Boolean {
return when (menuId) {
private fun onCheckedFilesActionChosen(menuId: Int?, checkedFiles: ArrayList<OCFile>): Boolean =
when (menuId) {
R.id.file_action_select_all -> {
fileListAdapter.selectAll()
updateActionModeAfterTogglingSelected()
Expand Down Expand Up @@ -1380,7 +1380,6 @@ class MainFileListFragment : Fragment(),
false
}
}
}

/**
* Update or remove the actionMode after applying any change to the selected items.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ class PassCodeActivity : AppCompatActivity(), NumberKeyboardListener, EnableBiom
finish()
}

private fun getPasscodeAction(action: String?): PasscodeAction {
return when (action) {
private fun getPasscodeAction(action: String?): PasscodeAction =
when (action) {
ACTION_REMOVE -> {
PasscodeAction.REMOVE
}
Expand All @@ -429,7 +429,6 @@ class PassCodeActivity : AppCompatActivity(), NumberKeyboardListener, EnableBiom
PasscodeAction.CHECK
}
}
}

override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean =
when (keyCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,8 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
return newUri
}

private fun insert(db: SQLiteDatabase, uri: Uri, values: ContentValues?): Uri {
return when (uriMatcher.match(uri)) {
private fun insert(db: SQLiteDatabase, uri: Uri, values: ContentValues?): Uri =
when (uriMatcher.match(uri)) {
ROOT_DIRECTORY, SINGLE_FILE -> {
val remotePath = values?.getAsString(ProviderTableMeta.FILE_PATH)
val accountName = values?.getAsString(ProviderTableMeta.FILE_ACCOUNT_OWNER)
Expand All @@ -211,7 +211,7 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
val doubleCheck = query(uri, projection, where, whereArgs, null)
// ugly patch; serious refactorization is needed to reduce work in
// FileDataStorageManager and bring it to FileContentProvider
return if (!doubleCheck.moveToFirst()) {
if (!doubleCheck.moveToFirst()) {
doubleCheck.close()
val fileId = db.insert(ProviderTableMeta.FILE_TABLE_NAME, null, values)
if (fileId <= 0) throw SQLException("ERROR $uri")
Expand Down Expand Up @@ -270,8 +270,6 @@ class FileContentProvider(val executors: Executors = Executors()) : ContentProvi
else -> throw IllegalArgumentException("Unknown uri id: $uri")
}

}

override fun onCreate(): Boolean {
dbHelper = DataBaseHelper(context)
// This sentence is for opening the database, which is necessary to perform the migration correctly to DB version 38
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ class DownloadFileUseCase(
val ocFile = params.file
val accountName = params.accountName

return if (ocFile.id == null) {
null
} else if (isDownloadAlreadyEnqueued(accountName, ocFile)) {
null
} else {
enqueueNewDownload(ocFile, accountName)
return ocFile.id?.let {
if (isDownloadAlreadyEnqueued(accountName, ocFile)) {
null
} else {
enqueueNewDownload(ocFile, accountName)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ open class MoveRemoteFileOperation(
*
* @param client Client object to communicate with the remote ownCloud server.
*/
override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> {
return if (targetRemotePath == sourceRemotePath) {
override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> =
if (targetRemotePath == sourceRemotePath) {
// nothing to do!
RemoteOperationResult(ResultCode.OK)
} else if (targetRemotePath.startsWith(sourceRemotePath)) {
Expand Down Expand Up @@ -115,7 +115,6 @@ open class MoveRemoteFileOperation(
}
result
}
}

/**
* For standard moves, we will use [OwnCloudClient.getUserFilesWebDavUri].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,18 @@ internal class StatusRequester {
(baseUrl.startsWith(HTTPS_SCHEME) &&
!redirectedUrl.startsWith(HTTPS_SCHEME))

fun updateLocationWithRedirectPath(oldLocation: String, redirectedLocation: String): String {
fun updateLocationWithRedirectPath(oldLocation: String, redirectedLocation: String): String =
/** Redirection with different endpoint.
* When asking for server.com/status.php and redirected to different.one/, we need to ask different.one/status.php
*/
return if (redirectedLocation.endsWith('/')) {
if (redirectedLocation.endsWith('/')) {
redirectedLocation.trimEnd('/') + OwnCloudClient.STATUS_PATH
} else if (!redirectedLocation.startsWith("/")) {
redirectedLocation
} else {
val oldLocationURL = URL(oldLocation)
URL(oldLocationURL.protocol, oldLocationURL.host, oldLocationURL.port, redirectedLocation).toString()
}
}

private fun getGetMethod(url: String): GetMethod =
GetMethod(URL(url)).apply {
Expand Down

0 comments on commit 57fd55b

Please sign in to comment.