Skip to content

Commit

Permalink
refactor: make objects data
Browse files Browse the repository at this point in the history
  • Loading branch information
FunkyMuse committed Dec 7, 2023
1 parent 7923048 commit a405e02
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ import okhttp3.ResponseBody
*/
sealed class ApiResult<out T> {


data class Success<T>(val value: T) : ApiResult<T>() {
val isValueAListAndNullOrEmpty get() = value is List<*> && value.isEmpty()
val isValueAListAndNotNullOrEmpty get() = value is List<*> && value.isNotEmpty()
} // handle UI changes when everything is loaded

object Loading : ApiResult<Nothing>() // handle loading state
data object Loading : ApiResult<Nothing>() // handle loading state
data class Error(val throwable: Throwable) :
ApiResult<Nothing>() //this one gets thrown when there's an error on your side or an error we throw from http

data class ApiError(val responseCode: Int, val errorBody: ResponseBody?) : ApiResult<Nothing>() //whenever the api throws an error
object Idle : ApiResult<Nothing>()
data object Idle : ApiResult<Nothing>()
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,27 @@ package com.crazylegend.retrofit.responsecode
* Created by funkymuse on 11/20/21 to long live and prosper !
*/
sealed interface ResponseCode {
object MovedPermanently : ResponseCode
object BadRequest : ResponseCode
object Unauthorized : ResponseCode
object Forbidden : ResponseCode
object NotFound : ResponseCode
object NotAllowed : ResponseCode
object NotAcceptable : ResponseCode
object ProxyAuthenticationRequired : ResponseCode
object Timeout : ResponseCode
object ConflictError : ResponseCode
object RequestPermanentlyDeleted:ResponseCode
object RequestTooLarge : ResponseCode
object AccountExists : ResponseCode
object ServerIsBusy : ResponseCode
object TooManyRequests :ResponseCode
object InternalServerError : ResponseCode
object NotImplemented : ResponseCode
object BadGateway : ResponseCode
object GatewayTimeout : ResponseCode
object AuthenticationRequired : ResponseCode

object GenericError : ResponseCode
data object MovedPermanently : ResponseCode
data object BadRequest : ResponseCode
data object Unauthorized : ResponseCode
data object Forbidden : ResponseCode
data object NotFound : ResponseCode
data object NotAllowed : ResponseCode
data object NotAcceptable : ResponseCode
data object ProxyAuthenticationRequired : ResponseCode
data object Timeout : ResponseCode
data object ConflictError : ResponseCode
data object RequestPermanentlyDeleted:ResponseCode
data object RequestTooLarge : ResponseCode
data object AccountExists : ResponseCode
data object ServerIsBusy : ResponseCode
data object TooManyRequests :ResponseCode
data object InternalServerError : ResponseCode
data object NotImplemented : ResponseCode
data object BadGateway : ResponseCode
data object GatewayTimeout : ResponseCode
data object AuthenticationRequired : ResponseCode
data object GenericError : ResponseCode
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ sealed interface ViewStatefulEvent {
data class Error(val throwable: Throwable) : ViewStatefulEvent
data class ApiError(val errorBody: ResponseBody?, val responseCode: Int) : ViewStatefulEvent

object Success : ViewStatefulEvent
object Loading : ViewStatefulEvent
object Idle : ViewStatefulEvent
data object Success : ViewStatefulEvent
data object Loading : ViewStatefulEvent
data object Idle : ViewStatefulEvent
}

val ViewStatefulEvent.isLoading get() = this is ViewStatefulEvent.Loading
Expand Down

0 comments on commit a405e02

Please sign in to comment.