From 33e5b72d8fbc91944dcbf8b0904b8ff01c1eb6f9 Mon Sep 17 00:00:00 2001 From: Shreyas Deshmukh Date: Fri, 18 Jul 2025 10:40:51 +0530 Subject: [PATCH 1/6] Introduce KdCard component and restrict direct usage of androidx.compose.material3.Card --- .../DesignSystemTest.kt | 8 +++++++ .../designsystem/components/Card.kt | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 design-system/src/commonMain/kotlin/com/developersbreach/designsystem/components/Card.kt diff --git a/composeApp/src/desktopTest/kotlin/com/developersbreach/kotlindictionarymultiplatform/DesignSystemTest.kt b/composeApp/src/desktopTest/kotlin/com/developersbreach/kotlindictionarymultiplatform/DesignSystemTest.kt index 8ee6686..f50af26 100644 --- a/composeApp/src/desktopTest/kotlin/com/developersbreach/kotlindictionarymultiplatform/DesignSystemTest.kt +++ b/composeApp/src/desktopTest/kotlin/com/developersbreach/kotlindictionarymultiplatform/DesignSystemTest.kt @@ -94,6 +94,14 @@ class DesignSystemTest { ) } + @Test + fun `no direct usage of androidx compose card should be allowed except designSystem`() { + checkNoDirectUsageExceptAllowed( + componentName = "androidx.compose.material3.Card", + excludePaths = arrayOf("$DESIGN_SYSTEM_PATH/Card.kt"), + ) + } + companion object { private const val DESIGN_SYSTEM_PATH = "design-system/src/commonMain/kotlin/com/developersbreach/designsystem/components" diff --git a/design-system/src/commonMain/kotlin/com/developersbreach/designsystem/components/Card.kt b/design-system/src/commonMain/kotlin/com/developersbreach/designsystem/components/Card.kt new file mode 100644 index 0000000..8e16ad2 --- /dev/null +++ b/design-system/src/commonMain/kotlin/com/developersbreach/designsystem/components/Card.kt @@ -0,0 +1,23 @@ +package com.developersbreach.designsystem.components + +import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.material3.Card +import androidx.compose.material3.CardColors +import androidx.compose.material3.CardElevation +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier + +@Composable +fun KdCard( + modifier: Modifier, + colors: CardColors, + elevation: CardElevation, + content: @Composable ColumnScope.() -> Unit, +) { + Card( + modifier = modifier, + content = content, + elevation = elevation, + colors = colors, + ) +} \ No newline at end of file From a44c25ce9fff16e8494e5061884c68ee7de5fec4 Mon Sep 17 00:00:00 2001 From: Shreyas Deshmukh Date: Fri, 18 Jul 2025 10:41:50 +0530 Subject: [PATCH 2/6] Add Home screen and refactor navigation: - Update `AppNavigation` to include a new `Home` destination and set it as the start destination. - Create `HomeScreen`, `HomeScreenUI`, `HomeViewModel`, and associated UI components (`HomeCard`, `HomeTopAppBar`, `HorizontalScroll`). - Add `HomeViewModel` to `ViewModelModule`. - Modify `TopicTopBar` to include a navigation up action. - Update `TopicScreen` to handle `onNavigateUp`. - Add new string resources for the Home screen. - Update `README.md` to reflect the addition of the Home page. - Add previews for `HomeScreen`. - Update previews for `TopicScreen` to include `onNavigateUp`. --- README.md | 3 +- .../previews/home/HomeScreenPreview.kt | 19 +++++++ .../previews/topic/TopicScreenPreview.kt | 1 + .../composeResources/values/string.xml | 4 ++ .../di/ViewModelModule.kt | 7 +++ .../ui/navigation/AppDestinations.kt | 3 + .../ui/navigation/AppNavigation.kt | 12 +++- .../ui/navigation/NavigationAction.kt | 3 + .../ui/screens/home/HomeCard.kt | 57 +++++++++++++++++++ .../ui/screens/home/HomeScreen.kt | 19 +++++++ .../ui/screens/home/HomeScreenUI.kt | 48 ++++++++++++++++ .../ui/screens/home/HomeTopAppBar.kt | 47 +++++++++++++++ .../ui/screens/home/HomeViewModel.kt | 29 ++++++++++ .../ui/screens/home/HorizontalScroll.kt | 55 ++++++++++++++++++ .../ui/screens/topic/TopicScreen.kt | 2 + .../ui/screens/topic/TopicScreenUI.kt | 3 +- .../ui/screens/topic/TopicTopAppBar.kt | 6 +- 17 files changed, 313 insertions(+), 5 deletions(-) create mode 100644 composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/home/HomeScreenPreview.kt create mode 100644 composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeCard.kt create mode 100644 composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeScreen.kt create mode 100644 composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeScreenUI.kt create mode 100644 composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeTopAppBar.kt create mode 100644 composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeViewModel.kt create mode 100644 composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HorizontalScroll.kt diff --git a/README.md b/README.md index 7221cd5..2988332 100644 --- a/README.md +++ b/README.md @@ -36,13 +36,14 @@ Access the latest APK for Kotlin Dictionary from the link below. - [ ] Implement caching on the `Detail Screen` to store previously viewed topic data - [x] Implement dynamic topic loading in `TopicRepository` to support scalability - [ ] Add bookmark feature for topic cards to allow users to save and revisit important topics -- [ ] Add a `Home Page` for navigation +- [x] Add a `Home Page` for navigation - [ ] Add a `Quiz Page` to host topic-based quizzes - [ ] Add a button in `DetailScreen` to attempt a quiz for that topic - [ ] Add a `Contributors Page` to showcase project contributors - [ ] Add a `Settings Page` with basic preferences - [ ] Implement a `Splash Screen` - [x] Integrate multiplatform paging for `Topic Screen` +- [ ] Add dark theme previews to the README --- diff --git a/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/home/HomeScreenPreview.kt b/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/home/HomeScreenPreview.kt new file mode 100644 index 0000000..635a60d --- /dev/null +++ b/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/home/HomeScreenPreview.kt @@ -0,0 +1,19 @@ +package com.developersbreach.kotlindictionarymultiplatform.previews.home + +import androidx.compose.runtime.Composable +import androidx.compose.ui.tooling.preview.PreviewLightDark +import com.developersbreach.kotlindictionarymultiplatform.previews.sampleTopicUiList +import com.developersbreach.kotlindictionarymultiplatform.ui.screens.home.HomeScreenUI +import com.developersbreach.kotlindictionarymultiplatform.ui.theme.KotlinDictionaryTheme + +@PreviewLightDark +@Composable +private fun HomeScreenPreview() { + KotlinDictionaryTheme { + HomeScreenUI( + topics = sampleTopicUiList(), + + onViewAllClick = {}, + ) + } +} \ No newline at end of file diff --git a/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/topic/TopicScreenPreview.kt b/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/topic/TopicScreenPreview.kt index ffbe3d1..5a125ed 100644 --- a/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/topic/TopicScreenPreview.kt +++ b/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/topic/TopicScreenPreview.kt @@ -17,6 +17,7 @@ private fun TopicScreenPreview() { searchQuery = "Search", onQueryChange = { }, onTopicClick = { }, + onNavigateUp = {}, ) } } \ No newline at end of file diff --git a/composeApp/src/commonMain/composeResources/values/string.xml b/composeApp/src/commonMain/composeResources/values/string.xml index beb55cb..f984df0 100644 --- a/composeApp/src/commonMain/composeResources/values/string.xml +++ b/composeApp/src/commonMain/composeResources/values/string.xml @@ -25,4 +25,8 @@ Icon Search Kotlin terms... Search + Menu + Welcome,\nKotlin Enthusiast! + Quizzes + View all \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/di/ViewModelModule.kt b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/di/ViewModelModule.kt index 909a263..5a7021f 100644 --- a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/di/ViewModelModule.kt +++ b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/di/ViewModelModule.kt @@ -2,6 +2,7 @@ package com.developersbreach.kotlindictionarymultiplatform.di import androidx.lifecycle.SavedStateHandle import com.developersbreach.kotlindictionarymultiplatform.ui.screens.detail.DetailViewModel +import com.developersbreach.kotlindictionarymultiplatform.ui.screens.home.HomeViewModel import com.developersbreach.kotlindictionarymultiplatform.ui.screens.topic.TopicViewModel import org.koin.core.module.dsl.viewModel import org.koin.dsl.module @@ -17,4 +18,10 @@ internal val viewModelModule = module { viewModel { TopicViewModel(get()) } + + viewModel { + HomeViewModel( + topicRepository = get(), + ) + } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/AppDestinations.kt b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/AppDestinations.kt index d5674b3..5d9c335 100644 --- a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/AppDestinations.kt +++ b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/AppDestinations.kt @@ -12,4 +12,7 @@ sealed interface AppDestinations { data class Detail( val topicId: String, ) : AppDestinations + + @Serializable + data object Home : AppDestinations } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/AppNavigation.kt b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/AppNavigation.kt index 547e993..b75fbf4 100644 --- a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/AppNavigation.kt +++ b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/AppNavigation.kt @@ -1,5 +1,6 @@ package com.developersbreach.kotlindictionarymultiplatform.ui.navigation +import HomeScreen import androidx.compose.runtime.Composable import androidx.compose.runtime.remember import androidx.navigation.compose.NavHost @@ -7,13 +8,14 @@ import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import com.developersbreach.kotlindictionarymultiplatform.ui.screens.detail.DetailScreen import com.developersbreach.kotlindictionarymultiplatform.ui.screens.detail.DetailViewModel +import com.developersbreach.kotlindictionarymultiplatform.ui.screens.home.HomeViewModel import com.developersbreach.kotlindictionarymultiplatform.ui.screens.topic.TopicScreen import com.developersbreach.kotlindictionarymultiplatform.ui.screens.topic.TopicViewModel import org.koin.compose.viewmodel.koinViewModel @Composable fun AppNavigation( - startDestination: AppDestinations = AppDestinations.TopicList, + startDestination: AppDestinations = AppDestinations.Home, ) { val navController = rememberNavController() val actions = remember(navController) { NavigationAction(navController) } @@ -29,6 +31,7 @@ fun AppNavigation( actions.navigateToDetail(selectedTopicId) }, viewModel = viewModel, + onNavigateUp = { navController.navigateUp() }, ) } @@ -39,5 +42,12 @@ fun AppNavigation( navigateUp = { navController.navigateUp() }, ) } + composable { + val viewModel: HomeViewModel = koinViewModel() + HomeScreen( + viewModel = viewModel, + navigateToTopicList = actions.navigateToTopic, + ) + } } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/NavigationAction.kt b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/NavigationAction.kt index eca0c35..e17ce98 100644 --- a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/NavigationAction.kt +++ b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/NavigationAction.kt @@ -9,4 +9,7 @@ class NavigationAction( val navigateToDetail: (String) -> Unit = { topicId -> navController.navigate(AppDestinations.Detail(topicId)) } + val navigateToTopic: () -> Unit = { + navController.navigate(AppDestinations.TopicList) + } } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeCard.kt b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeCard.kt new file mode 100644 index 0000000..9a46289 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeCard.kt @@ -0,0 +1,57 @@ +package com.developersbreach.kotlindictionarymultiplatform.ui.screens.home + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material3.CardDefaults +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Brush +import androidx.compose.ui.unit.dp +import com.developersbreach.designsystem.components.KdCard +import com.developersbreach.designsystem.components.KdText + +@Composable +fun HomeCard( + label: String, +) { + KdCard( + modifier = Modifier + .size(120.dp) + .clip(RoundedCornerShape(22.dp)), + colors = CardDefaults.cardColors( + containerColor = MaterialTheme.colorScheme.secondaryContainer, + ), + elevation = CardDefaults.cardElevation(defaultElevation = 2.dp), + content = { + Box( + modifier = Modifier + .fillMaxSize() + .background( + Brush.verticalGradient( + colors = listOf( + MaterialTheme.colorScheme.primary.copy(alpha = 0.8f), + MaterialTheme.colorScheme.primaryContainer, + ), + ), + ), + contentAlignment = Alignment.BottomStart, + ) { + KdText( + text = label, + maxLines = 1, + modifier = Modifier + .padding(12.dp) + .align(Alignment.BottomStart), + color = MaterialTheme.colorScheme.onSecondaryContainer, + ) + } + }, + ) +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeScreen.kt b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeScreen.kt new file mode 100644 index 0000000..1bc97b3 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeScreen.kt @@ -0,0 +1,19 @@ +import androidx.compose.runtime.Composable +import androidx.compose.runtime.collectAsState +import com.developersbreach.kotlindictionarymultiplatform.ui.screens.home.HomeScreenUI +import com.developersbreach.kotlindictionarymultiplatform.ui.screens.home.HomeViewModel + +@Composable +fun HomeScreen( + viewModel: HomeViewModel, + navigateToTopicList: () -> Unit, +) { + val topicsState = viewModel.topics.collectAsState() + + HomeScreenUI( + topics = topicsState.value, + + + onViewAllClick = navigateToTopicList, + ) +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeScreenUI.kt b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeScreenUI.kt new file mode 100644 index 0000000..05c5dbf --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeScreenUI.kt @@ -0,0 +1,48 @@ +package com.developersbreach.kotlindictionarymultiplatform.ui.screens.home + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import com.developersbreach.designsystem.components.KdScaffold +import com.developersbreach.designsystem.components.KdText +import com.developersbreach.kotlindictionarymultiplatform.ui.screens.topic.Topic +import kotlindictionarymultiplatform.composeapp.generated.resources.Res +import kotlindictionarymultiplatform.composeapp.generated.resources.topics +import kotlindictionarymultiplatform.composeapp.generated.resources.welcome +import org.jetbrains.compose.resources.stringResource + +@Composable +fun HomeScreenUI( + topics: List, + onViewAllClick: () -> Unit, +) { + KdScaffold( + topBar = { HomeTopAppBar() }, + modifier = Modifier, + ) { innerPadding -> + Column( + modifier = Modifier + .padding(horizontal = 16.dp) + .padding(top = innerPadding.calculateTopPadding()), + ) { + Spacer(modifier = Modifier.height(16.dp)) + KdText( + text = stringResource(Res.string.welcome), + style = MaterialTheme.typography.displayLarge, + color = MaterialTheme.colorScheme.onBackground, + modifier = Modifier, + ) + Spacer(modifier = Modifier.height(16.dp)) + HorizontalScroll( + title = stringResource(Res.string.topics), + topics = topics, + onViewAllClick = onViewAllClick, + ) + } + } +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeTopAppBar.kt b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeTopAppBar.kt new file mode 100644 index 0000000..c6f7f76 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeTopAppBar.kt @@ -0,0 +1,47 @@ +package com.developersbreach.kotlindictionarymultiplatform.ui.screens.home + +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Menu +import kotlindictionarymultiplatform.composeapp.generated.resources.menu +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.TopAppBarDefaults +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.style.TextAlign +import com.developersbreach.designsystem.components.KdIconButton +import com.developersbreach.designsystem.components.KdText +import com.developersbreach.designsystem.components.KdTopAppBar +import kotlindictionarymultiplatform.composeapp.generated.resources.Res +import org.jetbrains.compose.resources.stringResource + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun HomeTopAppBar() { + KdTopAppBar( + title = { + KdText( + text = "Kotlin Dictionary", + style = MaterialTheme.typography.displayMedium, + modifier = Modifier.fillMaxWidth(), + textAlign = TextAlign.Start, + color = MaterialTheme.colorScheme.onPrimary, + ) + }, + colors = TopAppBarDefaults.topAppBarColors( + containerColor = MaterialTheme.colorScheme.onPrimaryContainer, + titleContentColor = MaterialTheme.colorScheme.onPrimary, + navigationIconContentColor = MaterialTheme.colorScheme.onPrimary, + ), + navigationIcon = { + KdIconButton( + onClick = {}, + modifier = Modifier, + contentDescription = stringResource(Res.string.menu), + iconModifier = Modifier, + imageVector = Icons.Default.Menu, + ) + }, + ) +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeViewModel.kt b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeViewModel.kt new file mode 100644 index 0000000..800f615 --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeViewModel.kt @@ -0,0 +1,29 @@ +package com.developersbreach.kotlindictionarymultiplatform.ui.screens.home + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.developersbreach.kotlindictionarymultiplatform.data.topic.repository.TopicRepository +import com.developersbreach.kotlindictionarymultiplatform.ui.screens.topic.Topic +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.launch + +class HomeViewModel( + private val topicRepository: TopicRepository, +) : ViewModel() { + + private val _topics = MutableStateFlow>(emptyList()) + val topics: StateFlow> = _topics.asStateFlow() + + init { + fetchTopics() + } + + private fun fetchTopics() { + viewModelScope.launch { + val result = topicRepository.getTopicsPage(page = 1, pageSize = 5, query = "") + _topics.value = result + } + } +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HorizontalScroll.kt b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HorizontalScroll.kt new file mode 100644 index 0000000..669f11d --- /dev/null +++ b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HorizontalScroll.kt @@ -0,0 +1,55 @@ +package com.developersbreach.kotlindictionarymultiplatform.ui.screens.home + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.lazy.LazyRow +import androidx.compose.foundation.lazy.items +import androidx.compose.material3.MaterialTheme +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.dp +import com.developersbreach.designsystem.components.KdText +import com.developersbreach.kotlindictionarymultiplatform.ui.screens.topic.Topic +import kotlindictionarymultiplatform.composeapp.generated.resources.Res +import kotlindictionarymultiplatform.composeapp.generated.resources.view_all +import org.jetbrains.compose.resources.stringResource + +@Composable +fun HorizontalScroll( + title: String, + topics: List, + onViewAllClick: () -> Unit, +) { + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + ) { + KdText( + text = title, + style = MaterialTheme.typography.titleMedium.copy(fontWeight = FontWeight.Bold), + color = MaterialTheme.colorScheme.onBackground, + modifier = Modifier, + ) + Spacer(modifier = Modifier.weight(1f)) + KdText( + text = stringResource(Res.string.view_all), + style = MaterialTheme.typography.bodySmall, + color = MaterialTheme.colorScheme.onBackground, + modifier = Modifier + .clickable { onViewAllClick() }, + ) + } + Spacer(modifier = Modifier.height(8.dp)) + LazyRow { + items(topics) { topics -> + HomeCard(label = topics.name) + Spacer(modifier = Modifier.width(12.dp)) + } + } +} \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/topic/TopicScreen.kt b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/topic/TopicScreen.kt index f1788a9..d8402bd 100644 --- a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/topic/TopicScreen.kt +++ b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/topic/TopicScreen.kt @@ -8,6 +8,7 @@ import app.cash.paging.compose.collectAsLazyPagingItems fun TopicScreen( viewModel: TopicViewModel, onTopicClick: (String) -> Unit, + onNavigateUp: () -> Unit, ) { val pagingItems = viewModel.topics.collectAsLazyPagingItems() val searchQuery = viewModel.searchQuery.collectAsState().value @@ -17,5 +18,6 @@ fun TopicScreen( searchQuery = searchQuery, onQueryChange = viewModel::updateSearchQuery, onTopicClick = onTopicClick, + onNavigateUp = onNavigateUp, ) } \ No newline at end of file diff --git a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/topic/TopicScreenUI.kt b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/topic/TopicScreenUI.kt index 7084245..668ccca 100644 --- a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/topic/TopicScreenUI.kt +++ b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/topic/TopicScreenUI.kt @@ -16,10 +16,11 @@ fun TopicScreenUI( searchQuery: String, onQueryChange: (String) -> Unit, onTopicClick: (String) -> Unit, + onNavigateUp: () -> Unit, ) { KdScaffold( modifier = Modifier, - topBar = { TopicTopBar() }, + topBar = { TopicTopBar(onNavigateUp = onNavigateUp) }, ) { paddingValues -> Column( modifier = Modifier diff --git a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/topic/TopicTopAppBar.kt b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/topic/TopicTopAppBar.kt index b1bb812..8208ee0 100644 --- a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/topic/TopicTopAppBar.kt +++ b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/topic/TopicTopAppBar.kt @@ -19,7 +19,9 @@ import org.jetbrains.compose.resources.stringResource @OptIn(ExperimentalMaterial3Api::class) @Composable -fun TopicTopBar() { +fun TopicTopBar( + onNavigateUp: () -> Unit, +) { KdTopAppBar( title = { KdText( @@ -33,7 +35,7 @@ fun TopicTopBar() { KdIconButton( modifier = Modifier, iconModifier = Modifier, - onClick = {}, + onClick = onNavigateUp, imageVector = Icons.AutoMirrored.Filled.ArrowBack, contentDescription = stringResource(Res.string.back), ) From f90aba08c498916129cbe0a5a59bfd9c8baee7d3 Mon Sep 17 00:00:00 2001 From: Shreyas Deshmukh Date: Fri, 18 Jul 2025 11:03:29 +0530 Subject: [PATCH 3/6] Remove redundant empty lines from `HomeScreen` and `HomeScreenPreview` --- .../previews/home/HomeScreenPreview.kt | 3 +-- .../ui/screens/home/HomeScreen.kt | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/home/HomeScreenPreview.kt b/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/home/HomeScreenPreview.kt index 635a60d..9220564 100644 --- a/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/home/HomeScreenPreview.kt +++ b/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/home/HomeScreenPreview.kt @@ -11,8 +11,7 @@ import com.developersbreach.kotlindictionarymultiplatform.ui.theme.KotlinDiction private fun HomeScreenPreview() { KotlinDictionaryTheme { HomeScreenUI( - topics = sampleTopicUiList(), - + topics = sampleTopicUiList(), onViewAllClick = {}, ) } diff --git a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeScreen.kt b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeScreen.kt index 1bc97b3..b824d13 100644 --- a/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeScreen.kt +++ b/composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/home/HomeScreen.kt @@ -11,9 +11,7 @@ fun HomeScreen( val topicsState = viewModel.topics.collectAsState() HomeScreenUI( - topics = topicsState.value, - - + topics = topicsState.value, onViewAllClick = navigateToTopicList, ) } \ No newline at end of file From c704add36e2d466185fafb6f5cddd2e33d20e202 Mon Sep 17 00:00:00 2001 From: Shreyas Deshmukh <115153463+yesshreyes@users.noreply.github.com> Date: Fri, 18 Jul 2025 11:09:46 +0530 Subject: [PATCH 4/6] Add space between brackets --- .../previews/topic/TopicScreenPreview.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/topic/TopicScreenPreview.kt b/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/topic/TopicScreenPreview.kt index 5a125ed..644f6d7 100644 --- a/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/topic/TopicScreenPreview.kt +++ b/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/topic/TopicScreenPreview.kt @@ -17,7 +17,7 @@ private fun TopicScreenPreview() { searchQuery = "Search", onQueryChange = { }, onTopicClick = { }, - onNavigateUp = {}, + onNavigateUp = { }, ) } -} \ No newline at end of file +} From 13d97cf3c1bed172dfe0c02b4be5aaa57032c24c Mon Sep 17 00:00:00 2001 From: Shreyas Deshmukh Date: Fri, 18 Jul 2025 12:10:36 +0530 Subject: [PATCH 5/6] Reformat TopicScreenPreview.kt --- .../previews/topic/TopicScreenPreview.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/topic/TopicScreenPreview.kt b/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/topic/TopicScreenPreview.kt index 5a125ed..5eed989 100644 --- a/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/topic/TopicScreenPreview.kt +++ b/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/topic/TopicScreenPreview.kt @@ -17,7 +17,7 @@ private fun TopicScreenPreview() { searchQuery = "Search", onQueryChange = { }, onTopicClick = { }, - onNavigateUp = {}, + onNavigateUp = { }, ) } } \ No newline at end of file From 253ed9abc8c83921613c808ac03668ab86e95711 Mon Sep 17 00:00:00 2001 From: Shreyas Deshmukh Date: Fri, 18 Jul 2025 12:12:52 +0530 Subject: [PATCH 6/6] Reformat TopicScreenPreview.kt --- .../previews/topic/TopicScreenPreview.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/topic/TopicScreenPreview.kt b/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/topic/TopicScreenPreview.kt index 644f6d7..5eed989 100644 --- a/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/topic/TopicScreenPreview.kt +++ b/composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/topic/TopicScreenPreview.kt @@ -20,4 +20,4 @@ private fun TopicScreenPreview() { onNavigateUp = { }, ) } -} +} \ No newline at end of file