Skip to content

Commit 6a3e8a2

Browse files
authored
Merge pull request #1 from GetStream/reafctor/sealedx
Introduce SealedX KSP library
2 parents 8ed11b8 + 02b1043 commit 6a3e8a2

File tree

10 files changed

+93
-25
lines changed

10 files changed

+93
-25
lines changed

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ object Versions {
2020
internal const val APP_STARTUP = "1.1.1"
2121
internal const val LIFECYCLE = "2.6.0-alpha01"
2222
internal const val ROOM = "2.4.2"
23+
internal const val SEALEDX = "1.0.0"
2324

2425
internal const val LANDSCAPIST_GLIDE = "1.6.0"
2526
internal const val ACCOMPANIST = "0.25.0"
@@ -77,6 +78,7 @@ object Dependencies {
7778
const val accompanistIndicator =
7879
"com.google.accompanist:accompanist-pager-indicators:${Versions.ACCOMPANIST}"
7980
const val streamCompose = "io.getstream:stream-chat-android-compose:${Versions.STREAM_CHAT}"
81+
const val streamClient = "io.getstream:stream-chat-android-client:${Versions.STREAM_CHAT}"
8082

8183
const val appStartUp = "androidx.startup:startup-runtime:${Versions.APP_STARTUP}"
8284
const val hiltAndroid = "com.google.dagger:hilt-android:${Versions.HILT}"
@@ -85,6 +87,8 @@ object Dependencies {
8587
const val roomRuntime = "androidx.room:room-runtime:${Versions.ROOM}"
8688
const val roomKtx = "androidx.room:room-ktx:${Versions.ROOM}"
8789
const val roomCompiler = "androidx.room:room-compiler:${Versions.ROOM}"
90+
const val sealedXCore = "com.github.skydoves:sealedx-core:${Versions.SEALEDX}"
91+
const val sealedXProcessor = "com.github.skydoves:sealedx-processor:${Versions.SEALEDX}"
8892

8993
const val okHttp = "com.squareup.okhttp3:okhttp:${Versions.OKHTTP}"
9094
const val retrofit = "com.squareup.retrofit2:retrofit:${Versions.RETROFIT}"

core-data/build.gradle.kts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
id("org.jetbrains.kotlin.android")
44
id("org.jetbrains.kotlin.plugin.serialization")
55
id("kotlin-kapt")
6+
id("com.google.devtools.ksp")
67
id("dagger.hilt.android.plugin")
78
}
89

@@ -24,13 +25,24 @@ android {
2425
}
2526
}
2627

28+
kotlin {
29+
sourceSets.configureEach {
30+
kotlin.srcDir("$buildDir/generated/ksp/$name/kotlin/")
31+
}
32+
}
33+
2734
dependencies {
2835
api(project(":core-model"))
2936
api(project(":core-network"))
3037
api(project(":core-database"))
3138

39+
api(Dependencies.streamClient)
40+
3241
api(Dependencies.coroutines)
3342

3443
api(Dependencies.hiltAndroid)
3544
kapt(Dependencies.hiltCompiler)
45+
46+
implementation(Dependencies.sealedXCore)
47+
ksp(Dependencies.sealedXProcessor)
3648
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2022 Stream.IO, Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.getstream.whatsappclone.data.model
18+
19+
import com.skydoves.sealedx.core.Extensive
20+
import com.skydoves.sealedx.core.annotations.ExtensiveModel
21+
import com.skydoves.sealedx.core.annotations.ExtensiveSealed
22+
import io.getstream.chat.android.client.models.Channel
23+
import io.getstream.whatsappclone.model.WhatsAppUserExtensive
24+
25+
@ExtensiveSealed(
26+
models = [
27+
ExtensiveModel(type = Channel::class, name = "WhatsAppMessage"),
28+
ExtensiveModel(type = WhatsAppUserExtensive::class, name = "WhatsAppUser")
29+
]
30+
)
31+
sealed interface UiState {
32+
data class Success(val data: Extensive) : UiState
33+
object Loading : UiState
34+
object Error : UiState
35+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2022 Stream.IO, Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.getstream.whatsappclone.model
18+
19+
data class WhatsAppUserExtensive(
20+
val whatsappUserList: List<WhatsAppUser>
21+
)

feature-calls/src/main/kotlin/io/getstream/whatsappclone/calls/WhatsAppCalls.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import androidx.compose.foundation.lazy.items
2121
import androidx.compose.runtime.Composable
2222
import androidx.compose.runtime.getValue
2323
import androidx.lifecycle.compose.collectAsStateWithLifecycle
24+
import io.getstream.whatsappclone.data.model.WhatsAppUserUiState
2425
import io.getstream.whatsappclone.designsystem.component.WhatsAppError
2526
import io.getstream.whatsappclone.designsystem.component.WhatsAppLoadingColumn
2627
import io.getstream.whatsappclone.navigation.AppComposeNavigator
@@ -42,15 +43,15 @@ fun WhatsAppCalls(
4243
@Composable
4344
private fun WhatsAppCallsScreen(
4445
composeNavigator: AppComposeNavigator,
45-
whatsAppUsersUiState: WhatsAppUiState
46+
whatsAppUsersUiState: WhatsAppUserUiState
4647
) {
4748
when (whatsAppUsersUiState) {
48-
WhatsAppUiState.Loading -> WhatsAppLoadingColumn()
49-
WhatsAppUiState.Error -> WhatsAppError()
50-
is WhatsAppUiState.Success -> {
49+
WhatsAppUserUiState.Loading -> WhatsAppLoadingColumn()
50+
WhatsAppUserUiState.Error -> WhatsAppError()
51+
is WhatsAppUserUiState.Success -> {
5152
LazyColumn {
5253
items(
53-
items = whatsAppUsersUiState.whatsAppUsers,
54+
items = whatsAppUsersUiState.data.whatsappUserList,
5455
key = { it.name }
5556
) {
5657
WhatsAppCallHistory(whatsAppUser = it) {

feature-calls/src/main/kotlin/io/getstream/whatsappclone/calls/WhatsAppCallsViewModel.kt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ package io.getstream.whatsappclone.calls
1919
import androidx.lifecycle.ViewModel
2020
import androidx.lifecycle.viewModelScope
2121
import dagger.hilt.android.lifecycle.HiltViewModel
22+
import io.getstream.whatsappclone.data.model.WhatsAppUserUiState
2223
import io.getstream.whatsappclone.data.repository.CallHistoryRepository
23-
import io.getstream.whatsappclone.model.WhatsAppUser
24+
import io.getstream.whatsappclone.model.WhatsAppUserExtensive
2425
import kotlinx.coroutines.flow.SharingStarted
2526
import kotlinx.coroutines.flow.StateFlow
2627
import kotlinx.coroutines.flow.flatMapLatest
@@ -33,24 +34,22 @@ class WhatsAppCallsViewModel @Inject constructor(
3334
callHistoryRepository: CallHistoryRepository
3435
) : ViewModel() {
3536

36-
val whatsAppUserState: StateFlow<WhatsAppUiState> =
37+
val whatsAppUserState: StateFlow<WhatsAppUserUiState> =
3738
callHistoryRepository.getCallHistoryUsersStream()
3839
.flatMapLatest {
3940
if (it.isSuccess) {
40-
flowOf(WhatsAppUiState.Success(it.getOrThrow()))
41+
flowOf(
42+
WhatsAppUserUiState.Success(
43+
WhatsAppUserExtensive(it.getOrThrow())
44+
)
45+
)
4146
} else {
42-
flowOf(WhatsAppUiState.Error)
47+
flowOf(WhatsAppUserUiState.Error)
4348
}
4449
}
4550
.stateIn(
4651
scope = viewModelScope,
4752
started = SharingStarted.WhileSubscribed(5_000),
48-
initialValue = WhatsAppUiState.Loading
53+
initialValue = WhatsAppUserUiState.Loading
4954
)
5055
}
51-
52-
sealed interface WhatsAppUiState {
53-
data class Success(val whatsAppUsers: List<WhatsAppUser>) : WhatsAppUiState
54-
object Error : WhatsAppUiState
55-
object Loading : WhatsAppUiState
56-
}

feature-chats/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ dependencies {
4747
implementation(project(":core-designsystem"))
4848
implementation(project(":core-navigation"))
4949
implementation(project(":core-network"))
50+
implementation(project(":core-data"))
5051

5152
// Stream chat Compose
5253
api(Dependencies.streamCompose)

feature-chats/src/main/kotlin/io/getstream/whatsappclone/chats/messages/WhatsAppMessageTopBar.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import androidx.compose.ui.unit.dp
3939
import androidx.lifecycle.compose.collectAsStateWithLifecycle
4040
import com.skydoves.landscapist.glide.GlideImage
4141
import io.getstream.chat.android.client.ChatClient
42+
import io.getstream.whatsappclone.data.model.WhatsAppMessageUiState
4243
import io.getstream.whatsappclone.designsystem.component.WhatsAppLoadingIndicator
4344
import io.getstream.whatsappclone.designsystem.icon.WhatsAppIcons
4445
import io.getstream.whatsappclone.designsystem.theme.WhatsAppCloneComposeTheme
@@ -122,14 +123,14 @@ private fun WhatsAppMessageUserInfo(
122123
modifier = Modifier
123124
.size(32.dp)
124125
.clip(CircleShape),
125-
imageModel = messageUiState.channel.image.takeIf { it.isNotEmpty() }
126+
imageModel = messageUiState.data.image.takeIf { it.isNotEmpty() }
126127
?: io.getstream.whatsappclone.designsystem.R.drawable.stream_logo,
127128
previewPlaceholder = io.getstream.whatsappclone.designsystem.R.drawable.placeholder
128129
)
129130

130131
Text(
131132
modifier = Modifier.padding(start = 12.dp),
132-
text = messageUiState.channel.name,
133+
text = messageUiState.data.name,
133134
color = MaterialTheme.colorScheme.tertiary,
134135
style = MaterialTheme.typography.bodyLarge
135136
)

feature-chats/src/main/kotlin/io/getstream/whatsappclone/chats/messages/WhatsAppMessagesViewModel.kt

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import androidx.lifecycle.ViewModel
2020
import androidx.lifecycle.viewModelScope
2121
import dagger.hilt.android.lifecycle.HiltViewModel
2222
import io.getstream.chat.android.client.ChatClient
23-
import io.getstream.chat.android.client.models.Channel
2423
import io.getstream.chat.android.client.utils.onError
2524
import io.getstream.chat.android.client.utils.onSuccess
25+
import io.getstream.whatsappclone.data.model.WhatsAppMessageUiState
2626
import io.getstream.whatsappclone.network.Dispatcher
2727
import io.getstream.whatsappclone.network.WhatsAppDispatchers
2828
import kotlinx.coroutines.CoroutineDispatcher
@@ -61,9 +61,3 @@ class WhatsAppMessagesViewModel @Inject constructor(
6161
sealed interface WhatsAppMessageEvent {
6262
class FetchChannel(val channelId: String) : WhatsAppMessageEvent
6363
}
64-
65-
sealed interface WhatsAppMessageUiState {
66-
data class Success(val channel: Channel) : WhatsAppMessageUiState
67-
object Loading : WhatsAppMessageUiState
68-
object Error : WhatsAppMessageUiState
69-
}

previews/preview.mp4

1.76 MB
Binary file not shown.

0 commit comments

Comments
 (0)