Skip to content

Commit cab0172

Browse files
committed
Migrate to Stream Chat SDK 5.0.1
1 parent 7edf53f commit cab0172

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

app/src/main/java/com/example/chattutorial/MainActivity.kt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,44 @@ import io.getstream.chat.android.client.logger.ChatLogLevel
99
import io.getstream.chat.android.client.models.User
1010
import io.getstream.chat.android.compose.ui.channels.ChannelsScreen
1111
import io.getstream.chat.android.compose.ui.theme.ChatTheme
12-
import io.getstream.chat.android.offline.ChatDomain
12+
import io.getstream.chat.android.offline.model.message.attachments.UploadAttachmentsNetworkType
13+
import io.getstream.chat.android.offline.plugin.configuration.Config
14+
import io.getstream.chat.android.offline.plugin.factory.StreamOfflinePluginFactory
1315

1416
class MainActivity : AppCompatActivity() {
1517

1618
override fun onCreate(savedInstanceState: Bundle?) {
1719
super.onCreate(savedInstanceState)
1820

19-
// 1 - Set up the client for API calls and the domain for offline storage
21+
// 1 - Set up the OfflinePlugin for offline storage
22+
val offlinePluginFactory = StreamOfflinePluginFactory(
23+
config = Config(
24+
backgroundSyncEnabled = true,
25+
userPresence = true,
26+
persistenceEnabled = true,
27+
uploadAttachmentsNetworkType = UploadAttachmentsNetworkType.NOT_ROAMING,
28+
),
29+
appContext = applicationContext,
30+
)
31+
32+
// 2 - Set up the client for API calls and with the plugin for offline storage
2033
val client = ChatClient.Builder("b67pax5b2wdq", applicationContext)
34+
.withPlugin(offlinePluginFactory)
2135
.logLevel(ChatLogLevel.ALL) // Set to NOTHING in prod
2236
.build()
23-
ChatDomain.Builder(client, applicationContext).build()
2437

25-
// 2 - Authenticate and connect the user
26-
val user = User(id = "tutorial-droid").apply {
27-
name = "Tutorial Droid"
38+
// 3 - Authenticate and connect the user
39+
val user = User(
40+
id = "tutorial-droid",
41+
name = "Tutorial Droid",
2842
image = "https://bit.ly/2TIt8NR"
29-
}
43+
)
3044
client.connectUser(
3145
user = user,
3246
token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoidHV0b3JpYWwtZHJvaWQifQ.NhEr0hP9W9nwqV7ZkdShxvi02C5PR7SJE7Cs4y7kyqg"
3347
).enqueue()
3448

35-
// 3 - Set up the Channels Screen UI
49+
// 4 - Set up the Channels Screen UI
3650
setContent {
3751
ChatTheme {
3852
ChannelsScreen(

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
}
99
dependencies {
1010
classpath "com.android.tools.build:gradle:7.1.2"
11-
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31'
11+
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10'
1212
}
1313
}
1414

0 commit comments

Comments
 (0)