This file contains hidden or 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 LifecycleAwareLazy<T>(lifecycle: Lifecycle, private val initializer: () -> T) : | |
| Lazy<T>, GenericLifecycleObserver { | |
| init { | |
| lifecycle.addObserver(this) | |
| } | |
| private object UNINITIALIZED_VALUE | |
| private var _value: Any? = UNINITIALIZED_VALUE |
This file contains hidden or 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 MyUnitTest { | |
| @get:Rule | |
| val coroutineRule = TestCoroutineRule() | |
| @Test | |
| fun `my test executed on TestCoroutineDispatcher`() = coroutineRule.runBlockingTest { | |
| assertEquals(42, answer()) | |
| } | |
| } |
This file contains hidden or 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
| ... | |
| <com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView ... /> | |
| <!-- Translucent gradient overlay background to make chat more visible --> | |
| <View | |
| android:layout_width="match_parent" | |
| android:layout_height="0dp" | |
| android:background="@drawable/bg_chat" | |
| app:layout_constraintBottom_toBottomOf="parent" | |
| app:layout_constraintTop_toTopOf="@+id/messagesList" /> |
This file contains hidden or 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.* |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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() |
OlderNewer