This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ChannelFragment : Fragment() { | |
//... | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
binding.messageListView.setMessageViewHolderFactory(MyCustomMessageViewHolderFactory()) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun updateMessagesList(messages: List<Message>) { | |
adapter.submitList(messages) | |
adapter.notifyDataSetChanged() | |
val scrollTarget = adapter.itemCount | |
messageListSmoothScroller.targetPosition = scrollTarget | |
messagesList.layoutManager?.startSmoothScroll(messageListSmoothScroller) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LiveStreamActivity : AppCompatActivity(R.layout.activity_main) { | |
private val adapter = MessagesListAdapter() | |
private val messageListSmoothScroller by lazy { | |
object : LinearSmoothScroller(this) { | |
val MILLISECONDS_PER_INCH = 400f | |
override fun calculateSpeedPerPixel(displayMetrics: DisplayMetrics?): Float { | |
return MILLISECONDS_PER_INCH / displayMetrics!!.densityDpi | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LiveStreamActivity : AppCompatActivity(R.layout.activity_main) { | |
private val adapter = MessagesListAdapter() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
loadMockVideoStream() | |
messagesList.adapter = adapter | |
val viewModel: LiveStreamViewModel by viewModels() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun requestChannel() { | |
val channelData = mapOf("name" to "Live stream chat") | |
val request = QueryChannelRequest() | |
.withData(channelData) | |
.withMessages(20) | |
.withWatch() | |
channelController.query(request).enqueue { | |
if (it.isSuccess) { | |
_viewState.postValue(State.Messages(it.data().messages)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
companion object { | |
private const val USER_ID = "bob" | |
private const val CHANNEL_TYPE = "livestream" | |
private const val CHANNEL_ID = "livestream-clone-android" // You'll want to make it unique per video | |
private const val USER_TOKEN = BuildConfig.USER_TOKEN | |
private val chatUser = User(id = USER_ID).apply { | |
name = USER_ID | |
image = getDummyAvatar(USER_ID) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LiveStreamViewModel() : ViewModel() { | |
private val chatClient = ChatClient.instance() | |
private val _viewState = MutableLiveData<State>() | |
private lateinit var channelController: ChannelController | |
val viewState: LiveData<State> = _viewState | |
init { | |
chatClient.setUser(chatUser, USER_TOKEN, object : InitConnectionListener() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LiveStreamActivity : AppCompatActivity(R.layout.activity_main) { | |
private val adapter = MessagesListAdapter() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
loadMockVideoStream() | |
messagesList.adapter = adapter | |
val viewModel: LiveStreamViewModel by viewModels() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
<androidx.cardview.widget.CardView | |
android:id="@+id/avatarWrapper" | |
android:layout_width="@dimen/avatar_size" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.getstream.livestreamclone | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import androidx.recyclerview.widget.DiffUtil | |
import androidx.recyclerview.widget.ListAdapter | |
import androidx.recyclerview.widget.RecyclerView | |
import io.getstream.chat.android.client.models.Message | |
import kotlinx.android.synthetic.main.item_message.view.* |
NewerOlder