Use the module library/core-utils in attachment-viewer library
No more usage of Rx
This commit is contained in:
parent
b8aaa177c2
commit
1e8f438122
|
@ -47,6 +47,7 @@ android {
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation project(":library:ui-styles")
|
implementation project(":library:ui-styles")
|
||||||
|
implementation project(":library:core-utils")
|
||||||
|
|
||||||
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
|
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,9 @@ import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import im.vector.lib.attachmentviewer.databinding.ItemVideoAttachmentBinding
|
import im.vector.lib.attachmentviewer.databinding.ItemVideoAttachmentBinding
|
||||||
import io.reactivex.Observable
|
import im.vector.lib.core.utils.timer.CountUpTimer
|
||||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
|
||||||
import io.reactivex.disposables.Disposable
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
|
|
||||||
// TODO, it would be probably better to use a unique media player
|
// TODO, it would be probably better to use a unique media player
|
||||||
// for better customization and control
|
// for better customization and control
|
||||||
|
@ -35,7 +32,7 @@ class VideoViewHolder constructor(itemView: View) :
|
||||||
|
|
||||||
private var isSelected = false
|
private var isSelected = false
|
||||||
private var mVideoPath: String? = null
|
private var mVideoPath: String? = null
|
||||||
private var progressDisposable: Disposable? = null
|
private var countUpTimer: CountUpTimer? = null
|
||||||
private var progress: Int = 0
|
private var progress: Int = 0
|
||||||
private var wasPaused = false
|
private var wasPaused = false
|
||||||
|
|
||||||
|
@ -47,8 +44,7 @@ class VideoViewHolder constructor(itemView: View) :
|
||||||
|
|
||||||
override fun onRecycled() {
|
override fun onRecycled() {
|
||||||
super.onRecycled()
|
super.onRecycled()
|
||||||
progressDisposable?.dispose()
|
stopTimer()
|
||||||
progressDisposable = null
|
|
||||||
mVideoPath = null
|
mVideoPath = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,8 +68,7 @@ class VideoViewHolder constructor(itemView: View) :
|
||||||
override fun entersBackground() {
|
override fun entersBackground() {
|
||||||
if (views.videoView.isPlaying) {
|
if (views.videoView.isPlaying) {
|
||||||
progress = views.videoView.currentPosition
|
progress = views.videoView.currentPosition
|
||||||
progressDisposable?.dispose()
|
stopTimer()
|
||||||
progressDisposable = null
|
|
||||||
views.videoView.stopPlayback()
|
views.videoView.stopPlayback()
|
||||||
views.videoView.pause()
|
views.videoView.pause()
|
||||||
}
|
}
|
||||||
|
@ -91,8 +86,7 @@ class VideoViewHolder constructor(itemView: View) :
|
||||||
} else {
|
} else {
|
||||||
progress = 0
|
progress = 0
|
||||||
}
|
}
|
||||||
progressDisposable?.dispose()
|
stopTimer()
|
||||||
progressDisposable = null
|
|
||||||
} else {
|
} else {
|
||||||
if (mVideoPath != null) {
|
if (mVideoPath != null) {
|
||||||
startPlaying()
|
startPlaying()
|
||||||
|
@ -107,11 +101,10 @@ class VideoViewHolder constructor(itemView: View) :
|
||||||
views.videoView.isVisible = true
|
views.videoView.isVisible = true
|
||||||
|
|
||||||
views.videoView.setOnPreparedListener {
|
views.videoView.setOnPreparedListener {
|
||||||
progressDisposable?.dispose()
|
stopTimer()
|
||||||
progressDisposable = Observable.interval(100, TimeUnit.MILLISECONDS)
|
countUpTimer = CountUpTimer(100).also {
|
||||||
.timeInterval()
|
it.tickListener = object : CountUpTimer.TickListener {
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
override fun onTick(milliseconds: Long) {
|
||||||
.subscribe {
|
|
||||||
val duration = views.videoView.duration
|
val duration = views.videoView.duration
|
||||||
val progress = views.videoView.currentPosition
|
val progress = views.videoView.currentPosition
|
||||||
val isPlaying = views.videoView.isPlaying
|
val isPlaying = views.videoView.isPlaying
|
||||||
|
@ -119,6 +112,9 @@ class VideoViewHolder constructor(itemView: View) :
|
||||||
eventListener?.get()?.onEvent(AttachmentEvents.VideoEvent(isPlaying, progress, duration))
|
eventListener?.get()?.onEvent(AttachmentEvents.VideoEvent(isPlaying, progress, duration))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
it.resume()
|
||||||
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
views.videoView.setVideoPath(mVideoPath)
|
views.videoView.setVideoPath(mVideoPath)
|
||||||
} catch (failure: Throwable) {
|
} catch (failure: Throwable) {
|
||||||
|
@ -134,6 +130,11 @@ class VideoViewHolder constructor(itemView: View) :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun stopTimer() {
|
||||||
|
countUpTimer?.stop()
|
||||||
|
countUpTimer = null
|
||||||
|
}
|
||||||
|
|
||||||
override fun handleCommand(commands: AttachmentCommands) {
|
override fun handleCommand(commands: AttachmentCommands) {
|
||||||
if (!isSelected) return
|
if (!isSelected) return
|
||||||
when (commands) {
|
when (commands) {
|
||||||
|
|
Loading…
Reference in New Issue