Skip to content

Commit

Permalink
Upgrade Stream Chat Depencency to v6
Browse files Browse the repository at this point in the history
  • Loading branch information
JcMinarro committed Apr 18, 2023
1 parent 36686d6 commit be6416b
Show file tree
Hide file tree
Showing 34 changed files with 123 additions and 117 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ dependencies {

// stream chat core + UI SDK
implementation(libs.stream.ui.components)
implementation(libs.stream.offline)
implementation(libs.stream.firebase)

// data binding
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package io.getstream.avengerschat.initializer
import android.content.Context
import android.content.Intent
import androidx.startup.Initializer
import io.getstream.android.push.firebase.FirebasePushDeviceGenerator
import io.getstream.avengerschat.BuildConfig
import io.getstream.avengerschat.R
import io.getstream.avengerschat.core.uicomponents.startup.StreamGlobalStyleInitializer
Expand All @@ -28,10 +29,10 @@ import io.getstream.chat.android.client.logger.ChatLogLevel
import io.getstream.chat.android.client.notifications.handler.NotificationConfig
import io.getstream.chat.android.client.notifications.handler.NotificationHandler
import io.getstream.chat.android.client.notifications.handler.NotificationHandlerFactory
import io.getstream.chat.android.offline.model.message.attachments.UploadAttachmentsNetworkType
import io.getstream.chat.android.offline.plugin.configuration.Config
import io.getstream.chat.android.models.UploadAttachmentsNetworkType
import io.getstream.chat.android.offline.plugin.factory.StreamOfflinePluginFactory
import io.getstream.chat.android.pushprovider.firebase.FirebasePushDeviceGenerator
import io.getstream.chat.android.state.plugin.config.StatePluginConfig
import io.getstream.chat.android.state.plugin.factory.StreamStatePluginFactory
import timber.log.Timber

/**
Expand All @@ -43,14 +44,13 @@ class StreamChatInitializer : Initializer<Unit> {
Timber.d("StreamChatInitializer is initialized")

val logLevel = if (BuildConfig.DEBUG) ChatLogLevel.ALL else ChatLogLevel.NOTHING
val offlinePluginFactory = StreamOfflinePluginFactory(
config = Config(
val offlinePluginFactory = StreamOfflinePluginFactory(appContext = context)
val statePluginFactory = StreamStatePluginFactory(
appContext = context,
config = StatePluginConfig(
backgroundSyncEnabled = true,
userPresence = true,
persistenceEnabled = true,
uploadAttachmentsNetworkType = UploadAttachmentsNetworkType.NOT_ROAMING
),
appContext = context
)
)

/**
Expand All @@ -60,7 +60,8 @@ class StreamChatInitializer : Initializer<Unit> {
*/
ChatClient.Builder(context.getString(R.string.stream_api_key), context)
.notifications(createNotificationConfig(), createNotificationHandler(context))
.withPlugin(offlinePluginFactory)
.withPlugins(offlinePluginFactory, statePluginFactory)
.uploadAttachmentsNetworkType(UploadAttachmentsNetworkType.NOT_ROAMING)
.logLevel(logLevel)
.build()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package io.getstream.avengerschat.core.data.repository.dm

import androidx.annotation.WorkerThread
import io.getstream.chat.android.client.models.User
import io.getstream.chat.android.models.User
import kotlinx.coroutines.flow.Flow

interface DirectMessageRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import io.getstream.avengerschat.core.network.AppDispatchers
import io.getstream.avengerschat.core.network.Dispatcher
import io.getstream.chat.android.client.ChatClient
import io.getstream.chat.android.client.api.models.QueryUsersRequest
import io.getstream.chat.android.client.models.Filters
import io.getstream.chat.android.client.models.User
import io.getstream.chat.android.client.utils.onSuccessSuspend
import io.getstream.chat.android.models.Filters
import io.getstream.chat.android.models.User
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
Expand Down Expand Up @@ -61,7 +61,7 @@ internal class DirectMessageRepositoryImpl @Inject constructor(
)
val result = chatClient.queryUsers(usersRequest).await()
result.onSuccessSuspend {
emit(result.data())
emit(it)
}
}.flowOn(dispatcher)

Expand All @@ -77,7 +77,7 @@ internal class DirectMessageRepositoryImpl @Inject constructor(
extraData = mapOf()
).await()
result.onSuccessSuspend {
emit(result.data().cid)
emit(it.cid)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ internal class GuestRepositoryImpl @Inject constructor(
// fetch a guest token.
val result = chatClient.getGuestToken(name, name).await()
result.onSuccessSuspend {
emit(result.data().token)
emit(it.token)
}
}.flowOn(dispatcher)
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package io.getstream.avengerschat.core.data.repository.home
import androidx.annotation.WorkerThread
import io.getstream.avengerschat.core.model.Avenger
import io.getstream.avengerschat.core.model.LiveRoomInfo
import io.getstream.chat.android.client.models.ConnectionData
import io.getstream.chat.android.models.ConnectionData
import kotlinx.coroutines.flow.Flow

interface HomeRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import io.getstream.avengerschat.core.model.Avenger
import io.getstream.avengerschat.core.network.AppDispatchers
import io.getstream.avengerschat.core.network.Dispatcher
import io.getstream.chat.android.client.ChatClient
import io.getstream.chat.android.client.models.User
import io.getstream.chat.android.client.utils.onSuccessSuspend
import io.getstream.chat.android.models.User
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
Expand Down Expand Up @@ -58,7 +58,7 @@ internal class HomeRepositoryImpl @Inject constructor(
)
val result = chatClient.connectUser(user, avenger.token).await()
result.onSuccessSuspend {
emit(result.data())
emit(it)
}
}.flowOn(dispatcher)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package io.getstream.avengerschat.core.data.repository.user

import androidx.annotation.WorkerThread
import io.getstream.avengerschat.core.model.Avenger
import io.getstream.chat.android.client.models.User
import io.getstream.chat.android.models.User
import kotlinx.coroutines.flow.Flow

interface UserProfileEditRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import io.getstream.avengerschat.core.model.Avenger
import io.getstream.avengerschat.core.network.AppDispatchers
import io.getstream.avengerschat.core.network.Dispatcher
import io.getstream.chat.android.client.ChatClient
import io.getstream.chat.android.client.models.User
import io.getstream.chat.android.client.utils.onSuccessSuspend
import io.getstream.chat.android.models.User
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
Expand Down Expand Up @@ -50,7 +50,7 @@ internal class UserProfileEditRepositoryImpl @Inject constructor(
)
val result = chatClient.updateUser(user).await()
result.onSuccessSuspend {
emit(result.data())
emit(it)
}
}.flowOn(dispatcher)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import android.content.Context
import androidx.annotation.ColorInt
import io.getstream.avengerschat.core.uicomponents.extensions.drawable
import io.getstream.chat.android.ui.ChatUI
import io.getstream.chat.android.ui.StyleTransformer
import io.getstream.chat.android.ui.SupportedReactions
import io.getstream.chat.android.ui.TransformStyle
import io.getstream.chat.android.ui.helper.StyleTransformer
import io.getstream.chat.android.ui.helper.SupportedReactions
import io.getstream.chat.android.ui.helper.TransformStyle

/**
* StreamGlobalStyles unify the styles of the Stream UI components by using the
Expand Down Expand Up @@ -67,10 +67,10 @@ object StreamGlobalStyles {
)
}

TransformStyle.messageInputStyleTransformer =
TransformStyle.messageComposerStyleTransformer =
StyleTransformer { messageInputStyle ->
messageInputStyle.copy(
sendButtonEnabledIcon = messageInputStyle.sendButtonEnabledIcon.apply {
sendMessageButtonIconDrawable = messageInputStyle.sendMessageButtonIconDrawable.apply {
setTint(color)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import coil.load
import coil.request.ImageRequest
import coil.transform.CircleCropTransformation
import com.skydoves.androidveil.VeilLayout
import io.getstream.chat.android.client.models.User
import io.getstream.chat.android.ui.avatar.AvatarView
import io.getstream.chat.android.models.User
import io.getstream.chat.android.ui.widgets.avatar.UserAvatarView

object ViewBinding {
@JvmStatic
Expand Down Expand Up @@ -71,7 +71,7 @@ object ViewBinding {

@JvmStatic
@BindingAdapter("user")
fun bindUser(avatarView: AvatarView, user: User?) {
user?.let { avatarView.setUserData(it) }
fun bindUser(avatarView: UserAvatarView, user: User?) {
user?.let { avatarView.setUser(it) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ package io.getstream.avengerschat.extensions

import android.content.Context
import android.text.format.DateUtils
import com.getstream.sdk.chat.adapter.MessageListItem
import com.getstream.sdk.chat.utils.DateFormatter
import io.getstream.avengerschat.core.uicomponents.R
import io.getstream.chat.android.client.models.User
import io.getstream.chat.android.models.User
import io.getstream.chat.android.ui.common.helper.DateFormatter
import io.getstream.chat.android.ui.feature.messages.list.adapter.MessageListItem
import org.threeten.bp.Instant
import org.threeten.bp.LocalDateTime
import org.threeten.bp.ZoneId
Expand All @@ -30,7 +30,7 @@ import java.util.Date
fun MessageListItem.MessageItem.localDate(context: Context): String {
val formatter = DateFormatter.from(context)
val date = message.createdAt ?: message.createdLocallyAt
return formatter.formatDate(date?.let(::toLocalDateTime))
return formatter.formatDate(date)
}

private fun toLocalDateTime(date: Date): LocalDateTime {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ import android.view.ViewGroup
import androidx.fragment.app.activityViewModels
import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel
import com.skydoves.bindables.BindingFragment
import dagger.hilt.android.AndroidEntryPoint
import io.getstream.avengerschat.core.uicomponents.extensions.addOnBackPressedDispatcher
import io.getstream.avengerschat.feature.chat.component.StreamMessageListUIComponent
import io.getstream.avengerschat.feature.chat.component.streamMessageListComponent
import io.getstream.avengerschat.feature.chat.databinding.FragmentMessageListBinding
import io.getstream.avengerschat.feature.home.common.HomeViewModel
import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModel

@AndroidEntryPoint
class MessageListFragment :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package io.getstream.avengerschat.feature.chat.binding

import androidx.databinding.BindingAdapter
import io.getstream.avengerschat.feature.chat.R
import io.getstream.chat.android.client.models.User
import io.getstream.chat.android.ui.channel.list.header.ChannelListHeaderView
import io.getstream.chat.android.models.User
import io.getstream.chat.android.ui.feature.channels.header.ChannelListHeaderView

internal object ViewBinding {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import androidx.lifecycle.LifecycleOwner
import io.getstream.avengerschat.core.uicomponents.stream.StreamComponents
import io.getstream.avengerschat.core.uicomponents.stream.StreamUIComponent
import io.getstream.avengerschat.feature.chat.R
import io.getstream.chat.android.ui.channel.list.ChannelListView
import io.getstream.chat.android.ui.channel.list.viewmodel.ChannelListViewModel
import io.getstream.chat.android.ui.channel.list.viewmodel.bindView
import io.getstream.chat.android.ui.channel.list.viewmodel.factory.ChannelListViewModelFactory
import io.getstream.chat.android.ui.feature.channels.list.ChannelListView
import io.getstream.chat.android.ui.viewmodel.channels.ChannelListViewModel
import io.getstream.chat.android.ui.viewmodel.channels.ChannelListViewModelFactory
import io.getstream.chat.android.ui.viewmodel.channels.bindView

/**
* Stream channel list UI component.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ package io.getstream.avengerschat.feature.chat.component

import android.view.View
import androidx.lifecycle.LifecycleOwner
import com.getstream.sdk.chat.viewmodel.MessageInputViewModel
import com.getstream.sdk.chat.viewmodel.messages.MessageListViewModel
import io.getstream.avengerschat.core.uicomponents.stream.StreamComponents
import io.getstream.avengerschat.core.uicomponents.stream.StreamUIComponent
import io.getstream.avengerschat.feature.chat.R
import io.getstream.chat.android.ui.message.input.MessageInputView
import io.getstream.chat.android.ui.message.input.viewmodel.bindView
import io.getstream.chat.android.ui.message.list.MessageListView
import io.getstream.chat.android.ui.message.list.header.MessageListHeaderView
import io.getstream.chat.android.ui.message.list.header.viewmodel.MessageListHeaderViewModel
import io.getstream.chat.android.ui.message.list.header.viewmodel.bindView
import io.getstream.chat.android.ui.message.list.viewmodel.bindView
import io.getstream.chat.android.ui.message.list.viewmodel.factory.MessageListViewModelFactory
import io.getstream.chat.android.ui.common.state.messages.Edit
import io.getstream.chat.android.ui.common.state.messages.MessageMode
import io.getstream.chat.android.ui.feature.messages.composer.MessageComposerView
import io.getstream.chat.android.ui.feature.messages.header.MessageListHeaderView
import io.getstream.chat.android.ui.feature.messages.list.MessageListView
import io.getstream.chat.android.ui.viewmodel.messages.MessageComposerViewModel
import io.getstream.chat.android.ui.viewmodel.messages.MessageListHeaderViewModel
import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModel
import io.getstream.chat.android.ui.viewmodel.messages.MessageListViewModelFactory
import io.getstream.chat.android.ui.viewmodel.messages.bindView

/**
* Stream message list UI component.
Expand All @@ -52,8 +52,8 @@ class StreamMessageListUIComponent constructor(
val messageListViewModel: MessageListViewModel by lazy(LazyThreadSafetyMode.NONE) {
factory.create(MessageListViewModel::class.java)
}
private val messageInputViewModel: MessageInputViewModel by lazy(LazyThreadSafetyMode.NONE) {
factory.create(MessageInputViewModel::class.java)
private val messageInputViewModel: MessageComposerViewModel by lazy(LazyThreadSafetyMode.NONE) {
factory.create(MessageComposerViewModel::class.java)
}

@StreamComponents
Expand All @@ -70,25 +70,26 @@ class StreamMessageListUIComponent constructor(
messageListViewModel.bindView(it, lifecycleOwner)
}
val messageInputView =
view.findViewById<MessageInputView>(R.id.messageInputView)
view.findViewById<MessageComposerView>(R.id.messageInputView)
messageInputView?.let {
messageInputViewModel.bindView(it, lifecycleOwner)
}

// observe thread modes states.
messageListViewModel.mode.observe(lifecycleOwner) {
when (it) {
is MessageListViewModel.Mode.Thread -> {
is MessageMode.MessageThread -> {
messageListHeaderViewModel.setActiveThread(it.parentMessage)
messageInputViewModel.setActiveThread(it.parentMessage)
}
is MessageListViewModel.Mode.Normal -> {
is MessageMode.Normal -> {
messageListHeaderViewModel.resetThread()
messageInputViewModel.resetThread()
}
}
messageInputViewModel.setMessageMode(it)
}
messageListView?.setMessageEditHandler{
messageInputViewModel.performMessageAction(Edit(it))
}
messageListView?.setMessageEditHandler(messageInputViewModel::postMessageToEdit)
}
}

Expand Down
4 changes: 2 additions & 2 deletions feature-chat/src/main/res/layout/fragment_channel_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<io.getstream.chat.android.ui.channel.list.header.ChannelListHeaderView
<io.getstream.chat.android.ui.feature.channels.header.ChannelListHeaderView
android:id="@+id/channelListHeaderView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -41,7 +41,7 @@
tools:background="@color/colorPrimary"
tools:layout_height="56dp" />

<io.getstream.chat.android.ui.channel.list.ChannelListView
<io.getstream.chat.android.ui.feature.channels.list.ChannelListView
android:id="@+id/channelListView"
android:layout_width="0dp"
android:layout_height="0dp"
Expand Down
10 changes: 5 additions & 5 deletions feature-chat/src/main/res/layout/fragment_message_list.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
android:layout_width="match_parent"
android:layout_height="match_parent">

<io.getstream.chat.android.ui.message.list.header.MessageListHeaderView
<io.getstream.chat.android.ui.feature.messages.header.MessageListHeaderView
android:id="@+id/messageListHeaderView"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<io.getstream.chat.android.ui.message.list.MessageListView
<io.getstream.chat.android.ui.feature.messages.list.MessageListView
android:id="@+id/messageListView"
android:layout_width="0dp"
android:layout_height="0dp"
Expand All @@ -49,10 +49,10 @@
app:streamUiMessageTextColorDateSeparator="@color/white"
app:streamUiMessageTextSizeUserName="15sp"
app:streamUiMessageTextStyleUserName="bold"
app:streamUiMuteUserEnabled="false"
app:streamUiPinMessageEnabled="true" />
app:streamUiPinMessageEnabled="true"
/>

<io.getstream.chat.android.ui.message.input.MessageInputView
<io.getstream.chat.android.ui.feature.messages.composer.MessageComposerView
android:id="@+id/messageInputView"
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand Down
Loading

0 comments on commit be6416b

Please sign in to comment.