Skip to content

Commit 6ce1837

Browse files
committed
refactor: unify platform enums into DiscoveryPlatform in core domain
- Consolidate redundant `HomePlatform` and `SearchPlatform` enums into a single `DiscoveryPlatform` in the core domain module. - Update `GithubRepoSummary` and its UI counterpart to use `DiscoveryPlatform` instead of raw strings for available platforms. - Migrate `HomeRepository`, `SearchRepository`, and their implementations to use the unified `DiscoveryPlatform` for filtering. - Refactor `CachedRepositoriesDataSource` to support the new shared platform model. - Move and rename `HomePlatformMapper` to `DiscoveryPlatformIconMapper` in the core presentation module for broader reuse. - Update asset-to-platform detection logic in `SearchRepositoryImpl` and `AppHeader` to map file extensions (e.g., .apk, .exe, .dmg) directly to `DiscoveryPlatform` constants. - Adjust `HomeViewModel`, `SearchViewModel`, and associated state/action classes to reflect the new enum type. - Update UI components including `RepositoryCard`, `PlatformChip`, and `HomeRoot` to handle the unified platform model.
1 parent ff390db commit 6ce1837

20 files changed

Lines changed: 105 additions & 119 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package zed.rainxch.core.domain.model
2+
3+
enum class DiscoveryPlatform {
4+
All,
5+
Android,
6+
Macos,
7+
Windows,
8+
Linux,
9+
}

core/domain/src/commonMain/kotlin/zed/rainxch/core/domain/model/GithubRepoSummary.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ data class GithubRepoSummary(
1818
val releasesUrl: String,
1919
val updatedAt: String,
2020
val isFork: Boolean = false,
21-
val availablePlatforms: List<String> = emptyList(),
21+
val availablePlatforms: List<DiscoveryPlatform> = emptyList(),
2222
)

core/presentation/src/commonMain/kotlin/zed/rainxch/core/presentation/components/RepositoryCard.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import androidx.compose.ui.text.style.TextOverflow
4141
import androidx.compose.ui.tooling.preview.Preview
4242
import androidx.compose.ui.unit.dp
4343
import org.jetbrains.compose.resources.stringResource
44+
import zed.rainxch.core.domain.model.DiscoveryPlatform
4445
import zed.rainxch.core.presentation.model.DiscoveryRepositoryUi
4546
import zed.rainxch.core.presentation.model.GithubRepoSummaryUi
4647
import zed.rainxch.core.presentation.model.GithubUserUi
@@ -303,7 +304,7 @@ fun RepositoryCard(
303304

304305
@Composable
305306
fun PlatformChip(
306-
platform: String,
307+
platform: DiscoveryPlatform,
307308
modifier: Modifier = Modifier,
308309
) {
309310
Surface(
@@ -312,7 +313,7 @@ fun PlatformChip(
312313
color = MaterialTheme.colorScheme.surfaceContainerHighest,
313314
) {
314315
Text(
315-
text = platform,
316+
text = platform.name,
316317
style = MaterialTheme.typography.labelSmall,
317318
color = MaterialTheme.colorScheme.onSurfaceVariant,
318319
fontWeight = FontWeight.Medium,

core/presentation/src/commonMain/kotlin/zed/rainxch/core/presentation/model/GithubRepoSummaryUi.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package zed.rainxch.core.presentation.model
22

33
import kotlinx.collections.immutable.ImmutableList
44
import kotlinx.collections.immutable.persistentListOf
5+
import zed.rainxch.core.domain.model.DiscoveryPlatform
56

67
data class GithubRepoSummaryUi(
78
val id: Long,
@@ -18,5 +19,5 @@ data class GithubRepoSummaryUi(
1819
val releasesUrl: String,
1920
val updatedAt: String,
2021
val isFork: Boolean = false,
21-
val availablePlatforms: ImmutableList<String> = persistentListOf(),
22+
val availablePlatforms: ImmutableList<DiscoveryPlatform> = persistentListOf(),
2223
)

feature/home/presentation/src/commonMain/kotlin/zed/rainxch/home/presentation/utils/HomePlatformMapper.kt renamed to core/presentation/src/commonMain/kotlin/zed/rainxch/core/presentation/utils/DiscoveryPlatformIconMapper.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
package zed.rainxch.home.presentation.utils
1+
package zed.rainxch.core.presentation.utils
22

33
import androidx.compose.runtime.Composable
44
import androidx.compose.ui.graphics.vector.ImageVector
55
import org.jetbrains.compose.resources.vectorResource
6+
import zed.rainxch.core.domain.model.DiscoveryPlatform
67
import zed.rainxch.githubstore.core.presentation.res.*
7-
import zed.rainxch.home.domain.model.HomePlatform
88

99
@Composable
10-
fun HomePlatform.toIcons(): List<ImageVector> =
10+
fun DiscoveryPlatform.toIcons(): List<ImageVector> =
1111
when (this) {
12-
HomePlatform.All -> {
12+
DiscoveryPlatform.All -> {
1313
listOf(
1414
vectorResource(Res.drawable.ic_platform_android),
1515
vectorResource(Res.drawable.ic_platform_linux),
@@ -18,19 +18,19 @@ fun HomePlatform.toIcons(): List<ImageVector> =
1818
)
1919
}
2020

21-
HomePlatform.Android -> {
21+
DiscoveryPlatform.Android -> {
2222
listOf(vectorResource(Res.drawable.ic_platform_android))
2323
}
2424

25-
HomePlatform.Macos -> {
25+
DiscoveryPlatform.Macos -> {
2626
listOf(vectorResource(Res.drawable.ic_platform_macos))
2727
}
2828

29-
HomePlatform.Windows -> {
29+
DiscoveryPlatform.Windows -> {
3030
listOf(vectorResource(Res.drawable.ic_platform_windows))
3131
}
3232

33-
HomePlatform.Linux -> {
33+
DiscoveryPlatform.Linux -> {
3434
listOf(vectorResource(Res.drawable.ic_platform_linux))
3535
}
3636
}

feature/details/presentation/src/commonMain/kotlin/zed/rainxch/details/presentation/components/AppHeader.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import androidx.compose.ui.text.font.FontWeight
4141
import androidx.compose.ui.unit.dp
4242
import com.skydoves.landscapist.coil3.CoilImage
4343
import org.jetbrains.compose.resources.stringResource
44+
import zed.rainxch.core.domain.model.DiscoveryPlatform
4445
import zed.rainxch.core.domain.model.GithubRelease
4546
import zed.rainxch.core.domain.model.GithubRepoSummary
4647
import zed.rainxch.core.domain.model.GithubUserProfile
@@ -252,22 +253,22 @@ fun AppHeader(
252253
}
253254
}
254255

255-
private fun derivePlatformsFromAssets(release: GithubRelease?): List<String> {
256+
private fun derivePlatformsFromAssets(release: GithubRelease?): List<DiscoveryPlatform> {
256257
if (release == null) return emptyList()
257258
val names = release.assets.map { it.name.lowercase() }
258259
return buildList {
259260
when {
260-
names.any { it.endsWith(".apk") } -> add("Android")
261+
names.any { it.endsWith(".apk") } -> add(DiscoveryPlatform.Android)
261262

262-
names.any { it.endsWith(".exe") || it.endsWith(".msi") } -> add("Windows")
263+
names.any { it.endsWith(".exe") || it.endsWith(".msi") } -> add(DiscoveryPlatform.Windows)
263264

264-
names.any { it.endsWith(".dmg") || it.endsWith(".pkg") } -> add("macOS")
265+
names.any { it.endsWith(".dmg") || it.endsWith(".pkg") } -> add(DiscoveryPlatform.Macos)
265266

266267
names.any {
267268
it.endsWith(".appimage") ||
268269
it.endsWith(".deb") ||
269270
it.endsWith(".rpm")
270-
} -> add("Linux")
271+
} -> add(DiscoveryPlatform.Linux)
271272
}
272273
}
273274
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package zed.rainxch.home.data.data_source
22

3+
import zed.rainxch.core.domain.model.DiscoveryPlatform
34
import zed.rainxch.home.data.dto.CachedRepoResponse
4-
import zed.rainxch.home.domain.model.HomePlatform
55

66
interface CachedRepositoriesDataSource {
7-
suspend fun getCachedTrendingRepos(platform: HomePlatform): CachedRepoResponse?
7+
suspend fun getCachedTrendingRepos(platform: DiscoveryPlatform): CachedRepoResponse?
88

9-
suspend fun getCachedHotReleaseRepos(platform: HomePlatform): CachedRepoResponse?
9+
suspend fun getCachedHotReleaseRepos(platform: DiscoveryPlatform): CachedRepoResponse?
1010

11-
suspend fun getCachedMostPopularRepos(platform: HomePlatform): CachedRepoResponse?
11+
suspend fun getCachedMostPopularRepos(platform: DiscoveryPlatform): CachedRepoResponse?
1212
}

feature/home/data/src/commonMain/kotlin/zed/rainxch/home/data/data_source/impl/CachedRepositoriesDataSourceImpl.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import kotlinx.coroutines.withContext
1616
import kotlinx.serialization.SerializationException
1717
import kotlinx.serialization.json.Json
1818
import zed.rainxch.core.domain.logging.GitHubStoreLogger
19+
import zed.rainxch.core.domain.model.DiscoveryPlatform
1920
import zed.rainxch.home.data.data_source.CachedRepositoriesDataSource
2021
import zed.rainxch.home.data.dto.CachedGithubRepoSummary
2122
import zed.rainxch.home.data.dto.CachedRepoResponse
2223
import zed.rainxch.home.domain.model.HomeCategory
23-
import zed.rainxch.home.domain.model.HomePlatform
2424
import kotlin.coroutines.cancellation.CancellationException
2525
import kotlin.time.Clock
2626
import kotlin.time.Duration.Companion.hours
@@ -55,17 +55,17 @@ class CachedRepositoriesDataSourceImpl(
5555
val fetchedAt: Instant,
5656
)
5757

58-
override suspend fun getCachedTrendingRepos(platform: HomePlatform): CachedRepoResponse? =
58+
override suspend fun getCachedTrendingRepos(platform: DiscoveryPlatform): CachedRepoResponse? =
5959
fetchCachedReposForCategory(platform, HomeCategory.TRENDING)
6060

61-
override suspend fun getCachedHotReleaseRepos(platform: HomePlatform): CachedRepoResponse? =
61+
override suspend fun getCachedHotReleaseRepos(platform: DiscoveryPlatform): CachedRepoResponse? =
6262
fetchCachedReposForCategory(platform, HomeCategory.HOT_RELEASE)
6363

64-
override suspend fun getCachedMostPopularRepos(platform: HomePlatform): CachedRepoResponse? =
64+
override suspend fun getCachedMostPopularRepos(platform: DiscoveryPlatform): CachedRepoResponse? =
6565
fetchCachedReposForCategory(platform, HomeCategory.MOST_POPULAR)
6666

6767
private suspend fun fetchCachedReposForCategory(
68-
platform: HomePlatform,
68+
platform: DiscoveryPlatform,
6969
category: HomeCategory,
7070
): CachedRepoResponse? {
7171
val cacheKey = CacheKey(platform, category)
@@ -82,7 +82,7 @@ class CachedRepositoriesDataSourceImpl(
8282
}
8383

8484
return withContext(Dispatchers.IO) {
85-
if (platform == HomePlatform.All) {
85+
if (platform == DiscoveryPlatform.All) {
8686
val paths =
8787
when (category) {
8888
HomeCategory.TRENDING -> {
@@ -200,11 +200,11 @@ class CachedRepositoriesDataSourceImpl(
200200
} else {
201201
val platformName =
202202
when (platform) {
203-
HomePlatform.Android -> "android"
204-
HomePlatform.Windows -> "windows"
205-
HomePlatform.Macos -> "macos"
206-
HomePlatform.Linux -> "linux"
207-
HomePlatform.All -> error("Unreachable: All is handled above")
203+
DiscoveryPlatform.Android -> "android"
204+
DiscoveryPlatform.Windows -> "windows"
205+
DiscoveryPlatform.Macos -> "macos"
206+
DiscoveryPlatform.Linux -> "linux"
207+
DiscoveryPlatform.All -> error("Unreachable: All is handled above")
208208
}
209209

210210
val path =
@@ -252,7 +252,7 @@ class CachedRepositoriesDataSourceImpl(
252252
}
253253

254254
private data class CacheKey(
255-
val platform: HomePlatform,
255+
val platform: DiscoveryPlatform,
256256
val category: HomeCategory,
257257
)
258258
}

feature/home/data/src/commonMain/kotlin/zed/rainxch/home/data/repository/HomeRepositoryImpl.kt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ import zed.rainxch.core.data.dto.GithubRepoSearchResponse
3030
import zed.rainxch.core.data.mappers.toSummary
3131
import zed.rainxch.core.data.network.executeRequest
3232
import zed.rainxch.core.domain.logging.GitHubStoreLogger
33+
import zed.rainxch.core.domain.model.DiscoveryPlatform
3334
import zed.rainxch.core.domain.model.GithubRepoSummary
3435
import zed.rainxch.core.domain.model.PaginatedDiscoveryRepositories
3536
import zed.rainxch.core.domain.model.Platform
3637
import zed.rainxch.core.domain.model.RateLimitException
3738
import zed.rainxch.home.data.data_source.CachedRepositoriesDataSource
3839
import zed.rainxch.home.data.mappers.toGithubRepoSummary
39-
import zed.rainxch.home.domain.model.HomePlatform
4040
import zed.rainxch.home.domain.repository.HomeRepository
4141
import kotlin.time.Clock
4242
import kotlin.time.Duration.Companion.days
@@ -51,13 +51,13 @@ class HomeRepositoryImpl(
5151
) : HomeRepository {
5252
private fun cacheKey(
5353
category: String,
54-
requestedPlatform: HomePlatform,
54+
requestedPlatform: DiscoveryPlatform,
5555
page: Int,
5656
): String = "home:$category:${requestedPlatform.name}:page$page"
5757

5858
@OptIn(ExperimentalTime::class)
5959
override fun getTrendingRepositories(
60-
platform: HomePlatform,
60+
platform: DiscoveryPlatform,
6161
page: Int,
6262
): Flow<PaginatedDiscoveryRepositories> =
6363
flow {
@@ -129,7 +129,7 @@ class HomeRepositoryImpl(
129129

130130
@OptIn(ExperimentalTime::class)
131131
override fun getHotReleaseRepositories(
132-
platform: HomePlatform,
132+
platform: DiscoveryPlatform,
133133
page: Int,
134134
): Flow<PaginatedDiscoveryRepositories> =
135135
flow {
@@ -201,7 +201,7 @@ class HomeRepositoryImpl(
201201

202202
@OptIn(ExperimentalTime::class)
203203
override fun getMostPopular(
204-
platform: HomePlatform,
204+
platform: DiscoveryPlatform,
205205
page: Int,
206206
): Flow<PaginatedDiscoveryRepositories> =
207207
flow {
@@ -270,7 +270,7 @@ class HomeRepositoryImpl(
270270
}.flowOn(Dispatchers.IO)
271271

272272
private fun searchReposWithInstallersFlow(
273-
platform: HomePlatform,
273+
platform: DiscoveryPlatform,
274274
baseQuery: String,
275275
sort: String,
276276
order: String,
@@ -434,15 +434,15 @@ class HomeRepositoryImpl(
434434

435435
private fun buildSimplifiedQuery(
436436
baseQuery: String,
437-
requestedPlatform: HomePlatform,
437+
requestedPlatform: DiscoveryPlatform,
438438
): String {
439439
val topic =
440440
when (requestedPlatform) {
441-
HomePlatform.All -> null
442-
HomePlatform.Android -> "android"
443-
HomePlatform.Windows -> "desktop"
444-
HomePlatform.Macos -> "macos"
445-
HomePlatform.Linux -> "linux"
441+
DiscoveryPlatform.All -> null
442+
DiscoveryPlatform.Android -> "android"
443+
DiscoveryPlatform.Windows -> "desktop"
444+
DiscoveryPlatform.Macos -> "macos"
445+
DiscoveryPlatform.Linux -> "linux"
446446
}
447447

448448
return if (topic == null) baseQuery else "$baseQuery topic:$topic"

feature/home/domain/src/commonMain/kotlin/zed/rainxch/home/domain/model/HomePlatform.kt

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)