Commit dcc24a08 by 刘鹏

Merge branch 'd/lancet/4.3.93_muse' into 'd/4.3.93_muse'

fix  18162

See merge request app_android_lib/YDL-Component!56
parents 5ee5bcec 63dbb89e
...@@ -886,12 +886,16 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -886,12 +886,16 @@ class PlayMeditationActivity : BaseActivity() {
mDisposable?.dispose() mDisposable?.dispose()
initRxTimeOff((minute * 60 * 1000).toLong(), 1) initRxTimeOff((minute * 60 * 1000).toLong(), 1)
} }
val event = MeditationFloatEvent(false,(minute * 60 * 1000).toLong())
EventBus.getDefault().post(event)
} else { } else {
initPlayCompletionListener() initPlayCompletionListener()
mDisposable?.dispose() mDisposable?.dispose()
tv_time_off.visibility = View.GONE tv_time_off.visibility = View.GONE
tv_time_off_pure_music.visibility = View.GONE tv_time_off_pure_music.visibility = View.GONE
mMediaPlayer?.isLooping = false mMediaPlayer?.isLooping = false
val event = MeditationFloatEvent(false,0)
EventBus.getDefault().post(event)
} }
} }
} }
......
...@@ -4,5 +4,6 @@ import com.yidianling.muse.bean.MeditationPlayModuleBean ...@@ -4,5 +4,6 @@ import com.yidianling.muse.bean.MeditationPlayModuleBean
class MeditationFloatEvent( class MeditationFloatEvent(
val show: Boolean, val show: Boolean,
val time:Long?=null,
val meditationDetail: MeditationPlayModuleBean.MeditationDetail?=null val meditationDetail: MeditationPlayModuleBean.MeditationDetail?=null
) )
\ No newline at end of file
...@@ -28,12 +28,20 @@ import com.yidianling.muse.activity.PlayMeditationActivity ...@@ -28,12 +28,20 @@ import com.yidianling.muse.activity.PlayMeditationActivity
import com.yidianling.muse.bean.MeditationPlayModuleBean import com.yidianling.muse.bean.MeditationPlayModuleBean
import com.yidianling.muse.constants.MuseBIConstants import com.yidianling.muse.constants.MuseBIConstants
import com.yidianling.muse.event.MeditationFloatEvent import com.yidianling.muse.event.MeditationFloatEvent
import com.yidianling.muse.helper.FloatViewTouchListener
import com.yidianling.muse.helper.MediaPlayerManager import com.yidianling.muse.helper.MediaPlayerManager
import com.yidianling.muse.utils.MediaPlayerTimeUtil
import de.greenrobot.event.EventBus import de.greenrobot.event.EventBus
import io.feeeei.circleseekbar.CircleSeekBar import io.feeeei.circleseekbar.CircleSeekBar
import io.reactivex.Observable
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_play_meditation.*
import kotlinx.android.synthetic.main.player_control_view.*
import java.util.* import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.math.roundToInt import kotlin.math.roundToInt
class MeditationWindowService : LifecycleService() { class MeditationWindowService : LifecycleService() {
...@@ -55,6 +63,10 @@ class MeditationWindowService : LifecycleService() { ...@@ -55,6 +63,10 @@ class MeditationWindowService : LifecycleService() {
private var windowIsShow = false private var windowIsShow = false
private var mDisposable: Disposable? = null
private var mObservable: Observable<Long>? = null
private var mObserver: Observer<Long>? = null
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
...@@ -87,7 +99,7 @@ class MeditationWindowService : LifecycleService() { ...@@ -87,7 +99,7 @@ class MeditationWindowService : LifecycleService() {
format = PixelFormat.RGBA_8888 format = PixelFormat.RGBA_8888
width = outMetrics.widthPixels - dp2px(32F) width = outMetrics.widthPixels - dp2px(32F)
height = WRAP_CONTENT height = WRAP_CONTENT
gravity = Gravity.CENTER_HORIZONTAL or Gravity.TOP gravity = Gravity.LEFT or Gravity.TOP
x = outMetrics.widthPixels /2 - width / 2 x = outMetrics.widthPixels /2 - width / 2
y = outMetrics.heightPixels - height * 2 y = outMetrics.heightPixels - height * 2
...@@ -99,21 +111,31 @@ class MeditationWindowService : LifecycleService() { ...@@ -99,21 +111,31 @@ class MeditationWindowService : LifecycleService() {
tvTitle = floatRootView?.findViewById(R.id.tv_title) tvTitle = floatRootView?.findViewById(R.id.tv_title)
ivProgress = floatRootView?.findViewById(R.id.progress_bar) ivProgress = floatRootView?.findViewById(R.id.progress_bar)
ivPlayOrPause = floatRootView?.findViewById(R.id.iv_play_status) ivPlayOrPause = floatRootView?.findViewById(R.id.iv_play_status)
// floatRootView?.setOnTouchListener(FloatViewTouchListener(layoutParams, mWindowManager)) floatRootView?.setOnTouchListener(FloatViewTouchListener(layoutParams, mWindowManager))
mWindowManager.addView(floatRootView, layoutParams) mWindowManager.addView(floatRootView, layoutParams)
windowIsShow = true windowIsShow = true
} }
fun onEventMainThread(event: MeditationFloatEvent) { fun onEventMainThread(event: MeditationFloatEvent) {
if (!event.show) { if (event.time!=null){
hideFloatWindow() if (event.time>0){
} initRxTimeOff(event.time)
if (event.show && event.meditationDetail != null) { }else{
if (!windowIsShow) { mDisposable?.dispose()
showWindow() }
}else{
if (!event.show) {
hideFloatWindow()
}
if (event.show && event.meditationDetail != null) {
if (!windowIsShow) {
showWindow()
}
updateFloatView(event.meditationDetail)
} }
updateFloatView(event.meditationDetail)
} }
} }
private fun updateFloatView(meditation: MeditationPlayModuleBean.MeditationDetail) { private fun updateFloatView(meditation: MeditationPlayModuleBean.MeditationDetail) {
...@@ -259,6 +281,46 @@ class MeditationWindowService : LifecycleService() { ...@@ -259,6 +281,46 @@ class MeditationWindowService : LifecycleService() {
return (dp * scale + 0.5f).toInt() return (dp * scale + 0.5f).toInt()
} }
private fun initRxTimeOff(time: Long) {
mObservable = Observable.interval(0, 1, TimeUnit.SECONDS)
.take(time / 1000 + 1)
.map { t -> time - t * 1000 }
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
mObserver = object : Observer<Long> {
override fun onSubscribe(d: Disposable) {
mDisposable = d
}
override fun onNext(t: Long) {
}
override fun onError(e: Throwable) {
}
override fun onComplete() {
if (mMediaPlayer?.isPlaying == true) {
mMediaPlayer?.stop()
ivPlayOrPause?.setImageResource(R.drawable.icon_meditation_float_pause)
}
hideFloatWindow()
}
}
if (mObserver != null && mObserver is Observer<Long>) {
mObservable?.subscribe(mObserver as Observer<Long>)
}
if (mDisposable?.isDisposed == true && mObserver != null && mObserver is Observer<Long>) {
mObservable?.subscribe(mObserver as Observer<Long>)
}
}
private fun postPlayRecord( private fun postPlayRecord(
isQuit: Int, isQuit: Int,
playTime: Int, playTime: Int,
......
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