This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun serialize(src: Result<*, *>?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement? { | |
return when (src) { | |
// Ignore Loading or Err states | |
is Result.Loading -> context?.serialize("") | |
is Result.Err -> context?.serialize("") | |
// Thanks God that the original type is passed inside the | |
// ParameterizedType field. | |
// It lets us to use it for a real serialization |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.fidesmo.devicemanager.helpers | |
import com.google.gson.* | |
import com.google.gson.internal.LinkedTreeMap | |
import java.lang.reflect.ParameterizedType | |
import java.lang.reflect.Type | |
import java.lang.reflect.WildcardType | |
class ResultSerializer : JsonSerializer<Result<*, *>>, JsonDeserializer<Result<*, *>> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.fidesmo.devicemanager.helpers | |
// Based on https://github.com/danneu/kotlin-result | |
typealias NetworkResult<V, E> = Result<V, E> | |
fun <V, E> Result<V, E>.getOrElse(default: V) = when (this) { | |
is Result.Ok<V> -> value | |
is Result.Err<E> -> default | |
is Result.Loading -> default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ResultSerializer : JsonSerializer<Result<*, *>>, JsonDeserializer<Result<*, *>> { | |
override fun serialize(src: Result<*, *>?, | |
typeOfSrc: Type?, | |
context: JsonSerializationContext?): JsonElement? { | |
// TODO | |
} | |
override fun deserialize(json: JsonElement?, | |
typeOfT: Type?, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val gson = GsonBuilder() | |
.registerTypeHierarchyAdapter(Result::class.java, ResultSerializer()) | |
.create() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class Result <out V, out E> { | |
// Idle state | |
object Loading : Result<Nothing, Nothing>() | |
// Operation finished correctly with result saved on value | |
data class Ok <out V > constructor (val value: V): Result<V, Nothing>() | |
// Operation finished with error | |
data class Err <out E> constructor (val error: E): Result<Nothing, E>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum DeliveryState: StateType { | |
case notStarted | |
case settingUp(appId: AppId, | |
serviceId: ServiceId, | |
description: ServiceDescription? = null) | |
case going(progres: DeliveryProgress) | |
case idle(reason: Idle) | |
case failed(error: Error) | |
case finished(status: ServiceStatus) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class DeliveryState: StateType { | |
object NotStarted: DeliveryState() | |
data class SettingUp (val appId: AppId, | |
val serviceId: ServiceId, | |
val description: ServiceDescription? = null): DeliveryState() | |
data class Going (val progress: DeliveryProgress): DeliveryState() | |
data class IsIdle (val reason: Idle): DeliveryState() | |
data class Failed (val error: Throwable): DeliveryState() | |
data class Finished (val status: ServiceStatus): DeliveryState() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This middleware executes the async requests related with the Rest API | |
internal val networkMiddleware: Middleware<AppState> = { dispatch, state -> | |
{ next -> | |
{ action -> | |
when (action) { | |
// an async operation is called | |
is SetDeviceInfo -> { getDeviceDescription(deviceId = action.deviceId, | |
deviceInfo = action.payload, | |
dispatch = dispatch) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export FABRIC_API_TOKEN=1111 | |
export FABRIC_BUILD_SECRET=x1x1x1x1x1 | |
export GITHUB_TOKEN=11xx1x1x1x1 |