-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from aritra-tech/news_screen
News screen impl.
- Loading branch information
Showing
34 changed files
with
627 additions
and
85 deletions.
There are no files selected for viewing
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 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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,20 @@ | ||
package data.remote | ||
|
||
import com.aritra.coinify.BuildKonfig.API_KEY | ||
import domain.model.Listings | ||
import domain.model.crypto.Listings | ||
import domain.model.news.News | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.call.body | ||
import io.ktor.client.plugins.HttpTimeout | ||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation | ||
import io.ktor.client.plugins.defaultRequest | ||
import io.ktor.client.plugins.logging.LogLevel | ||
import io.ktor.client.plugins.logging.Logger | ||
import io.ktor.client.plugins.logging.Logging | ||
import io.ktor.client.request.get | ||
import io.ktor.client.request.headers | ||
import io.ktor.serialization.kotlinx.json.json | ||
import kotlinx.serialization.json.Json | ||
import utils.Constants.BASE_URL | ||
import utils.Constants.REQUEST_TIME_OUT | ||
import utils.Constants.NEWS_URL | ||
|
||
object ApiClient { | ||
private val client = HttpClient { | ||
install(ContentNegotiation) { | ||
json( | ||
json = Json { | ||
prettyPrint = true | ||
isLenient = false | ||
ignoreUnknownKeys = true | ||
coerceInputValues = true | ||
explicitNulls = true | ||
} | ||
) | ||
} | ||
install(Logging) { | ||
level = LogLevel.ALL | ||
logger = object : Logger { | ||
override fun log(message: String) { | ||
println(message) | ||
} | ||
} | ||
} | ||
install(HttpTimeout) { | ||
requestTimeoutMillis = REQUEST_TIME_OUT | ||
connectTimeoutMillis = REQUEST_TIME_OUT | ||
socketTimeoutMillis = REQUEST_TIME_OUT | ||
} | ||
defaultRequest { | ||
headers { | ||
append("X-CMC_PRO_API_KEY", API_KEY) | ||
} | ||
} | ||
} | ||
class ApiClient(private val client: HttpClient) { | ||
|
||
suspend fun getListings(): Listings { | ||
return client.get(BASE_URL + "cryptocurrency/listings/latest").body() | ||
} | ||
|
||
suspend fun getAllNews(): News { | ||
return client.get(NEWS_URL + "v2/news/?lang=EN").body() | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,72 @@ | ||
package di | ||
|
||
import domain.repository.ListingRepository | ||
import com.aritra.coinify.BuildKonfig.API_KEY | ||
import data.remote.ApiClient | ||
import domain.repository.CoinifyRepository | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.plugins.HttpTimeout | ||
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation | ||
import io.ktor.client.plugins.defaultRequest | ||
import io.ktor.client.plugins.logging.LogLevel | ||
import io.ktor.client.plugins.logging.Logger | ||
import io.ktor.client.plugins.logging.Logging | ||
import io.ktor.client.request.headers | ||
import io.ktor.http.HttpHeaders | ||
import io.ktor.serialization.kotlinx.json.json | ||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.json.Json | ||
import org.koin.dsl.module | ||
import presentation.home.HomeViewModel | ||
import presentation.news.NewsViewModel | ||
import presentation.settings.SettingsViewModel | ||
import utils.Constants.REQUEST_TIME_OUT | ||
import utils.ThemeViewModel | ||
import utils.coreComponent | ||
import utils.viewModelDefinition | ||
|
||
@OptIn(ExperimentalSerializationApi::class) | ||
val appModule = module { | ||
|
||
single { ListingRepository() } | ||
single { | ||
HttpClient { | ||
install(ContentNegotiation) { | ||
json( | ||
json = Json { | ||
prettyPrint = true | ||
isLenient = false | ||
ignoreUnknownKeys = true | ||
coerceInputValues = true | ||
explicitNulls = true | ||
} | ||
) | ||
} | ||
install(Logging) { | ||
level = LogLevel.ALL | ||
logger = object : Logger { | ||
override fun log(message: String) { | ||
println(message) | ||
} | ||
} | ||
// filter { filter-> filter.url.host.contains("coinmarketcap.com") } | ||
// sanitizeHeader { header-> header == HttpHeaders.Authorization } | ||
} | ||
install(HttpTimeout) { | ||
requestTimeoutMillis = REQUEST_TIME_OUT | ||
connectTimeoutMillis = REQUEST_TIME_OUT | ||
socketTimeoutMillis = REQUEST_TIME_OUT | ||
} | ||
defaultRequest { | ||
headers { | ||
append("X-CMC_PRO_API_KEY", API_KEY) | ||
} | ||
} | ||
} | ||
} | ||
single { CoinifyRepository(get()) } | ||
single { ApiClient(get()) } | ||
single { coreComponent.appPreferences } | ||
|
||
viewModelDefinition { HomeViewModel(get()) } | ||
viewModelDefinition { SettingsViewModel(get()) } | ||
viewModelDefinition { ThemeViewModel(get()) } | ||
viewModelDefinition { NewsViewModel(get()) } | ||
} |
2 changes: 1 addition & 1 deletion
2
...src/commonMain/kotlin/domain/model/BTC.kt → ...monMain/kotlin/domain/model/crypto/BTC.kt
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
2 changes: 1 addition & 1 deletion
2
...rc/commonMain/kotlin/domain/model/Data.kt → ...onMain/kotlin/domain/model/crypto/Data.kt
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
2 changes: 1 addition & 1 deletion
2
...ommonMain/kotlin/domain/model/Listings.kt → ...in/kotlin/domain/model/crypto/Listings.kt
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
2 changes: 1 addition & 1 deletion
2
...ommonMain/kotlin/domain/model/Platform.kt → ...in/kotlin/domain/model/crypto/Platform.kt
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
2 changes: 1 addition & 1 deletion
2
...c/commonMain/kotlin/domain/model/Quote.kt → ...nMain/kotlin/domain/model/crypto/Quote.kt
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
2 changes: 1 addition & 1 deletion
2
.../commonMain/kotlin/domain/model/Status.kt → ...Main/kotlin/domain/model/crypto/Status.kt
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
2 changes: 1 addition & 1 deletion
2
...src/commonMain/kotlin/domain/model/USD.kt → ...monMain/kotlin/domain/model/crypto/USD.kt
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
37 changes: 37 additions & 0 deletions
37
composeApp/src/commonMain/kotlin/domain/model/news/Data.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package domain.model.news | ||
|
||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class Data( | ||
@SerialName("body") | ||
val body: String = "", | ||
@SerialName("categories") | ||
val categories: String = "", | ||
@SerialName("downvotes") | ||
val downvotes: String = "", | ||
@SerialName("guid") | ||
val guid: String = "", | ||
@SerialName("id") | ||
val id: String = "", | ||
@SerialName("imageurl") | ||
val imageurl: String = "", | ||
@SerialName("lang") | ||
val lang: String = "", | ||
@SerialName("published_on") | ||
val publishedOn: Int = 0, | ||
@SerialName("source") | ||
val source: String = "", | ||
@SerialName("source_info") | ||
val sourceInfo: SourceInfo = SourceInfo(), | ||
@SerialName("tags") | ||
val tags: String = "", | ||
@SerialName("title") | ||
val title: String = "", | ||
@SerialName("upvotes") | ||
val upvotes: String = "", | ||
@SerialName("url") | ||
val url: String = "" | ||
) |
20 changes: 20 additions & 0 deletions
20
composeApp/src/commonMain/kotlin/domain/model/news/News.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package domain.model.news | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class News ( | ||
@SerialName("Data") | ||
val `data`: List<Data> = listOf(), | ||
@SerialName("HasWarning") | ||
val hasWarning: Boolean = false, | ||
@SerialName("Message") | ||
val message: String = "", | ||
@SerialName("Promoted") | ||
val promoted: List<String> = listOf(), | ||
@SerialName("RateLimit") | ||
val rateLimit: RateLimit = RateLimit(), | ||
@SerialName("Type") | ||
val type: Int = 0 | ||
) |
6 changes: 6 additions & 0 deletions
6
composeApp/src/commonMain/kotlin/domain/model/news/RateLimit.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package domain.model.news | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
class RateLimit |
14 changes: 14 additions & 0 deletions
14
composeApp/src/commonMain/kotlin/domain/model/news/SourceInfo.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package domain.model.news | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class SourceInfo ( | ||
@SerialName("img") | ||
val img: String = "", | ||
@SerialName("lang") | ||
val lang: String = "", | ||
@SerialName("name") | ||
val name: String = "" | ||
) |
18 changes: 18 additions & 0 deletions
18
composeApp/src/commonMain/kotlin/domain/repository/CoinifyRepository.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package domain.repository | ||
|
||
import data.remote.ApiClient | ||
import domain.model.crypto.Listings | ||
import domain.model.news.News | ||
|
||
class CoinifyRepository( | ||
private val apiClient: ApiClient | ||
): CryptoAPI { | ||
|
||
override suspend fun getListing(): Listings { | ||
return apiClient.getListings() | ||
} | ||
|
||
override suspend fun getAllNews(): News { | ||
return apiClient.getAllNews() | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
composeApp/src/commonMain/kotlin/domain/repository/CryptoAPI.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package domain.repository | ||
|
||
import domain.model.crypto.Listings | ||
import domain.model.news.News | ||
|
||
interface CryptoAPI { | ||
suspend fun getListing(): Listings | ||
suspend fun getAllNews(): News | ||
} |
7 changes: 0 additions & 7 deletions
7
composeApp/src/commonMain/kotlin/domain/repository/CryptoDao.kt
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
composeApp/src/commonMain/kotlin/domain/repository/ListingRepository.kt
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.