Skip to content

Commit 17adcfd

Browse files
authored
Merge pull request #26 from DevelopersBreach/shreyas/home-screen
Add `Home Page` with horizontal topic scroll
2 parents 34b96f5 + 253ed9a commit 17adcfd

File tree

19 files changed

+341
-5
lines changed

19 files changed

+341
-5
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,14 @@ Access the latest APK for Kotlin Dictionary from the link below.
3636
- [ ] Implement caching on the `Detail Screen` to store previously viewed topic data
3737
- [x] Implement dynamic topic loading in `TopicRepository` to support scalability
3838
- [ ] Add bookmark feature for topic cards to allow users to save and revisit important topics
39-
- [ ] Add a `Home Page` for navigation
39+
- [x] Add a `Home Page` for navigation
4040
- [ ] Add a `Quiz Page` to host topic-based quizzes
4141
- [ ] Add a button in `DetailScreen` to attempt a quiz for that topic
4242
- [ ] Add a `Contributors Page` to showcase project contributors
4343
- [ ] Add a `Settings Page` with basic preferences
4444
- [ ] Implement a `Splash Screen`
4545
- [x] Integrate multiplatform paging for `Topic Screen`
46+
- [ ] Add dark theme previews to the README
4647

4748
---
4849

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.developersbreach.kotlindictionarymultiplatform.previews.home
2+
3+
import androidx.compose.runtime.Composable
4+
import androidx.compose.ui.tooling.preview.PreviewLightDark
5+
import com.developersbreach.kotlindictionarymultiplatform.previews.sampleTopicUiList
6+
import com.developersbreach.kotlindictionarymultiplatform.ui.screens.home.HomeScreenUI
7+
import com.developersbreach.kotlindictionarymultiplatform.ui.theme.KotlinDictionaryTheme
8+
9+
@PreviewLightDark
10+
@Composable
11+
private fun HomeScreenPreview() {
12+
KotlinDictionaryTheme {
13+
HomeScreenUI(
14+
topics = sampleTopicUiList(),
15+
onViewAllClick = {},
16+
)
17+
}
18+
}

composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/topic/TopicScreenPreview.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ private fun TopicScreenPreview() {
1717
searchQuery = "Search",
1818
onQueryChange = { },
1919
onTopicClick = { },
20+
onNavigateUp = { },
2021
)
2122
}
2223
}

composeApp/src/commonMain/composeResources/values/string.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@
2525
<string name="icon">Icon</string>
2626
<string name="search_kotlin_terms">Search Kotlin terms...</string>
2727
<string name="search">Search</string>
28+
<string name="menu">Menu</string>
29+
<string name="welcome">Welcome,\nKotlin Enthusiast!</string>
30+
<string name="quizzes">Quizzes</string>
31+
<string name="view_all">View all</string>
2832
</resources>

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/di/ViewModelModule.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.developersbreach.kotlindictionarymultiplatform.di
22

33
import androidx.lifecycle.SavedStateHandle
44
import com.developersbreach.kotlindictionarymultiplatform.ui.screens.detail.DetailViewModel
5+
import com.developersbreach.kotlindictionarymultiplatform.ui.screens.home.HomeViewModel
56
import com.developersbreach.kotlindictionarymultiplatform.ui.screens.topic.TopicViewModel
67
import org.koin.core.module.dsl.viewModel
78
import org.koin.dsl.module
@@ -17,4 +18,10 @@ internal val viewModelModule = module {
1718
viewModel {
1819
TopicViewModel(get())
1920
}
21+
22+
viewModel {
23+
HomeViewModel(
24+
topicRepository = get(),
25+
)
26+
}
2027
}

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/AppDestinations.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@ sealed interface AppDestinations {
1212
data class Detail(
1313
val topicId: String,
1414
) : AppDestinations
15+
16+
@Serializable
17+
data object Home : AppDestinations
1518
}

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/AppNavigation.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package com.developersbreach.kotlindictionarymultiplatform.ui.navigation
22

3+
import HomeScreen
34
import androidx.compose.runtime.Composable
45
import androidx.compose.runtime.remember
56
import androidx.navigation.compose.NavHost
67
import androidx.navigation.compose.composable
78
import androidx.navigation.compose.rememberNavController
89
import com.developersbreach.kotlindictionarymultiplatform.ui.screens.detail.DetailScreen
910
import com.developersbreach.kotlindictionarymultiplatform.ui.screens.detail.DetailViewModel
11+
import com.developersbreach.kotlindictionarymultiplatform.ui.screens.home.HomeViewModel
1012
import com.developersbreach.kotlindictionarymultiplatform.ui.screens.topic.TopicScreen
1113
import com.developersbreach.kotlindictionarymultiplatform.ui.screens.topic.TopicViewModel
1214
import org.koin.compose.viewmodel.koinViewModel
1315

1416
@Composable
1517
fun AppNavigation(
16-
startDestination: AppDestinations = AppDestinations.TopicList,
18+
startDestination: AppDestinations = AppDestinations.Home,
1719
) {
1820
val navController = rememberNavController()
1921
val actions = remember(navController) { NavigationAction(navController) }
@@ -29,6 +31,7 @@ fun AppNavigation(
2931
actions.navigateToDetail(selectedTopicId)
3032
},
3133
viewModel = viewModel,
34+
onNavigateUp = { navController.navigateUp() },
3235
)
3336
}
3437

@@ -39,5 +42,12 @@ fun AppNavigation(
3942
navigateUp = { navController.navigateUp() },
4043
)
4144
}
45+
composable<AppDestinations.Home> {
46+
val viewModel: HomeViewModel = koinViewModel()
47+
HomeScreen(
48+
viewModel = viewModel,
49+
navigateToTopicList = actions.navigateToTopic,
50+
)
51+
}
4252
}
4353
}

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/navigation/NavigationAction.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ class NavigationAction(
99
val navigateToDetail: (String) -> Unit = { topicId ->
1010
navController.navigate(AppDestinations.Detail(topicId))
1111
}
12+
val navigateToTopic: () -> Unit = {
13+
navController.navigate(AppDestinations.TopicList)
14+
}
1215
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.developersbreach.kotlindictionarymultiplatform.ui.screens.home
2+
3+
import androidx.compose.foundation.background
4+
import androidx.compose.foundation.layout.Box
5+
import androidx.compose.foundation.layout.fillMaxSize
6+
import androidx.compose.foundation.layout.padding
7+
import androidx.compose.foundation.layout.size
8+
import androidx.compose.foundation.shape.RoundedCornerShape
9+
import androidx.compose.material3.CardDefaults
10+
import androidx.compose.material3.MaterialTheme
11+
import androidx.compose.runtime.Composable
12+
import androidx.compose.ui.Alignment
13+
import androidx.compose.ui.Modifier
14+
import androidx.compose.ui.draw.clip
15+
import androidx.compose.ui.graphics.Brush
16+
import androidx.compose.ui.unit.dp
17+
import com.developersbreach.designsystem.components.KdCard
18+
import com.developersbreach.designsystem.components.KdText
19+
20+
@Composable
21+
fun HomeCard(
22+
label: String,
23+
) {
24+
KdCard(
25+
modifier = Modifier
26+
.size(120.dp)
27+
.clip(RoundedCornerShape(22.dp)),
28+
colors = CardDefaults.cardColors(
29+
containerColor = MaterialTheme.colorScheme.secondaryContainer,
30+
),
31+
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
32+
content = {
33+
Box(
34+
modifier = Modifier
35+
.fillMaxSize()
36+
.background(
37+
Brush.verticalGradient(
38+
colors = listOf(
39+
MaterialTheme.colorScheme.primary.copy(alpha = 0.8f),
40+
MaterialTheme.colorScheme.primaryContainer,
41+
),
42+
),
43+
),
44+
contentAlignment = Alignment.BottomStart,
45+
) {
46+
KdText(
47+
text = label,
48+
maxLines = 1,
49+
modifier = Modifier
50+
.padding(12.dp)
51+
.align(Alignment.BottomStart),
52+
color = MaterialTheme.colorScheme.onSecondaryContainer,
53+
)
54+
}
55+
},
56+
)
57+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import androidx.compose.runtime.Composable
2+
import androidx.compose.runtime.collectAsState
3+
import com.developersbreach.kotlindictionarymultiplatform.ui.screens.home.HomeScreenUI
4+
import com.developersbreach.kotlindictionarymultiplatform.ui.screens.home.HomeViewModel
5+
6+
@Composable
7+
fun HomeScreen(
8+
viewModel: HomeViewModel,
9+
navigateToTopicList: () -> Unit,
10+
) {
11+
val topicsState = viewModel.topics.collectAsState()
12+
13+
HomeScreenUI(
14+
topics = topicsState.value,
15+
onViewAllClick = navigateToTopicList,
16+
)
17+
}

0 commit comments

Comments
 (0)