From 695e8d0de2ad758aa6c27fceabe31a388c60cfe4 Mon Sep 17 00:00:00 2001 From: Moriafly <62319450+Moriafly@users.noreply.github.com> Date: Sun, 24 Jan 2021 09:54:55 +0800 Subject: [PATCH] v1.4.0-beta-290 --- app/build.gradle | 2 +- app/src/main/AndroidManifest.xml | 3 + .../music/ui/activity/PlayerActivity.kt | 59 ++----- .../music/ui/activity/PlaylistActivity2.kt | 167 ++++++++++++++++++ .../com/dirror/music/ui/base/BaseActivity.kt | 27 +++ .../{dialog => base}/BaseBottomSheetDialog.kt | 2 +- .../dirror/music/ui/dialog/AppInfoDialog.kt | 1 + .../ui/dialog/CreateLocalPlaylistDialog.kt | 1 + .../music/ui/dialog/PlayerMenuMoreDialog.kt | 2 +- .../dirror/music/ui/dialog/PlaylistDialog.kt | 1 + .../dirror/music/ui/dialog/SongMenuDialog.kt | 1 + .../dirror/music/ui/fragment/MyFragment.kt | 10 +- .../music/ui/viewmodel/MyFragmentViewModel.kt | 24 +-- .../music/ui/viewmodel/PlaylistViewModel.kt | 47 +++++ 14 files changed, 289 insertions(+), 58 deletions(-) create mode 100644 app/src/main/java/com/dirror/music/ui/activity/PlaylistActivity2.kt create mode 100644 app/src/main/java/com/dirror/music/ui/base/BaseActivity.kt rename app/src/main/java/com/dirror/music/ui/{dialog => base}/BaseBottomSheetDialog.kt (95%) create mode 100644 app/src/main/java/com/dirror/music/ui/viewmodel/PlaylistViewModel.kt diff --git a/app/build.gradle b/app/build.gradle index 91235416..45f6a33c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -29,7 +29,7 @@ android { applicationId "com.dirror.music" minSdkVersion 23 targetSdkVersion 30 - versionCode 289 + versionCode 290 versionName "2.4.0-beta" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index bc0f4c4b..29a171ce 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -54,6 +54,9 @@ + + binding.includePlay.tvName.text = standardSongData.name + binding.includePlay.tvArtist.text = standardSongData.artists?.let { parseArtist(it) } + SongPicture.getSongPicture(standardSongData, SongPicture.TYPE_LARGE) { + binding.includePlay.ivCover.setImageBitmap(it) + } + } + } + + override fun onStart() { + super.onStart() + refreshLayoutPlay() + refreshPlayState() + } + + override fun onDestroy() { + super.onDestroy() + // 解绑 + unregisterReceiver(musicBroadcastReceiver) + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/dirror/music/ui/base/BaseActivity.kt b/app/src/main/java/com/dirror/music/ui/base/BaseActivity.kt new file mode 100644 index 00000000..ec87249d --- /dev/null +++ b/app/src/main/java/com/dirror/music/ui/base/BaseActivity.kt @@ -0,0 +1,27 @@ +package com.dirror.music.ui.base + +import android.os.Bundle +import androidx.appcompat.app.AppCompatActivity + +abstract class BaseActivity: AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + initBinding() + initView() + initListener() + initObserver() + initBroadcastReceiver() + } + + protected open fun initBinding() { } + + protected open fun initView() { } + + protected open fun initListener() { } + + protected open fun initObserver() { } + + protected open fun initBroadcastReceiver() { } + +} \ No newline at end of file diff --git a/app/src/main/java/com/dirror/music/ui/dialog/BaseBottomSheetDialog.kt b/app/src/main/java/com/dirror/music/ui/base/BaseBottomSheetDialog.kt similarity index 95% rename from app/src/main/java/com/dirror/music/ui/dialog/BaseBottomSheetDialog.kt rename to app/src/main/java/com/dirror/music/ui/base/BaseBottomSheetDialog.kt index 9dd8aa27..70966fa4 100644 --- a/app/src/main/java/com/dirror/music/ui/dialog/BaseBottomSheetDialog.kt +++ b/app/src/main/java/com/dirror/music/ui/base/BaseBottomSheetDialog.kt @@ -1,4 +1,4 @@ -package com.dirror.music.ui.dialog +package com.dirror.music.ui.base import android.content.Context import android.os.Bundle diff --git a/app/src/main/java/com/dirror/music/ui/dialog/AppInfoDialog.kt b/app/src/main/java/com/dirror/music/ui/dialog/AppInfoDialog.kt index 1ef21b96..c6a10722 100644 --- a/app/src/main/java/com/dirror/music/ui/dialog/AppInfoDialog.kt +++ b/app/src/main/java/com/dirror/music/ui/dialog/AppInfoDialog.kt @@ -7,6 +7,7 @@ import com.dirror.music.MyApplication import com.dirror.music.databinding.DialogTextInfoBinding import com.dirror.music.foyou.sentence.foyoulibrary.FoyouLibrary import com.dirror.music.room.AppDatabase +import com.dirror.music.ui.base.BaseBottomSheetDialog import com.dirror.music.util.Secure import com.dirror.music.util.defaultTypeface import com.dirror.music.util.getVisionCode diff --git a/app/src/main/java/com/dirror/music/ui/dialog/CreateLocalPlaylistDialog.kt b/app/src/main/java/com/dirror/music/ui/dialog/CreateLocalPlaylistDialog.kt index 829961e8..726931cf 100644 --- a/app/src/main/java/com/dirror/music/ui/dialog/CreateLocalPlaylistDialog.kt +++ b/app/src/main/java/com/dirror/music/ui/dialog/CreateLocalPlaylistDialog.kt @@ -3,6 +3,7 @@ package com.dirror.music.ui.dialog import android.content.Context import com.dirror.music.databinding.DialogCreateLocalPlaylistBinding import com.dirror.music.music.local.LocalPlaylist +import com.dirror.music.ui.base.BaseBottomSheetDialog import com.dirror.music.util.toast /** diff --git a/app/src/main/java/com/dirror/music/ui/dialog/PlayerMenuMoreDialog.kt b/app/src/main/java/com/dirror/music/ui/dialog/PlayerMenuMoreDialog.kt index e6d183dc..5c553b2a 100644 --- a/app/src/main/java/com/dirror/music/ui/dialog/PlayerMenuMoreDialog.kt +++ b/app/src/main/java/com/dirror/music/ui/dialog/PlayerMenuMoreDialog.kt @@ -8,7 +8,7 @@ import com.dirror.music.music.local.MyFavorite import com.dirror.music.music.standard.data.StandardSongData import com.dirror.music.ui.activity.FeedbackActivity import com.dirror.music.ui.activity.PlayHistoryActivity -import com.dirror.music.util.toast +import com.dirror.music.ui.base.BaseBottomSheetDialog class PlayerMenuMoreDialog(context: Context) : BaseBottomSheetDialog(context) { diff --git a/app/src/main/java/com/dirror/music/ui/dialog/PlaylistDialog.kt b/app/src/main/java/com/dirror/music/ui/dialog/PlaylistDialog.kt index 8f7d3ce7..c7d3f399 100644 --- a/app/src/main/java/com/dirror/music/ui/dialog/PlaylistDialog.kt +++ b/app/src/main/java/com/dirror/music/ui/dialog/PlaylistDialog.kt @@ -6,6 +6,7 @@ import com.dirror.music.MyApplication import com.dirror.music.R import com.dirror.music.adapter.PlaylistDialogAdapter import com.dirror.music.databinding.DialogPlayListBinding +import com.dirror.music.ui.base.BaseBottomSheetDialog class PlaylistDialog(context: Context): BaseBottomSheetDialog(context) { diff --git a/app/src/main/java/com/dirror/music/ui/dialog/SongMenuDialog.kt b/app/src/main/java/com/dirror/music/ui/dialog/SongMenuDialog.kt index 4b01669f..bfc51d08 100644 --- a/app/src/main/java/com/dirror/music/ui/dialog/SongMenuDialog.kt +++ b/app/src/main/java/com/dirror/music/ui/dialog/SongMenuDialog.kt @@ -8,6 +8,7 @@ import com.dirror.music.data.PLAYLIST_TAG_NORMAL import com.dirror.music.databinding.DialogSongMenuBinding import com.dirror.music.music.local.MyFavorite import com.dirror.music.music.standard.data.StandardSongData +import com.dirror.music.ui.base.BaseBottomSheetDialog import com.dirror.music.util.toast class SongMenuDialog diff --git a/app/src/main/java/com/dirror/music/ui/fragment/MyFragment.kt b/app/src/main/java/com/dirror/music/ui/fragment/MyFragment.kt index 7ce840d3..c1f7d193 100644 --- a/app/src/main/java/com/dirror/music/ui/fragment/MyFragment.kt +++ b/app/src/main/java/com/dirror/music/ui/fragment/MyFragment.kt @@ -13,6 +13,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.dirror.music.MyApplication import com.dirror.music.adapter.PlaylistAdapter +import com.dirror.music.data.PLAYLIST_TAG_MY_FAVORITE import com.dirror.music.data.PlaylistData import com.dirror.music.databinding.FragmentMyBinding import com.dirror.music.music.standard.data.SOURCE_LOCAL @@ -20,6 +21,7 @@ import com.dirror.music.music.standard.data.StandardLocalPlaylistData import com.dirror.music.ui.activity.LocalMusicActivity import com.dirror.music.ui.activity.PlayHistoryActivity import com.dirror.music.ui.activity.PlaylistActivity +import com.dirror.music.ui.activity.PlaylistActivity2 import com.dirror.music.ui.viewmodel.MainViewModel import com.dirror.music.ui.viewmodel.MyFragmentViewModel import com.dirror.music.util.* @@ -57,9 +59,11 @@ class MyFragment : Fragment() { binding.apply { // 我喜欢的音乐 clMyFavorite.setOnClickListener { - val intent = Intent(this@MyFragment.context, PlaylistActivity::class.java) - intent.putExtra(PlaylistActivity.EXTRA_PLAYLIST_SOURCE, SOURCE_LOCAL) - intent.putExtra(PlaylistActivity.EXTRA_LONG_PLAYLIST_ID, 0L) + val intent = Intent(this@MyFragment.context, PlaylistActivity2::class.java).apply { + putExtra(PlaylistActivity2.EXTRA_PLAYLIST_SOURCE, SOURCE_LOCAL) + putExtra(PlaylistActivity2.EXTRA_LONG_PLAYLIST_ID, 0L) + putExtra(PlaylistActivity2.EXTRA_INT_TAG, PLAYLIST_TAG_MY_FAVORITE) + } startActivity(intent) } // 新建歌单 diff --git a/app/src/main/java/com/dirror/music/ui/viewmodel/MyFragmentViewModel.kt b/app/src/main/java/com/dirror/music/ui/viewmodel/MyFragmentViewModel.kt index ebdb62ad..b537df9e 100644 --- a/app/src/main/java/com/dirror/music/ui/viewmodel/MyFragmentViewModel.kt +++ b/app/src/main/java/com/dirror/music/ui/viewmodel/MyFragmentViewModel.kt @@ -37,17 +37,19 @@ class MyFragmentViewModel : ViewModel() { val url = "${CloudMusicApi.USER_PLAYLIST}?limit=30&offset=${offset * 30}&uid=${uid}" loge(url, "myFragment") MagicHttp.OkHttpManager().newGet(url, { - val userPlaylistData = Gson().fromJson(it, UserPlaylistData::class.java) - for (playlist in userPlaylistData.playlist) { - _userPlaylistList.add(playlist) - } - if (userPlaylistData.more && offset < 3) { - offset++ - updatePlaylist() - } else { - offset = 0 - runOnMainThread { - userPlaylistList.value = _userPlaylistList + runOnMainThread { + val userPlaylistData = Gson().fromJson(it, UserPlaylistData::class.java) + for (playlist in userPlaylistData.playlist) { + _userPlaylistList.add(playlist) + } + if (userPlaylistData.more && offset < 3) { + offset++ + updatePlaylist() + } else { + offset = 0 + runOnMainThread { + userPlaylistList.value = _userPlaylistList + } } } }, { }) diff --git a/app/src/main/java/com/dirror/music/ui/viewmodel/PlaylistViewModel.kt b/app/src/main/java/com/dirror/music/ui/viewmodel/PlaylistViewModel.kt new file mode 100644 index 00000000..ded7d9c8 --- /dev/null +++ b/app/src/main/java/com/dirror/music/ui/viewmodel/PlaylistViewModel.kt @@ -0,0 +1,47 @@ +package com.dirror.music.ui.viewmodel + +import androidx.lifecycle.MutableLiveData +import androidx.lifecycle.ViewModel +import com.dirror.music.data.PLAYLIST_TAG_NORMAL +import com.dirror.music.music.local.MyFavorite +import com.dirror.music.music.standard.data.SOURCE_LOCAL +import com.dirror.music.music.standard.data.SOURCE_NETEASE +import com.dirror.music.music.standard.data.StandardSongData +import com.dirror.music.util.runOnMainThread + +class PlaylistViewModel: ViewModel() { + + // id + var id = 0L + + // source + var source = SOURCE_NETEASE + + // tag + var tag = PLAYLIST_TAG_NORMAL + + // 歌单 + var playlist = MutableLiveData>() + + /** + * 更新歌单 + */ + fun updatePlaylist() { + + // 数据库 + when (source) { + SOURCE_LOCAL -> { + // 我喜欢的歌曲 + if (id == 0L) { + MyFavorite.read { + runOnMainThread { + playlist.value = it + } + } + } + } + } + + } + +} \ No newline at end of file