-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added shared feature homepage module, added store5 for caching
- Loading branch information
1 parent
be25713
commit fc57e1d
Showing
31 changed files
with
603 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed | ||
plugins { | ||
alias(libs.plugins.kotlin.multiplatform) | ||
alias(libs.plugins.com.android.library) | ||
alias(libs.plugins.kotlin.serialization) | ||
} | ||
|
||
kotlin { | ||
androidTarget { | ||
compilations.all { | ||
kotlinOptions { | ||
jvmTarget = libs.versions.jvmTargetVersion.get() | ||
} | ||
} | ||
} | ||
|
||
listOf( | ||
iosX64(), | ||
iosArm64(), | ||
iosSimulatorArm64() | ||
).forEach { | ||
it.binaries.framework { | ||
baseName = "core-base" | ||
isStatic = true | ||
} | ||
} | ||
|
||
sourceSets { | ||
commonMain.dependencies { | ||
api(libs.kotlin.serialization) | ||
} | ||
commonTest.dependencies { | ||
implementation(libs.kotlin.test) | ||
} | ||
} | ||
} | ||
|
||
android { | ||
namespace = "com.spotify.app.core_base.shared" | ||
compileSdk = libs.versions.compileSdkVersion.get().toInt() | ||
defaultConfig { | ||
minSdk = libs.versions.minSdkVersion.get().toInt() | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...d/core-base/src/commonMain/kotlin/com/spotify/app/core_base/shared/data/base/DtoMapper.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,8 @@ | ||
package com.spotify.app.core_base.shared.data.base | ||
|
||
interface DtoMapper<Domain, DTO> { | ||
|
||
fun asDto(domain: Domain): DTO | ||
|
||
fun asDomain(dto: DTO): Domain | ||
} |
10 changes: 10 additions & 0 deletions
10
shared/core-base/src/commonMain/kotlin/com/spotify/app/core_base/shared/data/dto/ImageDTO.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,10 @@ | ||
package com.spotify.app.core_base.shared.data.dto | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class ImageDTO( | ||
@SerialName("url") | ||
val url: String | ||
) |
19 changes: 19 additions & 0 deletions
19
...se/src/commonMain/kotlin/com/spotify/app/core_base/shared/domain/mapper/ImageDtoMapper.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,19 @@ | ||
package com.spotify.app.core_base.shared.domain.mapper | ||
|
||
import com.spotify.app.core_base.shared.data.base.DtoMapper | ||
import com.spotify.app.core_base.shared.data.dto.ImageDTO | ||
import com.spotify.app.core_base.shared.domain.model.Image | ||
|
||
object ImageDtoMapper : DtoMapper<Image, ImageDTO> { | ||
override fun asDto(domain: Image): ImageDTO { | ||
return ImageDTO( | ||
url = domain.url | ||
) | ||
} | ||
|
||
override fun asDomain(dto: ImageDTO): Image { | ||
return Image( | ||
url = dto.url | ||
) | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...ed/core-base/src/commonMain/kotlin/com/spotify/app/core_base/shared/domain/model/Image.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,5 @@ | ||
package com.spotify.app.core_base.shared.domain.model | ||
|
||
data class Image( | ||
val url: String | ||
) |
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
87 changes: 87 additions & 0 deletions
87
...network/src/commonMain/kotlin/com/spotify/app/core_network/shared/impl/util/Extensions.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,87 @@ | ||
package com.spotify.app.core_network.shared.impl.util | ||
|
||
import com.spotify.app.core_network.shared.impl.data.model.RestClientResult | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.collectLatest | ||
import kotlinx.coroutines.flow.map | ||
import org.mobilenativefoundation.store.store5.StoreReadResponse | ||
|
||
suspend inline fun <DTO, Domain> RestClientResult<DTO>.mapFromDTO( | ||
crossinline dataMapper: suspend (t: DTO?) -> Domain | ||
): RestClientResult<Domain> { | ||
return when (status) { | ||
RestClientResult.Status.LOADING -> { | ||
RestClientResult.loading() | ||
} | ||
|
||
RestClientResult.Status.SUCCESS -> { | ||
RestClientResult.success(data = dataMapper.invoke(data)) | ||
} | ||
|
||
RestClientResult.Status.ERROR -> { | ||
RestClientResult.error(errorMessage = errorMessage.orEmpty(), errorCode = errorCode) | ||
} | ||
} | ||
} | ||
|
||
fun <T> Flow<StoreReadResponse<RestClientResult<T>>>.mapStoreResponseToRestClientResult(): Flow<RestClientResult<T?>> = | ||
this.map { | ||
when (it) { | ||
is StoreReadResponse.Data -> { | ||
when (it.value.status) { | ||
RestClientResult.Status.SUCCESS -> { | ||
RestClientResult.success(it.value.data) | ||
} | ||
|
||
RestClientResult.Status.ERROR -> { | ||
RestClientResult.error( | ||
errorMessage = it.value.errorMessage.orEmpty(), | ||
errorCode = it.value.errorCode | ||
) | ||
} | ||
|
||
RestClientResult.Status.LOADING -> { | ||
RestClientResult.loading() | ||
} | ||
} | ||
} | ||
|
||
is StoreReadResponse.Error.Exception -> { | ||
RestClientResult.error(errorMessage = it.errorMessageOrNull().orEmpty()) | ||
} | ||
|
||
is StoreReadResponse.Error.Message -> { | ||
RestClientResult.error(errorMessage = it.errorMessageOrNull().orEmpty()) | ||
} | ||
|
||
is StoreReadResponse.Loading -> { | ||
RestClientResult.loading() | ||
} | ||
|
||
is StoreReadResponse.NoNewData -> { | ||
RestClientResult.error(errorMessage = it.errorMessageOrNull().orEmpty()) | ||
} | ||
} | ||
} | ||
|
||
suspend fun <T> Flow<RestClientResult<T>>.collect( | ||
onLoading: suspend () -> Unit, | ||
onSuccess: suspend (data: T) -> Unit, | ||
onError: suspend (errorMessage: String, errorCode: Int?) -> Unit | ||
) { | ||
this.collectLatest { | ||
when (it.status) { | ||
RestClientResult.Status.LOADING -> { | ||
onLoading.invoke() | ||
} | ||
|
||
RestClientResult.Status.SUCCESS -> { | ||
onSuccess.invoke(it.data!!) | ||
} | ||
|
||
RestClientResult.Status.ERROR -> { | ||
onError.invoke(it.errorMessage.orEmpty(), it.errorCode) | ||
} | ||
} | ||
} | ||
} |
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,58 @@ | ||
@Suppress("DSL_SCOPE_VIOLATION") // TODO: Remove once KTIJ-19369 is fixed | ||
plugins { | ||
alias(libs.plugins.kotlin.multiplatform) | ||
alias(libs.plugins.com.android.library) | ||
alias(libs.plugins.kotlin.serialization) | ||
} | ||
|
||
kotlin { | ||
androidTarget { | ||
compilations.all { | ||
kotlinOptions { | ||
jvmTarget = libs.versions.jvmTargetVersion.get() | ||
} | ||
} | ||
} | ||
|
||
listOf( | ||
iosX64(), | ||
iosArm64(), | ||
iosSimulatorArm64() | ||
).forEach { | ||
it.binaries.framework { | ||
baseName = "feature-homepage" | ||
isStatic = true | ||
} | ||
} | ||
|
||
sourceSets { | ||
commonMain.dependencies { | ||
|
||
// Shared Core Base Module | ||
implementation(project(":shared:core-base")) | ||
|
||
// Shared Core Network Module | ||
implementation(project(":shared:core-network")) | ||
|
||
// Store5 | ||
implementation(libs.bundles.store) | ||
|
||
// Koin | ||
implementation(libs.koin) | ||
|
||
} | ||
commonTest.dependencies { | ||
implementation(libs.kotlin.test) | ||
} | ||
} | ||
} | ||
|
||
val modulePackageName = "com.spotify.app.feature_homepage.shared" | ||
|
||
android { | ||
namespace = modulePackageName | ||
compileSdk = libs.versions.compileSdkVersion.get().toInt() | ||
defaultConfig { | ||
minSdk = libs.versions.minSdkVersion.get().toInt() | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ommonMain/kotlin/com/spotify/app/feature_homepage/shared/data/dto/FeaturedPlaylistsDTO.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,13 @@ | ||
package com.spotify.app.feature_homepage.shared.data.dto | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class FeaturedPlaylistsDTO( | ||
@SerialName("message") | ||
val message: String, | ||
|
||
@SerialName("playlists") | ||
val playlists: PlaylistDTO | ||
) |
13 changes: 13 additions & 0 deletions
13
...age/src/commonMain/kotlin/com/spotify/app/feature_homepage/shared/data/dto/PlaylistDTO.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,13 @@ | ||
package com.spotify.app.feature_homepage.shared.data.dto | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class PlaylistDTO( | ||
@SerialName("items") | ||
val items: List<PlaylistItemDTO>, | ||
|
||
@SerialName("total") | ||
val total: Int | ||
) |
Oops, something went wrong.