Skip to content
Permalink
Browse files
refactor: bind the video using Kohii
  • Loading branch information
eneim committed Jun 27, 2020
1 parent fca4afa commit de8e41eeebff46b73c03ba9fb8f77c5e9fa7ac03
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
@@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="kohii.tut.c201">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
@@ -6,14 +6,19 @@ import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import kohii.v1.exoplayer.Kohii

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val kohii = Kohii[this]

val container: RecyclerView = findViewById(R.id.container)
val adapter = MainAdapter(diffCallback = object : DiffUtil.ItemCallback<VideoItem>() {
kohii.register(this)
.addBucket(container)

val adapter = MainAdapter(kohii, diffCallback = object : DiffUtil.ItemCallback<VideoItem>() {
override fun areItemsTheSame(oldItem: VideoItem, newItem: VideoItem): Boolean =
oldItem === newItem

@@ -4,8 +4,10 @@ import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil.ItemCallback
import androidx.recyclerview.widget.ListAdapter
import kohii.v1.exoplayer.Kohii

class MainAdapter(
private val kohii: Kohii,
diffCallback: ItemCallback<VideoItem>
) : ListAdapter<VideoItem, VideoViewHolder>(diffCallback) {

@@ -16,6 +18,9 @@ class MainAdapter(
}

override fun onBindViewHolder(holder: VideoViewHolder, position: Int) {
// TODO: bind the Video here.
val videoItem = getItem(position) ?: return
kohii.setUp(videoItem.videoUrl) {
tag = "${videoItem.videoUrl}+${position}"
}.bind(holder.playerView)
}
}

0 comments on commit de8e41e

Please sign in to comment.