From a9596dd95b8afb013c33147ba82d521e267a392a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20=C4=90=E1=BB=A9c=20Tu=E1=BA=A5n=20Minh?= Date: Mon, 23 Oct 2023 10:18:42 +0700 Subject: [PATCH 01/21] Add Android Auto Support, Add foregroundServiceType for Download Service, Add PlaylistFragment header to fix performance for RecyclerView --- app/src/main/AndroidManifest.xml | 5 +- .../ui/fragment/other/PlaylistFragment.kt | 62 ++-- app/src/main/res/layout/fragment_playlist.xml | 343 +++++++++--------- .../res/layout/fragment_playlist_header.xml | 142 ++++++++ app/src/main/res/values/styles.xml | 4 + app/src/main/res/xml/automotive_app_desc.xml | 3 + .../parser/MusixmatchLyricsParser.kt | 4 +- 7 files changed, 363 insertions(+), 200 deletions(-) create mode 100644 app/src/main/res/layout/fragment_playlist_header.xml create mode 100644 app/src/main/res/xml/automotive_app_desc.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 0ad0cbd1..59623eaa 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -136,12 +136,15 @@ + android:exported="false" + android:foregroundServiceType="dataSync"> + diff --git a/app/src/main/java/com/maxrave/simpmusic/ui/fragment/other/PlaylistFragment.kt b/app/src/main/java/com/maxrave/simpmusic/ui/fragment/other/PlaylistFragment.kt index 9d6f6124..08db2b18 100644 --- a/app/src/main/java/com/maxrave/simpmusic/ui/fragment/other/PlaylistFragment.kt +++ b/app/src/main/java/com/maxrave/simpmusic/ui/fragment/other/PlaylistFragment.kt @@ -2,7 +2,6 @@ package com.maxrave.simpmusic.ui.fragment.other import android.content.Intent import android.graphics.Bitmap -import android.graphics.drawable.ColorDrawable import android.graphics.drawable.GradientDrawable import android.os.Bundle import android.util.Log @@ -109,7 +108,6 @@ class PlaylistFragment: Fragment() { adapter = playlistItemAdapter layoutManager = LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false) setHasFixedSize(false) - isNestedScrollingEnabled = false } var id = requireArguments().getString("id") val downloaded = arguments?.getInt("downloaded") @@ -473,6 +471,7 @@ class PlaylistFragment: Fragment() { binding.topAppBarLayout.addOnOffsetChangedListener { it, verticalOffset -> if(abs(it.totalScrollRange) == abs(verticalOffset)) { binding.topAppBar.background = viewModel.gradientDrawable.value + binding.collapsingToolbarLayout.isTitleEnabled = true if (viewModel.gradientDrawable.value != null ){ if (viewModel.gradientDrawable.value?.colors != null){ requireActivity().window.statusBarColor = viewModel.gradientDrawable.value?.colors!!.first() @@ -481,6 +480,7 @@ class PlaylistFragment: Fragment() { } else { + binding.collapsingToolbarLayout.isTitleEnabled = false binding.topAppBar.background = null requireActivity().window.statusBarColor = ContextCompat.getColor(requireContext(), R.color.colorPrimaryDark) } @@ -590,7 +590,8 @@ class PlaylistFragment: Fragment() { if (it?.id?.startsWith("RDEM") == true || it?.id?.startsWith("RDAMVM") == true) { btDownload.visibility = View.GONE } - topAppBar.title = it?.title + collapsingToolbarLayout.title = it?.title + tvTitle.text = it?.title tvPlaylistAuthor.text = it?.author?.name if (it?.year != "") { tvYearAndCategory.text = requireContext().getString(R.string.year_and_category, it?.year.toString(), "Playlist") @@ -610,14 +611,15 @@ class PlaylistFragment: Fragment() { playlistItemAdapter.updateList(list) if (viewModel.gradientDrawable.value == null) { viewModel.gradientDrawable.observe(viewLifecycleOwner) { gradient -> - fullRootLayout.background = gradient - toolbarBackground = gradient?.colors?.get(0) - topAppBarLayout.background = ColorDrawable(toolbarBackground!!) + //fullRootLayout.background = gradient +// toolbarBackground = gradient?.colors?.get(0) + topAppBarLayout.background = gradient } } else { - fullRootLayout.background = gradientDrawable - topAppBarLayout.background = ColorDrawable(toolbarBackground!!) +// fullRootLayout.background = gradientDrawable +// topAppBarLayout.background = ColorDrawable(toolbarBackground!!) + topAppBarLayout.background = gradientDrawable } binding.rootLayout.visibility = View.VISIBLE binding.loadingLayout.visibility = View.GONE @@ -674,7 +676,8 @@ class PlaylistFragment: Fragment() { if (it != null) { viewModel.insertRadioPlaylist(it.toPlaylistEntity()) } - topAppBar.title = it?.title + collapsingToolbarLayout.title = it?.title + tvTitle.text = it?.title tvPlaylistAuthor.text = it?.author?.name if (it?.year != "") { tvYearAndCategory.text = requireContext().getString(R.string.year_and_category, it?.year.toString(), "Playlist") @@ -695,14 +698,15 @@ class PlaylistFragment: Fragment() { if (viewModel.gradientDrawable.value == null) { viewModel.gradientDrawable.observe(viewLifecycleOwner) { gradient -> - fullRootLayout.background = gradient - toolbarBackground = gradient?.colors?.get(0) - topAppBarLayout.background = ColorDrawable(toolbarBackground!!) +// fullRootLayout.background = gradient +// toolbarBackground = gradient?.colors?.get(0) + topAppBarLayout.background = gradient } } else { - fullRootLayout.background = gradientDrawable - topAppBarLayout.background = ColorDrawable(toolbarBackground!!) +// fullRootLayout.background = gradientDrawable +// topAppBarLayout.background = ColorDrawable(toolbarBackground!!) + topAppBarLayout.background = gradientDrawable } binding.rootLayout.visibility = View.VISIBLE binding.loadingLayout.visibility = View.GONE @@ -732,7 +736,8 @@ class PlaylistFragment: Fragment() { if (it != null) { viewModel.insertPlaylist(it.toPlaylistEntity()) } - topAppBar.title = it?.title + collapsingToolbarLayout.title = it?.title + tvTitle.text = it?.title tvPlaylistAuthor.text = it?.author?.name if (it?.year != "") { tvYearAndCategory.text = requireContext().getString(R.string.year_and_category, it?.year.toString(), "Playlist") @@ -753,14 +758,16 @@ class PlaylistFragment: Fragment() { if (viewModel.gradientDrawable.value == null) { viewModel.gradientDrawable.observe(viewLifecycleOwner) { gradient -> - fullRootLayout.background = gradient - toolbarBackground = gradient?.colors?.get(0) - topAppBarLayout.background = ColorDrawable(toolbarBackground!!) +// fullRootLayout.background = gradient +// toolbarBackground = gradient?.colors?.get(0) +// topAppBarLayout.background = ColorDrawable(toolbarBackground!!) + topAppBarLayout.background = gradient } } else { - fullRootLayout.background = gradientDrawable - topAppBarLayout.background = ColorDrawable(toolbarBackground!!) +// fullRootLayout.background = gradientDrawable +// topAppBarLayout.background = ColorDrawable(toolbarBackground!!) + topAppBarLayout.background = gradientDrawable } binding.rootLayout.visibility = View.VISIBLE binding.loadingLayout.visibility = View.GONE @@ -819,7 +826,8 @@ class PlaylistFragment: Fragment() { btDownload.setImageResource(R.drawable.download_button) } } - topAppBar.title = playlistEntity.title + collapsingToolbarLayout.title = playlistEntity.title + tvTitle.text = playlistEntity.title tvPlaylistAuthor.text = playlistEntity.author tvYearAndCategory.text = requireContext().getString(R.string.year_and_category, playlistEntity.year.toString(), "Playlist") tvTrackCountAndDuration.text = requireContext().getString(R.string.album_length, playlistEntity.trackCount.toString(), @@ -833,14 +841,16 @@ class PlaylistFragment: Fragment() { loadImage(playlistEntity.thumbnails) if (viewModel.gradientDrawable.value == null) { viewModel.gradientDrawable.observe(viewLifecycleOwner) { gradient -> - fullRootLayout.background = gradient - toolbarBackground = gradient?.colors?.get(0) - topAppBarLayout.background = ColorDrawable(toolbarBackground!!) +// fullRootLayout.background = gradient +// toolbarBackground = gradient?.colors?.get(0) +// topAppBarLayout.background = ColorDrawable(toolbarBackground!!) + topAppBarLayout.background = gradient } } else { - fullRootLayout.background = gradientDrawable - topAppBarLayout.background = ColorDrawable(toolbarBackground!!) +// fullRootLayout.background = gradientDrawable +// topAppBarLayout.background = ColorDrawable(toolbarBackground!!) + topAppBarLayout.background = gradientDrawable } viewModel.getListTrack(playlistEntity.tracks) viewModel.listTrack.observe(viewLifecycleOwner) { listTrack -> diff --git a/app/src/main/res/layout/fragment_playlist.xml b/app/src/main/res/layout/fragment_playlist.xml index a0b74617..08cebb65 100644 --- a/app/src/main/res/layout/fragment_playlist.xml +++ b/app/src/main/res/layout/fragment_playlist.xml @@ -28,6 +28,7 @@ android:layout_height="wrap_content" android:id="@+id/topAppBarLayout" android:fitsSystemWindows="true"> + - - - + app:layout_collapseParallaxMultiplier="0.7"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:id="@+id/rvListSong" + android:overScrollMode="never" + tools:listitem="@layout/item_popular_song" + android:layout_marginStart="10sp" + android:layout_marginEnd="10sp" + app:layout_behavior="@string/appbar_scrolling_view_behavior" + android:paddingBottom="180dp" + android:clipToPadding="false"> + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_playlist_header.xml b/app/src/main/res/layout/fragment_playlist_header.xml new file mode 100644 index 00000000..3e6e7de0 --- /dev/null +++ b/app/src/main/res/layout/fragment_playlist_header.xml @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 5f774a15..c5c91d8a 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -21,6 +21,10 @@ bold @font/roboto_bold +