-
Couldn't load subscription status.
- Fork 0
Refactor Topic Screen to load data from Firestore
#23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9a3ab1b
- Integrate Firestore for fetching topics data.
yesshreyes 3c36718
Migrate ktor-client-okhttp dependency to version catalog
yesshreyes 2095ac1
Update README with progress on v0.2.0 roadmap
yesshreyes 301a529
Changed `Get APK` button color
yesshreyes e7cc486
Remove bookmark functionality from topic screen
yesshreyes 911a04c
Handle null topic names and descriptions
yesshreyes 27c9efe
Refactor: Improve naming of Firestore data models
yesshreyes fa724f5
Refactor: Organize network related classes
yesshreyes bd85fab
Refactor `TopicRepository` to use constructor injection for `HttpClie…
yesshreyes 4631445
Merge remote-tracking branch 'origin/shreyas/topic-screen-firestore' …
yesshreyes 451822e
Refactor Firestore response handling and remove unused strings
yesshreyes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
19 changes: 19 additions & 0 deletions
19
.../com/developersbreach/kotlindictionarymultiplatform/data/topic/model/FirestoreResponse.kt
This file contains hidden or 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,19 @@ | ||
| package com.developersbreach.kotlindictionarymultiplatform.data.topic.model | ||
|
|
||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class FirestoreDocument( | ||
| @SerialName("fields") val fields: Map<String, FirestoreField>, | ||
| ) | ||
|
|
||
| @Serializable | ||
| data class FirestoreField( | ||
| @SerialName("stringValue") val stringValue: String, | ||
| ) | ||
|
|
||
| @Serializable | ||
| data class FirestoreResponse( | ||
| @SerialName("documents") val documents: List<FirestoreDocument>, | ||
| ) |
4 changes: 4 additions & 0 deletions
4
...nMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/data/topic/model/Topic.kt
This file contains hidden or 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,5 +1,9 @@ | ||
| package com.developersbreach.kotlindictionarymultiplatform.data.topic.model | ||
|
|
||
| import kotlinx.serialization.Serializable | ||
|
|
||
| @Serializable | ||
| data class Topic( | ||
| val name: String, | ||
| val description: String, | ||
| ) |
37 changes: 19 additions & 18 deletions
37
...m/developersbreach/kotlindictionarymultiplatform/data/topic/repository/TopicRepository.kt
This file contains hidden or 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,28 +1,29 @@ | ||
| package com.developersbreach.kotlindictionarymultiplatform.data.topic.repository | ||
|
|
||
| import arrow.core.Either | ||
| import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.FirestoreResponse | ||
| import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.Topic | ||
| import com.developersbreach.kotlindictionarymultiplatform.data.topic.utils.FirestoreConstants | ||
| import com.developersbreach.kotlindictionarymultiplatform.data.topic.utils.toTopic | ||
| import io.ktor.client.HttpClient | ||
| import io.ktor.client.call.body | ||
| import io.ktor.client.request.get | ||
| import io.ktor.client.plugins.contentnegotiation.ContentNegotiation | ||
| import io.ktor.serialization.kotlinx.json.json | ||
| import kotlinx.serialization.json.Json | ||
|
|
||
| object TopicRepository { | ||
| fun getTopics(): Either<Throwable, List<Topic>> { | ||
|
|
||
| private val client = HttpClient { | ||
| install(ContentNegotiation) { | ||
| json(Json { ignoreUnknownKeys = true }) | ||
| } | ||
| } | ||
|
|
||
| suspend fun getTopics(): Either<Throwable, List<Topic>> { | ||
| return Either.catch { | ||
| listOf( | ||
| Topic("Variables"), | ||
| Topic("Strings"), | ||
| Topic("Functions"), | ||
| Topic("Coroutines"), | ||
| Topic("Classes"), | ||
| Topic("Interfaces"), | ||
| Topic("Objects"), | ||
| Topic("Collections"), | ||
| Topic("Null Safety"), | ||
| Topic("Lambdas"), | ||
| Topic("Higher-Order Functions"), | ||
| Topic("Delegation"), | ||
| Topic("Sealed Classes"), | ||
| Topic("Generics"), | ||
| Topic("Annotations"), | ||
| ) | ||
| val response: FirestoreResponse = client.get(FirestoreConstants.TOPICS_URL).body() | ||
| response.documents.map { it.toTopic() } | ||
| } | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
...com/developersbreach/kotlindictionarymultiplatform/data/topic/utils/FirestoreConstants.kt
This file contains hidden or 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 com.developersbreach.kotlindictionarymultiplatform.data.topic.utils | ||
|
|
||
| object FirestoreConstants { | ||
| const val TOPICS_URL = | ||
| "https://firestore.googleapis.com/v1/projects/kotlin-dictionary/databases/(default)/documents/topics" | ||
| } |
11 changes: 11 additions & 0 deletions
11
...ain/kotlin/com/developersbreach/kotlindictionarymultiplatform/data/topic/utils/Mappers.kt
This file contains hidden or 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,11 @@ | ||
| package com.developersbreach.kotlindictionarymultiplatform.data.topic.utils | ||
|
|
||
| import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.FirestoreDocument | ||
| import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.Topic | ||
|
|
||
| fun FirestoreDocument.toTopic(): Topic { | ||
| return Topic( | ||
| name = fields["name"]?.stringValue.orEmpty(), | ||
| description = fields["description"]?.stringValue.orEmpty(), | ||
| ) | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.