|
@@ -1,26 +1,32 @@
|
|
|
package com.swago.room.music
|
|
|
|
|
|
-import android.content.Intent
|
|
|
import android.os.Bundle
|
|
|
import android.view.Gravity
|
|
|
import android.view.View
|
|
|
-import androidx.appcompat.app.AppCompatActivity
|
|
|
import androidx.fragment.app.viewModels
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
import com.alibaba.android.arouter.launcher.ARouter
|
|
|
-import com.chad.library.adapter.base.BaseQuickAdapter
|
|
|
import com.swago.baseswago.agora.AgoraManager
|
|
|
import com.swago.baseswago.constant.ARouteConstant
|
|
|
-import com.swago.baseswago.cusview.SwagoRecyclerView
|
|
|
-import com.swago.baseswago.dialog.BaseListDialogFragment
|
|
|
-import com.swago.baseswago.model.MomentModel
|
|
|
-import com.swago.baseswago.util.LogUtil
|
|
|
+import com.swago.baseswago.dialog.BaseXDFragment
|
|
|
+import com.swago.baseswago.dialog.ChoiceDialogFragment
|
|
|
+import com.swago.baseswago.util.AppContext
|
|
|
import com.swago.room.R
|
|
|
+import com.swago.room.database.DBHelper
|
|
|
import com.swago.room.databinding.DialogMyMusicBinding
|
|
|
|
|
|
-class MyMusicDialog : BaseListDialogFragment<DialogMyMusicBinding, MusicModel>() {
|
|
|
- private val musicVm by viewModels<MusicVm>()
|
|
|
+class MyMusicDialog : BaseXDFragment<DialogMyMusicBinding>() {
|
|
|
+ val music_binding get() = binding
|
|
|
+ var isLocalCome = false
|
|
|
+ private val musicList by lazy {
|
|
|
+ ArrayList<MusicModel>()
|
|
|
+ }
|
|
|
+ private val adapter by lazy {
|
|
|
+ MyMusicAdapter()
|
|
|
+ }
|
|
|
+ val layoutManager: RecyclerView.LayoutManager
|
|
|
+ get() = LinearLayoutManager(activity)
|
|
|
|
|
|
companion object {
|
|
|
const val select_local_result = 10002
|
|
@@ -38,91 +44,98 @@ class MyMusicDialog : BaseListDialogFragment<DialogMyMusicBinding, MusicModel>()
|
|
|
setDimAmount(0.5f)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- override val smartRecyclerView: SwagoRecyclerView<MusicModel> by lazy {
|
|
|
- binding.swagoRv as SwagoRecyclerView<MusicModel>
|
|
|
- }
|
|
|
- override val adapter: BaseQuickAdapter<MusicModel, *> by lazy {
|
|
|
- MyMusicAdapter()
|
|
|
- }
|
|
|
-
|
|
|
- override val layoutManager: RecyclerView.LayoutManager by lazy {
|
|
|
- LinearLayoutManager(context)
|
|
|
- }
|
|
|
- override val loadData: (page: Int) -> Unit = {
|
|
|
- musicVm.loadMediaItems()
|
|
|
- }
|
|
|
-
|
|
|
- override fun initViewData() {
|
|
|
- binding.ivClose.setOnClickListener {
|
|
|
+ override fun initOther() {
|
|
|
+ music_binding.rvMusic.layoutManager = layoutManager
|
|
|
+ music_binding.rvMusic.adapter = adapter
|
|
|
+ music_binding.ivClose.setOnClickListener {
|
|
|
dismissAllowingStateLoss()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
override fun initLiveData() {
|
|
|
- musicVm.musicListData.observe(this) {
|
|
|
- if (!it.isNullOrEmpty()){
|
|
|
- binding.clAdd.visibility = View.VISIBLE
|
|
|
- binding.clNoContent.visibility = View.GONE
|
|
|
- smartRecyclerView.onFetchDataFinish(it, false)
|
|
|
- } else {
|
|
|
- binding.clAdd.visibility = View.GONE
|
|
|
- binding.clNoContent.visibility = View.VISIBLE
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
+ val data = DBHelper.getMusicModel()?.loadAll()
|
|
|
+ if (!data.isNullOrEmpty()){
|
|
|
+ music_binding.clAdd.visibility = View.VISIBLE
|
|
|
+ music_binding.clNoContent.visibility = View.GONE
|
|
|
+ musicList.addAll(data)
|
|
|
+ adapter.setNewData(musicList)
|
|
|
+ } else {
|
|
|
+ music_binding.clAdd.visibility = View.GONE
|
|
|
+ music_binding.clNoContent.visibility = View.VISIBLE
|
|
|
}
|
|
|
- adapter.setOnItemClickListener { _, _, position ->
|
|
|
- if (adapter.data.size > position){
|
|
|
- AgoraManager.getRtcEngine()?.startAudioMixing(
|
|
|
- adapter.data[position].data,
|
|
|
- false,
|
|
|
- false,
|
|
|
- -1,
|
|
|
- 0
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- binding.clAdd.setOnClickListener {
|
|
|
+ music_binding.clAdd.setOnClickListener {
|
|
|
+ isLocalCome = true
|
|
|
ARouter.getInstance()
|
|
|
.build(ARouteConstant.Room.musicList)
|
|
|
- .withParcelableArrayList("data",adapter.data as ArrayList<MusicModel>)
|
|
|
- .navigation(activity, select_local_result)
|
|
|
+ .navigation()
|
|
|
}
|
|
|
- binding.clNoContent.setOnClickListener {
|
|
|
+ music_binding.clNoContent.setOnClickListener {
|
|
|
+ isLocalCome = true
|
|
|
ARouter.getInstance()
|
|
|
.build(ARouteConstant.Room.musicList)
|
|
|
- .withParcelableArrayList("data",adapter.data as ArrayList<MusicModel>)
|
|
|
- .navigation(activity, select_local_result)
|
|
|
+ .navigation()
|
|
|
}
|
|
|
|
|
|
adapter.setOnItemChildClickListener { _, view, position ->
|
|
|
when(view?.id){
|
|
|
R.id.ivRecall -> {
|
|
|
+ ChoiceDialogFragment.newInstance(AppContext.getContext().getString(R.string.do_delete_room_admin),
|
|
|
+ rightChoiceText = AppContext.getContext().getString(R.string.delete)).apply {
|
|
|
+ this.sureFun = {
|
|
|
+ DBHelper.getMusicModel()?.delete(adapter.data[position])
|
|
|
+ musicList.remove(adapter.data[position])
|
|
|
+ adapter.setNewData(musicList)
|
|
|
+ if (adapter.data.isEmpty()){
|
|
|
+ music_binding.clAdd.visibility = View.GONE
|
|
|
+ music_binding.clNoContent.visibility = View.VISIBLE
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.show(childFragmentManager,"ChoiceDialogFragment")
|
|
|
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- override fun loadMoreNeed(): Boolean {
|
|
|
- return false
|
|
|
- }
|
|
|
|
|
|
- override fun refreshNeed(): Boolean {
|
|
|
- return false
|
|
|
+ adapter.setOnItemClickListener { _, _, position ->
|
|
|
+ if (adapter.data[position].getIsPlaying()){
|
|
|
+ adapter.data[position].setIsPlaying(false)
|
|
|
+ adapter.notifyItemChanged(position)
|
|
|
+ AgoraManager.getRtcEngine()?.stopAudioMixing()
|
|
|
+ return@setOnItemClickListener
|
|
|
+ }
|
|
|
+ adapter.data.forEachIndexed { index, musicModel ->
|
|
|
+ if (musicModel.isPlaying()){
|
|
|
+ adapter.data[index].setIsPlaying(false)
|
|
|
+ adapter.notifyItemChanged(index)
|
|
|
+ return@forEachIndexed
|
|
|
+ }
|
|
|
+ }
|
|
|
+ adapter.data[position].setIsPlaying(true)
|
|
|
+ AgoraManager.getRtcEngine()?.startAudioMixing(
|
|
|
+ adapter.data[position].data,
|
|
|
+ false,
|
|
|
+ false,
|
|
|
+ -1,
|
|
|
+ 0
|
|
|
+ )
|
|
|
+ adapter.notifyItemChanged(position)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
|
- super.onActivityResult(requestCode, resultCode, data)
|
|
|
- if (resultCode == AppCompatActivity.RESULT_OK){
|
|
|
- when(requestCode){
|
|
|
- select_local_result -> {
|
|
|
- val model = data?.getParcelableArrayExtra("data") as List<MusicModel>
|
|
|
- smartRecyclerView.onFetchDataFinish(model, false)
|
|
|
- }
|
|
|
+ override fun onResume() {
|
|
|
+ super.onResume()
|
|
|
+ if (isLocalCome){
|
|
|
+ isLocalCome = false
|
|
|
+ val data = DBHelper.getMusicModel()?.loadAll()
|
|
|
+ if (!data.isNullOrEmpty()){
|
|
|
+ binding.clAdd.visibility = View.VISIBLE
|
|
|
+ binding.clNoContent.visibility = View.GONE
|
|
|
+ musicList.clear()
|
|
|
+ musicList.addAll(data)
|
|
|
+ adapter.setNewData(musicList)
|
|
|
+ } else {
|
|
|
+ binding.clAdd.visibility = View.GONE
|
|
|
+ binding.clNoContent.visibility = View.VISIBLE
|
|
|
}
|
|
|
}
|
|
|
}
|