Commit 89f8a399 by 范玉宾

time off single loop playlist

parent 7f7c465b
...@@ -14,7 +14,7 @@ ext { ...@@ -14,7 +14,7 @@ ext {
"m-dynamic" : "0.0.7.73", "m-dynamic" : "0.0.7.73",
"m-article" : "0.0.0.10", "m-article" : "0.0.0.10",
"m-muse" : "0.0.28.37", "m-muse" : "0.0.28.38",
"m-tests" : "0.0.24.18", "m-tests" : "0.0.24.18",
"m-course" : "0.0.43.37", "m-course" : "0.0.43.37",
...@@ -99,7 +99,7 @@ ext { ...@@ -99,7 +99,7 @@ ext {
"m-dynamic" : "0.0.7.73", "m-dynamic" : "0.0.7.73",
"m-article" : "0.0.0.8", "m-article" : "0.0.0.8",
"m-muse" : "0.0.28.37", "m-muse" : "0.0.28.38",
"m-tests" : "0.0.24.18", "m-tests" : "0.0.24.18",
"m-course" : "0.0.43.37", "m-course" : "0.0.43.37",
//-------------- 业务模块 API 层 -------------- //-------------- 业务模块 API 层 --------------
......
...@@ -87,87 +87,58 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv ...@@ -87,87 +87,58 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv
} }
iv_video_background?.setOnClickListener {
// homeEvent?.museMoreClick(Gson().toJson(bean))
if (Utils.isFastClick()) {
//防止连击
return@setOnClickListener
}
if (!moreLink.isNullOrBlank()) {
NewH5Activity.start(context, H5Params(moreLink, null))
}
} val greeting = bean.mditationIndexInfo?.greetings ?: "你好"
val greeting = bean.mditationIndexInfo?.greetings?:"你好"
tv_time.text = greeting tv_time.text = greeting
val slogan = val slogan =
if (bean.mditationIndexInfo?.desc.isNullOrBlank()){ if (bean.mditationIndexInfo?.desc.isNullOrBlank()) {
"无常的日子里,呼吸间拾起力量" "无常的日子里,呼吸间拾起力量"
}else{ } else {
bean.mditationIndexInfo?.desc bean.mditationIndexInfo?.desc
} }
tv_meditation_slogan.text = slogan tv_meditation_slogan.text = slogan
val videoUrl = bean.mditationIndexInfo?.videoLink val videoUrl = bean.mditationIndexInfo?.videoLink
val videoThumbnailUrl = bean.mditationIndexInfo?.mditationIndexUrl
video_view?.setVideoPath(videoUrl)
if (videoUrl.isNullOrBlank()){ video_view?.setOnErrorListener { mp, what, extra ->
Glide.with(this) true
.load(videoThumbnailUrl) }
.transition(withCrossFade()) video_view?.setOnPreparedListener {
.into(iv_video_background) it?.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING)
}else{ video_view?.setOnInfoListener { mp, what, extra ->
GlideApp.with(this) if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START) {
.load(videoThumbnailUrl) video_view.setBackgroundColor(Color.TRANSPARENT)
.transition(withCrossFade())
.into(iv_video_background)
video_view?.setVideoPath(videoUrl)
video_view?.setOnErrorListener { mp, what, extra ->
Glide.with(this)
.load(bean.mditationIndexInfo?.mditationIndexUrl)
.transition(withCrossFade())
.into(iv_video_background)
true
}
video_view?.setOnPreparedListener {
it?.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING)
video_view?.setOnInfoListener { mp, what, extra ->
if (what == MediaPlayer.MEDIA_INFO_VIDEO_RENDERING_START){
iv_video_background.visibility = View.GONE
video_view.setBackgroundColor(Color.TRANSPARENT)
}
true
} }
it?.start() true
it?.setVolume(0.0F,0.0F)
} }
video_view?.setOnCompletionListener { video_view?.start() } it?.start()
it?.setVolume(0.0F, 0.0F)
} }
video_view?.setOnCompletionListener { video_view?.start() }
bean.mditationListResponse?.forEach { bean.mditationListResponse?.forEach {
meditationTitles.add(it.comment) meditationTitles.add(it.comment)
} }
view_pager.adapter = MeditationViewPagerAdapter(mContext,bean) view_pager.adapter = MeditationViewPagerAdapter(mContext, bean)
tab_layout.addOnTabSelectedListener(object :TabLayout.OnTabSelectedListener{ tab_layout.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab?) { override fun onTabSelected(tab: TabLayout.Tab?) {
var text:String? = tab?.text.toString().trim() var text: String? = tab?.text.toString().trim()
val spStr = SpannableString(text) val spStr = SpannableString(text)
val styleSpan = StyleSpan(Typeface.BOLD) val styleSpan = StyleSpan(Typeface.BOLD)
spStr.setSpan(styleSpan,0,text?.length?:0,Spanned.SPAN_INCLUSIVE_EXCLUSIVE) spStr.setSpan(styleSpan, 0, text?.length ?: 0, Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
tab?.text = spStr tab?.text = spStr
} }
override fun onTabUnselected(tab: TabLayout.Tab?) { override fun onTabUnselected(tab: TabLayout.Tab?) {
var text:String? = tab?.text.toString().trim() var text: String? = tab?.text.toString().trim()
val spStr = SpannableString(text) val spStr = SpannableString(text)
val styleSpan = StyleSpan(Typeface.NORMAL) val styleSpan = StyleSpan(Typeface.NORMAL)
spStr.setSpan(styleSpan,0,text?.length?:0,Spanned.SPAN_INCLUSIVE_EXCLUSIVE) spStr.setSpan(styleSpan, 0, text?.length ?: 0, Spanned.SPAN_INCLUSIVE_EXCLUSIVE)
tab?.text = spStr tab?.text = spStr
} }
...@@ -177,9 +148,8 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv ...@@ -177,9 +148,8 @@ class HomeMuseView(private val mContext: Context, private var homeEvent: IHomeEv
}) })
TabLayoutMediator(tab_layout,view_pager){ TabLayoutMediator(tab_layout, view_pager) { tab, position ->
tab, position -> tab.text = meditationTitles[position]
tab.text = meditationTitles[position]
}.attach() }.attach()
} }
......
...@@ -21,7 +21,8 @@ ...@@ -21,7 +21,8 @@
<FrameLayout <FrameLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:background="#999999">
<com.yidianling.home.widget.AdaptiveVideoView <com.yidianling.home.widget.AdaptiveVideoView
android:id="@+id/video_view" android:id="@+id/video_view"
...@@ -30,11 +31,11 @@ ...@@ -30,11 +31,11 @@
android:focusable="false" android:focusable="false"
android:focusableInTouchMode="false" /> android:focusableInTouchMode="false" />
<ImageView <!-- <ImageView-->
android:id="@+id/iv_video_background" <!-- android:id="@+id/iv_video_background"-->
android:layout_width="match_parent" <!-- android:layout_width="match_parent"-->
android:layout_height="match_parent" <!-- android:layout_height="match_parent"-->
android:scaleType="fitCenter"/> <!-- android:scaleType="fitCenter"/>-->
<androidx.constraintlayout.widget.ConstraintLayout <androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent" android:layout_width="match_parent"
......
...@@ -4,7 +4,6 @@ import android.content.Intent ...@@ -4,7 +4,6 @@ import android.content.Intent
import android.os.Bundle import android.os.Bundle
import com.blankj.utilcode.util.SPUtils import com.blankj.utilcode.util.SPUtils
import com.ydl.ydlcommon.base.BaseActivity import com.ydl.ydlcommon.base.BaseActivity
import com.ydl.ydlcommon.bean.StatusBarOptions
import com.ydl.ydlcommon.utils.StatusBarUtils import com.ydl.ydlcommon.utils.StatusBarUtils
import com.ydl.ydlcommon.utils.remind.ToastHelper import com.ydl.ydlcommon.utils.remind.ToastHelper
import com.yidianling.muse.R import com.yidianling.muse.R
...@@ -85,12 +84,8 @@ class MeditationTimeOffActivity : BaseActivity() { ...@@ -85,12 +84,8 @@ class MeditationTimeOffActivity : BaseActivity() {
} }
override fun getStatusViewOptions(): StatusBarOptions {
return StatusBarOptions(true, false)
}
override fun initDataAndEvent() { override fun initDataAndEvent() {
StatusBarUtils.setWindowStatusBarColor(this, R.color.platform_main_theme)
} }
override fun layoutResId(): Int { override fun layoutResId(): Int {
......
...@@ -12,10 +12,10 @@ import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions ...@@ -12,10 +12,10 @@ import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.ydl.webview.H5Params import com.ydl.webview.H5Params
import com.ydl.webview.NewH5Activity import com.ydl.webview.NewH5Activity
import com.ydl.ydlcommon.base.BaseActivity import com.ydl.ydlcommon.base.BaseActivity
import com.ydl.ydlcommon.bean.StatusBarOptions
import com.ydl.ydlcommon.data.http.ThrowableConsumer import com.ydl.ydlcommon.data.http.ThrowableConsumer
import com.ydl.ydlcommon.event.MeditationEvent import com.ydl.ydlcommon.event.MeditationEvent
import com.ydl.ydlcommon.modular.ModularServiceManager import com.ydl.ydlcommon.modular.ModularServiceManager
import com.ydl.ydlcommon.utils.StatusBarUtils
import com.ydl.ydlcommon.utils.StatusBarUtils.Companion.setTransparentForImageView import com.ydl.ydlcommon.utils.StatusBarUtils.Companion.setTransparentForImageView
import com.ydl.ydlcommon.utils.StatusBarUtils.Companion.statusBarLightMode import com.ydl.ydlcommon.utils.StatusBarUtils.Companion.statusBarLightMode
import com.ydl.ydlcommon.utils.Utils import com.ydl.ydlcommon.utils.Utils
...@@ -27,6 +27,7 @@ import com.yidianling.muse.bean.MeditationPlayModuleBean ...@@ -27,6 +27,7 @@ import com.yidianling.muse.bean.MeditationPlayModuleBean
import com.yidianling.muse.event.MeditationFloatEvent import com.yidianling.muse.event.MeditationFloatEvent
import com.yidianling.muse.helper.MediaPlayerManager import com.yidianling.muse.helper.MediaPlayerManager
import com.yidianling.muse.utils.MediaPlayerTimeUtil import com.yidianling.muse.utils.MediaPlayerTimeUtil
import com.yidianling.muse.utils.MeditationFloatPermissionUtil
import com.yidianling.muse.widget.QuitMeditationDialog import com.yidianling.muse.widget.QuitMeditationDialog
import com.yidianling.muse.widget.ShareMeditationDialog import com.yidianling.muse.widget.ShareMeditationDialog
import com.yidianling.user.api.service.IUserService import com.yidianling.user.api.service.IUserService
...@@ -62,6 +63,7 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -62,6 +63,7 @@ class PlayMeditationActivity : BaseActivity() {
private var meditations = mutableListOf<MeditationPlayModuleBean.MeditationDetail>() private var meditations = mutableListOf<MeditationPlayModuleBean.MeditationDetail>()
private var currentMeditation: MeditationPlayModuleBean.MeditationDetail? = null private var currentMeditation: MeditationPlayModuleBean.MeditationDetail? = null
private var currentMeditationIndex = 0
private var shareTitle = "" private var shareTitle = ""
private var shareUrl = "" private var shareUrl = ""
...@@ -85,6 +87,9 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -85,6 +87,9 @@ class PlayMeditationActivity : BaseActivity() {
private var mObservable: Observable<Long>? = null private var mObservable: Observable<Long>? = null
private var mObserver: Observer<Long>? = null private var mObserver: Observer<Long>? = null
private var status = 0
private var buried:String? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
setTransparentForImageView(this, null) setTransparentForImageView(this, null)
statusBarLightMode(this) statusBarLightMode(this)
...@@ -105,7 +110,7 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -105,7 +110,7 @@ class PlayMeditationActivity : BaseActivity() {
} }
override fun initDataAndEvent() { override fun initDataAndEvent() {
StatusBarUtils.setWindowStatusBarColor(this, R.color.platform_main_theme)
} }
private fun getData() { private fun getData() {
...@@ -113,7 +118,6 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -113,7 +118,6 @@ class PlayMeditationActivity : BaseActivity() {
if (meditationType == null || (mediaId == null && meditationType != 0)) { if (meditationType == null || (mediaId == null && meditationType != 0)) {
return return
} }
// 声音详情 // 声音详情
if (meditationType == 0) { if (meditationType == 0) {
MuseHttp.getInstance().getPureMusicPlayDetail( MuseHttp.getInstance().getPureMusicPlayDetail(
...@@ -142,7 +146,9 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -142,7 +146,9 @@ class PlayMeditationActivity : BaseActivity() {
businessType = meditationPlayBean.businessType businessType = meditationPlayBean.businessType
val status = meditationPlayBean.status status = meditationPlayBean.status
buried = meditationPlayBean.buried
collected = status == 1 collected = status == 1
...@@ -212,7 +218,9 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -212,7 +218,9 @@ class PlayMeditationActivity : BaseActivity() {
businessType = meditationPlayBean.businessType businessType = meditationPlayBean.businessType
val status = meditationPlayBean.status status = meditationPlayBean.status
buried = meditationPlayBean.buried
collected = status == 1 collected = status == 1
...@@ -329,10 +337,6 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -329,10 +337,6 @@ class PlayMeditationActivity : BaseActivity() {
return R.layout.activity_play_meditation return R.layout.activity_play_meditation
} }
override fun getStatusViewOptions(): StatusBarOptions {
return StatusBarOptions(true, false)
}
private fun initView() { private fun initView() {
shareImageUrl = mediaCoverUrl shareImageUrl = mediaCoverUrl
...@@ -378,10 +382,6 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -378,10 +382,6 @@ class PlayMeditationActivity : BaseActivity() {
} }
iv_back.setOnClickListener { iv_back.setOnClickListener {
// MeditationViewModel.isVisible.postValue(true)
// MeditationViewModel.meditation.postValue(currentMeditation)
// MeditationViewModel.meditations.postValue(meditations as ArrayList<MeditationPlayModuleBean.MeditationDetail>)
// LogUtil.d("Lancet=======","post $currentMeditation")
val event = MeditationFloatEvent(true,meditationDetail = currentMeditation) val event = MeditationFloatEvent(true,meditationDetail = currentMeditation)
EventBus.getDefault().post(event) EventBus.getDefault().post(event)
...@@ -583,10 +583,46 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -583,10 +583,46 @@ class PlayMeditationActivity : BaseActivity() {
}) })
initPlayCompletionListener()
}
private fun initPlayCompletionListener(isLoop:Boolean = false,isSingle:Boolean = false){
mMediaPlayer?.setOnCompletionListener { mMediaPlayer?.setOnCompletionListener {
postPlayRecord(isQuit = 0, postPlayRecord(isQuit = 0,
playTime = (seekbar_play_progress.progress / 1000.00).roundToInt(), playTime = (seekbar_play_progress.progress / 1000.00).roundToInt(),
isComplete = 1) isComplete = 1)
if (isLoop){
if (isSingle || meditations.size == 1){
MediaPlayerManager.getInstance(this)?.setAudioPath(currentMeditation?.mediaUrl?:"")
}else{
currentMeditationIndex = meditations.indexOf(currentMeditation)
if(currentMeditationIndex == meditations.size - 1){
currentMeditationIndex = 0
}else{
currentMeditationIndex++
}
currentMeditation = meditations[currentMeditationIndex]
val event = MeditationEvent(
currentMeditation?.mediaId?.toInt()?:0,
meditationId?:0L,
meditationType?:0,
businessType,
status = status,
buried = buried?:"",
mediaUrl = currentMeditation?.mediaUrl?:"",
mediaCoverUrl = currentMeditation?.coverImageUrl?:"",
title = currentMeditation?.title?:"",
desc = currentMeditation?.desc?:""
)
EventBus.getDefault().post(event)
}
}
isPlaying = if (it.isPlaying) { isPlaying = if (it.isPlaying) {
exo_play.setImageResource(R.drawable.icon_pause_play) exo_play.setImageResource(R.drawable.icon_pause_play)
true true
...@@ -598,7 +634,6 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -598,7 +634,6 @@ class PlayMeditationActivity : BaseActivity() {
mMediaPlayer?.pause() mMediaPlayer?.pause()
} }
} }
} }
private fun postPlayRecord(isQuit: Int, playTime: Int, isComplete: Int) { private fun postPlayRecord(isQuit: Int, playTime: Int, isComplete: Int) {
...@@ -704,22 +739,24 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -704,22 +739,24 @@ class PlayMeditationActivity : BaseActivity() {
val minute = data?.extras?.getInt("TIME_OFF_MINUTE", 0) val minute = data?.extras?.getInt("TIME_OFF_MINUTE", 0)
if (minute != null && minute > 0) { if (minute != null && minute > 0) {
if (meditationType == 0) { if (meditationType == 0) {
initPlayCompletionListener(isLoop = true,isSingle = true)
tv_time_off_pure_music.visibility = View.VISIBLE tv_time_off_pure_music.visibility = View.VISIBLE
tv_time_off.visibility = View.GONE tv_time_off.visibility = View.GONE
mDisposable?.dispose() mDisposable?.dispose()
initRxTimeOff((minute * 60 * 1000).toLong(), 0) initRxTimeOff((minute * 60 * 1000).toLong(), 0)
} else { } else {
initPlayCompletionListener(isLoop = true,isSingle = false)
tv_time_off_pure_music.visibility = View.GONE tv_time_off_pure_music.visibility = View.GONE
tv_time_off.visibility = View.VISIBLE tv_time_off.visibility = View.VISIBLE
mDisposable?.dispose() mDisposable?.dispose()
initRxTimeOff((minute * 60 * 1000).toLong(), 1) initRxTimeOff((minute * 60 * 1000).toLong(), 1)
} }
} else { } else {
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
} }
} }
} }
...@@ -798,19 +835,21 @@ class PlayMeditationActivity : BaseActivity() { ...@@ -798,19 +835,21 @@ class PlayMeditationActivity : BaseActivity() {
if (event.mediaUrl == MediaPlayerManager.getInstance(this)?.getAudioPath()) { if (event.mediaUrl == MediaPlayerManager.getInstance(this)?.getAudioPath()) {
return return
} }
initMediaPlayer(event.mediaUrl, 0) initMediaPlayer(event.mediaUrl, 0)
} }
} }
override fun onBackPressed() {
val event = MeditationFloatEvent(true,meditationDetail = currentMeditation)
EventBus.getDefault().post(event)
super.onBackPressed()
}
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
if (EventBus.getDefault().isRegistered(this)) { if (EventBus.getDefault().isRegistered(this)) {
EventBus.getDefault().unregister(this) EventBus.getDefault().unregister(this)
} }
mDisposable?.dispose() mDisposable?.dispose()
mTimer.cancel() mTimer.cancel()
} }
......
...@@ -27,7 +27,6 @@ class MediaPlayerManager private constructor() { ...@@ -27,7 +27,6 @@ class MediaPlayerManager private constructor() {
mMediaPlayer?.reset() mMediaPlayer?.reset()
mMediaPlayer?.setAudioAttributes(attrs) mMediaPlayer?.setAudioAttributes(attrs)
mMediaPlayer?.setDataSource(path) mMediaPlayer?.setDataSource(path)
mMediaPlayer?.isLooping = isLoop
mMediaPlayer?.prepareAsync() mMediaPlayer?.prepareAsync()
mMediaPlayer?.setOnPreparedListener { mMediaPlayer?.setOnPreparedListener {
listener?.onPrepared(it) listener?.onPrepared(it)
......
...@@ -18,7 +18,6 @@ import android.view.WindowManager ...@@ -18,7 +18,6 @@ import android.view.WindowManager
import android.widget.ImageView import android.widget.ImageView
import android.widget.TextView import android.widget.TextView
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.content.getSystemService
import androidx.lifecycle.LifecycleService import androidx.lifecycle.LifecycleService
import com.bumptech.glide.Glide import com.bumptech.glide.Glide
import com.ydl.ydlcommon.data.http.ThrowableConsumer import com.ydl.ydlcommon.data.http.ThrowableConsumer
...@@ -27,7 +26,6 @@ import com.yidianling.muse.R ...@@ -27,7 +26,6 @@ import com.yidianling.muse.R
import com.yidianling.muse.activity.PlayMeditationActivity import com.yidianling.muse.activity.PlayMeditationActivity
import com.yidianling.muse.bean.MeditationPlayModuleBean import com.yidianling.muse.bean.MeditationPlayModuleBean
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 de.greenrobot.event.EventBus import de.greenrobot.event.EventBus
import io.feeeei.circleseekbar.CircleSeekBar import io.feeeei.circleseekbar.CircleSeekBar
...@@ -84,30 +82,23 @@ class MeditationWindowService : LifecycleService() { ...@@ -84,30 +82,23 @@ class MeditationWindowService : LifecycleService() {
} }
flags = flags =
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL or WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
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.CENTER_HORIZONTAL or Gravity.BOTTOM x = outMetrics.widthPixels /2 - width / 2
y = outMetrics.heightPixels - height * 2
} }
floatRootView = floatRootView =
LayoutInflater.from(this).inflate(R.layout.layout_meditation_play_float_view, null) LayoutInflater.from(this).inflate(R.layout.layout_meditation_play_float_view, null)
ivClose = floatRootView?.findViewById(R.id.iv_close) ivClose = floatRootView?.findViewById(R.id.iv_close)
ivCover = floatRootView?.findViewById(R.id.iv_cover) ivCover = floatRootView?.findViewById(R.id.iv_cover)
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
} }
...@@ -124,9 +115,7 @@ class MeditationWindowService : LifecycleService() { ...@@ -124,9 +115,7 @@ class MeditationWindowService : LifecycleService() {
} }
private fun updateFloatView(meditation: MeditationPlayModuleBean.MeditationDetail) { private fun updateFloatView(meditation: MeditationPlayModuleBean.MeditationDetail) {
mMediaPlayer = MediaPlayerManager.getInstance(this)?.getMediaPlayer() mMediaPlayer = MediaPlayerManager.getInstance(this)?.getMediaPlayer()
floatRootView?.setOnClickListener { floatRootView?.setOnClickListener {
val intent = Intent(this, PlayMeditationActivity::class.java) val intent = Intent(this, PlayMeditationActivity::class.java)
intent.putExtra("MEDIA_ID", meditation.mediaId) intent.putExtra("MEDIA_ID", meditation.mediaId)
...@@ -138,7 +127,6 @@ class MeditationWindowService : LifecycleService() { ...@@ -138,7 +127,6 @@ class MeditationWindowService : LifecycleService() {
} }
if (mMediaPlayer?.isPlaying == true) { if (mMediaPlayer?.isPlaying == true) {
ivPlayOrPause?.setImageResource(R.drawable.icon_meditation_float_play) ivPlayOrPause?.setImageResource(R.drawable.icon_meditation_float_play)
} else { } else {
ivPlayOrPause?.setImageResource(R.drawable.icon_meditation_float_pause) ivPlayOrPause?.setImageResource(R.drawable.icon_meditation_float_pause)
...@@ -198,6 +186,11 @@ class MeditationWindowService : LifecycleService() { ...@@ -198,6 +186,11 @@ class MeditationWindowService : LifecycleService() {
meditation.meditationId.toInt(), meditation.meditationId.toInt(),
meditation.mediaId ?: 0L meditation.mediaId ?: 0L
) )
if (mMediaPlayer?.isPlaying == true) {
ivPlayOrPause?.setImageResource(R.drawable.icon_meditation_float_play)
} else {
ivPlayOrPause?.setImageResource(R.drawable.icon_meditation_float_pause)
}
} }
ivClose?.setOnClickListener { ivClose?.setOnClickListener {
......
package com.yidianling.muse.utils
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.provider.Settings
object MeditationFloatPermissionUtil {
const val REQUEST_FLOAT_CODE=1001
private fun commonROMPermissionCheck(context: Context?):Boolean {
var result = true
if (Build.VERSION.SDK_INT >= 23){
try {
val clazz:Class<*> = Settings::class.java
val canDrawOverlays = clazz.getDeclaredMethod("canDrawOverlays",Context::class.java)
result = canDrawOverlays.invoke(null, context) as Boolean
}catch (e:Exception){
}
}
return result
}
fun checkSuspendedWindowPermission(context: Activity,block:() -> Unit){
if(commonROMPermissionCheck(context)){
block
}else{
context.startActivityForResult(Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION).apply {
data = Uri.parse("package:${context.packageName}")
}, REQUEST_FLOAT_CODE)
}
}
}
\ No newline at end of file
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