From 7a6872c4155144145ee4305e36ef6c84ba13f852 Mon Sep 17 00:00:00 2001 From: ianngech Date: Sat, 12 Mar 2022 22:25:30 +0300 Subject: [PATCH] added all the requests available on coinLore --- .../example/coinloreapi/api/CoinLoreAPI.kt | 12 ---- .../coinloreapi/api/CoinLoreAPIRequests.kt | 43 +++++++++++++++ .../example/coinloreapi/di/NetworkModule.kt | 6 +- .../coinloreapi/di/RepositoryModule.kt | 6 +- .../coinloreapi/models/CoinMarketsResponse.kt | 6 ++ .../models/CoinMarketsResponseItem.kt | 23 ++++++++ .../models/CoinSocialMediaResponse.kt | 11 ++++ .../coinloreapi/models/CoinTickerResponse.kt | 4 ++ .../models/CoinTickerResponseItem.kt | 39 +++++++++++++ .../models/CoinsTickersResponse.kt | 11 ++++ .../com/example/coinloreapi/models/Data.kt | 39 +++++++++++++ .../coinloreapi/models/ExchangeItemDetail.kt | 13 +++++ .../coinloreapi/models/ExchangeItemDetails.kt | 7 +++ .../models/ExchangeItemResponse.kt | 11 ++++ .../coinloreapi/models/ExchangesItems.kt | 39 +++++++++++++ .../com/example/coinloreapi/models/Info.kt | 11 ++++ .../com/example/coinloreapi/models/Pairs.kt | 19 +++++++ .../com/example/coinloreapi/models/Reddit.kt | 11 ++++ .../com/example/coinloreapi/models/Twitter.kt | 11 ++++ .../coinloreapi/repository/CoinLoreApi.kt | 46 ++++++++++++++++ .../repository/GlobalCoinRepository.kt | 55 ------------------- .../com/example/cryptknow/MainActivity.kt | 6 +- .../cryptknow/ui/components/HomeComponent.kt | 10 ++-- 23 files changed, 358 insertions(+), 81 deletions(-) delete mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/api/CoinLoreAPI.kt create mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/api/CoinLoreAPIRequests.kt create mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinMarketsResponse.kt create mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinMarketsResponseItem.kt create mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinSocialMediaResponse.kt create mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinTickerResponse.kt create mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinTickerResponseItem.kt create mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinsTickersResponse.kt create mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Data.kt create mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/ExchangeItemDetail.kt create mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/ExchangeItemDetails.kt create mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/ExchangeItemResponse.kt create mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/ExchangesItems.kt create mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Info.kt create mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Pairs.kt create mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Reddit.kt create mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Twitter.kt create mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/repository/CoinLoreApi.kt delete mode 100644 app/coinLoreAPI/src/main/java/com/example/coinloreapi/repository/GlobalCoinRepository.kt diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/api/CoinLoreAPI.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/api/CoinLoreAPI.kt deleted file mode 100644 index 085ce1b..0000000 --- a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/api/CoinLoreAPI.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.example.coinloreapi.api - -import com.example.coinloreapi.models.GlobalCoinResponse -import retrofit2.Response -import retrofit2.http.GET - - -interface CoinLoreAPI{ - - @GET("api/global/") - suspend fun getGlobalCoinData():Response -} \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/api/CoinLoreAPIRequests.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/api/CoinLoreAPIRequests.kt new file mode 100644 index 0000000..e0788cf --- /dev/null +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/api/CoinLoreAPIRequests.kt @@ -0,0 +1,43 @@ +package com.example.coinloreapi.api + +import com.example.coinloreapi.models.* +import retrofit2.Response +import retrofit2.http.GET +import retrofit2.http.Query + + +interface CoinLoreAPIRequests { + + @GET("api/global/") + suspend fun getGlobalCoinData(): Response + + @GET("api/tickers/") + suspend fun getCoinsTickers( + @Query("start") start: Long? = null, + @Query("limit") limit: Long? = null, + ): Response + + @GET("api/ticker/") + suspend fun getCoinTicker( + @Query("id") id: Int + ): Response + + @GET("api/coin/markets") + suspend fun getCoinMarkets( + @Query("id") id: Int + ): Response + + @GET("api/exchanges/") + suspend fun getAllExchanges():Response> + + @GET("api/exchange/") + suspend fun getExchange( + @Query("id") id:Int + ):Response + + @GET("api/coin/social_stats/") + suspend fun getCoinSocialMedia( + @Query("id") id:Int + ):Response + +} \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/di/NetworkModule.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/di/NetworkModule.kt index 3a1ddb0..3316044 100644 --- a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/di/NetworkModule.kt +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/di/NetworkModule.kt @@ -1,6 +1,6 @@ package com.example.coinloreapi.di -import com.example.coinloreapi.api.CoinLoreAPI +import com.example.coinloreapi.api.CoinLoreAPIRequests import com.example.coinloreapi.utils.Constants.COIN_LORE_BASE_API import okhttp3.Interceptor import okhttp3.OkHttpClient @@ -47,6 +47,6 @@ fun provideOkHttpClient(httpLoggingInterceptor: HttpLoggingInterceptor):OkHttpCl .build() } -fun provideCoinLoreApi(retrofit: Retrofit):CoinLoreAPI{ - return retrofit.create(CoinLoreAPI::class.java) +fun provideCoinLoreApi(retrofit: Retrofit):CoinLoreAPIRequests{ + return retrofit.create(CoinLoreAPIRequests::class.java) } \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/di/RepositoryModule.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/di/RepositoryModule.kt index df23070..4f88901 100644 --- a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/di/RepositoryModule.kt +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/di/RepositoryModule.kt @@ -1,12 +1,12 @@ package com.example.coinloreapi.di -import com.example.coinloreapi.repository.GlobalCoinRepository +import com.example.coinloreapi.repository.CoinLoreApi import org.koin.dsl.module val repositoryModule = module { single { provideGlobalCoinRepository() } } -fun provideGlobalCoinRepository():GlobalCoinRepository{ - return GlobalCoinRepository() +fun provideGlobalCoinRepository():CoinLoreApi{ + return CoinLoreApi() } \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinMarketsResponse.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinMarketsResponse.kt new file mode 100644 index 0000000..829d8c5 --- /dev/null +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinMarketsResponse.kt @@ -0,0 +1,6 @@ +package com.example.coinloreapi.models + + +import com.google.gson.annotations.SerializedName + +class CoinMarketsResponse : ArrayList() \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinMarketsResponseItem.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinMarketsResponseItem.kt new file mode 100644 index 0000000..05130a2 --- /dev/null +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinMarketsResponseItem.kt @@ -0,0 +1,23 @@ +package com.example.coinloreapi.models + + +import com.google.gson.annotations.SerializedName + +data class CoinMarketsResponseItem( + @SerializedName("base") + val base: String, + @SerializedName("name") + val name: String, + @SerializedName("price") + val price: Double, + @SerializedName("price_usd") + val priceUsd: Double, + @SerializedName("quote") + val quote: String, + @SerializedName("time") + val time: Int, + @SerializedName("volume") + val volume: Double, + @SerializedName("volume_usd") + val volumeUsd: Double +) \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinSocialMediaResponse.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinSocialMediaResponse.kt new file mode 100644 index 0000000..f56c10b --- /dev/null +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinSocialMediaResponse.kt @@ -0,0 +1,11 @@ +package com.example.coinloreapi.models + + +import com.google.gson.annotations.SerializedName + +data class CoinSocialMediaResponse( + @SerializedName("reddit") + var reddit: Reddit? = null, + @SerializedName("twitter") + var twitter: Twitter? = null +) \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinTickerResponse.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinTickerResponse.kt new file mode 100644 index 0000000..148598a --- /dev/null +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinTickerResponse.kt @@ -0,0 +1,4 @@ +package com.example.coinloreapi.models + + +class CoinTickerResponse : ArrayList() \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinTickerResponseItem.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinTickerResponseItem.kt new file mode 100644 index 0000000..7de74dc --- /dev/null +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinTickerResponseItem.kt @@ -0,0 +1,39 @@ +package com.example.coinloreapi.models + + +import com.google.gson.annotations.SerializedName + +data class CoinTickerResponseItem( + @SerializedName("csupply") + val csupply: String, + @SerializedName("id") + val id: String, + @SerializedName("market_cap_usd") + val marketCapUsd: String, + @SerializedName("msupply") + val msupply: String, + @SerializedName("name") + val name: String, + @SerializedName("nameid") + val nameid: String, + @SerializedName("percent_change_1h") + val percentChange1h: String, + @SerializedName("percent_change_24h") + val percentChange24h: String, + @SerializedName("percent_change_7d") + val percentChange7d: String, + @SerializedName("price_btc") + val priceBtc: String, + @SerializedName("price_usd") + val priceUsd: String, + @SerializedName("rank") + val rank: Int, + @SerializedName("symbol") + val symbol: String, + @SerializedName("tsupply") + val tsupply: String, + @SerializedName("volume24") + val volume24: String, + @SerializedName("volume24_native") + val volume24Native: String +) \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinsTickersResponse.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinsTickersResponse.kt new file mode 100644 index 0000000..c0d081f --- /dev/null +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/CoinsTickersResponse.kt @@ -0,0 +1,11 @@ +package com.example.coinloreapi.models + + +import com.google.gson.annotations.SerializedName + +data class CoinsTickersResponse( + @SerializedName("data") + val data: List, + @SerializedName("info") + val info: Info +) \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Data.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Data.kt new file mode 100644 index 0000000..7dea79c --- /dev/null +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Data.kt @@ -0,0 +1,39 @@ +package com.example.coinloreapi.models + + +import com.google.gson.annotations.SerializedName + +data class Data( + @SerializedName("csupply") + val csupply: String, + @SerializedName("id") + val id: String, + @SerializedName("market_cap_usd") + val marketCapUsd: String, + @SerializedName("msupply") + val msupply: String, + @SerializedName("name") + val name: String, + @SerializedName("nameid") + val nameid: String, + @SerializedName("percent_change_1h") + val percentChange1h: String, + @SerializedName("percent_change_24h") + val percentChange24h: String, + @SerializedName("percent_change_7d") + val percentChange7d: String, + @SerializedName("price_btc") + val priceBtc: String, + @SerializedName("price_usd") + val priceUsd: String, + @SerializedName("rank") + val rank: Int, + @SerializedName("symbol") + val symbol: String, + @SerializedName("tsupply") + val tsupply: String, + @SerializedName("volume24") + val volume24: Double, + @SerializedName("volume24a") + val volume24a: Double +) \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/ExchangeItemDetail.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/ExchangeItemDetail.kt new file mode 100644 index 0000000..c6e9809 --- /dev/null +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/ExchangeItemDetail.kt @@ -0,0 +1,13 @@ +package com.example.coinloreapi.models + + +import com.google.gson.annotations.SerializedName + +data class ExchangeItemDetail( + @SerializedName("date_live") + var dateLive: String? = null, + @SerializedName("name") + var name: String? = null, + @SerializedName("url") + var url: String? = null +) \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/ExchangeItemDetails.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/ExchangeItemDetails.kt new file mode 100644 index 0000000..68e2834 --- /dev/null +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/ExchangeItemDetails.kt @@ -0,0 +1,7 @@ +package com.example.coinloreapi.models + +data class ExchangeItemDetails( + var date_live: String? = null, + var name: String? = null, + var url: String? = null +) \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/ExchangeItemResponse.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/ExchangeItemResponse.kt new file mode 100644 index 0000000..4f68c13 --- /dev/null +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/ExchangeItemResponse.kt @@ -0,0 +1,11 @@ +package com.example.coinloreapi.models + + +import com.google.gson.annotations.SerializedName + +data class ExchangeItemResponse( + @SerializedName("pairs") + var pairs: List? = null, + @SerializedName("0") + var exchangeItemDetail: ExchangeItemDetail? = null +) \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/ExchangesItems.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/ExchangesItems.kt new file mode 100644 index 0000000..e352287 --- /dev/null +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/ExchangesItems.kt @@ -0,0 +1,39 @@ +package com.example.coinloreapi.models + +data class ExchangesItems( + var `0`: String? = null, + var `1`: String? = null, + var `10`: Any? = null, + var `11`: Any? = null, + var `12`: Any? = null, + var `13`: String? = null, + var `14`: Any? = null, + var `2`: String? = null, + var `3`: String? = null, + var `4`: String? = null, + var `5`: String? = null, + var `6`: String? = null, + var `7`: String? = null, + var `8`: String? = null, + var `9`: String? = null, + var alexa: Any? = null, + var auto: String? = null, + var centralized: Any? = null, + var country: String? = null, + var date_added: String? = null, + var date_live: String? = null, + var dex: Any? = null, + var f: String? = null, + var fiat: String? = null, + var id: String? = null, + var mining: Any? = null, + var name: String? = null, + var name_id: String? = null, + var pairs: Int? = null, + var tr: Int? = null, + var udate: String? = null, + var url: String? = null, + var usdt: String? = null, + var volume_usd: Double? = null, + var volume_usd_adj: Double? = null +) \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Info.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Info.kt new file mode 100644 index 0000000..a74b3d9 --- /dev/null +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Info.kt @@ -0,0 +1,11 @@ +package com.example.coinloreapi.models + + +import com.google.gson.annotations.SerializedName + +data class Info( + @SerializedName("coins_num") + val coinsNum: Double, + @SerializedName("time") + val time: Double +) \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Pairs.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Pairs.kt new file mode 100644 index 0000000..b408a9c --- /dev/null +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Pairs.kt @@ -0,0 +1,19 @@ +package com.example.coinloreapi.models + + +import com.google.gson.annotations.SerializedName + +data class Pairs( + @SerializedName("base") + var base: String? = null, + @SerializedName("price") + var price: Double? = null, + @SerializedName("price_usd") + var priceUsd: Double? = null, + @SerializedName("quote") + var quote: Any? = null, + @SerializedName("time") + var time: Int? = null, + @SerializedName("volume") + var volume: Double? = null +) \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Reddit.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Reddit.kt new file mode 100644 index 0000000..ca1d568 --- /dev/null +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Reddit.kt @@ -0,0 +1,11 @@ +package com.example.coinloreapi.models + + +import com.google.gson.annotations.SerializedName + +data class Reddit( + @SerializedName("avg_active_users") + var avgActiveUsers: Double? = null, + @SerializedName("subscribers") + var subscribers: Int? = null +) \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Twitter.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Twitter.kt new file mode 100644 index 0000000..4f240d2 --- /dev/null +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/models/Twitter.kt @@ -0,0 +1,11 @@ +package com.example.coinloreapi.models + + +import com.google.gson.annotations.SerializedName + +data class Twitter( + @SerializedName("followers_count") + var followersCount: Int? = null, + @SerializedName("status_count") + var statusCount: Int? = null +) \ No newline at end of file diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/repository/CoinLoreApi.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/repository/CoinLoreApi.kt new file mode 100644 index 0000000..768f08e --- /dev/null +++ b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/repository/CoinLoreApi.kt @@ -0,0 +1,46 @@ +package com.example.coinloreapi.repository + +import com.example.coinloreapi.api.CoinLoreAPIRequests +import com.example.coinloreapi.api.coinLoreApiCall +import com.example.coinloreapi.models.* +import org.koin.java.KoinJavaComponent.inject + +class CoinLoreApi { + + private val coinLoreAPIRequests: CoinLoreAPIRequests by inject(CoinLoreAPIRequests::class.java) + private val TAG = CoinLoreApi::class.java.name + + + suspend fun getGlobalCoinResponse(): CoinLoreResponse { + return coinLoreApiCall(apiCall = { coinLoreAPIRequests.getGlobalCoinData() }) + } + + suspend fun getCoinsTickers( + start: Long? = null, + limit: Long? = null + ): CoinLoreResponse { + return coinLoreApiCall { coinLoreAPIRequests.getCoinsTickers(start = start, limit = limit) } + } + + suspend fun getCoinTicker(id: Int): CoinLoreResponse { + return coinLoreApiCall { coinLoreAPIRequests.getCoinTicker(id = id) } + } + + suspend fun getCoinMarkets(id: Int): CoinLoreResponse { + return coinLoreApiCall { coinLoreAPIRequests.getCoinMarkets(id = id) } + } + + + suspend fun getAllExchanges(): CoinLoreResponse> { + return coinLoreApiCall { coinLoreAPIRequests.getAllExchanges() } + } + + suspend fun getExchange(id:Int): CoinLoreResponse{ + return coinLoreApiCall { coinLoreAPIRequests.getExchange(id) } + } + + suspend fun getCoinSocialMedia(id: Int):CoinLoreResponse{ + return coinLoreApiCall { coinLoreAPIRequests.getCoinSocialMedia(id) } + } +} + diff --git a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/repository/GlobalCoinRepository.kt b/app/coinLoreAPI/src/main/java/com/example/coinloreapi/repository/GlobalCoinRepository.kt deleted file mode 100644 index 81b242d..0000000 --- a/app/coinLoreAPI/src/main/java/com/example/coinloreapi/repository/GlobalCoinRepository.kt +++ /dev/null @@ -1,55 +0,0 @@ -package com.example.coinloreapi.repository - -import android.util.Log -import com.example.coinloreapi.api.CoinLoreAPI -import com.example.coinloreapi.api.coinLoreApiCall -import com.example.coinloreapi.models.CoinLoreResponse -import com.example.coinloreapi.models.GlobalCoinResponse -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.async -import kotlinx.coroutines.withContext -import org.koin.java.KoinJavaComponent.inject -import retrofit2.Response -import java.io.IOException - -class GlobalCoinRepository { - - private val coinLoreAPI: CoinLoreAPI by inject(CoinLoreAPI::class.java) - private val TAG = GlobalCoinRepository::class.java.name - - suspend fun getGlobalCoin(): CoinLoreResponse = - withContext(Dispatchers.IO) { - try { - val responseDeffered = async { coinLoreAPI.getGlobalCoinData() } - val response: Response = responseDeffered.await() - Log.d(TAG, "response: ${response.raw()}") - if (response.isSuccessful) { - Log.d(TAG, "success") - CoinLoreResponse( - data = response.body(), - message = "successful", - isOk = true, - httpStatus = response.code() - ) - } else { - Log.e(TAG, "error: ${response}") - CoinLoreResponse( - data = response.body(), - message = response.errorBody().toString(), - isOk = false, - httpStatus = response.code() - ) - } - - } catch (error: IOException) { - - CoinLoreResponse(message = error.localizedMessage) - } - } - - suspend fun getGlobalCoinResponse():CoinLoreResponse{ - return coinLoreApiCall(apiCall = {coinLoreAPI.getGlobalCoinData()}) - } - -} - diff --git a/app/src/main/java/com/example/cryptknow/MainActivity.kt b/app/src/main/java/com/example/cryptknow/MainActivity.kt index 1e328e2..b9a941b 100644 --- a/app/src/main/java/com/example/cryptknow/MainActivity.kt +++ b/app/src/main/java/com/example/cryptknow/MainActivity.kt @@ -7,14 +7,14 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material.MaterialTheme import androidx.compose.material.Surface import androidx.compose.ui.Modifier -import com.example.coinloreapi.repository.GlobalCoinRepository +import com.example.coinloreapi.repository.CoinLoreApi import com.example.cryptknow.ui.components.HomeItems import com.example.cryptknow.ui.theme.CryptKnowTheme import org.koin.android.ext.android.inject class MainActivity : ComponentActivity() { - private val coinRepository:GlobalCoinRepository by inject() + private val coinLoreApi:CoinLoreApi by inject() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -25,7 +25,7 @@ class MainActivity : ComponentActivity() { modifier = Modifier.fillMaxSize(), color = MaterialTheme.colors.background ) { - HomeItems(coinRepository = coinRepository) + HomeItems(coinLoreApi = coinLoreApi) } } } diff --git a/app/src/main/java/com/example/cryptknow/ui/components/HomeComponent.kt b/app/src/main/java/com/example/cryptknow/ui/components/HomeComponent.kt index d8dad3e..378c651 100644 --- a/app/src/main/java/com/example/cryptknow/ui/components/HomeComponent.kt +++ b/app/src/main/java/com/example/cryptknow/ui/components/HomeComponent.kt @@ -10,19 +10,19 @@ import androidx.compose.runtime.produceState import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import com.example.coinloreapi.models.CoinLoreResponse -import com.example.coinloreapi.models.GlobalCoinResponse -import com.example.coinloreapi.repository.GlobalCoinRepository +import com.example.coinloreapi.models.CoinSocialMediaResponse +import com.example.coinloreapi.repository.CoinLoreApi @Composable -fun HomeItems(coinRepository: GlobalCoinRepository){ +fun HomeItems(coinLoreApi: CoinLoreApi){ Column( modifier = Modifier.fillMaxSize(), verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally ) { - val coinState by produceState(initialValue = CoinLoreResponse() ){ - val response = coinRepository.getGlobalCoinResponse() + val coinState by produceState(initialValue = CoinLoreResponse() ){ + val response = coinLoreApi.getCoinSocialMedia(4) value = response } if(coinState.isOk == false){