Commit 123bc6a5 by 万齐军

feature: 视频播放

parent 53610264
...@@ -15,7 +15,7 @@ import com.ydl.confide.intro.BindingViewHolder ...@@ -15,7 +15,7 @@ import com.ydl.confide.intro.BindingViewHolder
class VideoShowAdapter(private val data: List<ConfideHomeBodyBean>?, private val event: IConfideHomeEvent) : class VideoShowAdapter(private val data: List<ConfideHomeBodyBean>?, private val event: IConfideHomeEvent) :
RecyclerView.Adapter<BindingViewHolder<ItemVideoShowBinding>>() { RecyclerView.Adapter<BindingViewHolder<ItemVideoShowBinding>>() {
private val dataList:List<ItemVideoShowViewModel> = data?.map { ItemVideoShowViewModel().mapOf(it) } ?: emptyList() private val dataList: List<ItemVideoShowViewModel> = data?.map { ItemVideoShowViewModel().mapOf(it) } ?: emptyList()
override fun onCreateViewHolder( override fun onCreateViewHolder(
parent: ViewGroup, parent: ViewGroup,
viewType: Int viewType: Int
...@@ -74,7 +74,7 @@ internal fun ItemVideoShowViewModel.mapOf(bean: ConfideHomeBodyBean): ItemVideoS ...@@ -74,7 +74,7 @@ internal fun ItemVideoShowViewModel.mapOf(bean: ConfideHomeBodyBean): ItemVideoS
name.set(bean.confidedName) name.set(bean.confidedName)
coverUrl.set(bean.coverPicture) coverUrl.set(bean.coverPicture)
videoCoverUrl.set(bean.coverVideoPicture) videoCoverUrl.set(bean.coverVideoPicture)
state.set(bean.confideLine?:0) state.set(bean.confideLine ?: 0)
linkUrl = bean.linkUrl linkUrl = bean.linkUrl
return this return this
} }
......
...@@ -67,11 +67,6 @@ class ExpertIntroActivity : AppCompatActivity() { ...@@ -67,11 +67,6 @@ class ExpertIntroActivity : AppCompatActivity() {
val h5Paramsqing = H5Params(YDL_H5 + "confideOrderList", null) val h5Paramsqing = H5Params(YDL_H5 + "confideOrderList", null)
NewH5Activity.start(this, h5Paramsqing) NewH5Activity.start(this, h5Paramsqing)
} }
data.add(VideoViewModel())
data.add(VideoViewModel())
data.add(VideoViewModel())
data.add(VideoViewModel())
data.add(VideoViewModel())
binding.viewPager.orientation = ViewPager2.ORIENTATION_VERTICAL binding.viewPager.orientation = ViewPager2.ORIENTATION_VERTICAL
binding.viewPager.offscreenPageLimit = 1 binding.viewPager.offscreenPageLimit = 1
adapter = IntroAdapter(this, data, this) adapter = IntroAdapter(this, data, this)
...@@ -89,11 +84,11 @@ class ExpertIntroActivity : AppCompatActivity() { ...@@ -89,11 +84,11 @@ class ExpertIntroActivity : AppCompatActivity() {
} }
private fun loadMore() { private fun loadMore() {
data.add(VideoViewModel()) // data.add(VideoViewModel())
data.add(VideoViewModel()) // data.add(VideoViewModel())
data.add(VideoViewModel()) // data.add(VideoViewModel())
data.add(VideoViewModel()) // data.add(VideoViewModel())
data.add(VideoViewModel()) // data.add(VideoViewModel())
adapter.notifyItemRangeInserted(data.size - 5, 5) // adapter.notifyItemRangeInserted(data.size - 5, 5)
} }
} }
\ No newline at end of file
...@@ -29,6 +29,8 @@ internal class ItemIntroHolder(binding: ItemExpertIntroBinding) : ...@@ -29,6 +29,8 @@ internal class ItemIntroHolder(binding: ItemExpertIntroBinding) :
private var disposable: Disposable? = null private var disposable: Disposable? = null
private var video: IjkVideoView? = null private var video: IjkVideoView? = null
@Volatile
private var isTouch = false
fun onDetach() { fun onDetach() {
stopTiming() stopTiming()
...@@ -66,9 +68,11 @@ internal class ItemIntroHolder(binding: ItemExpertIntroBinding) : ...@@ -66,9 +68,11 @@ internal class ItemIntroHolder(binding: ItemExpertIntroBinding) :
} }
override fun onStartTrackingTouch(seekBar: SeekBar?) { override fun onStartTrackingTouch(seekBar: SeekBar?) {
isTouch = true
} }
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
isTouch = false
if (seekBar != null) { if (seekBar != null) {
video?.seekTo(seekBar.progress) video?.seekTo(seekBar.progress)
video?.start() video?.start()
...@@ -102,6 +106,7 @@ internal class ItemIntroHolder(binding: ItemExpertIntroBinding) : ...@@ -102,6 +106,7 @@ internal class ItemIntroHolder(binding: ItemExpertIntroBinding) :
disposable = Observable.interval(300, TimeUnit.MILLISECONDS) disposable = Observable.interval(300, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.computation()) .subscribeOn(Schedulers.computation())
.filter { !isTouch }
.subscribe { .subscribe {
val pos = (video?.mMediaPlayer as IjkMediaPlayer?)?.currentPosition ?: 0 val pos = (video?.mMediaPlayer as IjkMediaPlayer?)?.currentPosition ?: 0
if (pos > 0) { if (pos > 0) {
...@@ -118,7 +123,7 @@ internal class ItemIntroHolder(binding: ItemExpertIntroBinding) : ...@@ -118,7 +123,7 @@ internal class ItemIntroHolder(binding: ItemExpertIntroBinding) :
class VideoViewModel { class VideoViewModel {
val name = ObservableField<String>("") val name = ObservableField<String>("")
val avatar = ObservableField<String>("") val avatar = ObservableField<String>("")
val count = ObservableInt() val count = ObservableField<String>("")
val lineStatus = ObservableInt() val lineStatus = ObservableInt()
val intro = ObservableField<String>("") val intro = ObservableField<String>("")
val tag = ObservableField<String>("") val tag = ObservableField<String>("")
...@@ -132,10 +137,10 @@ class VideoViewModel { ...@@ -132,10 +137,10 @@ class VideoViewModel {
internal fun VideoViewModel.mapOf(bean: ConfideHomeBodyBean): VideoViewModel { internal fun VideoViewModel.mapOf(bean: ConfideHomeBodyBean): VideoViewModel {
name.set(bean.confidedName) name.set(bean.confidedName)
avatar.set(bean.confidedIcon) avatar.set(bean.confidedIcon)
// count.set(bean.confideHearNum) count.set(bean.confideHearNum)
intro.set(bean.categoryContent) intro.set(bean.confideContent)
val sb = StringBuilder() val sb = StringBuilder()
bean.confidedTag?.forEach { sb.append(it).append("|") } bean.confidedTag?.forEach { sb.append(it).append(" | ") }
sb.setLength(sb.length - 1) sb.setLength(sb.length - 1)
tag.set(sb.toString()) tag.set(sb.toString())
if (bean.videoUrl != null) { if (bean.videoUrl != null) {
......
...@@ -2,10 +2,22 @@ ...@@ -2,10 +2,22 @@
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background"> <item android:id="@android:id/background">
<shape> <selector>
<corners android:radius="4dp" /> <item android:state_pressed="true">
<solid android:color="#59FFFFFF" /> <shape>
</shape> <corners android:radius="4dp" />
<solid android:color="#59FFFFFF" />
<stroke android:width="1dp" />
</shape>
</item>
<item>
<shape>
<corners android:radius="4dp" />
<solid android:color="#59FFFFFF" />
<stroke android:width="2dp" />
</shape>
</item>
</selector>
</item> </item>
<item android:id="@android:id/secondaryProgress"> <item android:id="@android:id/secondaryProgress">
...@@ -18,12 +30,26 @@ ...@@ -18,12 +30,26 @@
</item> </item>
<item android:id="@android:id/progress"> <item android:id="@android:id/progress">
<clip> <selector>
<shape> <item android:state_pressed="true">
<corners android:radius="4dp" /> <clip>
<solid android:color="@color/white" /> <shape>
</shape> <corners android:radius="4dp" />
</clip> <solid android:color="@color/white" />
<stroke android:width="1dp" />
</shape>
</clip>
</item>
<item>
<clip>
<shape>
<corners android:radius="4dp" />
<solid android:color="@color/white" />
<stroke android:width="2dp" />
</shape>
</clip>
</item>
</selector>
</item> </item>
</layer-list> </layer-list>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"> <item android:state_pressed="true">
<shape android:shape="oval"> <shape android:shape="rectangle">
<solid android:color="@color/white" /> <solid android:color="@color/white" />
<size android:width="6dp" android:height="6dp" /> <size android:width="6dp" android:height="8dp" />
<corners android:radius="2dp" />
</shape> </shape>
</item> </item>
<item> <item android:state_pressed="false">
<shape android:shape="oval"> <shape android:shape="oval">
<solid android:color="@color/white" /> <solid android:color="@color/white" />
<size android:width="6dp" android:height="6dp" /> <size android:width="8dp" android:height="8dp" />
<stroke android:width="2dp" android:color="@color/transparent" />
</shape> </shape>
</item> </item>
</selector> </selector>
\ No newline at end of file
...@@ -52,11 +52,9 @@ ...@@ -52,11 +52,9 @@
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="23dp" android:layout_marginBottom="23dp"
android:maxHeight="4dp" android:maxHeight="8dp"
android:paddingStart="0dp" android:paddingStart="0dp"
android:paddingTop="4dp"
android:paddingEnd="0dp" android:paddingEnd="0dp"
android:paddingBottom="4dp"
android:progressDrawable="@drawable/confide_seekbar_style" android:progressDrawable="@drawable/confide_seekbar_style"
android:splitTrack="false" android:splitTrack="false"
android:thumb="@drawable/confide_seekbar_thumb" android:thumb="@drawable/confide_seekbar_thumb"
...@@ -146,6 +144,7 @@ ...@@ -146,6 +144,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="@color/white" android:textColor="@color/white"
android:text="@{item.count}"
android:textSize="13sp" android:textSize="13sp"
app:layout_constraintBottom_toBottomOf="@+id/tvName" app:layout_constraintBottom_toBottomOf="@+id/tvName"
app:layout_constraintLeft_toRightOf="@+id/tvName" app:layout_constraintLeft_toRightOf="@+id/tvName"
...@@ -201,6 +200,7 @@ ...@@ -201,6 +200,7 @@
android:layout_height="46dp" android:layout_height="46dp"
android:layout_marginRight="10dp" android:layout_marginRight="10dp"
android:layout_marginBottom="20dp" android:layout_marginBottom="20dp"
app:circle="@{true}"
app:imageUrl="@{item.avatar}" app:imageUrl="@{item.avatar}"
app:layout_constraintBottom_toTopOf="@+id/btnChat" app:layout_constraintBottom_toTopOf="@+id/btnChat"
app:layout_constraintRight_toRightOf="parent" /> app:layout_constraintRight_toRightOf="parent" />
......
...@@ -7,10 +7,14 @@ import android.widget.ImageView ...@@ -7,10 +7,14 @@ import android.widget.ImageView
import androidx.databinding.BindingAdapter import androidx.databinding.BindingAdapter
import com.ydl.ydl_image.module.GlideApp import com.ydl.ydl_image.module.GlideApp
@BindingAdapter("imageUrl") @BindingAdapter("imageUrl", "circle", requireAll = false)
fun setImageUrl(imageView: ImageView, url: String?) { fun setImageUrl(imageView: ImageView, url: String?, circle: Boolean = false) {
if (url.isNullOrEmpty()) return if (url.isNullOrEmpty()) return
GlideApp.with(imageView).load(url).into(imageView) if (circle) {
GlideApp.with(imageView).load(url).circleCrop().into(imageView)
} else {
GlideApp.with(imageView).load(url).into(imageView)
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment