Skip to content

Commit 5b88bbc

Browse files
committed
chore: Add basic shared logic
Bug: #68 Change-Id: Iac7b7e3222411f47ce6df969d1507774b20572bd
1 parent f28ea27 commit 5b88bbc

14 files changed

Lines changed: 214 additions & 15 deletions

File tree

composeApp/src/androidMain/kotlin/app/icampuspass/AndroidApp.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ class AndroidApp : Application() {
1414
extraModules = listOf(
1515
module {
1616
factory<GreetingScreenViewModel> {
17-
GreetingScreenViewModel()
17+
GreetingScreenViewModel(
18+
userRepository = get()
19+
)
1820
}
1921

2022
factory<MainScreenViewModel> {

composeApp/src/androidMain/kotlin/app/icampuspass/views/screens/GreetingScreen.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import androidx.compose.ui.tooling.preview.Wallpapers.YELLOW_DOMINATED_EXAMPLE
2929
import app.icampuspass.models.Greeting
3030
import app.icampuspass.composeapp.generated.resources.Res
3131
import app.icampuspass.composeapp.generated.resources.compose_multiplatform
32+
import app.icampuspass.models.getPlatform
3233
import app.icampuspass.viewmodels.GreetingScreenViewModel
3334
import app.icampuspass.views.theme.Theme
3435
import org.jetbrains.compose.resources.painterResource
@@ -38,11 +39,15 @@ import org.koin.androidx.compose.koinViewModel
3839
fun GreetingScreen(
3940
viewModel: GreetingScreenViewModel = koinViewModel()
4041
) {
41-
GreetingScreenContent()
42+
GreetingScreenContent(
43+
greeting = remember { viewModel.getGreeting().greet() }
44+
)
4245
}
4346

4447
@Composable
45-
private fun GreetingScreenContent() {
48+
private fun GreetingScreenContent(
49+
greeting: String
50+
) {
4651
var showContent by remember { mutableStateOf(value = false) }
4752

4853
Column(
@@ -57,8 +62,6 @@ private fun GreetingScreenContent() {
5762
}
5863

5964
AnimatedVisibility(visible = showContent) {
60-
val greeting = remember { Greeting().greet() }
61-
6265
Column(
6366
modifier = Modifier.fillMaxWidth(),
6467
horizontalAlignment = Alignment.CenterHorizontally
@@ -102,6 +105,8 @@ private fun GreetingScreenContent() {
102105
@Composable
103106
private fun GreetingScreenPreview() {
104107
Theme {
105-
GreetingScreenContent()
108+
GreetingScreenContent(
109+
greeting = remember { Greeting(platform = getPlatform()).greet() }
110+
)
106111
}
107112
}

iosApp/iosApp/Views/Screens/GreetingScreen.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import Shared
44
import SwiftUI
55

66
struct GreetingScreen: View {
7-
@StateViewModel var viewModel = GreetingScreenViewModel()
7+
@StateViewModel var viewModel = GreetingScreenViewModel(
8+
userRepository: KoinDependencies().userRepository
9+
)
810

911
@State private var showContent = false
1012

@@ -22,7 +24,7 @@ struct GreetingScreen: View {
2224
.font(.system(size: 200))
2325
.foregroundColor(.accentColor)
2426

25-
Text("SwiftUI: \(Greeting().greet())")
27+
Text("SwiftUI: \(Greeting(platform: getPlatform()).greet())")
2628
}
2729
.transition(.move(edge: .top).combined(with: .opacity))
2830
}

shared/src/commonMain/kotlin/app/icampuspass/Koin.kt

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
package app.icampuspass
22

3+
import app.icampuspass.models.Greeting
4+
import app.icampuspass.models.Platform
35
import app.icampuspass.models.UserAccountRepository
46
import app.icampuspass.models.UserRepository
57
import app.icampuspass.models.database.DatabaseHelper
8+
import app.icampuspass.models.getPlatform
9+
import io.ktor.client.HttpClient
10+
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
11+
import io.ktor.client.plugins.cookies.HttpCookies
12+
import io.ktor.http.ContentType
13+
import io.ktor.serialization.kotlinx.json.json
14+
import kotlinx.serialization.json.Json
615
import org.koin.core.context.startKoin
716
import org.koin.core.module.Module
817
import org.koin.dsl.module
@@ -12,14 +21,43 @@ val commonModule = module {
1221
DatabaseHelper(driverFactory = get())
1322
}
1423

24+
single<Greeting> {
25+
Greeting(platform = get())
26+
}
27+
28+
single<HttpClient> {
29+
HttpClient {
30+
install(plugin = ContentNegotiation) {
31+
json(
32+
json = get(),
33+
contentType = ContentType.Any
34+
)
35+
}
36+
37+
install(plugin = HttpCookies)
38+
}
39+
}
40+
41+
single<Json> {
42+
Json {
43+
ignoreUnknownKeys = true
44+
}
45+
}
46+
47+
single<Platform> {
48+
getPlatform()
49+
}
50+
1551
single<UserAccountRepository> {
1652
UserAccountRepository().apply {
1753
init()
1854
}
1955
}
2056

2157
single<UserRepository> {
22-
UserRepository().apply {
58+
UserRepository(
59+
greeting = get()
60+
).apply {
2361
init()
2462
}
2563
}

shared/src/commonMain/kotlin/app/icampuspass/models/Greeting.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package app.icampuspass.models
22

3-
class Greeting {
4-
private val platform = getPlatform()
5-
3+
class Greeting(
4+
private val platform: Platform
5+
) {
66
fun greet(): String {
77
return "Hello, ${platform.name}!"
88
}

shared/src/commonMain/kotlin/app/icampuspass/models/UserRepository.kt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,40 @@ import kotlinx.coroutines.CoroutineScope
44
import kotlinx.coroutines.SupervisorJob
55
import kotlinx.coroutines.launch
66

7-
class UserRepository() {
7+
class UserRepository(
8+
private val greeting: Greeting
9+
) {
810
private val scope = CoroutineScope(context = SupervisorJob())
911

1012
fun init() {
1113
scope.launch {}
1214
}
15+
16+
fun getGreeting(): Greeting {
17+
return greeting
18+
}
19+
20+
fun getEducationUnits() {}
21+
22+
fun getEducationUnitById(id: Int) {}
23+
24+
fun getCurrentEducationUnit() {}
25+
26+
fun getUsers() {}
27+
28+
fun getUserById(id: Int) {}
29+
30+
fun getCurrentUser() {}
31+
32+
fun getAccounts() {}
33+
34+
fun getAccountById(id: Int) {}
35+
36+
fun getCurrentAccounts() {}
37+
38+
fun getClassSchedules() {}
39+
40+
fun getClassScheduleById(id: Int) {}
41+
42+
fun getCurrentClassSchedule() {}
1343
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package app.icampuspass.models.data
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class Account(
7+
val id: Int
8+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package app.icampuspass.models.data
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class Schedule(
7+
val account: Account
8+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package app.icampuspass.models.data
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class Session(
7+
val id: String,
8+
val courseSession: String,
9+
val courseName: String,
10+
val instructorName: String,
11+
val location: String,
12+
val gradeNumber: String,
13+
val examSeatNumber: String?
14+
)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package app.icampuspass.models.data
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class User(
7+
val id: Int
8+
)

0 commit comments

Comments
 (0)