update
This commit is contained in:
parent
c8124ad849
commit
207f2e32ae
@ -31,6 +31,7 @@ import melody.offline.music.adapter.LikedSongsAdapter
|
|||||||
import melody.offline.music.ads.AdPlacement
|
import melody.offline.music.ads.AdPlacement
|
||||||
import melody.offline.music.ads.LolAdWrapper
|
import melody.offline.music.ads.LolAdWrapper
|
||||||
import melody.offline.music.bean.FavoriteBean
|
import melody.offline.music.bean.FavoriteBean
|
||||||
|
import melody.offline.music.bean.PlaylistItem
|
||||||
import melody.offline.music.databinding.ActivityLikedSongsBinding
|
import melody.offline.music.databinding.ActivityLikedSongsBinding
|
||||||
import melody.offline.music.fragment.MoMeFragment
|
import melody.offline.music.fragment.MoMeFragment
|
||||||
import melody.offline.music.service.MyDownloadService
|
import melody.offline.music.service.MyDownloadService
|
||||||
@ -38,29 +39,31 @@ import melody.offline.music.service.ViewModelMain
|
|||||||
import melody.offline.music.util.AnalysisUtil
|
import melody.offline.music.util.AnalysisUtil
|
||||||
import melody.offline.music.util.DownloadUtil
|
import melody.offline.music.util.DownloadUtil
|
||||||
import melody.offline.music.util.LogTag
|
import melody.offline.music.util.LogTag
|
||||||
|
import melody.offline.music.util.asPlaylistItem
|
||||||
|
import melody.offline.music.view.ListMoreBottomSheetDialog
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
|
||||||
@OptIn(UnstableApi::class)
|
@OptIn(UnstableApi::class)
|
||||||
class MoLikedSongsActivity : MoBaseActivity(), LikedSongsAdapter.OnItemFavoritesClickListener,
|
class MoLikedSongsActivity : MoBaseActivity(), LikedSongsAdapter.OnItemFavoritesClickListener,
|
||||||
LikedSongsAdapter.OnMoreClickListener {
|
LikedSongsAdapter.OnMoreClickListener, ListMoreBottomSheetDialog.ListMoreViewListener,
|
||||||
|
ListMoreBottomSheetDialog.UpdateAdapterListener {
|
||||||
|
|
||||||
private val requests: Channel<Request> = Channel(Channel.UNLIMITED)
|
private val requests: Channel<Request> = Channel(Channel.UNLIMITED)
|
||||||
|
|
||||||
sealed class Request {
|
sealed class Request {
|
||||||
data object TryAgain : Request()
|
data object TryAgain : Request()
|
||||||
data class UpdateFavorite(val bean: FavoriteBean) : Request()
|
data class OnFavorites(val bean: PlaylistItem) : Request()
|
||||||
data class OnFavorites(val bean: FavoriteBean) : Request()
|
data class OnDownload(val bean: PlaylistItem) : Request()
|
||||||
data class OnDownload(val favoriteBean: FavoriteBean) : Request()
|
data class OnDownloadRemove(val bean: PlaylistItem) : Request()
|
||||||
data class OnDownloadRemove(val id: String) : Request()
|
data class OnUpdateDownloadUi(val bean: PlaylistItem) : Request()
|
||||||
data class OnUpdateDownloadUi(val id: String) : Request()
|
data class OnAddPlaylist(val bean: PlaylistItem) : Request()
|
||||||
data class OnAddPlaylist(val bean: FavoriteBean) : Request()
|
data class OnUpdateCurrentListItem(val bean: PlaylistItem): Request()
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var binding: ActivityLikedSongsBinding
|
private lateinit var binding: ActivityLikedSongsBinding
|
||||||
private var adapter: LikedSongsAdapter? = null
|
private var adapter: LikedSongsAdapter? = null
|
||||||
private var favoriteBeans: MutableList<FavoriteBean> = mutableListOf()
|
private var myList: MutableList<PlaylistItem> = mutableListOf()
|
||||||
private var currentPosition = -1
|
private var moreDialog: ListMoreBottomSheetDialog? = null
|
||||||
private var isAnimationRunning = false//动画是否正在进行
|
|
||||||
|
|
||||||
override suspend fun main() {
|
override suspend fun main() {
|
||||||
binding = ActivityLikedSongsBinding.inflate(layoutInflater)
|
binding = ActivityLikedSongsBinding.inflate(layoutInflater)
|
||||||
@ -70,7 +73,6 @@ class MoLikedSongsActivity : MoBaseActivity(), LikedSongsAdapter.OnItemFavorites
|
|||||||
initView()
|
initView()
|
||||||
initAdapter()
|
initAdapter()
|
||||||
LolAdWrapper.shared.loadAdIfNotCached(this, AdPlacement.INST_ME_PAGE_LIST)
|
LolAdWrapper.shared.loadAdIfNotCached(this, AdPlacement.INST_ME_PAGE_LIST)
|
||||||
initDownloadFlow()
|
|
||||||
initData()
|
initData()
|
||||||
onReceive()
|
onReceive()
|
||||||
}
|
}
|
||||||
@ -92,43 +94,38 @@ class MoLikedSongsActivity : MoBaseActivity(), LikedSongsAdapter.OnItemFavorites
|
|||||||
initData()
|
initData()
|
||||||
}
|
}
|
||||||
|
|
||||||
is Request.UpdateFavorite -> {
|
|
||||||
val currentFavoriteBean =
|
|
||||||
App.appFavoriteDBManager.getFavoriteBeanByID(it.bean.videoId)
|
|
||||||
if (currentFavoriteBean != null) {
|
|
||||||
updateFavoriteUi(currentFavoriteBean.isFavorite)
|
|
||||||
} else {
|
|
||||||
updateFavoriteUi(false)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
is Request.OnFavorites -> {
|
is Request.OnFavorites -> {
|
||||||
it.bean.isFavorite = !it.bean.isFavorite
|
it.bean.isFavorite = !it.bean.isFavorite
|
||||||
adapter?.notifyDataSetChanged()
|
adapter?.notifyDataSetChanged()//更新list
|
||||||
|
|
||||||
updateFavoriteUi(it.bean.isFavorite)
|
updateFavoriteUi(it.bean.isFavorite)//更新对话框
|
||||||
|
|
||||||
val currentFavoriteBean =
|
val currentFavoriteBean = App.appFavoriteDBManager.getFavoriteBeanByID(it.bean.videoId)
|
||||||
App.appFavoriteDBManager.getFavoriteBeanByID(it.bean.videoId)
|
|
||||||
if (currentFavoriteBean != null) {
|
if (currentFavoriteBean != null) {
|
||||||
App.appFavoriteDBManager.updateFavoriteBean(it.bean)
|
currentFavoriteBean.isFavorite = it.bean.isFavorite
|
||||||
|
App.appFavoriteDBManager.updateFavoriteBean(currentFavoriteBean)//更新数据库
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
is Request.OnDownload -> {
|
is Request.OnDownload -> {
|
||||||
val id = it.favoriteBean.videoId
|
val id = it.bean.videoId
|
||||||
LogTag.LogD(TAG, "OnDownload id->${id}")
|
LogTag.LogD(TAG, "OnDownload id->${id}")
|
||||||
val currentOfflineBean = App.appOfflineDBManager.getOfflineBeanByID(id)
|
val currentOfflineBean = App.appOfflineDBManager.getOfflineBeanByID(id)
|
||||||
if (currentOfflineBean != null && currentOfflineBean.bytesDownloaded?.let { bytes -> bytes > 0 } == true) {//判断当前数据库是否有这条数据。
|
if (currentOfflineBean != null && currentOfflineBean.bytesDownloaded?.let { bytes -> bytes > 0 } == true) {//判断当前数据库是否有这条数据。
|
||||||
if (currentPosition >= 0) {
|
showRemoveDownloadDialogHint(it.bean)
|
||||||
val videoId = favoriteBeans[currentPosition].videoId
|
|
||||||
showRemoveDownloadDialogHint(videoId)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
//判断是否已经下载了这条数据,已经下载,就直接进行数据库数据存储,反之走下载流程。
|
//判断是否已经下载了这条数据,已经下载,就直接进行数据库数据存储,反之走下载流程。
|
||||||
if (DownloadUtil.downloadResourceExist(id)) {
|
if (DownloadUtil.downloadResourceExist(id)) {
|
||||||
insertOfflineData(it.favoriteBean)
|
insertOfflineData(FavoriteBean(
|
||||||
requests.trySend(Request.OnUpdateDownloadUi(id))
|
videoId = it.bean.videoId,
|
||||||
|
title = it.bean.title,
|
||||||
|
name = it.bean.name,
|
||||||
|
thumbnail = it.bean.thumbnail,
|
||||||
|
isFavorite = it.bean.isFavorite
|
||||||
|
))
|
||||||
|
it.bean.isOffline = true
|
||||||
|
requests.trySend(Request.OnUpdateDownloadUi(it.bean))
|
||||||
|
requests.trySend(Request.OnUpdateCurrentListItem(it.bean))
|
||||||
} else {
|
} else {
|
||||||
val downloadRequest = DownloadRequest.Builder(id, id.toUri())
|
val downloadRequest = DownloadRequest.Builder(id, id.toUri())
|
||||||
.setCustomCacheKey(id).build()
|
.setCustomCacheKey(id).build()
|
||||||
@ -153,10 +150,16 @@ class MoLikedSongsActivity : MoBaseActivity(), LikedSongsAdapter.OnItemFavorites
|
|||||||
this@MoLikedSongsActivity, AdPlacement.INST_DOWNLOAD
|
this@MoLikedSongsActivity, AdPlacement.INST_DOWNLOAD
|
||||||
)
|
)
|
||||||
|
|
||||||
insertOfflineData(it.favoriteBean)
|
insertOfflineData(FavoriteBean(
|
||||||
|
videoId = it.bean.videoId,
|
||||||
|
title = it.bean.title,
|
||||||
|
name = it.bean.name,
|
||||||
|
thumbnail = it.bean.thumbnail,
|
||||||
|
isFavorite = it.bean.isFavorite
|
||||||
|
))
|
||||||
val jsonObject = JSONObject()
|
val jsonObject = JSONObject()
|
||||||
jsonObject.put(
|
jsonObject.put(
|
||||||
"download_id", "${it.favoriteBean.videoId}"
|
"download_id", it.bean.videoId
|
||||||
)
|
)
|
||||||
val songMap = mutableMapOf(
|
val songMap = mutableMapOf(
|
||||||
Pair(
|
Pair(
|
||||||
@ -176,36 +179,33 @@ class MoLikedSongsActivity : MoBaseActivity(), LikedSongsAdapter.OnItemFavorites
|
|||||||
}
|
}
|
||||||
|
|
||||||
is Request.OnDownloadRemove -> {
|
is Request.OnDownloadRemove -> {
|
||||||
LogTag.LogD(TAG, "OnDownloadRemove id->${it.id}")
|
|
||||||
val currentOfflineBean =
|
val currentOfflineBean =
|
||||||
App.appOfflineDBManager.getOfflineBeanByID(it.id)
|
App.appOfflineDBManager.getOfflineBeanByID(it.bean.videoId)
|
||||||
if (currentOfflineBean != null) {
|
if (currentOfflineBean != null) {
|
||||||
App.appOfflineDBManager.deleteOfflineBean(currentOfflineBean)
|
App.appOfflineDBManager.deleteOfflineBean(currentOfflineBean)
|
||||||
|
it.bean.isOffline = false
|
||||||
}
|
}
|
||||||
|
requests.trySend(Request.OnUpdateDownloadUi(it.bean))
|
||||||
requests.trySend(Request.OnUpdateDownloadUi(it.id))
|
requests.trySend(Request.OnUpdateCurrentListItem(it.bean))
|
||||||
}
|
}
|
||||||
|
|
||||||
is Request.OnUpdateDownloadUi -> {
|
is Request.OnUpdateDownloadUi -> {
|
||||||
val offBean = App.appOfflineDBManager.getOfflineBeanByID(it.id)
|
moreDialog?.updateDownloadBtnUi(it.bean.isOffline)
|
||||||
if (offBean != null && offBean.bytesDownloaded?.let { bytes -> bytes > 0 } == true) {
|
|
||||||
binding.downloadLoading.visibility = View.GONE
|
|
||||||
binding.downloadImg.visibility = View.VISIBLE
|
|
||||||
binding.downloadImg.setImageResource(R.drawable.more_downloaded_icon)
|
|
||||||
binding.downloadTv.text =
|
|
||||||
getString(R.string.download_remove_offline)
|
|
||||||
LogTag.LogD(TAG,"like OnUpdateDownloadUi 1111")
|
|
||||||
} else {
|
|
||||||
binding.downloadLoading.visibility = View.GONE
|
|
||||||
binding.downloadImg.visibility = View.VISIBLE
|
|
||||||
binding.downloadImg.setImageResource(R.drawable.more_download_icon)
|
|
||||||
binding.downloadTv.text = getString(R.string.download_save_offline)
|
|
||||||
LogTag.LogD(TAG,"like OnUpdateDownloadUi 2222")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
is Request.OnAddPlaylist -> {
|
is Request.OnAddPlaylist -> {
|
||||||
showAddPlaylistBottomDialog(it.bean)
|
showAddPlaylistBottomDialog(FavoriteBean(
|
||||||
|
videoId = it.bean.videoId,
|
||||||
|
title = it.bean.title,
|
||||||
|
name = it.bean.name,
|
||||||
|
thumbnail = it.bean.thumbnail,
|
||||||
|
isFavorite = it.bean.isFavorite
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
is Request.OnUpdateCurrentListItem -> {
|
||||||
|
//更新数据集合当前的item数据
|
||||||
|
updateCurrentItem(it.bean.videoId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,38 +246,15 @@ class MoLikedSongsActivity : MoBaseActivity(), LikedSongsAdapter.OnItemFavorites
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initView() {
|
private fun initView() {
|
||||||
binding.layoutInfo.setOnClickListener { }
|
|
||||||
binding.backBtn.setOnClickListener {
|
binding.backBtn.setOnClickListener {
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
binding.tryAgainBtn.setOnClickListener {
|
binding.tryAgainBtn.setOnClickListener {
|
||||||
requests.trySend(Request.TryAgain)
|
requests.trySend(Request.TryAgain)
|
||||||
}
|
}
|
||||||
binding.bottomCloseBtn.setOnClickListener {
|
|
||||||
hideBottomLayout()
|
|
||||||
}
|
|
||||||
binding.bottomBlankLayout.setOnClickListener {
|
|
||||||
hideBottomLayout()
|
|
||||||
}
|
|
||||||
binding.favoritesBtn.setOnClickListener {
|
|
||||||
if (currentPosition >= 0) {
|
|
||||||
requests.trySend(Request.OnFavorites(favoriteBeans[currentPosition]))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
binding.moreDownloadBtn.setOnClickListener {
|
|
||||||
if (currentPosition >= 0) {
|
|
||||||
requests.trySend(Request.OnDownload(favoriteBeans[currentPosition]))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
binding.moreAddPlaylistBtn.setOnClickListener {
|
|
||||||
if (currentPosition >= 0) {
|
|
||||||
requests.trySend(Request.OnAddPlaylist(favoriteBeans[currentPosition]))
|
|
||||||
hideBottomLayout()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showRemoveDownloadDialogHint(id: String) {
|
private fun showRemoveDownloadDialogHint(bean: PlaylistItem) {
|
||||||
val inflater = LayoutInflater.from(this)
|
val inflater = LayoutInflater.from(this)
|
||||||
val dialogView = inflater.inflate(R.layout.dialog_hint, null)
|
val dialogView = inflater.inflate(R.layout.dialog_hint, null)
|
||||||
val okBtn = dialogView.findViewById<TextView>(R.id.dialog_ok_btn)
|
val okBtn = dialogView.findViewById<TextView>(R.id.dialog_ok_btn)
|
||||||
@ -288,7 +265,7 @@ class MoLikedSongsActivity : MoBaseActivity(), LikedSongsAdapter.OnItemFavorites
|
|||||||
dialog.show()
|
dialog.show()
|
||||||
okBtn.setOnClickListener {
|
okBtn.setOnClickListener {
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
requests.trySend(Request.OnDownloadRemove(id))
|
requests.trySend(Request.OnDownloadRemove(bean))
|
||||||
}
|
}
|
||||||
cancelBtn.setOnClickListener {
|
cancelBtn.setOnClickListener {
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
@ -296,7 +273,7 @@ class MoLikedSongsActivity : MoBaseActivity(), LikedSongsAdapter.OnItemFavorites
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initAdapter() {
|
private fun initAdapter() {
|
||||||
adapter = LikedSongsAdapter(this, favoriteBeans)
|
adapter = LikedSongsAdapter(this, myList)
|
||||||
adapter?.setOnFavoritesItemClickListener(this)
|
adapter?.setOnFavoritesItemClickListener(this)
|
||||||
adapter?.setOnMoreClickListener(this)
|
adapter?.setOnMoreClickListener(this)
|
||||||
binding.rv.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
|
binding.rv.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)
|
||||||
@ -304,182 +281,82 @@ class MoLikedSongsActivity : MoBaseActivity(), LikedSongsAdapter.OnItemFavorites
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onFavoritesItemClick(position: Int) {
|
override fun onFavoritesItemClick(position: Int) {
|
||||||
requests.trySend(Request.OnFavorites(favoriteBeans[position]))
|
requests.trySend(Request.OnFavorites(myList[position]))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMoreClick(position: Int) {
|
override fun onMoreClick(position: Int) {
|
||||||
currentPosition = position
|
moreDialog = ListMoreBottomSheetDialog(
|
||||||
if (!isAnimationRunning) {
|
this@MoLikedSongsActivity,
|
||||||
toggleBottomLayout(position)
|
myList[position],
|
||||||
}
|
this@MoLikedSongsActivity,
|
||||||
}
|
this@MoLikedSongsActivity
|
||||||
|
)
|
||||||
private fun initDownloadFlow() {
|
moreDialog?.setListMoreViewListener(this@MoLikedSongsActivity)
|
||||||
ViewModelMain.modelDownloadsFlow.observe(this) { downloads ->
|
moreDialog?.show()
|
||||||
if (currentPosition >= 0) {
|
|
||||||
val id = favoriteBeans[currentPosition].videoId
|
|
||||||
val currentScreenDownloads = downloads[id]
|
|
||||||
if (currentScreenDownloads != null) {
|
|
||||||
updateDownloadUI(currentScreenDownloads)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun updateDownloadUI(download: Download) {
|
|
||||||
LogTag.LogD(TAG,"like updateDownloadUI download-${download.state}")
|
|
||||||
when (download.state) {
|
|
||||||
Download.STATE_DOWNLOADING -> {
|
|
||||||
binding.downloadLoading.visibility = View.VISIBLE
|
|
||||||
binding.downloadImg.setImageResource(R.drawable.more_download_icon)
|
|
||||||
binding.downloadImg.visibility = View.GONE
|
|
||||||
|
|
||||||
binding.downloadTv.text = getString(R.string.download_saving)
|
|
||||||
|
|
||||||
binding.moreDownloadBtn.isClickable = false
|
|
||||||
binding.moreDownloadBtn.isEnabled = false
|
|
||||||
}
|
|
||||||
|
|
||||||
Download.STATE_COMPLETED -> {
|
|
||||||
binding.downloadLoading.visibility = View.GONE
|
|
||||||
binding.downloadImg.setImageResource(R.drawable.more_downloaded_icon)
|
|
||||||
binding.downloadImg.visibility = View.VISIBLE
|
|
||||||
|
|
||||||
binding.downloadTv.text = getString(R.string.download_remove_offline)
|
|
||||||
|
|
||||||
binding.moreDownloadBtn.isClickable = true
|
|
||||||
binding.moreDownloadBtn.isEnabled = true
|
|
||||||
|
|
||||||
val jsonObject = JSONObject()
|
|
||||||
jsonObject.put(
|
|
||||||
"download_id", download.request.id
|
|
||||||
)
|
|
||||||
val songMap = mutableMapOf(
|
|
||||||
Pair(
|
|
||||||
AnalysisUtil.PARAM_VALUE, jsonObject.toString()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
AnalysisUtil.logEvent(AnalysisUtil.PLAYER_B_DOWNLOAD_SUCCESS_ACTION, songMap)
|
|
||||||
}
|
|
||||||
|
|
||||||
Download.STATE_FAILED -> {
|
|
||||||
binding.downloadLoading.visibility = View.GONE
|
|
||||||
binding.downloadImg.setImageResource(R.drawable.error)
|
|
||||||
binding.downloadImg.visibility = View.VISIBLE
|
|
||||||
|
|
||||||
binding.downloadTv.text = getString(R.string.download_save_offline)
|
|
||||||
|
|
||||||
binding.moreDownloadBtn.isClickable = true
|
|
||||||
binding.moreDownloadBtn.isEnabled = true
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
binding.downloadLoading.visibility = View.GONE
|
|
||||||
binding.downloadImg.setImageResource(R.drawable.more_download_icon)
|
|
||||||
binding.downloadImg.visibility = View.VISIBLE
|
|
||||||
|
|
||||||
binding.downloadTv.text = getString(R.string.download_save_offline)
|
|
||||||
|
|
||||||
binding.moreDownloadBtn.isClickable = true
|
|
||||||
binding.moreDownloadBtn.isEnabled = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateFavoriteUi(b: Boolean) {
|
private fun updateFavoriteUi(b: Boolean) {
|
||||||
if (b) {
|
if (moreDialog != null) {
|
||||||
binding.favoritesImg.setImageResource(R.drawable.favorited_icon)
|
moreDialog?.updateFavoriteUi(b)
|
||||||
} else {
|
|
||||||
binding.favoritesImg.setImageResource(R.drawable.not_favorited_icon)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleBottomLayout(position: Int) {
|
private suspend fun updateCurrentItem(id: String) {
|
||||||
if (binding.bottomLayout.visibility == View.VISIBLE) {
|
//更新当前界面的数据集合
|
||||||
hideBottomLayout()
|
myList.forEach { item ->
|
||||||
} else {
|
if (item.videoId == id) {
|
||||||
showBottomLayout(position)
|
val favoriteBean = App.appFavoriteDBManager.getFavoriteBeanByID(item.videoId)
|
||||||
|
val offlineBean = App.appOfflineDBManager.getOfflineBeanByID(item.videoId)
|
||||||
|
item.isFavorite = favoriteBean?.isFavorite ?: false
|
||||||
|
item.isOffline = offlineBean?.isOffline ?: false
|
||||||
|
item.bytesDownloaded = offlineBean?.bytesDownloaded
|
||||||
|
item.size = offlineBean?.size
|
||||||
|
}
|
||||||
|
}
|
||||||
|
myList.forEach { item ->
|
||||||
|
if (item.videoId == id) {
|
||||||
|
LogTag.LogD(TAG, "updateCurrentItem -> $item")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showBottomLayout(position: Int) {
|
override fun onFavoritesClicked(playlistItem: PlaylistItem) {
|
||||||
val slideUpAnimation = AnimationUtils.loadAnimation(this, R.anim.slide_up)
|
requests.trySend(Request.OnFavorites(playlistItem))
|
||||||
slideUpAnimation.setAnimationListener(object : Animation.AnimationListener {
|
|
||||||
override fun onAnimationStart(animation: Animation) {
|
|
||||||
isAnimationRunning = true
|
|
||||||
// 动画开始时禁用按钮
|
|
||||||
animationLoadingNotClick(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onAnimationEnd(animation: Animation) {
|
|
||||||
isAnimationRunning = false
|
|
||||||
// 动画结束时启用按钮
|
|
||||||
animationLoadingNotClick(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onAnimationRepeat(animation: Animation) {
|
|
||||||
// 可选:处理动画重复的情况
|
|
||||||
}
|
|
||||||
})
|
|
||||||
binding.bottomLayout.startAnimation(slideUpAnimation)
|
|
||||||
binding.bottomLayout.visibility = View.VISIBLE
|
|
||||||
|
|
||||||
val bean = favoriteBeans[position]
|
|
||||||
Glide.with(this).load(bean.thumbnail).into(binding.songImg)
|
|
||||||
binding.title.text = bean.title
|
|
||||||
if (bean.name.isEmpty()) {
|
|
||||||
binding.name.visibility = View.GONE
|
|
||||||
} else {
|
|
||||||
binding.name.visibility = View.VISIBLE
|
|
||||||
binding.name.text = bean.name
|
|
||||||
}
|
|
||||||
requests.trySend(Request.UpdateFavorite(bean))
|
|
||||||
|
|
||||||
val currentDownload = DownloadUtil.getCurrentIdDownload(bean.videoId)
|
|
||||||
if (currentDownload != null) {
|
|
||||||
//是否下载过资源,下载过资源就不走download的ui更新,因为 它肯定状态为3
|
|
||||||
if(DownloadUtil.downloadResourceExist(bean.videoId)){
|
|
||||||
requests.trySend(Request.OnUpdateDownloadUi(bean.videoId))
|
|
||||||
}else{
|
|
||||||
updateDownloadUI(currentDownload)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
requests.trySend(Request.OnUpdateDownloadUi(bean.videoId))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun hideBottomLayout() {
|
override fun onDownloadClicked(playlistItem: PlaylistItem) {
|
||||||
val slideDownAnimation = AnimationUtils.loadAnimation(this, R.anim.slide_down)
|
requests.trySend(Request.OnDownload(playlistItem))
|
||||||
slideDownAnimation.setAnimationListener(object : Animation.AnimationListener {
|
}
|
||||||
override fun onAnimationStart(animation: Animation?) {
|
|
||||||
isAnimationRunning = true
|
|
||||||
animationLoadingNotClick(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onAnimationEnd(animation: Animation?) {
|
override fun onAddToPlaylistClicked(playlistItem: PlaylistItem) {
|
||||||
isAnimationRunning = false
|
requests.trySend(Request.OnAddPlaylist(playlistItem))
|
||||||
animationLoadingNotClick(true)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun onAnimationRepeat(animation: Animation?) {
|
override fun onUpdateAdapterListener(download: Download, playlistItem: PlaylistItem) {
|
||||||
}
|
requests.trySend(Request.OnUpdateCurrentListItem(playlistItem))
|
||||||
})
|
|
||||||
binding.bottomLayout.startAnimation(slideDownAnimation)
|
|
||||||
binding.bottomLayout.visibility = View.GONE
|
|
||||||
|
|
||||||
//隐藏布局后则,解除点击限制
|
|
||||||
binding.moreDownloadBtn.isClickable = true
|
|
||||||
binding.moreDownloadBtn.isEnabled = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NotifyDataSetChanged")
|
@SuppressLint("NotifyDataSetChanged")
|
||||||
private suspend fun initData() {
|
private suspend fun initData() {
|
||||||
showLoadingUi()
|
showLoadingUi()
|
||||||
favoriteBeans.clear()
|
|
||||||
val beans = App.appFavoriteDBManager.getAllFavoriteBeans()
|
val beans = App.appFavoriteDBManager.getAllFavoriteBeans()
|
||||||
val filteredBeans = beans.filter { it.isFavorite }
|
val filteredBeans = beans.filter { it.isFavorite }
|
||||||
favoriteBeans.addAll(filteredBeans)
|
if (filteredBeans.isNotEmpty()) {
|
||||||
if (favoriteBeans.size > 0) {
|
myList.clear()
|
||||||
|
filteredBeans.forEach { favoriteItem->
|
||||||
|
val offlineBean = App.appOfflineDBManager.getOfflineBeanByID(favoriteItem.videoId)
|
||||||
|
myList.add(PlaylistItem(
|
||||||
|
videoId = favoriteItem.videoId,
|
||||||
|
title = favoriteItem.title,
|
||||||
|
name = favoriteItem.name,
|
||||||
|
thumbnail = favoriteItem.thumbnail,
|
||||||
|
isOffline = offlineBean?.isOffline ?: false,
|
||||||
|
isFavorite = favoriteItem.isFavorite,
|
||||||
|
bytesDownloaded = offlineBean?.bytesDownloaded,
|
||||||
|
size = offlineBean?.size
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
showDataUi()
|
showDataUi()
|
||||||
} else {
|
} else {
|
||||||
showNoContentUi()
|
showNoContentUi()
|
||||||
@ -489,16 +366,6 @@ class MoLikedSongsActivity : MoBaseActivity(), LikedSongsAdapter.OnItemFavorites
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun animationLoadingNotClick(b: Boolean) {
|
|
||||||
binding.layoutInfo.isClickable = b
|
|
||||||
binding.bottomCloseBtn.isClickable = b
|
|
||||||
binding.bottomBlankLayout.isClickable = b
|
|
||||||
binding.moreDownloadBtn.isClickable = b
|
|
||||||
binding.moreAddPlaylistBtn.isClickable = b
|
|
||||||
binding.favoritesBtn.isClickable = b
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private fun showDataUi() {
|
private fun showDataUi() {
|
||||||
binding.loadingLayout.visibility = View.GONE
|
binding.loadingLayout.visibility = View.GONE
|
||||||
binding.noContentLayout.visibility = View.GONE
|
binding.noContentLayout.visibility = View.GONE
|
||||||
|
|||||||
@ -12,12 +12,13 @@ import melody.offline.music.R
|
|||||||
import melody.offline.music.activity.MoLikedSongsActivity
|
import melody.offline.music.activity.MoLikedSongsActivity
|
||||||
import melody.offline.music.activity.MoPlayDetailsActivity
|
import melody.offline.music.activity.MoPlayDetailsActivity
|
||||||
import melody.offline.music.bean.FavoriteBean
|
import melody.offline.music.bean.FavoriteBean
|
||||||
|
import melody.offline.music.bean.PlaylistItem
|
||||||
import melody.offline.music.databinding.LikedListItemBinding
|
import melody.offline.music.databinding.LikedListItemBinding
|
||||||
import melody.offline.music.media.MediaControllerManager
|
import melody.offline.music.media.MediaControllerManager
|
||||||
|
|
||||||
class LikedSongsAdapter(
|
class LikedSongsAdapter(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
private val list: List<FavoriteBean>,
|
private val list: List<PlaylistItem>,
|
||||||
) :
|
) :
|
||||||
RecyclerView.Adapter<LikedSongsAdapter.ViewHolder>() {
|
RecyclerView.Adapter<LikedSongsAdapter.ViewHolder>() {
|
||||||
|
|
||||||
@ -59,7 +60,7 @@ class LikedSongsAdapter(
|
|||||||
RecyclerView.ViewHolder(binding.root) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
@SuppressLint("SetTextI18n")
|
||||||
fun bind(bean: FavoriteBean) {
|
fun bind(bean: PlaylistItem) {
|
||||||
|
|
||||||
binding.apply {
|
binding.apply {
|
||||||
Glide.with(context)
|
Glide.with(context)
|
||||||
|
|||||||
@ -154,198 +154,4 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/bottom_layout"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_alignParentBottom="true"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:visibility="gone">
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:id="@+id/bottom_blank_layout"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_marginTop="68dp"
|
|
||||||
android:layout_weight="3" />
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/layout_info"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:background="@drawable/drw_bottom_layout_bg"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:paddingBottom="32dp"
|
|
||||||
android:visibility="visible">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/bottomCloseBtn"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="32dp"
|
|
||||||
android:gravity="center">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="30dp"
|
|
||||||
android:layout_height="4dp"
|
|
||||||
android:background="@drawable/drw_bottom_close_btn_bg"
|
|
||||||
android:gravity="center" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:paddingStart="18dp"
|
|
||||||
android:paddingEnd="18dp">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<androidx.cardview.widget.CardView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:elevation="0dp"
|
|
||||||
app:cardBackgroundColor="@color/transparent"
|
|
||||||
app:cardCornerRadius="10dp"
|
|
||||||
app:cardElevation="0dp">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/songImg"
|
|
||||||
android:layout_width="50dp"
|
|
||||||
android:layout_height="50dp"
|
|
||||||
android:src="@mipmap/app_logo" />
|
|
||||||
|
|
||||||
</androidx.cardview.widget.CardView>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_marginStart="12dp"
|
|
||||||
android:layout_marginEnd="12dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<melody.offline.music.view.MarqueeTextView
|
|
||||||
android:id="@+id/title"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:fontFamily="@font/regular_font"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:text="@string/app_name"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textSize="14dp" />
|
|
||||||
|
|
||||||
<melody.offline.music.view.MarqueeTextView
|
|
||||||
android:id="@+id/name"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:fontFamily="@font/regular_font"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:text="@string/app_name"
|
|
||||||
android:textColor="@color/white_60"
|
|
||||||
android:textSize="12dp" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/favoritesBtn"
|
|
||||||
android:layout_width="32dp"
|
|
||||||
android:layout_height="32dp"
|
|
||||||
android:background="@drawable/drw_round_48_bg"
|
|
||||||
android:gravity="center">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/favoritesImg"
|
|
||||||
android:layout_width="16dp"
|
|
||||||
android:layout_height="16dp"
|
|
||||||
android:src="@drawable/not_favorited_icon" />
|
|
||||||
</LinearLayout>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<View
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="1dp"
|
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:background="@color/liner_color" />
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/moreDownloadBtn"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="48dp"
|
|
||||||
android:layout_marginTop="4dp"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<RelativeLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:id="@+id/downloadImg"
|
|
||||||
android:layout_width="24dp"
|
|
||||||
android:layout_height="24dp"
|
|
||||||
android:src="@drawable/more_download_icon" />
|
|
||||||
|
|
||||||
<ProgressBar
|
|
||||||
android:id="@+id/downloadLoading"
|
|
||||||
android:layout_width="24dp"
|
|
||||||
android:layout_height="24dp"
|
|
||||||
android:indeterminateTint="@color/green"
|
|
||||||
android:progressBackgroundTint="@color/green"
|
|
||||||
android:progressTint="@color/green"
|
|
||||||
android:visibility="gone" />
|
|
||||||
|
|
||||||
|
|
||||||
</RelativeLayout>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/downloadTv"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="12dp"
|
|
||||||
android:text="@string/download_save_offline"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textSize="14dp" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/moreAddPlaylistBtn"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="48dp"
|
|
||||||
android:layout_marginTop="4dp"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<ImageView
|
|
||||||
android:layout_width="24dp"
|
|
||||||
android:layout_height="24dp"
|
|
||||||
android:src="@drawable/more_add_playlist_icon" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/addPlaylistTv"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="12dp"
|
|
||||||
android:text="@string/add_to_playlist"
|
|
||||||
android:textColor="@color/white"
|
|
||||||
android:textSize="14dp" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
</LinearLayout>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user