Skip to content

Commit f9d50c4

Browse files
authored
Merge pull request #250 from rainxchzed/search-improvement
refactor(search): Overhaul search logic for relevance and performance
2 parents c34a4d0 + 847685a commit f9d50c4

File tree

11 files changed

+399
-348
lines changed

11 files changed

+399
-348
lines changed

core/data/src/commonMain/kotlin/zed/rainxch/core/data/dto/GithubRepoNetworkModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ data class GithubRepoNetworkModel(
1717
@SerialName("language") val language: String? = null,
1818
@SerialName("topics") val topics: List<String>? = null,
1919
@SerialName("releases_url") val releasesUrl: String,
20-
@SerialName("updated_at") val updatedAt: String
20+
@SerialName("updated_at") val updatedAt: String,
21+
@SerialName("fork") val fork: Boolean = false
2122
)

core/data/src/commonMain/kotlin/zed/rainxch/core/data/mappers/GithubRepoMapper.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fun GithubRepoNetworkModel.toSummary(): GithubRepoSummary = GithubRepoSummary(
2222
topics = topics,
2323
releasesUrl = releasesUrl,
2424
updatedAt = updatedAt,
25-
defaultBranch = defaultBranch
25+
defaultBranch = defaultBranch,
26+
isFork = fork
2627
)
2728

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ data class GithubRepoSummary(
1717
val topics: List<String>?,
1818
val releasesUrl: String,
1919
val updatedAt: String,
20+
val isFork: Boolean = false,
21+
val availablePlatforms: List<String> = emptyList(),
2022
)

core/presentation/src/commonMain/composeResources/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,8 @@
329329
<string name="released_days_ago">Released %1$d day(s) ago</string>
330330
<string name="released_on_date">Released on %1$s</string>
331331

332+
<string name="forked_repository">Fork</string>
333+
332334
<string name="bottom_nav_home_title">Home</string>
333335
<string name="bottom_nav_search_title">Search</string>
334336
<string name="bottom_nav_apps_title">Apps</string>

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

Lines changed: 87 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import androidx.compose.foundation.layout.Column
77
import androidx.compose.foundation.layout.Row
88
import androidx.compose.foundation.layout.Spacer
99
import androidx.compose.foundation.layout.fillMaxSize
10+
import androidx.compose.foundation.layout.ExperimentalLayoutApi
11+
import androidx.compose.foundation.layout.FlowRow
1012
import androidx.compose.foundation.layout.fillMaxWidth
1113
import androidx.compose.foundation.layout.height
1214
import androidx.compose.foundation.layout.offset
@@ -15,11 +17,13 @@ import androidx.compose.foundation.layout.size
1517
import androidx.compose.foundation.shape.CircleShape
1618
import androidx.compose.foundation.shape.RoundedCornerShape
1719
import androidx.compose.material.icons.Icons
20+
import androidx.compose.material.icons.automirrored.outlined.CallSplit
1821
import androidx.compose.material.icons.filled.CheckCircle
1922
import androidx.compose.material.icons.filled.Favorite
2023
import androidx.compose.material.icons.filled.OpenInBrowser
2124
import androidx.compose.material.icons.filled.Star
2225
import androidx.compose.material.icons.filled.Update
26+
import androidx.compose.material.icons.outlined.CallSplit
2327
import androidx.compose.material3.Card
2428
import androidx.compose.material3.CardDefaults
2529
import androidx.compose.material3.CircularWavyProgressIndicator
@@ -51,7 +55,7 @@ import zed.rainxch.core.presentation.theme.GithubStoreTheme
5155
import zed.rainxch.core.presentation.utils.formatReleasedAt
5256
import zed.rainxch.core.presentation.utils.formatUpdatedAt
5357

54-
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
58+
@OptIn(ExperimentalMaterial3ExpressiveApi::class, ExperimentalLayoutApi::class)
5559
@Composable
5660
fun RepositoryCard(
5761
discoveryRepository: DiscoveryRepository,
@@ -150,15 +154,25 @@ fun RepositoryCard(
150154

151155
Spacer(modifier = Modifier.height(4.dp))
152156

153-
Text(
154-
text = discoveryRepository.repository.name,
155-
fontWeight = FontWeight.Bold,
156-
style = MaterialTheme.typography.titleLarge,
157-
color = MaterialTheme.colorScheme.onSurface,
158-
maxLines = 1,
159-
softWrap = false,
160-
overflow = TextOverflow.Ellipsis
161-
)
157+
Row(
158+
verticalAlignment = Alignment.CenterVertically,
159+
horizontalArrangement = Arrangement.spacedBy(8.dp)
160+
) {
161+
Text(
162+
text = discoveryRepository.repository.name,
163+
fontWeight = FontWeight.Bold,
164+
style = MaterialTheme.typography.titleLarge,
165+
color = MaterialTheme.colorScheme.onSurface,
166+
maxLines = 1,
167+
softWrap = false,
168+
overflow = TextOverflow.Ellipsis,
169+
modifier = Modifier.weight(1f, fill = false)
170+
)
171+
172+
if (discoveryRepository.repository.isFork) {
173+
ForkBadge()
174+
}
175+
}
162176

163177
Spacer(modifier = Modifier.height(4.dp))
164178

@@ -218,6 +232,19 @@ fun RepositoryCard(
218232
)
219233
}
220234

235+
if (discoveryRepository.repository.availablePlatforms.isNotEmpty()) {
236+
Spacer(Modifier.height(12.dp))
237+
238+
FlowRow(
239+
horizontalArrangement = Arrangement.spacedBy(6.dp),
240+
verticalArrangement = Arrangement.spacedBy(6.dp)
241+
) {
242+
discoveryRepository.repository.availablePlatforms.forEach { platform ->
243+
PlatformChip(platform = platform)
244+
}
245+
}
246+
}
247+
221248
Spacer(Modifier.height(12.dp))
222249

223250
Text(
@@ -263,6 +290,56 @@ fun RepositoryCard(
263290
}
264291
}
265292

293+
@Composable
294+
fun PlatformChip(
295+
platform: String,
296+
modifier: Modifier = Modifier
297+
) {
298+
Surface(
299+
modifier = modifier,
300+
shape = RoundedCornerShape(8.dp),
301+
color = MaterialTheme.colorScheme.surfaceContainerHighest
302+
) {
303+
Text(
304+
text = platform,
305+
style = MaterialTheme.typography.labelSmall,
306+
color = MaterialTheme.colorScheme.onSurfaceVariant,
307+
fontWeight = FontWeight.Medium,
308+
modifier = Modifier.padding(horizontal = 8.dp, vertical = 3.dp)
309+
)
310+
}
311+
}
312+
313+
@Composable
314+
fun ForkBadge(
315+
modifier: Modifier = Modifier
316+
) {
317+
Surface(
318+
modifier = modifier,
319+
shape = RoundedCornerShape(12.dp),
320+
color = MaterialTheme.colorScheme.secondaryContainer
321+
) {
322+
Row(
323+
modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp),
324+
verticalAlignment = Alignment.CenterVertically,
325+
horizontalArrangement = Arrangement.spacedBy(4.dp)
326+
) {
327+
Icon(
328+
imageVector = Icons.AutoMirrored.Outlined.CallSplit,
329+
contentDescription = null,
330+
modifier = Modifier.size(14.dp),
331+
tint = MaterialTheme.colorScheme.onSecondaryContainer
332+
)
333+
Text(
334+
text = stringResource(Res.string.forked_repository),
335+
style = MaterialTheme.typography.labelSmall,
336+
color = MaterialTheme.colorScheme.onSecondaryContainer,
337+
fontWeight = FontWeight.SemiBold
338+
)
339+
}
340+
}
341+
}
342+
266343
@Composable
267344
fun InstallStatusBadge(
268345
isUpdateAvailable: Boolean,

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

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import androidx.compose.foundation.border
66
import androidx.compose.foundation.layout.Arrangement
77
import androidx.compose.foundation.layout.Box
88
import androidx.compose.foundation.layout.Column
9+
import androidx.compose.foundation.layout.ExperimentalLayoutApi
10+
import androidx.compose.foundation.layout.FlowRow
911
import androidx.compose.foundation.layout.Row
1012
import androidx.compose.foundation.layout.Spacer
1113
import androidx.compose.foundation.layout.fillMaxSize
@@ -41,9 +43,12 @@ import zed.rainxch.core.domain.model.GithubRelease
4143
import zed.rainxch.core.domain.model.GithubRepoSummary
4244
import zed.rainxch.core.domain.model.GithubUserProfile
4345
import zed.rainxch.core.domain.model.InstalledApp
46+
import zed.rainxch.core.presentation.components.ForkBadge
47+
import zed.rainxch.core.presentation.components.PlatformChip
48+
import zed.rainxch.core.presentation.utils.formatReleasedAt
4449
import zed.rainxch.details.presentation.model.DownloadStage
4550

46-
@OptIn(ExperimentalMaterial3ExpressiveApi::class)
51+
@OptIn(ExperimentalMaterial3ExpressiveApi::class, ExperimentalLayoutApi::class)
4752
@Composable
4853
fun AppHeader(
4954
author: GithubUserProfile?,
@@ -144,6 +149,10 @@ fun AppHeader(
144149
color = MaterialTheme.colorScheme.onBackground,
145150
modifier = Modifier.weight(1f, fill = false)
146151
)
152+
153+
if (repository.isFork) {
154+
ForkBadge()
155+
}
147156
}
148157

149158
Text(
@@ -182,6 +191,30 @@ fun AppHeader(
182191
)
183192
}
184193
}
194+
195+
release?.publishedAt?.let { publishedAt ->
196+
Spacer(Modifier.height(4.dp))
197+
198+
Text(
199+
text = formatReleasedAt(publishedAt),
200+
style = MaterialTheme.typography.bodySmall,
201+
color = MaterialTheme.colorScheme.outline,
202+
)
203+
}
204+
}
205+
}
206+
207+
val platforms = derivePlatformsFromAssets(release)
208+
if (platforms.isNotEmpty()) {
209+
Spacer(Modifier.height(12.dp))
210+
211+
FlowRow(
212+
horizontalArrangement = Arrangement.spacedBy(6.dp),
213+
verticalArrangement = Arrangement.spacedBy(6.dp)
214+
) {
215+
platforms.forEach { platform ->
216+
PlatformChip(platform = platform)
217+
}
185218
}
186219
}
187220

@@ -195,6 +228,17 @@ fun AppHeader(
195228
}
196229
}
197230

231+
private fun derivePlatformsFromAssets(release: GithubRelease?): List<String> {
232+
if (release == null) return emptyList()
233+
val names = release.assets.map { it.name.lowercase() }
234+
val platforms = mutableListOf<String>()
235+
if (names.any { it.endsWith(".apk") }) platforms.add("Android")
236+
if (names.any { it.endsWith(".exe") || it.endsWith(".msi") }) platforms.add("Windows")
237+
if (names.any { it.endsWith(".dmg") || it.endsWith(".pkg") }) platforms.add("macOS")
238+
if (names.any { it.endsWith(".appimage") || it.endsWith(".deb") || it.endsWith(".rpm") }) platforms.add("Linux")
239+
return platforms
240+
}
241+
198242
@Composable
199243
fun InstallStatusBadge(
200244
isUpdateAvailable: Boolean,

0 commit comments

Comments
 (0)