Skip to content

Commit ab490b3

Browse files
authored
Merge branch 'master' into shreyas/migrate-openai-to-gemini
2 parents bb45203 + 49cdd62 commit ab490b3

File tree

45 files changed

+588
-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.

45 files changed

+588
-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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ plugins {
88
alias(libs.plugins.kotlinMultiplatform) apply false
99
alias(libs.plugins.serialization) apply false
1010
alias(libs.plugins.googleSecrets) apply false
11-
}
12-
11+
alias(libs.plugins.jetbrainsKotlinJvm) apply false
12+
}

composeApp/build.gradle.kts

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

2020
ktlint {
21+
version.set("1.3.0")
2122
android = true
2223
ignoreFailures = false
2324
reporters {
@@ -147,14 +148,19 @@ android {
147148

148149
dependencies {
149150
debugImplementation(compose.uiTooling)
151+
ktlint(project(":custom-ktlint-rules"))
150152
}
151153

152154
compose.desktop {
153155
application {
154156
mainClass = "com.developersbreach.kotlindictionarymultiplatform.MainKt"
155157

156158
nativeDistributions {
157-
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
159+
targetFormats(
160+
TargetFormat.Dmg,
161+
TargetFormat.Msi,
162+
TargetFormat.Deb,
163+
)
158164
packageName = "com.developersbreach.kotlindictionarymultiplatform"
159165
packageVersion = "1.0.0"
160166
}
@@ -164,13 +170,24 @@ compose.desktop {
164170
fun ApplicationDefaultConfig.setupBuildConfigFields(
165171
properties: Properties,
166172
) {
167-
fun secret(key: String): String = System.getenv(key) ?: properties.getProperty(key, "")
173+
fun secret(
174+
key: String,
175+
): String {
176+
return System.getenv(key) ?: properties.getProperty(
177+
key,
178+
"",
179+
)
180+
}
168181

169182
if (secret("GEMINI_API_KEY").isEmpty()) {
170183
error("GEMINI_API_KEY not set in local.properties")
171184
}
172185

173-
buildConfigField(type = "String", name = "GEMINI_API_KEY", value = "\"${secret("GEMINI_API_KEY")}\"")
186+
buildConfigField(
187+
type = "String",
188+
name = "GEMINI_API_KEY",
189+
value = "\"${secret("GEMINI_API_KEY")}\"",
190+
)
174191
}
175192

176193
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.GEMINI_API_KEY
13+
actual fun getOpenApiKey(): String {
14+
return BuildConfig.GEMINI_API_KEY
15+
}

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

Lines changed: 59 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,74 @@ import com.developersbreach.kotlindictionarymultiplatform.data.detail.model.Synt
77
import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.Topic
88
import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.TopicUi
99

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

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

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

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

50-
fun sampleTopicList(): List<Topic> = listOf(
51-
Topic("Smart Casts"),
52-
Topic("Null Safety"),
53-
Topic("Coroutines"),
54-
Topic("Lambdas"),
55-
Topic("Sealed Classes"),
56-
)
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+
}
5771

58-
fun sampleTopicUiList(): List<TopicUi> =
59-
sampleTopicList().map { topic ->
72+
fun sampleTopicUiList(): List<TopicUi> {
73+
return sampleTopicList().map { topic ->
6074
TopicUi(
6175
name = topic.name,
6276
initial = topic.name.firstOrNull()?.uppercase() ?: "",
6377
isBookmarked = true,
6478
)
65-
}
79+
}
80+
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,13 @@ class FakeTopicViewModel : TopicViewModelFakeBase() {
2929
)
3030
override val bookmarkedStates = MutableStateFlow(List(sampleTopicList().size) { true })
3131

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

34-
override fun toggleBookmark(index: Int) {}
36+
override fun toggleBookmark(
37+
index: Int,
38+
) {}
3539
}
3640

3741
// Base class to avoid needing Android ViewModel
@@ -41,9 +45,13 @@ abstract class TopicViewModelFakeBase {
4145
abstract val filteredTopics: StateFlow<List<TopicUi>>
4246
abstract val bookmarkedStates: StateFlow<List<Boolean>>
4347

44-
abstract fun updateSearchQuery(newQuery: String)
48+
abstract fun updateSearchQuery(
49+
newQuery: String,
50+
)
4551

46-
abstract fun toggleBookmark(index: Int)
52+
abstract fun toggleBookmark(
53+
index: Int,
54+
)
4755
}
4856

4957
@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
}

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/data/detail/repository/DetailRepository.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,14 @@ import com.developersbreach.kotlindictionarymultiplatform.getOpenApiKey
77

88
class DetailRepository {
99

10-
suspend fun fetchTopic(topicId: String): Either<Throwable, KotlinTopicDetails> =
11-
Either.catch {
12-
KtorHttpClient.generateTopicDetails(topicId, getOpenApiKey())
10+
suspend fun fetchTopic(
11+
topicId: String,
12+
): Either<Throwable, KotlinTopicDetails> {
13+
return Either.catch {
14+
KtorHttpClient.generateTopicDetails(
15+
topicId = topicId,
16+
apiKey = getOpenApiKey(),
17+
)
1318
}
19+
}
1420
}

composeApp/src/commonMain/kotlin/com/developersbreach/kotlindictionarymultiplatform/data/topic/repository/TopicRepository.kt

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,25 @@ import arrow.core.Either
44
import com.developersbreach.kotlindictionarymultiplatform.data.topic.model.Topic
55

66
object TopicRepository {
7-
fun getTopics(): Either<Throwable, List<Topic>> = Either.catch {
8-
listOf(
9-
Topic("Variables"),
10-
Topic("Strings"),
11-
Topic("Functions"),
12-
Topic("Coroutines"),
13-
Topic("Classes"),
14-
Topic("Interfaces"),
15-
Topic("Objects"),
16-
Topic("Collections"),
17-
Topic("Null Safety"),
18-
Topic("Lambdas"),
19-
Topic("Higher-Order Functions"),
20-
Topic("Delegation"),
21-
Topic("Sealed Classes"),
22-
Topic("Generics"),
23-
Topic("Annotations"),
24-
)
7+
fun getTopics(): Either<Throwable, List<Topic>> {
8+
return Either.catch {
9+
listOf(
10+
Topic("Variables"),
11+
Topic("Strings"),
12+
Topic("Functions"),
13+
Topic("Coroutines"),
14+
Topic("Classes"),
15+
Topic("Interfaces"),
16+
Topic("Objects"),
17+
Topic("Collections"),
18+
Topic("Null Safety"),
19+
Topic("Lambdas"),
20+
Topic("Higher-Order Functions"),
21+
Topic("Delegation"),
22+
Topic("Sealed Classes"),
23+
Topic("Generics"),
24+
Topic("Annotations"),
25+
)
26+
}
2527
}
2628
}

0 commit comments

Comments
 (0)