在前面的改造过程中,为了解决
- 多个View调用Presenter时,部分View只需要使用到Presenter的部分功能,采用了数据驱动UI的方式解决
- MVP存在异步线程更新UI的问题,采用在监听数据时判断当前是否是UI线程才进行回调
这里我们需要进一步解决剩余的问题:更新UI的时候需要结合当前V层的生命周期进行(在用户可见的情况下进行更新,不可见时就暂停相关的操作)
因此,这里首先处理,让View层能够通知到Presenter生命周期的变化
这里创建ILifecycle接口,让相应的Presenter去实现,为了让Presenter层能感知activity层的生命周期变化
package com.example.jetpackbysob.musiclisttest1.lifecycle
/**
* Project_name:JetPackBySob
* Created by:ChenFuXu.
* Date: 2022/5/2 16:45
*
* 该接口让Presenter层实现,为了让Presenter能感知activity层的生命周期变化
*/
interface ILifecycle {
fun onCreate()
fun onStart()
fun onResume()
fun onPause()
fun onStop()
fun onDestroy()
}
这里MusicPresenter实现了ILifecycle接口,通过在activity中的不同生命周期中调用相应的Presenter的相应的生命周期方法,实现了P层感知V层的生命周期了
V层: MusicActivity
package com.example.jetpackbysob.musiclisttest1
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.jetpackbysob.R
import kotlinx.android.synthetic.main.activity_music_list.*
/**
* Project_name:JetPackBySob
* Created by:ChenFuXu.
* Date: 2022/5/1 12:50
*/
class MusicActivity : AppCompatActivity() {
companion object {
private const val TAG = "MusicActivity"
}
private val mMusicPresenter by lazy {
MusicPresenter.instance
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_music_list)
initDataListener()
initViewListener()
mMusicPresenter.onCreate()
}
override fun onStart() {
super.onStart()
mMusicPresenter.onStart()
}
override fun onResume() {
super.onResume()
mMusicPresenter.onResume()
}
override fun onPause() {
super.onPause()
mMusicPresenter.onPause()
}
override fun onStop() {
super.onStop()
mMusicPresenter.onStop()
}
override fun onDestroy() {
super.onDestroy()
mMusicPresenter.onDestroy()
}
/**
* 监听数据的变化
*/
private fun initDataListener() {
println("$TAG, cfx initDataListener Thread.currentThread().name = ${Thread.currentThread().name}")
mMusicPresenter.mMusicList.addListener {
println("$TAG, cfx initDataListener Thread.currentThread().name = ${Thread.currentThread().name}")
// 音乐列表数据变化
println("$TAG, cfx initDataListener mMusicList.size = ${it?.size}")
get_music_count.text = "共 ${it?.size} 首音乐"
}
mMusicPresenter.mLoadState.addListener {
// 播放状态的数据变化
println("$TAG, cfx initDataListener mLoadState = $it")
}
}
private fun initViewListener() {
get_music_list.setOnClickListener {
// 获取音乐列表
mMusicPresenter.getMusicList()
}
}
}
P层:MusicPresenter
package com.example.jetpackbysob.musiclisttest1
import com.example.jetpackbysob.musiclisttest.domain.MusicBean
import com.example.jetpackbysob.musiclisttest1.lifecycle.ILifecycle
/**
* Project_name:JetPackBySob
* Created by:ChenFuXu.
* Date: 2022/5/1 12:52
*/
class MusicPresenter : ILifecycle {
companion object {
private const val TAG = "MusicPresenter"
val instance by lazy {
MusicPresenter()
}
}
enum class MusicLoadState {
LOADING, EMPTY, SUCCESS, ERROR
}
private val mMusicModel by lazy {
MusicModel()
}
val mMusicList = DataListenerContainer<List<MusicBean>>()
val mLoadState = DataListenerContainer<MusicLoadState>()
private val page = 1
private val size = 30
/**
* 获取音乐列表
*/
fun getMusicList() {
mLoadState.value = MusicLoadState.LOADING
// 从model层获取音乐列表,这个操作一般是异步操作,子线程执行
mMusicModel.loadMusicListByPage(page, size, object: MusicModel.OnMusicLoadResult {
override fun onSuccess(result: List<MusicBean>) {
// 加载音乐列表成功
mMusicList.value = result
mLoadState.value = if (result.isEmpty()) {
MusicLoadState.EMPTY
} else {
MusicLoadState.SUCCESS
}
println("$TAG getMusicList onSuccess 获取音乐列表成功")
}
override fun onError(msg: String, code: Int) {
// 加载音乐列表失败
mLoadState.value = MusicLoadState.ERROR
println("$TAG getMusicList onError msg: $msg code: $code")
}
})
}
override fun onCreate() {
}
override fun onStart() {
}
override fun onResume() {
}
override fun onPause() {
}
override fun onStop() {
}
override fun onDestroy() {
}
}
上述虽然解决了P层感知到了一个V层(activity)生命周期的问题,但如果存在多个activity需要和Presenter进行交互呢?,所以这里需要抽取BaseActivity,让Presenter感知BaseActivity的生命周期,对于下层的View只需要继承BaseActivity就可以了
BaseActivity
package com.example.jetpackbysob.musiclisttest1.base
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.jetpackbysob.musiclisttest1.lifecycle.ILifecycle
/**
* Project_name:JetPackBySob
* Created by:ChenFuXu.
* Date: 2022/5/2 17:25
*/
open class BaseActivity : AppCompatActivity() {
private val mLifecycleListener = arrayListOf<ILifecycle>()
/**
* 添加相应的生命周期监听者
*/
fun addLifecycleListener(listener: ILifecycle) {
if (!mLifecycleListener.contains(listener)) {
mLifecycleListener.add(listener)
}
}
/**
* 移除生命周期的监听者
*/
fun removeLifecycleListener(listener: ILifecycle) {
mLifecycleListener.remove(listener)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
/**
* 遍历集合,循环通知到所有实现ILifecycle的Presenter
*/
mLifecycleListener.forEach {
it.onCreate()
}
}
override fun onStart() {
super.onStart()
/**
* 遍历集合,循环通知到所有实现ILifecycle的Presenter
*/
mLifecycleListener.forEach {
it.onStart()
}
}
override fun onResume() {
super.onResume()
/**
* 遍历集合,循环通知到所有实现ILifecycle的Presenter
*/
mLifecycleListener.forEach {
it.onResume()
}
}
override fun onPause() {
super.onPause()
/**
* 遍历集合,循环通知到所有实现ILifecycle的Presenter
*/
mLifecycleListener.forEach {
it.onPause()
}
}
override fun onStop() {
super.onStop()
/**
* 遍历集合,循环通知到所有实现ILifecycle的Presenter
*/
mLifecycleListener.forEach {
it.onStop()
}
}
override fun onDestroy() {
super.onDestroy()
/**
* 遍历集合,循环通知到所有实现ILifecycle的Presenter
*/
mLifecycleListener.forEach {
it.onDestroy()
}
}
}
MusicActivity
package com.example.jetpackbysob.musiclisttest1
import android.os.Bundle
import com.example.jetpackbysob.R
import com.example.jetpackbysob.musiclisttest1.base.BaseActivity
import kotlinx.android.synthetic.main.activity_music_list.*
/**
* Project_name:JetPackBySob
* Created by:ChenFuXu.
* Date: 2022/5/1 12:50
*/
class MusicActivity : BaseActivity() {
companion object {
private const val TAG = "MusicActivity"
}
private val mMusicPresenter by lazy {
MusicPresenter.instance
}
init {
/**
* 让P层感知activity的生命周期
*/
addLifecycleListener(mMusicPresenter)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_music_list)
initDataListener()
initViewListener()
}
override fun onDestroy() {
super.onDestroy()
}
/**
* 监听数据的变化
*/
private fun initDataListener() {
println("$TAG, cfx initDataListener Thread.currentThread().name = ${Thread.currentThread().name}")
mMusicPresenter.mMusicList.addListener {
println("$TAG, cfx initDataListener Thread.currentThread().name = ${Thread.currentThread().name}")
// 音乐列表数据变化
println("$TAG, cfx initDataListener mMusicList.size = ${it?.size}")
get_music_count.text = "共 ${it?.size} 首音乐"
}
mMusicPresenter.mLoadState.addListener {
// 播放状态的数据变化
println("$TAG, cfx initDataListener mLoadState = $it")
}
}
private fun initViewListener() {
get_music_list.setOnClickListener {
// 获取音乐列表
mMusicPresenter.getMusicList()
}
}
}
对于需要让Presenter感知avctivity生命周期的,只需要在MusicActivity中addLifecycleListener(mMusicPresenter)即可,在BaseActvity中保留集合,循环遍历通知所有的Presenter,而当存在多个界面需要让Presenter感知activity的生命周期的话,那就继承BaseActivity
这样的话,多个activity让Presenter感知生命周期的问题也解决了,可是View层不止有activity,还有fragment,fragment中也会持有相应的Presenter进行逻辑交互,那么fragment又怎么处理呢
解决思路:可以创建一个公共的LifecycleProvider,这个类的职责是管理注册进来的接口ILifecycle 、保存当前的生命周期状态,这样activity需要就去获取,fragment需要就去get,就能解决现在存在的问题
LifecycleProvider
package com.example.jetpackbysob.musiclisttest1.lifecycle
/**
* Project_name:JetPackBySob
* Created by:ChenFuXu.
* Date: 2022/5/2 20:42
*
* 这个类的职责是管理注册进来的接口:ILifecycle
* 保存当前的生命周期状态
*/
class LifecycleProvider {
private val mLifecycleListeners = arrayListOf<ILifecycle>()
// 当前的生命周期状态
private var mCurrentLifeState: LifeState? = null
/**
* 添加Lifecycle
*/
fun addLifecycle(lifecycleListener: ILifecycle) {
if (!mLifecycleListeners.contains(lifecycleListener)) {
mLifecycleListeners.add(lifecycleListener)
}
}
/**
* 移除Lifecycle
*/
fun removeLifecycle(lifecycleListener: ILifecycle) {
mLifecycleListeners.remove(lifecycleListener)
}
/**
* 改变生命周期的状态
*/
fun makeLifeState(state: LifeState) {
mCurrentLifeState = state
when (state) {
LifeState.ON_CREATE -> {
handlerCreateState()
}
LifeState.ON_START -> {
handlerStartState()
}
LifeState.ON_RESUME -> {
handlerResumeState()
}
LifeState.ON_PAUSE -> {
handlerPauseState()
}
LifeState.ON_STOP -> {
handlerStopState()
}
LifeState.ON_DESTROY -> {
handlerDestroyState()
}
}
}
private fun handlerDestroyState() {
mLifecycleListeners.forEach {
it.onDestroy()
}
// 清空所有数据
mLifecycleListeners.clear()
}
private fun handlerStopState() {
mLifecycleListeners.forEach {
it.onStop()
}
}
private fun handlerPauseState() {
mLifecycleListeners.forEach {
it.onPause()
}
}
private fun handlerResumeState() {
mLifecycleListeners.forEach {
it.onResume()
}
}
private fun handlerStartState() {
mLifecycleListeners.forEach {
it.onStart()
}
}
private fun handlerCreateState() {
mLifecycleListeners.forEach {
it.onCreate()
}
}
}
LifeState:生命周期枚举类
package com.example.jetpackbysob.musiclisttest1.lifecycle
/**
* Project_name:JetPackBySob
* Created by:ChenFuXu.
* Date: 2022/5/2 20:45
*
* 生命周期状态的枚举类
*/
enum class LifeState {
ON_CREATE, ON_START, ON_RESUME, ON_PAUSE, ON_STOP, ON_DESTROY
}
这样的话,如果是多个activity就在BaseActivity实例化LifecycleProvider对象,多个Fragment就在BaseFragment中实例化LifecycleProvider对象
BaseActivity
package com.example.jetpackbysob.musiclisttest.base
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.jetpackbysob.musiclisttest.lifecycle.ILifecycleOwner
import com.example.jetpackbysob.musiclisttest.lifecycle.LifeState
import com.example.jetpackbysob.musiclisttest.lifecycle.LifecycleProvider
/**
* Project_name:JetPackBySob
* Created by:ChenFuXu.
* Date: 2022/5/2 17:25
*/
open class BaseActivity : AppCompatActivity() {
private val mLifecycleProvider by lazy {
LifecycleProvider()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mLifecycleProvider.makeLifeState(LifeState.ON_CREATE)
}
override fun onStart() {
super.onStart()
mLifecycleProvider.makeLifeState(LifeState.ON_START)
}
override fun onResume() {
super.onResume()
mLifecycleProvider.makeLifeState(LifeState.ON_RESUME)
}
override fun onPause() {
super.onPause()
mLifecycleProvider.makeLifeState(LifeState.ON_PAUSE)
}
override fun onStop() {
super.onStop()
mLifecycleProvider.makeLifeState(LifeState.ON_STOP)
}
override fun onDestroy() {
super.onDestroy()
mLifecycleProvider.makeLifeState(LifeState.ON_DESTROY)
}
}
MusicActivity继承BaseActivity,添加多个Presenter
package com.example.jetpackbysob.musiclisttest1
import android.os.Bundle
import android.util.Log
import com.example.jetpackbysob.R
import com.example.jetpackbysob.musiclisttest1.base.BaseActivity
import kotlinx.android.synthetic.main.activity_music_list.*
/**
* Project_name:JetPackBySob
* Created by:ChenFuXu.
* Date: 2022/5/1 12:50
*/
class MusicActivity : BaseActivity() {
companion object {
private const val TAG = "MusicActivity"
}
private val mMusicPresenter by lazy {
MusicPresenter.instance
}
private val mPlayerPresenter by lazy {
PlayerPresenter.instance
}
init {
// 将多个Presenter添加到Lifecycle中
// 使得每个Presenter都能监听到生命周期的变化
mLifecycleProvider.addLifecycle(mMusicPresenter)
mLifecycleProvider.addLifecycle(mPlayerPresenter)
}
init {
Log.d(TAG, "cfx MusicActivity init")
MusicPresenter.mOwner = this
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_music_list)
initDataListener()
initViewListener()
}
override fun onDestroy() {
super.onDestroy()
}
/**
* 监听数据的变化
*/
private fun initDataListener() {
println("$TAG, cfx initDataListener Thread.currentThread().name = ${Thread.currentThread().name}")
mMusicPresenter.mMusicList.addListener {
println("$TAG, cfx initDataListener Thread.currentThread().name = ${Thread.currentThread().name}")
// 音乐列表数据变化
println("$TAG, cfx initDataListener mMusicList.size = ${it?.size}")
get_music_count.text = "共 ${it?.size} 首音乐"
}
mMusicPresenter.mLoadState.addListener {
// 播放状态的数据变化
println("$TAG, cfx initDataListener mLoadState = $it")
}
}
private fun initViewListener() {
get_music_list.setOnClickListener {
// 获取音乐列表
mMusicPresenter.getMusicList()
}
}
}
BaseFragment
package com.example.jetpackbysob.musiclisttest1.base
import android.os.Bundle
import androidx.fragment.app.Fragment
import com.example.jetpackbysob.musiclisttest.lifecycle.LifeState
import com.example.jetpackbysob.musiclisttest.lifecycle.LifecycleProvider
/**
* Project_name:JetPackBySob
* Created by:ChenFuXu.
* Date: 2022/5/2 21:16
*/
open class BaseFragment : Fragment() {
val mLifecycleProvider by lazy {
LifecycleProvider()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mLifecycleProvider.makeLifeState(LifeState.ON_CREATE)
}
override fun onStart() {
super.onStart()
mLifecycleProvider.makeLifeState(LifeState.ON_START)
}
override fun onResume() {
super.onResume()
mLifecycleProvider.makeLifeState(LifeState.ON_RESUME)
}
override fun onPause() {
super.onPause()
mLifecycleProvider.makeLifeState(LifeState.ON_PAUSE)
}
override fun onStop() {
super.onStop()
mLifecycleProvider.makeLifeState(LifeState.ON_STOP)
}
override fun onDestroy() {
super.onDestroy()
mLifecycleProvider.makeLifeState(LifeState.ON_DESTROY)
}
}
多个Fragment继承BaseFragment,同样进行添加Presenter
package com.example.jetpackbysob.musiclisttest1
import android.os.Bundle
import com.example.jetpackbysob.musiclisttest1.base.BaseFragment
/**
* Project_name:JetPackBySob
* Created by:ChenFuXu.
* Date: 2022/5/2 21:10
*/
class MusicDetailFragment : BaseFragment() {
private val mMusicPresenter by lazy {
MusicPresenter.instance
}
init {
mLifecycleProvider.addLifecycle(mMusicPresenter)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
}
override fun onStart() {
super.onStart()
}
override fun onResume() {
super.onResume()
}
override fun onPause() {
super.onPause()
}
override fun onStop() {
super.onStop()
}
override fun onDestroy() {
super.onDestroy()
}
}
前文中解决了多个activity、fragment的生命周期让Presenter进行感知,以及创建了LifecycleProvider,让activity、frament去获取,通过addLifecycle()方法添加的是实现了ILifecycle接口的Presenter,可是如果Presenter没有实现该接口,该Presenter就没法添加进去,或者该接口由Presenter的内部类实现的,那么又应该怎么办呢?
解决思路:将添加方法addLifecycle()内置到Presenter内部去实现
创建ILifecycleOwner接口,这个接口用来返回LifecycleProvider对象,因为在BaseFragment、BaseActivity中拥有LifecycleProvider对象,所以只有让他们实现该接口,并在方法中返回LifecycleProvider对象就可以了
package com.example.jetpackbysob.musiclisttest1.lifecycle
/**
* Project_name:JetPackBySob
* Created by:ChenFuXu.
* Date: 2022/5/2 22:24
*/
interface ILifecycleOwner {
/**
* 获取LifecycleProvider
*/
fun getLifecycleProvider(): LifecycleProvider
}
BaseActivity中实现ILifecycleOwner接口获取mLifecycleProvider对象,在MusicActivity中是继承了BaseActivity,所以MusicPresenter.mOwner = this,将实现了ILifecycleOwner接口的BaseActivity对象给到了MusicPresenter
在MusicPresenter内部通过mOwner.getLifecycleProvider将实现了ILifecycle的内部类(或者如果是MusicPresenter实现了ILifecycle接口,就添加this自身),完成了将addLifecycle()内置到Presenter内部去实现
BaseActivity
package com.example.jetpackbysob.musiclisttest1.base
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.jetpackbysob.musiclisttest1.lifecycle.ILifecycleOwner
import com.example.jetpackbysob.musiclisttest1.lifecycle.LifeState
import com.example.jetpackbysob.musiclisttest1.lifecycle.LifecycleProvider
/**
* Project_name:JetPackBySob
* Created by:ChenFuXu.
* Date: 2022/5/2 17:25
*/
open class BaseActivity : AppCompatActivity(), ILifecycleOwner {
val mLifecycleProvider by lazy {
LifecycleProvider()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mLifecycleProvider.makeLifeState(LifeState.ON_CREATE)
}
override fun onStart() {
super.onStart()
mLifecycleProvider.makeLifeState(LifeState.ON_START)
}
override fun onResume() {
super.onResume()
mLifecycleProvider.makeLifeState(LifeState.ON_RESUME)
}
override fun onPause() {
super.onPause()
mLifecycleProvider.makeLifeState(LifeState.ON_PAUSE)
}
override fun onStop() {
super.onStop()
mLifecycleProvider.makeLifeState(LifeState.ON_STOP)
}
override fun onDestroy() {
super.onDestroy()
mLifecycleProvider.makeLifeState(LifeState.ON_DESTROY)
}
override fun getLifecycleProvider(): LifecycleProvider {
return mLifecycleProvider
}
}
MusicActivity
package com.example.jetpackbysob.musiclisttest1
import android.os.Bundle
import android.util.Log
import com.example.jetpackbysob.R
import com.example.jetpackbysob.musiclisttest1.base.BaseActivity
import kotlinx.android.synthetic.main.activity_music_list.*
/**
* Project_name:JetPackBySob
* Created by:ChenFuXu.
* Date: 2022/5/1 12:50
*/
class MusicActivity : BaseActivity() {
companion object {
private const val TAG = "MusicActivity"
}
private val mMusicPresenter by lazy {
MusicPresenter.instance
}
private val mPlayerPresenter by lazy {
PlayerPresenter.instance
}
init {
Log.d(TAG, "cfx MusicActivity init")
MusicPresenter.mOwner = this
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_music_list)
initDataListener()
initViewListener()
}
override fun onDestroy() {
super.onDestroy()
}
/**
* 监听数据的变化
*/
private fun initDataListener() {
println("$TAG, cfx initDataListener Thread.currentThread().name = ${Thread.currentThread().name}")
mMusicPresenter.mMusicList.addListener {
println("$TAG, cfx initDataListener Thread.currentThread().name = ${Thread.currentThread().name}")
// 音乐列表数据变化
println("$TAG, cfx initDataListener mMusicList.size = ${it?.size}")
get_music_count.text = "共 ${it?.size} 首音乐"
}
mMusicPresenter.mLoadState.addListener {
// 播放状态的数据变化
println("$TAG, cfx initDataListener mLoadState = $it")
}
}
private fun initViewListener() {
get_music_list.setOnClickListener {
// 获取音乐列表
mMusicPresenter.getMusicList()
}
}
}
MusicPresenter
package com.example.jetpackbysob.musiclisttest1
import android.util.Log
import com.example.jetpackbysob.musiclisttest1.domain.MusicBean
import com.example.jetpackbysob.musiclisttest1.lifecycle.ILifecycle
import com.example.jetpackbysob.musiclisttest1.lifecycle.ILifecycleOwner
/**
* Project_name:JetPackBySob
* Created by:ChenFuXu.
* Date: 2022/5/1 12:52
*/
class MusicPresenter() : ILifecycle {
companion object {
private const val TAG = "MusicPresenter"
val instance by lazy {
MusicPresenter()
}
var mOwner : ILifecycleOwner? = null
}
enum class MusicLoadState {
LOADING, EMPTY, SUCCESS, ERROR
}
private val mMusicModel by lazy {
MusicModel()
}
private val mViewLifeImpl by lazy {
ViewLifeImpl()
}
val mMusicList = DataListenerContainer<List<MusicBean>>()
val mLoadState = DataListenerContainer<MusicLoadState>()
private val page = 1
private val size = 30
init {
Log.d(TAG, "cfx MusicPresenter init")
mOwner?.getLifecycleProvider()?.addLifecycle(mViewLifeImpl)
}
inner class ViewLifeImpl : ILifecycle {
override fun onCreate() {
Log.d(TAG, "cfx ViewLifeImpl onCreate")
}
override fun onStart() {
Log.d(TAG, "cfx ViewLifeImpl onStart")
}
override fun onResume() {
Log.d(TAG, "cfx ViewLifeImpl onResume")
}
override fun onPause() {
Log.d(TAG, "cfx ViewLifeImpl onPause")
}
override fun onStop() {
Log.d(TAG, "cfx ViewLifeImpl onStop")
}
override fun onDestroy() {
Log.d(TAG, "cfx ViewLifeImpl onDestroy")
}
}
/**
* 获取音乐列表
*/
fun getMusicList() {
mLoadState.value = MusicLoadState.LOADING
// 从model层获取音乐列表,这个操作一般是异步操作,子线程执行
mMusicModel.loadMusicListByPage(page, size, object: MusicModel.OnMusicLoadResult {
override fun onSuccess(result: List<MusicBean>) {
// 加载音乐列表成功
mMusicList.value = result
mLoadState.value = if (result.isEmpty()) {
MusicLoadState.EMPTY
} else {
MusicLoadState.SUCCESS
}
println("$TAG getMusicList onSuccess 获取音乐列表成功")
}
override fun onError(msg: String, code: Int) {
// 加载音乐列表失败
mLoadState.value = MusicLoadState.ERROR
println("$TAG getMusicList onError msg: $msg code: $code")
}
})
}
override fun onCreate() {
Log.d(TAG, "cfx MusicPresenter onCreate")
}
override fun onStart() {
Log.d(TAG, "cfx MusicPresenter onStart")
}
override fun onResume() {
Log.d(TAG, "cfx MusicPresenter onResume")
}
override fun onPause() {
Log.d(TAG, "cfx MusicPresenter onPause")
}
override fun onStop() {
Log.d(TAG, "cfx MusicPresenter onStop")
}
override fun onDestroy() {
Log.d(TAG, "cfx MusicPresenter onDestory")
}
}