Loading app/src/main/java/foundation/e/apps/api/ApiCaller.kt 0 → 100644 +21 −0 Original line number Diff line number Diff line package foundation.e.apps.api import retrofit2.Response suspend fun <T> getResult(apiCall: suspend () -> Response<T>): Result<T> { return try { fetchResult(apiCall()) } catch (e: Exception) { Result.error(e.message ?: e.toString()) } } private fun <T> fetchResult(response: Response<T>): Result<T> { if (response.isSuccessful) { response.body()?.let { return Result.success(it) } } return Result.error(response.message(), response.body()) } app/src/main/java/foundation/e/apps/api/Result.kt 0 → 100644 +47 −0 Original line number Diff line number Diff line package foundation.e.apps.api data class Result<T>(val status: Status, val data: T?, val message: String?) { enum class Status { SUCCESS, ERROR, LOADING } companion object { fun <T> success(data: T): Result<T> { return Result( Status.SUCCESS, data, null ) } fun <T> error(message: String, data: T? = null): Result<T> { return Result( Status.ERROR, data, message ) } fun <T> loading(data: T? = null): Result<T> { return Result( Status.LOADING, data, null ) } } fun isSuccess() = status == Status.SUCCESS fun handleResult(handler: () -> Unit, defaultErrorData: T?) : T? { if(isSuccess()) { handler() return data ?: defaultErrorData } return defaultErrorData } } app/src/main/java/foundation/e/apps/api/exodus/ExodusTrackerApi.kt 0 → 100644 +15 −0 Original line number Diff line number Diff line package foundation.e.apps.api.exodus import retrofit2.Response import retrofit2.http.GET interface ExodusTrackerApi { companion object { const val BASE_URL = "https://exodus.ecloud.global/api/" const val VERSION = "190239" } @GET("trackers?v=$VERSION") suspend fun getTrackerList(): Response<Trackers> } No newline at end of file app/src/main/java/foundation/e/apps/api/exodus/Trackers.kt 0 → 100644 +25 −0 Original line number Diff line number Diff line package foundation.e.apps.api.exodus data class Trackers ( val trackers: Map<String, Tracker> ) data class Tracker ( val id: Long, val name: String, val description: String, val creationDate: String, val codeSignature: String, val networkSignature: String, val website: String, val categories: List<Category> ) enum class Category { Advertisement, Analytics, CrashReporting, Identification, Location, Profiling } No newline at end of file app/src/main/java/foundation/e/apps/api/exodus/repositories/ITrackerRepository.kt 0 → 100644 +5 −0 Original line number Diff line number Diff line package foundation.e.apps.api.exodus.repositories interface ITrackerRepository { suspend fun getTrackerList(): Result<Boolean> } No newline at end of file Loading
app/src/main/java/foundation/e/apps/api/ApiCaller.kt 0 → 100644 +21 −0 Original line number Diff line number Diff line package foundation.e.apps.api import retrofit2.Response suspend fun <T> getResult(apiCall: suspend () -> Response<T>): Result<T> { return try { fetchResult(apiCall()) } catch (e: Exception) { Result.error(e.message ?: e.toString()) } } private fun <T> fetchResult(response: Response<T>): Result<T> { if (response.isSuccessful) { response.body()?.let { return Result.success(it) } } return Result.error(response.message(), response.body()) }
app/src/main/java/foundation/e/apps/api/Result.kt 0 → 100644 +47 −0 Original line number Diff line number Diff line package foundation.e.apps.api data class Result<T>(val status: Status, val data: T?, val message: String?) { enum class Status { SUCCESS, ERROR, LOADING } companion object { fun <T> success(data: T): Result<T> { return Result( Status.SUCCESS, data, null ) } fun <T> error(message: String, data: T? = null): Result<T> { return Result( Status.ERROR, data, message ) } fun <T> loading(data: T? = null): Result<T> { return Result( Status.LOADING, data, null ) } } fun isSuccess() = status == Status.SUCCESS fun handleResult(handler: () -> Unit, defaultErrorData: T?) : T? { if(isSuccess()) { handler() return data ?: defaultErrorData } return defaultErrorData } }
app/src/main/java/foundation/e/apps/api/exodus/ExodusTrackerApi.kt 0 → 100644 +15 −0 Original line number Diff line number Diff line package foundation.e.apps.api.exodus import retrofit2.Response import retrofit2.http.GET interface ExodusTrackerApi { companion object { const val BASE_URL = "https://exodus.ecloud.global/api/" const val VERSION = "190239" } @GET("trackers?v=$VERSION") suspend fun getTrackerList(): Response<Trackers> } No newline at end of file
app/src/main/java/foundation/e/apps/api/exodus/Trackers.kt 0 → 100644 +25 −0 Original line number Diff line number Diff line package foundation.e.apps.api.exodus data class Trackers ( val trackers: Map<String, Tracker> ) data class Tracker ( val id: Long, val name: String, val description: String, val creationDate: String, val codeSignature: String, val networkSignature: String, val website: String, val categories: List<Category> ) enum class Category { Advertisement, Analytics, CrashReporting, Identification, Location, Profiling } No newline at end of file
app/src/main/java/foundation/e/apps/api/exodus/repositories/ITrackerRepository.kt 0 → 100644 +5 −0 Original line number Diff line number Diff line package foundation.e.apps.api.exodus.repositories interface ITrackerRepository { suspend fun getTrackerList(): Result<Boolean> } No newline at end of file