Skip to content

Commit

Permalink
KMM :: Internal :: Code formatting and file renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
franmontiel committed Aug 29, 2023
1 parent 6e80a60 commit f98dbc2
Show file tree
Hide file tree
Showing 83 changed files with 342 additions and 245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.harmony.kotlin.error.notSupportedQuery

class DeviceStorageDataSource<T>(
private val sharedPreferences: SharedPreferences,
private val prefix: String = ""
private val prefix: String = "",
) : GetDataSource<T>, PutDataSource<T>, DeleteDataSource {

override suspend fun get(query: Query): T =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ open class AndroidLogger(private val isDebug: Boolean) : Logger {
private fun createClassTag(): String? {
val ignoreClass = listOf(
AndroidLogger::class.java.name,
Logger::class.java.name
Logger::class.java.name,
)
val stackTraceElement: StackTraceElement = Throwable().stackTrace
.first { it.className !in ignoreClass && !it.className.contains("DefaultImpls") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.util.regex.Pattern
open class BugfenderLogger(
context: Context,
applicationKey: String,
isDebug: Boolean
isDebug: Boolean,
) : Logger {
init {
Bugfender.init(context, applicationKey, isDebug)
Expand Down Expand Up @@ -94,7 +94,7 @@ open class BugfenderLogger(
private fun createClassTag(): String? {
val ignoreClass = listOf(
AndroidLogger::class.java.name,
Logger::class.java.name
Logger::class.java.name,
)
val stackTraceElement: StackTraceElement = Throwable().stackTrace
.first { it.className !in ignoreClass && !it.className.contains("DefaultImpls") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.junit.runner.Description

@ExperimentalCoroutinesApi
class CoroutinesTestRule(
private val testDispatcher: TestDispatcher = UnconfinedTestDispatcher()
private val testDispatcher: TestDispatcher = UnconfinedTestDispatcher(),
) : TestWatcher() {

override fun starting(description: Description?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class ViewModel<out VS : ViewState, in A : Action>(private val dispatch
onEach {
onChange(it)
}.launchIn(
CoroutineScope(coroutineContext)
CoroutineScope(coroutineContext),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import kotlin.reflect.KProperty

object Delegates {

fun <T : Any> weakReference(value: T):
ReadOnlyProperty<Any?, T?> = object : ReadOnlyProperty<Any?, T?> {
fun <T : Any> weakReference(value: T): ReadOnlyProperty<Any?, T?> = object : ReadOnlyProperty<Any?, T?> {
private val reference = WeakReference(value)
override fun getValue(thisRef: Any?, property: KProperty<*>): T? = reference.get()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ inline fun <T> Result<T>.onComplete(
onFailureLogger: Logger,
tag: String,
onSuccess: (T) -> Unit,
onFailure: ((Throwable) -> Unit) = { _ -> }
onFailure: ((Throwable) -> Unit) = { _ -> },
) {

if (this.isSuccess) {
this.onSuccess { onSuccess(it) }
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package com.harmony.kotlin.common.date
* Long typealias to provide meaning for second values
*/
typealias Seconds = Long

/**
* Long typealias to provide meaning for millisecond values
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ inline fun <R> tryOrThrow(
message: String = "Exception logged",
level: Logger.Level = Logger.Level
.WARNING,
block: () -> R
):
R {
block: () -> R,
): R {
return try {
block()
} catch (e: Exception) {
Expand All @@ -32,7 +31,7 @@ inline fun <R> tryOrCatch(
tag: String = "TryOrCatch",
message: String = "Exception logged",
level: Logger.Level = Logger.Level.WARNING,
block: () -> R
block: () -> R,
) {
return try {
block()
Expand All @@ -53,7 +52,7 @@ inline fun <R> tryOrNull(
tag: String = "TryOrNull",
message: String = "Exception logged",
level: Logger.Level = Logger.Level.WARNING,
block: () -> R
block: () -> R,
): R? {
return try {
block()
Expand All @@ -68,13 +67,14 @@ inline fun <R> tryOrNull(
*
* Optionally a logger and some parameters can be passed to log the Exception
*/
@Suppress("LongParameterList")
inline fun <R> tryOrDefault(
logger: Logger? = null,
tag: String = "TryOrDefault",
message: String = "Exception logged",
level: Logger.Level = Logger.Level.WARNING,
defaultValue: R,
block: () -> R
block: () -> R,
): R {
return try {
block()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface Logger {
DEBUG("DEBUG"),
INFO("INFO"),
WARNING("WARNING"),
ERROR("ERROR")
ERROR("ERROR"),
}

/** Logs a String object using a given level. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class DataSourceMapper<In, Out>(
private val putDataSource: PutDataSource<In>,
private val deleteDataSource: DeleteDataSource,
private val toOutMapper: Mapper<In, Out>,
private val toInMapper: Mapper<Out, In>
private val toInMapper: Mapper<Out, In>,
) : GetDataSource<Out>, PutDataSource<Out>, DeleteDataSource {

override suspend fun get(query: Query): Out = get(getDataSource, toOutMapper, query)
Expand All @@ -29,7 +29,7 @@ class DataSourceMapper<In, Out>(

class GetDataSourceMapper<In, Out>(
private val getDataSource: GetDataSource<In>,
private val toOutMapper: Mapper<In, Out>
private val toOutMapper: Mapper<In, Out>,
) : GetDataSource<Out> {

override suspend fun get(query: Query): Out = get(getDataSource, toOutMapper, query)
Expand All @@ -38,7 +38,7 @@ class GetDataSourceMapper<In, Out>(
class PutDataSourceMapper<In, Out>(
private val putDataSource: PutDataSource<In>,
private val toOutMapper: Mapper<In, Out>,
private val toInMapper: Mapper<Out, In>
private val toInMapper: Mapper<Out, In>,
) : PutDataSource<Out> {

override suspend fun put(query: Query, value: Out?): Out = put(putDataSource, toOutMapper, toInMapper, value, query)
Expand All @@ -47,15 +47,15 @@ class PutDataSourceMapper<In, Out>(
private suspend fun <In, Out> get(
getDataSource: GetDataSource<In>,
toOutMapper: Mapper<In, Out>,
query: Query
query: Query,
): Out = getDataSource.get(query).let { toOutMapper.map(it) }

private suspend fun <In, Out> put(
putDataSource: PutDataSource<In>,
toOutMapper: Mapper<In, Out>,
toInMapper: Mapper<Out, In>,
value: Out?,
query: Query
query: Query,
): Out {
val mapped = value?.let { toInMapper.map(it) }
return putDataSource.put(query, mapped).let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,21 @@ import com.harmony.kotlin.data.query.Query
* @param deleteQueryMapper Mapper for delete operations
*/
@Suppress("UNCHECKED_CAST")
class DataSourceQueryMapper<V,
GetQueryIn : Query, GetQueryOut : Query,
PutQueryIn : Query, PutQueryOut : Query,
DeleteQueryIn : Query, DeleteQueryOut : Query>(
class DataSourceQueryMapper<
V,
GetQueryIn : Query,
GetQueryOut : Query,
PutQueryIn : Query,
PutQueryOut : Query,
DeleteQueryIn : Query,
DeleteQueryOut : Query,
>(
private val getDataSource: GetDataSource<V>,
private val putDataSource: PutDataSource<V>,
private val deleteDataSource: DeleteDataSource,
private val getQueryMapper: Mapper<GetQueryIn, GetQueryOut>,
private val putQueryMapper: Mapper<PutQueryIn, PutQueryOut>,
private val deleteQueryMapper: Mapper<DeleteQueryIn, DeleteQueryOut>
private val deleteQueryMapper: Mapper<DeleteQueryIn, DeleteQueryOut>,
) : GetDataSource<V>, PutDataSource<V>, DeleteDataSource {

override suspend fun get(query: Query): V {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class DataSourceRetrier<V>(
logger?.d("RetryDataSource", "failed attempt ${this.maxAmountOfExecutions - retryCount + 1} of max retries ${this.maxAmountOfExecutions}:\n\t$error")
if (retryCount > 1 && retryIf(error)) {
executeWithRetries(retryCount - 1, functionToRetry)
} else throw error
} else {
throw error
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import com.harmony.kotlin.error.DataNotValidException

data class GetDataSourceValidator<T>(
private val getDataSource: GetDataSource<T>,
private val validator: Validator<T>
private val validator: Validator<T>,
) : GetDataSource<T> {

override suspend fun get(query: Query): T = getDataSource.get(query).let {
if (!validator.isValid(it)) throw
DataNotValidException() else it
if (!validator.isValid(it)) {
throw DataNotValidException()
} else {
it
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class FlowDataSourceMapper<In, Out>(
putDataSource: FlowPutDataSource<In>,
private val deleteDataSource: FlowDeleteDataSource,
toOutMapper: Mapper<In, Out>,
toInMapper: Mapper<Out, In>
toInMapper: Mapper<Out, In>,
) : FlowGetDataSource<Out>, FlowPutDataSource<Out>, FlowDeleteDataSource {

private val getDataSourceMapper = FlowGetDataSourceMapper(getDataSource, toOutMapper)
Expand All @@ -35,7 +35,7 @@ class FlowDataSourceMapper<In, Out>(

class FlowGetDataSourceMapper<In, Out>(
private val getDataSource: FlowGetDataSource<In>,
private val toOutMapper: Mapper<In, Out>
private val toOutMapper: Mapper<In, Out>,
) : FlowGetDataSource<Out> {

override fun get(query: Query): Flow<Out> = getDataSource.get(query).map { toOutMapper.map(it) }
Expand All @@ -44,7 +44,7 @@ class FlowGetDataSourceMapper<In, Out>(
class FlowPutDataSourceMapper<In, Out>(
private val putDataSource: FlowPutDataSource<In>,
private val toOutMapper: Mapper<In, Out>,
private val toInMapper: Mapper<Out, In>
private val toInMapper: Mapper<Out, In>,
) : FlowPutDataSource<Out> {

override fun put(query: Query, value: Out?): Flow<Out> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class FlowDataSourceValidator<T>(
private val getDataSource: FlowGetDataSource<T>,
private val putDataSource: FlowPutDataSource<T>,
private val deleteDataSource: FlowDeleteDataSource,
private val validator: Validator<T>
private val validator: Validator<T>,
) : FlowGetDataSource<T>, FlowPutDataSource<T>, FlowDeleteDataSource {

override fun get(query: Query): Flow<T> = getDataSource.get(query).map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class GetNetworkDataSource<T>(
private val httpClient: HttpClient,
private val networkResponseDecoder: NetworkResponseDecoder<T>,
private val globalHeaders: List<Pair<String, String>> = emptyList(),
private val exceptionMapper: Mapper<Exception, Exception> = IdentityMapper()
private val exceptionMapper: Mapper<Exception, Exception> = IdentityMapper(),
) : GetDataSource<T> {

/**
Expand Down Expand Up @@ -47,7 +47,7 @@ class PutNetworkDataSource<T>(
private val httpClient: HttpClient,
private val networkResponseDecoder: NetworkResponseDecoder<T>,
private val globalHeaders: List<Pair<String, String>> = emptyList(),
private val exceptionMapper: Mapper<Exception, Exception> = IdentityMapper()
private val exceptionMapper: Mapper<Exception, Exception> = IdentityMapper(),

) : PutDataSource<T> {

Expand Down Expand Up @@ -78,7 +78,7 @@ class PutNetworkDataSource<T>(
"Conflicting arguments to be used as request body:\n" +
"query.method.contentType=${contentType}\n" +
"value=${value}\n" +
"You must only provide one of them"
"You must only provide one of them",
)
}
// Updating query if value is passed as separated argument from the query
Expand Down Expand Up @@ -106,7 +106,7 @@ class DeleteNetworkDataSource(
private val url: String,
private val httpClient: HttpClient,
private val globalHeaders: List<Pair<String, String>> = emptyList(),
private val exceptionMapper: Mapper<Exception, Exception> = IdentityMapper()
private val exceptionMapper: Mapper<Exception, Exception> = IdentityMapper(),
) : DeleteDataSource {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fun HttpRequestBuilder.headers(values: List<Pair<String, String>>) {

suspend fun HttpRequestBuilder.oauthPasswordHeader(
tokenIdentifier: String = Default.TOKEN_IDENTIFIER,
getPasswordTokenInteractor: GetPasswordTokenInteractor
getPasswordTokenInteractor: GetPasswordTokenInteractor,
) {
try {
val passwordTokenInteractor = getPasswordTokenInteractor(tokenIdentifier)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ open class OAuthNetworkQuery(
urlParams = urlParams,
headers = headers,
suspendHeaders = suspendHeaders,
key = key
key = key,
),
GenericOAuthQuery

Expand All @@ -50,7 +50,7 @@ open class NetworkQuery(
val urlParams: List<Pair<String, String>> = emptyList(),
val headers: List<Pair<String, String>> = emptyList(),
val suspendHeaders: suspend () -> List<Pair<String, String>> = { emptyList() },
key: String? = null
key: String? = null,
) : KeyQuery(key ?: generateNetworkQueryKey(method, path, urlParams)) {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ suspend fun NetworkQuery.executeKtorRequest(httpClient: HttpClient, baseUrl: Str
contentType.params.forEach {
append(it.first, it.second)
}
}
)
},
),
)
}
is NetworkQuery.ContentType.Json<*> -> {
Expand All @@ -64,7 +64,6 @@ suspend fun NetworkQuery.executeKtorRequest(httpClient: HttpClient, baseUrl: Str
* **IMPORTANT:** This method is intended to be used only be used inside a Network DataSource
*/
fun NetworkQuery.generateKtorUrl(baseUrl: String): Url {

val sanitizedBaseUrl = baseUrl.removeSuffix("/")
val sanitizedPaths = this.path.split("/").filter { it.isNotEmpty() }.joinToString(separator = "/", prefix = "/")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class PaginationOffsetLimit<T>(
values: List<T>,
val offset: Int = 0,
val limit: Int = 10,
val size: Int = 10
val size: Int = 10,
) : Pagination<T>(values)

class PaginationPage<T>(values: List<T>) : Pagination<T>(values)
Loading

0 comments on commit f98dbc2

Please sign in to comment.