Skip to content

Commit

Permalink
style: changed functions with just return to expression body in modul…
Browse files Browse the repository at this point in the history
…e `owncloudDomain`
  • Loading branch information
JuancaG05 committed Jan 10, 2025
1 parent 6ab7174 commit 2490e60
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ class RequestTokenUseCase(
private val oAuthRepository: OAuthRepository
) : BaseUseCaseWithResult<TokenResponse, RequestTokenUseCase.Params>() {

override fun run(params: Params): TokenResponse {
return oAuthRepository.performTokenRequest(params.tokenRequest)
}
override fun run(params: Params): TokenResponse =
oAuthRepository.performTokenRequest(params.tokenRequest)

data class Params(
val tokenRequest: TokenRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,21 @@ enum class UploadBehavior {
MOVE, COPY;

@Deprecated("Legacy Local Behavior. Remove asap")
fun toLegacyLocalBehavior(): Int {
return when (this) {
fun toLegacyLocalBehavior(): Int =
when (this) {
MOVE -> LEGACY_LOCAL_BEHAVIOUR_MOVE
COPY -> LEGACY_LOCAL_BEHAVIOUR_COPY
}
}

companion object {
private const val LEGACY_LOCAL_BEHAVIOUR_COPY = 0
private const val LEGACY_LOCAL_BEHAVIOUR_MOVE = 1

fun fromString(string: String): UploadBehavior {
return if (string.equals("MOVE", ignoreCase = true)) {
fun fromString(string: String): UploadBehavior =
if (string.equals("MOVE", ignoreCase = true)) {
MOVE
} else {
COPY
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ enum class AvailableOfflineStatus {
AVAILABLE_OFFLINE_PARENT;

companion object {
fun fromValue(value: Int?): AvailableOfflineStatus {
return when (value) {
fun fromValue(value: Int?): AvailableOfflineStatus =
when (value) {
AVAILABLE_OFFLINE.ordinal -> AVAILABLE_OFFLINE
AVAILABLE_OFFLINE_PARENT.ordinal -> AVAILABLE_OFFLINE_PARENT
else -> NOT_AVAILABLE_OFFLINE
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ data class OCCapability(
return (filesBigFileChunking.isTrue && doubleChunkingVersion != null && doubleChunkingVersion >= 1.0)
}

fun isFetchingAvatarAllowed(): Boolean {
return filesSharingUserProfilePicture.isTrue || filesSharingUserProfilePicture.isUnknown
}
fun isFetchingAvatarAllowed(): Boolean =
filesSharingUserProfilePicture.isTrue || filesSharingUserProfilePicture.isUnknown

fun isOpenInWebAllowed(): Boolean = filesAppProviders?.openWebUrl?.isNotBlank() ?: false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@

package com.owncloud.android.domain.extensions

fun Any.isOneOf(vararg values: Any): Boolean {
return this in values
}
fun Any.isOneOf(vararg values: Any): Boolean =
this in values
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ import com.owncloud.android.domain.files.model.OCFile

class SortFilesUseCase : BaseUseCase<List<OCFile>, SortFilesUseCase.Params>() {

override fun run(params: Params): List<OCFile> {
return when (params.sortType) {
override fun run(params: Params): List<OCFile> =
when (params.sortType) {
SortType.SORT_BY_NAME -> sortByName(params.listOfFiles, params.ascending)
SortType.SORT_BY_SIZE -> sortBySize(params.listOfFiles, params.ascending)
SortType.SORT_BY_DATE -> sortByDate(params.listOfFiles, params.ascending)
}
}

private fun sortByName(listOfFiles: List<OCFile>, ascending: Boolean): List<OCFile> {
val newListOfFiles =
Expand All @@ -40,15 +39,13 @@ class SortFilesUseCase : BaseUseCase<List<OCFile>, SortFilesUseCase.Params>() {
return newListOfFiles.sortedByDescending { it.isFolder }
}

private fun sortBySize(listOfFiles: List<OCFile>, ascending: Boolean): List<OCFile> {
return if (ascending) listOfFiles.sortedBy { it.length }
private fun sortBySize(listOfFiles: List<OCFile>, ascending: Boolean): List<OCFile> =
if (ascending) listOfFiles.sortedBy { it.length }
else listOfFiles.sortedByDescending { it.length }
}

private fun sortByDate(listOfFiles: List<OCFile>, ascending: Boolean): List<OCFile> {
return if (ascending) listOfFiles.sortedBy { it.modificationTimestamp }
private fun sortByDate(listOfFiles: List<OCFile>, ascending: Boolean): List<OCFile> =
if (ascending) listOfFiles.sortedBy { it.modificationTimestamp }
else listOfFiles.sortedByDescending { it.modificationTimestamp }
}

data class Params(
val listOfFiles: List<OCFile>,
Expand All @@ -61,13 +58,12 @@ enum class SortType {
SORT_BY_NAME, SORT_BY_SIZE, SORT_BY_DATE;

companion object {
fun fromPreferences(preferenceValue: Int): SortType {
return when (preferenceValue) {
fun fromPreferences(preferenceValue: Int): SortType =
when (preferenceValue) {
0 -> SORT_BY_NAME
1 -> SORT_BY_DATE
2 -> SORT_BY_SIZE
else -> throw IllegalStateException("Sort type not expected")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ import com.owncloud.android.domain.files.model.OCFileWithSyncInfo

class SortFilesWithSyncInfoUseCase : BaseUseCase<List<OCFileWithSyncInfo>, SortFilesWithSyncInfoUseCase.Params>() {

override fun run(params: Params): List<OCFileWithSyncInfo> {
return when (params.sortType) {
override fun run(params: Params): List<OCFileWithSyncInfo> =
when (params.sortType) {
SortType.SORT_BY_NAME -> sortByName(params.listOfFiles, params.ascending)
SortType.SORT_BY_SIZE -> sortBySize(params.listOfFiles, params.ascending)
SortType.SORT_BY_DATE -> sortByDate(params.listOfFiles, params.ascending)
}
}

private fun sortByName(listOfFiles: List<OCFileWithSyncInfo>, ascending: Boolean): List<OCFileWithSyncInfo> {
val newListOfFiles =
Expand All @@ -42,15 +41,13 @@ class SortFilesWithSyncInfoUseCase : BaseUseCase<List<OCFileWithSyncInfo>, SortF
return newListOfFiles.sortedByDescending { it.file.isFolder }
}

private fun sortBySize(listOfFiles: List<OCFileWithSyncInfo>, ascending: Boolean): List<OCFileWithSyncInfo> {
return if (ascending) listOfFiles.sortedBy { it.file.length }
private fun sortBySize(listOfFiles: List<OCFileWithSyncInfo>, ascending: Boolean): List<OCFileWithSyncInfo> =
if (ascending) listOfFiles.sortedBy { it.file.length }
else listOfFiles.sortedByDescending { it.file.length }
}

private fun sortByDate(listOfFiles: List<OCFileWithSyncInfo>, ascending: Boolean): List<OCFileWithSyncInfo> {
return if (ascending) listOfFiles.sortedBy { it.file.modificationTimestamp }
private fun sortByDate(listOfFiles: List<OCFileWithSyncInfo>, ascending: Boolean): List<OCFileWithSyncInfo> =
if (ascending) listOfFiles.sortedBy { it.file.modificationTimestamp }
else listOfFiles.sortedByDescending { it.file.modificationTimestamp }
}

data class Params(
val listOfFiles: List<OCFileWithSyncInfo>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ sealed class ServerInfo(
return true
}

override fun hashCode(): Int {
return javaClass.hashCode()
}
override fun hashCode(): Int =
javaClass.hashCode()

class OIDCServer(
ownCloudVersion: String,
Expand All @@ -51,9 +50,8 @@ sealed class ServerInfo(
return super.equals(other)
}

override fun hashCode(): Int {
return javaClass.hashCode()
}
override fun hashCode(): Int =
javaClass.hashCode()
}

class OAuth2Server(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ class GetServerInfoAsyncUseCase(
/**
* In case the user introduces a server url without prefix, we will try to connect to https
*/
private fun normalizeProtocolPrefix(url: String): String {
return if (!url.lowercase(Locale.getDefault()).startsWith(HTTP_PREFIX) &&
private fun normalizeProtocolPrefix(url: String): String =
if (!url.lowercase(Locale.getDefault()).startsWith(HTTP_PREFIX) &&
!url.lowercase(Locale.getDefault()).startsWith(HTTPS_PREFIX)
) {
return "$HTTPS_PREFIX$url"
"$HTTPS_PREFIX$url"
} else url
}

companion object {
const val TRAILING_SLASH = '/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ data class Event<out T>(private val content: T) {
/**
* Returns the content and prevents its use again.
*/
fun getContentIfNotHandled(): T? {
return if (hasBeenHandled) {
fun getContentIfNotHandled(): T? =
if (hasBeenHandled) {
null
} else {
hasBeenHandled = true
content
}
}

/**
* Returns the content, even if it's already been handled.
Expand Down

0 comments on commit 2490e60

Please sign in to comment.