Skip to content

Commit 719a835

Browse files
Merge remote-tracking branch 'origin/master' into yuga/detail-screen-scroll
# Conflicts: # composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/PreviewUtils.kt # composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/detail/DetailScreen.kt # composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/detail/DetailScreenUI.kt # composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/detail/DetailTopAppBar.kt # composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/detail/components/IntroductionSection.kt # composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/detail/components/PitfallsSection.kt # composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/detail/components/RelatedTopicsSection.kt # composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/detail/components/SectionsList.kt # composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/detail/components/SyntaxSection.kt # composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/ui/screens/detail/components/TableOfContents.kt
2 parents 4bacb59 + 49cdd62 commit 719a835

File tree

41 files changed

+553
-146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+553
-146
lines changed

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ ktlint_standard_no-empty-first-line-in-class-body = disabled
1414
ktlint_standard_annotation = disabled
1515
ktlint_standard_multiline-expression-wrapping = disabled
1616
ktlint_standard_string-template-indent = disabled
17+
ktlint_function_signature_rule_force_multiline_when_parameter_count_greater_or_equal_than=1
18+
ktlint_standard_chain-method-continuation = disabled
19+
ktlint_standard_function-expression-body = disabled
20+
ktlint_standard_statement-wrapping = enabled
21+
ktlint_standard_class-signature = disabled
1722

1823
[composeApp/build/generated/**]
1924
ktlint = disabled

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ plugins {
77
alias(libs.plugins.composeCompiler) apply false
88
alias(libs.plugins.kotlinMultiplatform) apply false
99
alias(libs.plugins.serialization) apply false
10+
alias(libs.plugins.jetbrainsKotlinJvm) apply false
1011
}

composeApp/build.gradle.kts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ plugins {
1717
}
1818

1919
ktlint {
20+
version.set("1.3.0")
2021
android = true
2122
ignoreFailures = false
2223
reporters {
@@ -145,14 +146,19 @@ android {
145146

146147
dependencies {
147148
debugImplementation(compose.uiTooling)
149+
ktlint(project(":custom-ktlint-rules"))
148150
}
149151

150152
compose.desktop {
151153
application {
152154
mainClass = "com.developersbreach.kotlindictionarymultiplatform.MainKt"
153155

154156
nativeDistributions {
155-
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
157+
targetFormats(
158+
TargetFormat.Dmg,
159+
TargetFormat.Msi,
160+
TargetFormat.Deb,
161+
)
156162
packageName = "com.developersbreach.kotlindictionarymultiplatform"
157163
packageVersion = "1.0.0"
158164
}
@@ -162,13 +168,24 @@ compose.desktop {
162168
fun ApplicationDefaultConfig.setupBuildConfigFields(
163169
properties: Properties,
164170
) {
165-
fun secret(key: String): String = System.getenv(key) ?: properties.getProperty(key, "")
171+
fun secret(
172+
key: String,
173+
): String {
174+
return System.getenv(key) ?: properties.getProperty(
175+
key,
176+
"",
177+
)
178+
}
166179

167180
if (secret("OPEN_API_KEY").isEmpty()) {
168181
error("OPEN_API_KEY not set in local.properties")
169182
}
170183

171-
buildConfigField(type = "String", name = "OPEN_API_KEY", value = "\"${secret("OPEN_API_KEY")}\"")
184+
buildConfigField(
185+
type = "String",
186+
name = "OPEN_API_KEY",
187+
value = "\"${secret("OPEN_API_KEY")}\"",
188+
)
172189
}
173190

174191
fun getLocalProperties(): Properties {

composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/MainActivity.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ import org.koin.android.ext.koin.androidContext
1010
import org.koin.core.context.startKoin
1111

1212
class MainActivity : ComponentActivity() {
13-
override fun onCreate(savedInstanceState: Bundle?) {
13+
override fun onCreate(
14+
savedInstanceState: Bundle?,
15+
) {
1416
super.onCreate(savedInstanceState)
1517

1618
startKoin {

composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Platform.android.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ class AndroidPlatform : Platform {
66
override val name: String = "Android ${Build.VERSION.SDK_INT}"
77
}
88

9-
actual fun getPlatform(): Platform = AndroidPlatform()
9+
actual fun getPlatform(): Platform {
10+
return AndroidPlatform()
11+
}
1012

11-
actual fun getOpenApiKey() = BuildConfig.OPEN_API_KEY
13+
actual fun getOpenApiKey(): String {
14+
return BuildConfig.OPEN_API_KEY
15+
}

composeApp/src/androidMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/previews/PreviewUtils.kt

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,58 +5,76 @@ import com.developersbreach.kotlindictionarymultiplatform.data.detail.model.Kotl
55
import com.developersbreach.kotlindictionarymultiplatform.data.detail.model.Section
66
import com.developersbreach.kotlindictionarymultiplatform.data.detail.model.Syntax
77
import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.Topic
8+
import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.TopicUi
89

9-
fun sampleCodeSnippet(): String = """
10-
fun greet(name: String): String {
11-
return "Hello, Sam!"
12-
}
13-
""".trimIndent()
10+
fun sampleCodeSnippet(): String {
11+
return """
12+
fun greet(name: String): String {
13+
return "Hello, Sam!"
14+
}
15+
""".trimIndent()
16+
}
1417

15-
fun topic() = "Smart Casts"
18+
fun topic(): String {
19+
return "Smart Casts"
20+
}
1621

17-
fun subtitle() = "Automatic casting of immutable values"
22+
fun subtitle(): String {
23+
return "Automatic casting of immutable values"
24+
}
1825

19-
fun fakeTopicDetails() = KotlinTopicDetails(
20-
topicId = "smart-cast",
21-
topicName = "Smart Cast",
22-
intro = "Smart casting allows the compiler to automatically cast types.",
23-
syntax = Syntax(
24-
signature = "if (x is String) println(x.length)",
25-
notes = "Works only with immutable vars",
26-
),
27-
sections = listOf(
28-
Section(
29-
heading = "Why Use It?",
30-
content = "Because it’s safer and reduces boilerplate.",
31-
codeExamples = listOf(
32-
CodeExample(
33-
description = "Basic usage of smart cast",
34-
code = """
35-
fun printLength(obj: Any) {
36-
if (obj is String) {
37-
println(obj.length) // Smart cast
38-
}
39-
}
40-
""".trimIndent(),
26+
fun fakeTopicDetails(): KotlinTopicDetails {
27+
return KotlinTopicDetails(
28+
topicId = "smart-cast",
29+
topicName = "Smart Cast",
30+
intro = "Smart casting allows the compiler to automatically cast types.",
31+
syntax =
32+
Syntax(
33+
signature = "if (x is String) println(x.length)",
34+
notes = "Works only with immutable vars",
35+
),
36+
sections =
37+
listOf(
38+
Section(
39+
heading = "Why Use It?",
40+
content = "Because it’s safer and reduces boilerplate.",
41+
codeExamples =
42+
listOf(
43+
CodeExample(
44+
description = "Basic usage of smart cast",
45+
code =
46+
"""
47+
fun printLength(obj: Any) {
48+
if (obj is String) {
49+
println(obj.length) // Smart cast
50+
}
51+
}
52+
""".trimIndent(),
53+
),
54+
),
4155
),
4256
),
43-
),
44-
),
45-
pitfalls = listOf("Doesn't work with mutable vars."),
46-
relatedTopics = listOf("Type Checking", "Safe Casts"),
47-
)
57+
pitfalls = listOf("Doesn't work with mutable vars."),
58+
relatedTopics = listOf("Type Checking", "Safe Casts"),
59+
)
60+
}
4861

49-
fun sampleTopicList(): List<Topic> = listOf(
50-
Topic("Smart Casts"),
51-
Topic("Null Safety"),
52-
Topic("Coroutines"),
53-
Topic("Lambdas"),
54-
Topic("Sealed Classes"),
55-
)
62+
fun sampleTopicList(): List<Topic> {
63+
return listOf(
64+
Topic("Smart Casts"),
65+
Topic("Null Safety"),
66+
Topic("Coroutines"),
67+
Topic("Lambdas"),
68+
Topic("Sealed Classes"),
69+
)
70+
}
5671

57-
val faketopiclist = listOf(
58-
"Introduction" to 0,
59-
"Examples" to 1,
60-
"Use Cases" to 2,
61-
"Best Practices" to 3,
62-
)
72+
fun sampleTopicUiList(): List<TopicUi> {
73+
return sampleTopicList().map { topic ->
74+
TopicUi(
75+
name = topic.name,
76+
initial = topic.name.firstOrNull()?.uppercase() ?: "",
77+
isBookmarked = true,
78+
)
79+
}
80+
}

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

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

33
import androidx.compose.runtime.Composable
44
import androidx.compose.ui.tooling.preview.PreviewLightDark
5+
import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.TopicUi
56
import com.developersbreach.kotlindictionarymultiplatform.previews.subtitle
67
import com.developersbreach.kotlindictionarymultiplatform.previews.topic
78
import com.developersbreach.kotlindictionarymultiplatform.ui.screens.topic.TopicCard
@@ -17,6 +18,11 @@ fun TopicCardPreview() {
1718
isBookmarked = false,
1819
onBookmarkClick = {},
1920
onCardClick = {},
21+
topicUi = TopicUi(
22+
name = "Emerson Vega",
23+
initial = "senectus",
24+
isBookmarked = false,
25+
),
2026
)
2127
}
2228
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.developersbreach.kotlindictionarymultiplatform.previews.topic
33
import androidx.compose.runtime.Composable
44
import androidx.compose.ui.tooling.preview.PreviewLightDark
55
import com.developersbreach.kotlindictionarymultiplatform.previews.sampleTopicList
6+
import com.developersbreach.kotlindictionarymultiplatform.previews.sampleTopicUiList
67
import com.developersbreach.kotlindictionarymultiplatform.ui.screens.topic.TopicList
78
import com.developersbreach.kotlindictionarymultiplatform.ui.theme.KotlinDictionaryTheme
89

@@ -11,7 +12,7 @@ import com.developersbreach.kotlindictionarymultiplatform.ui.theme.KotlinDiction
1112
fun TopicListPreview() {
1213
KotlinDictionaryTheme {
1314
TopicList(
14-
topics = sampleTopicList(),
15+
topics = sampleTopicUiList(),
1516
bookmarkedStates = List(sampleTopicList().size) { true },
1617
onBookmarkClick = {},
1718
onTopicClick = {},

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

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.compose.runtime.collectAsState
55
import androidx.compose.runtime.getValue
66
import androidx.compose.ui.tooling.preview.PreviewLightDark
77
import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.Topic
8+
import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.TopicUi
89
import com.developersbreach.kotlindictionarymultiplatform.previews.sampleTopicList
910
import com.developersbreach.kotlindictionarymultiplatform.ui.components.UiState
1011
import com.developersbreach.kotlindictionarymultiplatform.ui.components.UiStateHandler
@@ -17,24 +18,40 @@ import kotlinx.coroutines.flow.StateFlow
1718
class FakeTopicViewModel : TopicViewModelFakeBase() {
1819
override val topics = MutableStateFlow<UiState<List<Topic>>>(UiState.Success(sampleTopicList()))
1920
override val searchQuery = MutableStateFlow("")
20-
override val filteredTopics = MutableStateFlow(sampleTopicList())
21+
override val filteredTopics = MutableStateFlow(
22+
sampleTopicList().map { topic ->
23+
TopicUi(
24+
name = topic.name,
25+
initial = topic.name.firstOrNull()?.uppercase() ?: "",
26+
isBookmarked = true,
27+
)
28+
},
29+
)
2130
override val bookmarkedStates = MutableStateFlow(List(sampleTopicList().size) { true })
2231

23-
override fun updateSearchQuery(newQuery: String) {}
32+
override fun updateSearchQuery(
33+
newQuery: String,
34+
) {}
2435

25-
override fun toggleBookmark(index: Int) {}
36+
override fun toggleBookmark(
37+
index: Int,
38+
) {}
2639
}
2740

2841
// Base class to avoid needing Android ViewModel
2942
abstract class TopicViewModelFakeBase {
3043
abstract val topics: StateFlow<UiState<List<Topic>>>
3144
abstract val searchQuery: StateFlow<String>
32-
abstract val filteredTopics: StateFlow<List<Topic>>
45+
abstract val filteredTopics: StateFlow<List<TopicUi>>
3346
abstract val bookmarkedStates: StateFlow<List<Boolean>>
3447

35-
abstract fun updateSearchQuery(newQuery: String)
48+
abstract fun updateSearchQuery(
49+
newQuery: String,
50+
)
3651

37-
abstract fun toggleBookmark(index: Int)
52+
abstract fun toggleBookmark(
53+
index: Int,
54+
)
3855
}
3956

4057
@Composable

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/Log.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,41 @@ object Log {
77
tag: String,
88
message: String,
99
) {
10-
Logger.d(message, tag = tag)
10+
Logger.d(
11+
messageString = message,
12+
tag = tag,
13+
)
1114
}
1215

1316
fun i(
1417
tag: String,
1518
message: String,
1619
) {
17-
Logger.i(message, tag = tag)
20+
Logger.i(
21+
messageString = message,
22+
tag = tag,
23+
)
1824
}
1925

2026
fun w(
2127
tag: String,
2228
message: String,
2329
) {
24-
Logger.w(message, tag = tag)
30+
Logger.w(
31+
messageString = message,
32+
tag = tag,
33+
)
2534
}
2635

2736
fun e(
2837
tag: String,
2938
message: String,
3039
throwable: Throwable? = null,
3140
) {
32-
Logger.e(message, throwable, tag = tag)
41+
Logger.e(
42+
messageString = message,
43+
throwable = throwable,
44+
tag = tag,
45+
)
3346
}
3447
}

0 commit comments

Comments
 (0)