Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
YDL-Component-Medical
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨凯
YDL-Component-Medical
Commits
d79b500f
Commit
d79b500f
authored
Aug 02, 2022
by
王佳洋
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1,音频页面mvp分离
parent
8f1f52f0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
270 additions
and
186 deletions
+270
-186
AudioPlayActivity.kt
m-course/src/main/java/com/yidianling/course/coursePlay/AudioPlayActivity.kt
+48
-175
AudioPlayPresenter.kt
m-course/src/main/java/com/yidianling/course/coursePlay/presenter/AudioPlayPresenter.kt
+178
-9
IAudioPlayContract.kt
m-course/src/main/java/com/yidianling/course/coursePlay/presenter/IAudioPlayContract.kt
+44
-2
No files found.
m-course/src/main/java/com/yidianling/course/coursePlay/AudioPlayActivity.kt
View file @
d79b500f
...
...
@@ -12,9 +12,7 @@ import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import
com.bumptech.glide.request.RequestOptions
import
com.bumptech.glide.request.target.ViewTarget
import
com.bumptech.glide.request.transition.Transition
import
com.ydl.media.audio.AudioPlayer
import
com.ydl.media.audio.model.Music
import
com.ydl.media.view.PlayTypeEnum
import
com.ydl.media.view.PlayerFloatHelper
import
com.ydl.webview.H5Params
import
com.ydl.webview.NewH5Activity
...
...
@@ -23,8 +21,7 @@ import com.ydl.ydlcommon.base.BaseMvpActivity
import
com.ydl.ydlcommon.bean.ShareData
import
com.ydl.ydlcommon.data.PlatformDataManager
import
com.ydl.ydlcommon.modular.ModularServiceManager
import
com.ydl.ydlcommon.router.IYDLRouterConstant
import
com.ydl.ydlcommon.router.YdlCommonRouterManager
import
com.ydl.ydlcommon.router.YdlUserInfo
import
com.ydl.ydlcommon.utils.statusBar.StatusBarUtil
import
com.ydl.ydlcommon.view.dialog.CommonDialog
import
com.ydl.ydlcommon.view.dialog.YDLShareDialog
...
...
@@ -33,10 +30,8 @@ import com.yidianling.common.tools.ToastUtil
import
com.yidianling.course.BuildConfig
import
com.yidianling.course.CourseConstants
import
com.yidianling.course.R
import
com.yidianling.course.bean.COURSE_AUDIO
import
com.yidianling.course.bean.CourseExtraBean
import
com.yidianling.course.bean.CourseMediaBean
import
com.yidianling.course.bean.CourseMediaDetailBean
import
com.yidianling.course.coursePlay.presenter.AudioPlayPresenter
import
com.yidianling.course.coursePlay.presenter.IAudioPlayContract
import
com.yidianling.course.router.CourseIn
...
...
@@ -46,8 +41,6 @@ import com.yidianling.course.widget.CourseSpeedDialog
import
com.yidianling.ydl_pay.common.CommonPayDialog
import
jp.wasabeef.glide.transformations.BlurTransformation
import
kotlinx.android.synthetic.main.activity_audio_play.*
import
org.json.JSONException
import
org.json.JSONObject
import
java.util.*
...
...
@@ -58,16 +51,8 @@ import java.util.*
class
AudioPlayActivity
:
BaseMvpActivity
<
IAudioPlayContract
.
View
,
IAudioPlayContract
.
Presenter
>(),
IAudioPlayContract
.
View
{
private
val
ROUTER_PARAMS
=
"routerParam"
private
var
mCourseId
=
0
// 课程id
private
var
mReceiverPlayUrl
:
String
?
=
null
// 外部选中要播放的音/视频文件地址
private
var
mIsFromFloatView
=
false
// 是否是悬浮窗进入
private
var
mFrom
:
Int
=
0
private
var
mCourPlayBean
:
CourseMediaDetailBean
?
=
null
private
val
mPlayList
:
ArrayList
<
CourseMediaBean
>
=
ArrayList
()
// 播放列表
private
var
mCourseSpeedDialog
:
CourseSpeedDialog
?
=
null
private
var
mCourseListDialog
:
CourseListDialog
?
=
null
private
var
mCurrentPosition
=
0
override
fun
turnOnImmersiveStatusBar
():
Boolean
=
true
...
...
@@ -78,57 +63,16 @@ class AudioPlayActivity : BaseMvpActivity<IAudioPlayContract.View, IAudioPlayCon
override
fun
onNewIntent
(
intent
:
Intent
?)
{
super
.
onNewIntent
(
intent
)
intent
?.
let
{
val
courseId
=
it
.
getIntExtra
(
"course_id"
,
0
)
if
(
0
==
courseId
)
{
ToastUtil
.
toastShort
(
"参数错误"
)
finish
()
}
else
if
(
courseId
!=
mCourseId
)
{
mCourseId
=
courseId
mPresenter
.
getCoursePlayData
(
mCourseId
)
}
mPresenter
.
getNewIntent
(
it
)
}
}
override
fun
initDataAndEvent
()
{
getParams
()
initView
()
mPresenter
.
getCoursePlayData
(
mCourseId
)
}
private
fun
getParams
()
{
intent
?.
let
{
if
(
it
.
hasExtra
(
ROUTER_PARAMS
))
{
//路由传递的入参
val
json
=
it
.
getStringExtra
(
ROUTER_PARAMS
)
try
{
val
jsonObject
=
JSONObject
(
json
)
//课程ID
mCourseId
=
jsonObject
.
getInt
(
IYDLRouterConstant
.
EXTRA_ID
)
}
catch
(
e
:
JSONException
)
{
e
.
printStackTrace
()
}
return
}
//正常跳转所传参数
mCourseId
=
it
.
getIntExtra
(
"course_id"
,
0
)
mReceiverPlayUrl
=
it
.
getStringExtra
(
"coursePlayUrl"
)
mIsFromFloatView
=
it
.
getBooleanExtra
(
"isFromFloatView"
,
false
)
if
(!
TextUtils
.
isEmpty
(
mReceiverPlayUrl
)
&&
mIsFromFloatView
)
audio_play
.
mNonWifiTips
=
false
try
{
if
(
PlayerFloatHelper
.
playingType
==
PlayTypeEnum
.
PLAY_TYPE_COURSE
&&
audio_play
.
isPlaying
()
&&
TextUtils
.
isEmpty
(
mReceiverPlayUrl
)
)
{
mReceiverPlayUrl
=
audio_play
.
getAudioMusic
()
?.
path
}
}
catch
(
e
:
Exception
)
{
}
mFrom
=
it
.
getIntExtra
(
"from"
,
0
)
if
(
mCourseId
==
0
)
{
ToastUtil
.
toastShort
(
"参数错误"
)
finish
()
initView
()
mPresenter
.
run
{
getParams
(
it
)
getCoursePlayData
()
}
}
}
...
...
@@ -141,33 +85,26 @@ class AudioPlayActivity : BaseMvpActivity<IAudioPlayContract.View, IAudioPlayCon
}
}
iv_share
.
setOnClickListener
{
share
(
mCourPlayBean
?.
courseExtra
?.
shareData
)
mPresenter
.
share
(
)
}
audio_play
.
mListener
=
{
playPosition
->
togglePlaying
(
playPosition
)
mPresenter
.
togglePlaying
(
playPosition
)
}
}
//参加课程
private
fun
addCourseOrder
()
{
if
(
mCourseId
==
0
)
{
ToastUtil
.
toastShort
(
"请退出页面重试"
)
return
}
val
userInfo
=
YdlCommonRouterManager
.
getYdlCommonRoute
().
getUserInfo
()
if
(
userInfo
==
null
||
TextUtils
.
isEmpty
(
userInfo
.
userId
))
{
CourseIn
.
loginByOneKeyLogin
(
mContext
,
true
)
return
}
override
fun
loginByOneKeyLogin
()
{
CourseIn
.
loginByOneKeyLogin
(
mContext
,
true
)
}
override
fun
commonPayDialog
(
userInfo
:
YdlUserInfo
,
courseId
:
String
)
{
CommonPayDialog
.
Build
(
mContext
)
.
setCourseId
(
mCourseId
.
toString
()
)
.
setCourseId
(
courseId
)
.
setToken
(
userInfo
.
token
)
.
setUid
(
userInfo
.
userId
)
.
setFfrom
(
PlatformDataManager
.
getRam
().
getChannelName
())
.
setListener
(
object
:
CommonPayDialog
.
OnPayResultListener
{
override
fun
onSuccesed
()
{
mPresenter
.
getCoursePlayData
(
mCourseId
)
mPresenter
.
getCoursePlayData
()
}
override
fun
onFailed
()
{
...
...
@@ -177,62 +114,27 @@ class AudioPlayActivity : BaseMvpActivity<IAudioPlayContract.View, IAudioPlayCon
.
setIsTestEnvironment
(
BuildConfig
.
DEBUG
).
build
().
show
()
}
private
fun
togglePlaying
(
playPosition
:
Int
)
{
if
(
playPosition
>=
mPlayList
.
size
||
playPosition
<
0
)
{
ToastUtil
.
toastShort
(
"暂无内容"
)
}
else
if
(
mCurrentPosition
!=
playPosition
)
{
mCurrentPosition
=
playPosition
mCourPlayBean
?.
courseExtra
?.
let
{
if
(
isCanPlay
(
it
.
isBuy
))
audio_play
.
play
(
mCurrentPosition
)
}
}
}
private
fun
isCanPlay
(
isBuy
:
Boolean
):
Boolean
{
mPlayList
.
elementAtOrNull
(
mCurrentPosition
)
?.
let
{
if
(!
it
.
isDemo
&&
!
isBuy
)
{
if
(
audio_play
.
isPlaying
())
audio_play
.
pausePlay
()
buyCourseTipDialog
()
}
else
if
(
it
.
mediaType
==
COURSE_AUDIO
)
{
return
true
}
}
return
false
override
fun
play
(
playPosition
:
Int
)
{
audio_play
.
play
(
playPosition
)
}
privat
e
fun
buyCourseTipDialog
()
{
overrid
e
fun
buyCourseTipDialog
()
{
CommonDialog
(
this
)
.
setMessage
(
"\n购买课程,获取完整课程内容\n"
)
.
setLeftOnclick
(
"放弃"
)
{}
.
setRightClick
(
"购买"
)
{
addCourseOrder
()
// 跳转支付页
mPresenter
.
addCourseOrder
()
// 跳转支付页
}
.
setCancelAble
(
false
)
.
show
()
}
override
fun
onBackPressed
()
{
if
(
showFloatView
())
{
super
.
onBackPressed
()
}
}
private
fun
showFloatView
():
Boolean
{
if
(
audio_play
.
isPlaying
()
&&
PlayerFloatHelper
.
playingType
==
PlayTypeEnum
.
PLAY_TYPE_COURSE
)
{
audio_play
.
getAudioMusic
()
?.
coverPath
=
mCourPlayBean
?.
courseExtra
?.
pic
audio_play
.
getAudioMusic
()
?.
artist
=
mCourPlayBean
?.
courseExtra
?.
doctorName
PlayerFloatHelper
.
playTempData
.
clear
()
val
hashMap
=
HashMap
<
String
,
String
>()
hashMap
[
"course_id"
]
=
mCourseId
.
toString
()
hashMap
[
"media_type"
]
=
COURSE_AUDIO
.
toString
()
PlayerFloatHelper
.
playTempData
.
putAll
(
hashMap
)
}
return
true
mPresenter
.
showFloatView
()
super
.
onBackPressed
()
}
private
fun
share
(
share
:
ShareData
?)
{
override
fun
shareDialog
(
share
:
ShareData
?)
{
share
?.
let
{
YDLShareDialog
.
style1
(
this
,
...
...
@@ -269,21 +171,8 @@ class AudioPlayActivity : BaseMvpActivity<IAudioPlayContract.View, IAudioPlayCon
}
}
override
fun
updateView
(
bean
:
CourseMediaDetailBean
)
{
mCourPlayBean
=
bean
mPlayList
.
clear
()
setPlayList
(
bean
)
if
(!
TextUtils
.
isEmpty
(
mReceiverPlayUrl
))
{
mCurrentPosition
=
mPlayList
.
indexOfLast
{
TextUtils
.
equals
(
mReceiverPlayUrl
,
it
.
url
)
||
TextUtils
.
equals
(
mReceiverPlayUrl
!!
.
replace
(
"http"
,
"https"
),
it
.
url
)
}
}
bean
.
courseExtra
.
let
{
override
fun
updateView
(
bean
:
CourseExtraBean
,
currentPosition
:
Int
,
list
:
List
<
CourseMediaBean
>,
from
:
Int
)
{
bean
.
let
{
Glide
.
with
(
this
)
.
load
(
it
.
pic
)
.
transition
(
DrawableTransitionOptions
.
withCrossFade
())
...
...
@@ -306,37 +195,36 @@ class AudioPlayActivity : BaseMvpActivity<IAudioPlayContract.View, IAudioPlayCon
iv_detail
.
setOnClickListener
{
_
->
detailClick
(
it
)
}
tv_speed
.
setOnClickListener
{
speedClick
()
}
iv_speed
.
setOnClickListener
{
speedClick
()
}
tv_list
.
setOnClickListener
{
listClick
(
)
}
iv_list
.
setOnClickListener
{
listClick
(
)
}
tv_list
.
setOnClickListener
{
_
->
listClick
(
it
,
currentPosition
,
list
)
}
iv_list
.
setOnClickListener
{
_
->
listClick
(
it
,
currentPosition
,
list
)
}
}
audio_play
.
setData
(
mCurrentPosition
,
convertToMusics
(
mPlayList
),
bean
.
courseExtra
.
isBuy
,
mF
rom
)
audio_play
.
setData
(
currentPosition
,
mPresenter
.
convertToMusics
(
list
),
bean
.
isBuy
,
f
rom
)
}
private
fun
convertToMusics
(
list
:
List
<
CourseMediaBean
>):
ArrayList
<
Music
>
{
val
musics
=
ArrayList
<
Music
>()
try
{
for
(
i
in
list
.
indices
)
{
musics
.
add
(
Music
().
apply
{
path
=
list
[
i
].
url
coverPath
=
mCourPlayBean
?.
courseExtra
?.
pic
title
=
list
[
i
].
title
artist
=
list
[
i
].
doctorName
})
}
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
return
musics
override
fun
setNonWifiTips
(
show
:
Boolean
)
{
audio_play
.
mNonWifiTips
=
show
}
override
fun
audioIsPlaying
():
Boolean
=
audio_play
.
isPlaying
()
override
fun
audioPausePlay
()
=
audio_play
.
pausePlay
()
override
fun
getAudioPath
():
String
=
audio_play
.
getAudioMusic
()
?.
path
.
orEmpty
()
override
fun
getAudioMusic
():
Music
?
=
audio_play
.
getAudioMusic
()
override
fun
close
()
{
finish
()
}
private
fun
detailClick
(
extra
:
CourseExtraBean
)
{
if
(
TextUtils
.
isEmpty
(
extra
.
id
))
{
ToastUtil
.
toastShort
(
"课程id错误"
)
}
else
{
showFloatView
()
mPresenter
.
showFloatView
()
NewH5Activity
.
start
(
this
,
H5Params
(
CourseConstants
.
COURSE_DETAIL_H5
+
mCourseI
d
,
null
)
H5Params
(
CourseConstants
.
COURSE_DETAIL_H5
+
extra
.
i
d
,
null
)
)
// 跳转课程H5详情
}
}
...
...
@@ -351,20 +239,20 @@ class AudioPlayActivity : BaseMvpActivity<IAudioPlayContract.View, IAudioPlayCon
},
"courseSpeed"
)
}
private
fun
listClick
()
{
mCourPlayBean
?.
courseExtra
?
.
let
{
private
fun
listClick
(
extra
:
CourseExtraBean
,
currentPosition
:
Int
,
playList
:
List
<
CourseMediaBean
>
)
{
extra
.
let
{
showFragment
(
mCourseListDialog
?.
also
{
it
.
setCurrentPosition
(
mC
urrentPosition
)
it
.
setCurrentPosition
(
c
urrentPosition
)
}
?:
CourseListDialog
().
also
{
dialog
->
mCourseListDialog
=
dialog
mCourseListDialog
?.
setData
(
it
.
isBuy
,
mCurrentPosition
,
mP
layList
)
mCourseListDialog
?.
setData
(
it
.
isBuy
,
currentPosition
,
p
layList
)
dialog
.
mListener
=
object
:
CourseListListener
{
override
fun
addCourseOrder
()
{
this
@AudioPlayActivity
.
addCourseOrder
()
mPresenter
.
addCourseOrder
()
}
override
fun
togglePlaying
(
position
:
Int
)
{
this
@AudioPlayActivity
.
togglePlaying
(
position
)
mPresenter
.
togglePlaying
(
position
)
}
}
...
...
@@ -372,21 +260,6 @@ class AudioPlayActivity : BaseMvpActivity<IAudioPlayContract.View, IAudioPlayCon
}
}
//设置播放列表数据
private
fun
setPlayList
(
bean
:
CourseMediaDetailBean
)
{
if
(
bean
.
voiceSample
.
courseMedia
.
isNotEmpty
())
{
for
(
voiceSampleData
in
bean
.
voiceSample
.
courseMedia
)
{
voiceSampleData
.
isDemo
=
true
mPlayList
.
add
(
voiceSampleData
)
}
}
if
(
bean
.
voiceWhole
.
courseMedia
.
isNotEmpty
())
{
for
(
voiceCourseData
in
bean
.
voiceWhole
.
courseMedia
)
{
mPlayList
.
add
(
voiceCourseData
)
}
}
}
override
fun
onResume
()
{
super
.
onResume
()
if
(
PlayerFloatHelper
.
isShow
(
this
))
{
...
...
m-course/src/main/java/com/yidianling/course/coursePlay/presenter/AudioPlayPresenter.kt
View file @
d79b500f
package
com.yidianling.course.coursePlay.presenter
import
android.content.Intent
import
android.text.TextUtils
import
com.ydl.media.audio.model.Music
import
com.ydl.media.view.PlayTypeEnum
import
com.ydl.media.view.PlayerFloatHelper
import
com.ydl.ydlcommon.data.http.BaseResponse
import
com.ydl.ydlcommon.data.http.RxUtils
import
com.ydl.ydlcommon.mvp.base.BasePresenter
import
com.ydl.ydlcommon.router.IYDLRouterConstant
import
com.ydl.ydlcommon.router.YdlCommonRouterManager
import
com.ydl.ydlnet.client.observer.CommonObserver
import
com.yidianling.common.tools.ToastUtil
import
com.yidianling.course.bean.COURSE_AUDIO
import
com.yidianling.course.bean.CourseMediaBean
import
com.yidianling.course.bean.CourseMediaDetailBean
import
com.yidianling.course.coursePlay.model.AudioPlayModelImpl
import
org.json.JSONException
import
org.json.JSONObject
import
java.util.*
class
AudioPlayPresenter
:
BasePresenter
<
IAudioPlayContract
.
View
,
IAudioPlayContract
.
Model
>(),
IAudioPlayContract
.
Presenter
{
private
val
ROUTER_PARAMS
=
"routerParam"
private
var
mFrom
:
Int
=
0
private
var
mReceiverPlayUrl
:
String
?
=
null
// 外部选中要播放的音/视频文件地址
private
var
mIsFromFloatView
=
false
// 是否是悬浮窗进入
private
var
mCourPlayBean
:
CourseMediaDetailBean
?
=
null
private
val
mPlayList
:
ArrayList
<
CourseMediaBean
>
=
ArrayList
()
// 播放列表
private
var
mCurrentPosition
=
0
private
var
mCourseId
=
0
// 课程id
override
fun
createModel
():
IAudioPlayContract
.
Model
=
AudioPlayModelImpl
()
override
fun
getCoursePlayData
(
courseId
:
Int
)
{
override
fun
getParams
(
intent
:
Intent
)
{
intent
.
let
{
if
(
it
.
hasExtra
(
ROUTER_PARAMS
))
{
//路由传递的入参
val
json
=
it
.
getStringExtra
(
ROUTER_PARAMS
)
try
{
val
jsonObject
=
JSONObject
(
json
)
//课程ID
mCourseId
=
jsonObject
.
getInt
(
IYDLRouterConstant
.
EXTRA_ID
)
}
catch
(
e
:
JSONException
)
{
e
.
printStackTrace
()
}
return
}
//正常跳转所传参数
mCourseId
=
it
.
getIntExtra
(
"course_id"
,
0
)
mReceiverPlayUrl
=
it
.
getStringExtra
(
"coursePlayUrl"
)
mIsFromFloatView
=
it
.
getBooleanExtra
(
"isFromFloatView"
,
false
)
if
(!
TextUtils
.
isEmpty
(
mReceiverPlayUrl
)
&&
mIsFromFloatView
)
mView
.
setNonWifiTips
(
false
)
try
{
if
(
PlayerFloatHelper
.
playingType
==
PlayTypeEnum
.
PLAY_TYPE_COURSE
&&
mView
.
audioIsPlaying
()
&&
TextUtils
.
isEmpty
(
mReceiverPlayUrl
)
)
{
mReceiverPlayUrl
=
mView
.
getAudioPath
()
}
}
catch
(
e
:
Exception
)
{
}
mFrom
=
it
.
getIntExtra
(
"from"
,
0
)
if
(
mCourseId
==
0
)
{
ToastUtil
.
toastShort
(
"参数错误"
)
mView
.
close
()
}
}
}
override
fun
getNewIntent
(
intent
:
Intent
)
{
val
courseId
=
intent
.
getIntExtra
(
"course_id"
,
0
)
if
(
0
==
courseId
)
{
ToastUtil
.
toastShort
(
"参数错误"
)
mView
.
close
()
}
else
if
(
courseId
!=
mCourseId
)
{
mCourseId
=
courseId
getCoursePlayData
()
}
}
override
fun
getCoursePlayData
()
{
mView
.
showProgressDialog
()
mModel
.
getCoursePlayData
(
c
ourseId
)
mModel
.
getCoursePlayData
(
mC
ourseId
)
.
compose
(
RxUtils
.
applySchedulers
())
.
subscribe
(
object
:
CommonObserver
<
BaseResponse
<
CourseMediaDetailBean
>>()
{
override
fun
onError
(
s
:
String
?)
{
...
...
@@ -24,16 +94,27 @@ class AudioPlayPresenter : BasePresenter<IAudioPlayContract.View, IAudioPlayCont
override
fun
onSuccess
(
resp
:
BaseResponse
<
CourseMediaDetailBean
>?)
{
mView
.
dismissProgressDialog
()
resp
?.
let
{
if
(
it
.
code
==
200
)
{
//跟新view显示
if
(
it
.
data
!=
null
&&
it
.
data
is
CourseMediaDetailBean
)
{
mView
.
updateView
(
it
.
data
as
CourseMediaDetailBean
)
}
else
{
resp
?.
let
{
response
->
if
(
response
.
code
==
200
)
{
response
.
data
?.
let
{
bean
->
mCourPlayBean
=
bean
setPlayList
(
bean
)
if
(!
TextUtils
.
isEmpty
(
mReceiverPlayUrl
))
{
mCurrentPosition
=
mPlayList
.
indexOfLast
{
TextUtils
.
equals
(
mReceiverPlayUrl
,
it
.
url
)
||
TextUtils
.
equals
(
mReceiverPlayUrl
!!
.
replace
(
"http"
,
"https"
),
it
.
url
)
}
}
mView
.
updateView
(
bean
.
courseExtra
,
mCurrentPosition
,
mPlayList
,
mFrom
)
}
?:
let
{
ToastUtil
.
toastShort
(
"解析出错"
)
}
}
else
{
ToastUtil
.
toastShort
(
it
.
msg
)
ToastUtil
.
toastShort
(
response
.
msg
)
}
}
}
...
...
@@ -41,4 +122,91 @@ class AudioPlayPresenter : BasePresenter<IAudioPlayContract.View, IAudioPlayCont
})
}
//设置播放列表数据
private
fun
setPlayList
(
bean
:
CourseMediaDetailBean
)
{
mPlayList
.
clear
()
if
(
bean
.
voiceSample
.
courseMedia
.
isNotEmpty
())
{
for
(
voiceSampleData
in
bean
.
voiceSample
.
courseMedia
)
{
voiceSampleData
.
isDemo
=
true
mPlayList
.
add
(
voiceSampleData
)
}
}
if
(
bean
.
voiceWhole
.
courseMedia
.
isNotEmpty
())
{
for
(
voiceCourseData
in
bean
.
voiceWhole
.
courseMedia
)
{
mPlayList
.
add
(
voiceCourseData
)
}
}
}
override
fun
convertToMusics
(
list
:
List
<
CourseMediaBean
>):
ArrayList
<
Music
>
{
val
musics
=
ArrayList
<
Music
>()
try
{
for
(
i
in
list
.
indices
)
{
musics
.
add
(
Music
().
apply
{
path
=
list
[
i
].
url
coverPath
=
mCourPlayBean
?.
courseExtra
?.
pic
title
=
list
[
i
].
title
artist
=
list
[
i
].
doctorName
})
}
}
catch
(
e
:
Exception
)
{
e
.
printStackTrace
()
}
return
musics
}
override
fun
addCourseOrder
()
{
if
(
mCourseId
==
0
)
{
ToastUtil
.
toastShort
(
"请退出页面重试"
)
return
}
val
userInfo
=
YdlCommonRouterManager
.
getYdlCommonRoute
().
getUserInfo
()
if
(
userInfo
==
null
||
TextUtils
.
isEmpty
(
userInfo
.
userId
))
{
mView
.
loginByOneKeyLogin
()
return
}
mView
.
commonPayDialog
(
userInfo
,
mCourseId
.
toString
())
}
override
fun
togglePlaying
(
playPosition
:
Int
)
{
if
(
playPosition
>=
mPlayList
.
size
||
playPosition
<
0
)
{
ToastUtil
.
toastShort
(
"暂无内容"
)
}
else
if
(
mCurrentPosition
!=
playPosition
)
{
mCurrentPosition
=
playPosition
mCourPlayBean
?.
courseExtra
?.
let
{
if
(
isCanPlay
(
it
.
isBuy
))
mView
.
play
(
mCurrentPosition
)
}
}
}
private
fun
isCanPlay
(
isBuy
:
Boolean
):
Boolean
{
mPlayList
.
elementAtOrNull
(
mCurrentPosition
)
?.
let
{
if
(!
it
.
isDemo
&&
!
isBuy
)
{
if
(
mView
.
audioIsPlaying
())
mView
.
audioPausePlay
()
mView
.
buyCourseTipDialog
()
}
else
if
(
it
.
mediaType
==
COURSE_AUDIO
)
{
return
true
}
}
return
false
}
override
fun
share
()
{
mView
.
shareDialog
(
mCourPlayBean
?.
courseExtra
?.
shareData
)
}
override
fun
showFloatView
()
{
if
(
mView
.
audioIsPlaying
()
&&
PlayerFloatHelper
.
playingType
==
PlayTypeEnum
.
PLAY_TYPE_COURSE
)
{
mView
.
getAudioMusic
()
?.
coverPath
=
mCourPlayBean
?.
courseExtra
?.
pic
mView
.
getAudioMusic
()
?.
artist
=
mCourPlayBean
?.
courseExtra
?.
doctorName
PlayerFloatHelper
.
playTempData
.
clear
()
val
hashMap
=
HashMap
<
String
,
String
>()
hashMap
[
"course_id"
]
=
mCourseId
.
toString
()
hashMap
[
"media_type"
]
=
COURSE_AUDIO
.
toString
()
PlayerFloatHelper
.
playTempData
.
putAll
(
hashMap
)
}
}
}
\ No newline at end of file
m-course/src/main/java/com/yidianling/course/coursePlay/presenter/IAudioPlayContract.kt
View file @
d79b500f
package
com.yidianling.course.coursePlay.presenter
import
android.content.Intent
import
com.ydl.media.audio.model.Music
import
com.ydl.ydlcommon.bean.ShareData
import
com.ydl.ydlcommon.data.http.BaseResponse
import
com.ydl.ydlcommon.mvp.base.IModel
import
com.ydl.ydlcommon.mvp.base.IPresenter
import
com.ydl.ydlcommon.mvp.base.IView
import
com.ydl.ydlcommon.router.YdlUserInfo
import
com.yidianling.course.bean.CourseExtraBean
import
com.yidianling.course.bean.CourseMediaBean
import
com.yidianling.course.bean.CourseMediaDetailBean
import
io.reactivex.Observable
import
java.util.ArrayList
interface
IAudioPlayContract
{
...
...
@@ -15,14 +22,49 @@ interface IAudioPlayContract {
fun
dismissProgressDialog
()
fun
updateView
(
bean
:
Course
MediaDetailBean
)
fun
updateView
(
bean
:
Course
ExtraBean
,
currentPosition
:
Int
,
list
:
List
<
CourseMediaBean
>,
from
:
Int
)
fun
setNonWifiTips
(
show
:
Boolean
)
fun
audioIsPlaying
():
Boolean
fun
audioPausePlay
()
fun
getAudioPath
():
String
fun
getAudioMusic
():
Music
?
fun
loginByOneKeyLogin
()
fun
commonPayDialog
(
userInfo
:
YdlUserInfo
,
courseId
:
String
)
fun
buyCourseTipDialog
()
fun
shareDialog
(
share
:
ShareData
?)
fun
play
(
playPosition
:
Int
)
fun
close
()
}
interface
Presenter
:
IPresenter
<
View
>
{
fun
getCoursePlayData
(
courseId
:
Int
)
fun
getParams
(
intent
:
Intent
)
fun
getNewIntent
(
intent
:
Intent
)
fun
getCoursePlayData
()
fun
addCourseOrder
()
fun
togglePlaying
(
playPosition
:
Int
)
fun
share
()
fun
showFloatView
()
fun
convertToMusics
(
list
:
List
<
CourseMediaBean
>):
ArrayList
<
Music
>
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment