From ec47bc3d2e0f465edd52f3305bd2b63e1ea1d4c1 Mon Sep 17 00:00:00 2001 From: Hemanth S Date: Wed, 12 Aug 2020 03:01:09 +0530 Subject: [PATCH] Add detail navigation --- app/src/main/AndroidManifest.xml | 4 - .../retromusic/activities/MainActivity.kt | 2 - .../base/AbsSlidingMusicPanelActivity.kt | 5 +- .../monkey/retromusic/adapter/HomeAdapter.kt | 9 +- .../retromusic/adapter/album/AlbumAdapter.kt | 13 +- .../monkey/retromusic/extensions/ColorExt.kt | 14 ++ .../retromusic/extensions/FragmentExt.kt | 4 + .../retromusic/fragments/LibraryViewModel.kt | 4 +- .../fragments/MainActivityFragment.kt | 11 -- .../fragments/about/AboutActivity.kt | 148 ------------------ .../fragments/about/AboutFragment.kt | 6 +- .../fragments/albums/AlbumDetailsFragment.kt | 35 ++--- .../fragments/albums/AlbumsFragment.kt | 9 +- .../artists/ArtistDetailsFragment.kt | 35 ++--- .../fragments/base/AbsMusicServiceFragment.kt | 14 +- .../fragments/base/AbsPlayerFragment.kt | 12 +- .../fragments/base/AbsRecyclerViewFragment.kt | 3 +- .../fragments/genres/GenreDetailsFragment.kt | 4 +- .../retromusic/fragments/home/HomeFragment.kt | 8 +- .../fragments/library/LibraryFragment.kt | 39 +---- .../player/PlayerAlbumCoverFragment.kt | 1 + .../player/full/FullPlayerFragment.kt | 17 +- .../playlists/PlaylistDetailsFragment.kt | 6 +- .../fragments/search/SearchFragment.kt | 6 +- .../fragments/settings/SettingsFragment.kt | 4 +- .../layout-land/fragment_album_details.xml | 140 +++++++++++++++++ .../layout-land/fragment_artist_details.xml | 119 ++++++++++++++ .../res/layout/activity_album_details.xml | 4 +- .../res/layout/fragment_album_details.xml | 7 +- .../res/layout/fragment_artist_details.xml | 5 +- app/src/main/res/layout/fragment_material.xml | 4 +- .../res/layout/sliding_music_panel_layout.xml | 2 +- app/src/main/res/navigation/library_graph.xml | 3 +- app/src/main/res/transition/change_bounds.xml | 8 +- 34 files changed, 381 insertions(+), 324 deletions(-) delete mode 100644 app/src/main/java/code/name/monkey/retromusic/fragments/MainActivityFragment.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/fragments/about/AboutActivity.kt create mode 100644 app/src/main/res/layout-land/fragment_album_details.xml create mode 100644 app/src/main/res/layout-land/fragment_artist_details.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 92ee215f..16a51f6b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -106,7 +106,6 @@ - @@ -118,9 +117,6 @@ - AppCompatActivity.whichFragment(@IdRes id: Int): T { return supportFragmentManager.findFragmentById(id) as T } +@Suppress("UNCHECKED_CAST") +fun Fragment.whichFragment(@IdRes id: Int): T { + return childFragmentManager.findFragmentById(id) as T +} fun Fragment.showToast(@StringRes stringRes: Int) { showToast(getString(stringRes)) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt index f0c3cce0..e0a5498c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/LibraryViewModel.kt @@ -55,10 +55,10 @@ class LibraryViewModel( repository.topArtists(), repository.topAlbums(), repository.recentArtists(), - repository.recentAlbums(), + repository.recentAlbums()/*, repository.suggestions(), repository.favoritePlaylist(), - repository.homeGenres() + repository.homeGenres()*/ ) result.forEach { if (it != null && it.arrayList.isNotEmpty()) { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/MainActivityFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/MainActivityFragment.kt deleted file mode 100644 index 46507d44..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/MainActivityFragment.kt +++ /dev/null @@ -1,11 +0,0 @@ -package code.name.monkey.retromusic.fragments - -import androidx.annotation.LayoutRes -import code.name.monkey.retromusic.activities.MainActivity -import code.name.monkey.retromusic.fragments.base.AbsMusicServiceFragment - -open class MainActivityFragment(@LayoutRes layoutRes: Int) : AbsMusicServiceFragment(layoutRes) { - val mainActivity by lazy { - requireActivity() as MainActivity - } -} \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/about/AboutActivity.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/about/AboutActivity.kt deleted file mode 100644 index 0704256f..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/about/AboutActivity.kt +++ /dev/null @@ -1,148 +0,0 @@ -package code.name.monkey.retromusic.fragments.about - -import android.content.Intent -import android.content.pm.PackageManager -import android.net.Uri -import android.os.Bundle -import android.view.MenuItem -import android.view.View -import androidx.core.app.ShareCompat -import androidx.recyclerview.widget.DefaultItemAnimator -import androidx.recyclerview.widget.LinearLayoutManager -import code.name.monkey.retromusic.App -import code.name.monkey.retromusic.Constants.APP_INSTAGRAM_LINK -import code.name.monkey.retromusic.Constants.APP_TELEGRAM_LINK -import code.name.monkey.retromusic.Constants.APP_TWITTER_LINK -import code.name.monkey.retromusic.Constants.FAQ_LINK -import code.name.monkey.retromusic.Constants.GITHUB_PROJECT -import code.name.monkey.retromusic.Constants.PINTEREST -import code.name.monkey.retromusic.Constants.RATE_ON_GOOGLE_PLAY -import code.name.monkey.retromusic.Constants.TELEGRAM_CHANGE_LOG -import code.name.monkey.retromusic.Constants.TRANSLATE -import code.name.monkey.retromusic.R -import code.name.monkey.retromusic.activities.base.AbsBaseActivity -import code.name.monkey.retromusic.adapter.ContributorAdapter -import code.name.monkey.retromusic.extensions.applyToolbar -import code.name.monkey.retromusic.model.Contributor -import code.name.monkey.retromusic.util.NavigationUtil -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken -import kotlinx.android.synthetic.main.activity_about.* -import kotlinx.android.synthetic.main.card_credit.* -import kotlinx.android.synthetic.main.card_other.* -import kotlinx.android.synthetic.main.card_retro_info.* -import kotlinx.android.synthetic.main.card_social.* -import java.io.IOException -import java.nio.charset.StandardCharsets - -class AboutActivity : AbsBaseActivity(), View.OnClickListener { - - private val contributorsJson: String? - get() { - val json: String - try { - val inputStream = assets.open("contributors.json") - val size = inputStream.available() - val buffer = ByteArray(size) - inputStream.read(buffer) - inputStream.close() - json = String(buffer, StandardCharsets.UTF_8) - } catch (ex: IOException) { - ex.printStackTrace() - return null - } - return json - } - - override fun onCreate(savedInstanceState: Bundle?) { - setDrawUnderStatusBar() - super.onCreate(savedInstanceState) - setContentView(R.layout.activity_about) - setStatusbarColorAuto() - setNavigationbarColorAuto() - setLightNavigationBar(true) - - applyToolbar(toolbar) - version.setSummary(getAppVersion()) - setUpView() - loadContributors() - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - if (item.itemId == android.R.id.home) { - onBackPressed() - return true - } - return super.onOptionsItemSelected(item) - } - - private fun openUrl(url: String) { - val i = Intent(Intent.ACTION_VIEW) - i.data = Uri.parse(url) - i.flags = Intent.FLAG_ACTIVITY_NEW_TASK - startActivity(i) - } - - private fun setUpView() { - appGithub.setOnClickListener(this) - faqLink.setOnClickListener(this) - telegramLink.setOnClickListener(this) - appRate.setOnClickListener(this) - appTranslation.setOnClickListener(this) - appShare.setOnClickListener(this) - donateLink.setOnClickListener(this) - instagramLink.setOnClickListener(this) - twitterLink.setOnClickListener(this) - changelog.setOnClickListener(this) - openSource.setOnClickListener(this) - pinterestLink.setOnClickListener(this) - bugReportLink.setOnClickListener(this) - } - - override fun onClick(view: View) { - when (view.id) { - R.id.pinterestLink -> openUrl(PINTEREST) - R.id.faqLink -> openUrl(FAQ_LINK) - R.id.telegramLink -> openUrl(APP_TELEGRAM_LINK) - R.id.appGithub -> openUrl(GITHUB_PROJECT) - R.id.appTranslation -> openUrl(TRANSLATE) - R.id.appRate -> openUrl(RATE_ON_GOOGLE_PLAY) - R.id.appShare -> shareApp() - R.id.donateLink -> NavigationUtil.goToSupportDevelopment(this) - R.id.instagramLink -> openUrl(APP_INSTAGRAM_LINK) - R.id.twitterLink -> openUrl(APP_TWITTER_LINK) - R.id.changelog -> openUrl(TELEGRAM_CHANGE_LOG) - R.id.openSource -> NavigationUtil.goToOpenSource(this) - R.id.bugReportLink -> NavigationUtil.bugReport(this) - } - } - - private fun getAppVersion(): String { - return try { - val isPro = if (App.isProVersion()) "Pro" else "Free" - val packageInfo = packageManager.getPackageInfo(packageName, 0) - "${packageInfo.versionName} $isPro" - } catch (e: PackageManager.NameNotFoundException) { - e.printStackTrace() - "0.0.0" - } - } - - private fun shareApp() { - ShareCompat.IntentBuilder.from(this).setType("text/plain") - .setChooserTitle(R.string.share_app) - .setText(String.format(getString(R.string.app_share), packageName)).startChooser() - } - - private fun loadContributors() { - val type = object : TypeToken>() { - - }.type - val contributors = Gson().fromJson>(contributorsJson, type) - - val contributorAdapter = ContributorAdapter(contributors) - recyclerView.layoutManager = LinearLayoutManager(this) - recyclerView.itemAnimator = DefaultItemAnimator() - recyclerView.adapter = contributorAdapter - } -} diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/about/AboutFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/about/AboutFragment.kt index 3dbaf9ae..4f030ac0 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/about/AboutFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/about/AboutFragment.kt @@ -12,12 +12,11 @@ import code.name.monkey.retromusic.App import code.name.monkey.retromusic.Constants import code.name.monkey.retromusic.R import code.name.monkey.retromusic.adapter.ContributorAdapter -import code.name.monkey.retromusic.fragments.MainActivityFragment +import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment import code.name.monkey.retromusic.model.Contributor import code.name.monkey.retromusic.util.NavigationUtil import com.google.gson.Gson import com.google.gson.reflect.TypeToken -import kotlinx.android.synthetic.main.activity_about.* import kotlinx.android.synthetic.main.card_credit.* import kotlinx.android.synthetic.main.card_other.* import kotlinx.android.synthetic.main.card_retro_info.* @@ -25,10 +24,9 @@ import kotlinx.android.synthetic.main.card_social.* import java.io.IOException import java.nio.charset.StandardCharsets -class AboutFragment : MainActivityFragment(R.layout.fragment_about), View.OnClickListener { +class AboutFragment : AbsMainActivityFragment(R.layout.fragment_about), View.OnClickListener { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - mainActivity.setSupportActionBar(toolbar) version.setSummary(getAppVersion()) setUpView() loadContributors() diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumDetailsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumDetailsFragment.kt index ab8be6e9..66f5a231 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumDetailsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumDetailsFragment.kt @@ -8,18 +8,17 @@ import androidx.core.os.bundleOf import androidx.lifecycle.Observer import androidx.navigation.findNavController import androidx.navigation.fragment.findNavController +import androidx.navigation.fragment.navArgs import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager -import code.name.monkey.appthemehelper.util.MaterialUtil -import code.name.monkey.retromusic.EXTRA_ALBUM_ID import code.name.monkey.retromusic.EXTRA_ARTIST_ID import code.name.monkey.retromusic.R import code.name.monkey.retromusic.adapter.album.HorizontalAlbumAdapter import code.name.monkey.retromusic.adapter.song.SimpleSongAdapter -import code.name.monkey.retromusic.extensions.extraNotNull +import code.name.monkey.retromusic.extensions.applyColor import code.name.monkey.retromusic.extensions.show -import code.name.monkey.retromusic.fragments.MainActivityFragment +import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment import code.name.monkey.retromusic.glide.AlbumGlideRequest import code.name.monkey.retromusic.glide.ArtistGlideRequest import code.name.monkey.retromusic.glide.RetroMusicColoredTarget @@ -38,16 +37,17 @@ import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.core.parameter.parametersOf import java.util.* -class AlbumDetailsFragment : MainActivityFragment(R.layout.fragment_album_details), +class AlbumDetailsFragment : AbsMainActivityFragment(R.layout.fragment_album_details), AlbumClickListener { private lateinit var simpleSongAdapter: SimpleSongAdapter private lateinit var album: Album + private val args: AlbumDetailsFragmentArgs by navArgs() private val savedSortOrder: String get() = PreferenceUtil.albumDetailSongSortOrder private val detailsViewModel by viewModel { - parametersOf(extraNotNull(EXTRA_ALBUM_ID).value) + parametersOf(args.extraAlbumId) } override fun onActivityCreated(savedInstanceState: Bundle?) { @@ -56,6 +56,8 @@ class AlbumDetailsFragment : MainActivityFragment(R.layout.fragment_album_detail mainActivity.setBottomBarVisibility(View.GONE) toolbar.title = null + image.transitionName = getString(R.string.transition_album_art) + postponeEnterTransition() playerActivity?.addMusicServiceEventListener(detailsViewModel) detailsViewModel.getAlbum().observe(viewLifecycleOwner, Observer { @@ -100,13 +102,6 @@ class AlbumDetailsFragment : MainActivityFragment(R.layout.fragment_album_detail } } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - val activity = activity as AppCompatActivity - activity.supportActionBar?.setDisplayHomeAsUpEnabled(true) - } - override fun onDestroy() { super.onDestroy() playerActivity?.removeMusicServiceEventListener(detailsViewModel) @@ -234,19 +229,11 @@ class AlbumDetailsFragment : MainActivityFragment(R.layout.fragment_album_detail } private fun setColors(color: MediaNotificationProcessor) { - MaterialUtil.tintColor( - button = shuffleAction, - textColor = color.primaryTextColor, - backgroundColor = color.backgroundColor - ) - MaterialUtil.tintColor( - button = playAction, - textColor = color.primaryTextColor, - backgroundColor = color.backgroundColor - ) + shuffleAction.applyColor(color.backgroundColor) + playAction.applyColor(color.backgroundColor) } - override fun onAlbumClick(albumId: Int) { + override fun onAlbumClick(albumId: Int, view: View) { findNavController().navigate( R.id.albumDetailsFragment, bundleOf("extra_album_id" to albumId) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumsFragment.kt index 2e2a9c71..5c4b5aa6 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/albums/AlbumsFragment.kt @@ -94,12 +94,15 @@ class AlbumsFragment : } } - override fun onAlbumClick(albumId: Int) { + override fun onAlbumClick(albumId: Int, view: View) { val controller = requireActivity().findNavController(R.id.fragment_container) - controller.navigate(R.id.albumDetailsFragment, bundleOf(EXTRA_ALBUM_ID to albumId)) + controller.navigate( + R.id.albumDetailsFragment, + bundleOf(EXTRA_ALBUM_ID to albumId) + ) } } interface AlbumClickListener { - fun onAlbumClick(albumId: Int) + fun onAlbumClick(albumId: Int, view: View) } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistDetailsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistDetailsFragment.kt index d38b2e0b..d834ae31 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistDetailsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/artists/ArtistDetailsFragment.kt @@ -6,19 +6,20 @@ import android.view.View import androidx.core.os.bundleOf import androidx.core.text.HtmlCompat import androidx.lifecycle.Observer +import androidx.navigation.fragment.FragmentNavigatorExtras import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.DefaultItemAnimator import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager -import code.name.monkey.appthemehelper.util.MaterialUtil import code.name.monkey.retromusic.EXTRA_ARTIST_ID import code.name.monkey.retromusic.R import code.name.monkey.retromusic.adapter.album.HorizontalAlbumAdapter import code.name.monkey.retromusic.adapter.song.SimpleSongAdapter +import code.name.monkey.retromusic.extensions.applyColor import code.name.monkey.retromusic.extensions.extraNotNull import code.name.monkey.retromusic.extensions.show -import code.name.monkey.retromusic.fragments.MainActivityFragment import code.name.monkey.retromusic.fragments.albums.AlbumClickListener +import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment import code.name.monkey.retromusic.glide.ArtistGlideRequest import code.name.monkey.retromusic.glide.RetroMusicColoredTarget import code.name.monkey.retromusic.helper.MusicPlayerRemote @@ -35,7 +36,7 @@ import org.koin.core.parameter.parametersOf import java.util.* import kotlin.collections.ArrayList -class ArtistDetailsFragment : MainActivityFragment(R.layout.fragment_artist_details), +class ArtistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_artist_details), AlbumClickListener { private var biography: Spanned? = null @@ -49,12 +50,12 @@ class ArtistDetailsFragment : MainActivityFragment(R.layout.fragment_artist_deta parametersOf(extraNotNull(EXTRA_ARTIST_ID).value) } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) + override fun onActivityCreated(savedInstanceState: Bundle?) { + super.onActivityCreated(savedInstanceState) mainActivity.setSupportActionBar(toolbar) mainActivity.setBottomBarVisibility(View.GONE) toolbar.title = null - + setupRecyclerView() postponeEnterTransition() detailsViewModel.getArtist().observe(viewLifecycleOwner, Observer { startPostponedEnterTransition() @@ -63,7 +64,7 @@ class ArtistDetailsFragment : MainActivityFragment(R.layout.fragment_artist_deta detailsViewModel.getArtistInfo().observe(viewLifecycleOwner, Observer { artistInfo(it) }) - setupRecyclerView() + playAction.apply { setOnClickListener { MusicPlayerRemote.openQueue(artist.songs, 0, true) } } @@ -173,22 +174,18 @@ class ArtistDetailsFragment : MainActivityFragment(R.layout.fragment_artist_deta } private fun setColors(color: MediaNotificationProcessor) { - MaterialUtil.tintColor( - button = shuffleAction, - textColor = color.primaryTextColor, - backgroundColor = color.backgroundColor - ) - MaterialUtil.tintColor( - button = playAction, - textColor = color.primaryTextColor, - backgroundColor = color.backgroundColor - ) + shuffleAction.applyColor(color.backgroundColor) + playAction.applyColor(color.backgroundColor) } - override fun onAlbumClick(albumId: Int) { + override fun onAlbumClick(albumId: Int, view: View) { findNavController().navigate( R.id.albumDetailsFragment, - bundleOf("extra_album_id" to albumId) + bundleOf("extra_album_id" to albumId), + null, + FragmentNavigatorExtras( + view to getString(R.string.transition_album_art) + ) ) } } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMusicServiceFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMusicServiceFragment.kt index b5d666f1..d6e8d1ee 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMusicServiceFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMusicServiceFragment.kt @@ -7,6 +7,8 @@ import android.view.View import android.webkit.MimeTypeMap import androidx.annotation.LayoutRes import androidx.fragment.app.Fragment +import androidx.navigation.navOptions +import code.name.monkey.retromusic.R import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity import code.name.monkey.retromusic.interfaces.MusicServiceEventListener import code.name.monkey.retromusic.model.Song @@ -22,7 +24,17 @@ import java.util.* open class AbsMusicServiceFragment(@LayoutRes layout: Int) : Fragment(layout), MusicServiceEventListener { - + val navOptions by lazy { + navOptions { + launchSingleTop = true + anim { + enter = R.anim.retro_fragment_open_enter + exit = R.anim.retro_fragment_open_exit + popEnter = R.anim.retro_fragment_close_enter + popExit = R.anim.retro_fragment_close_exit + } + } + } var playerActivity: AbsMusicServiceActivity? = null private set diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerFragment.kt index 73d9ed45..62089b49 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerFragment.kt @@ -34,11 +34,8 @@ import kotlinx.android.synthetic.main.shadow_statusbar_toolbar.* import org.koin.androidx.viewmodel.ext.android.sharedViewModel import java.io.FileNotFoundException -abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMusicServiceFragment(layout), - Toolbar.OnMenuItemClickListener, - PaletteColorHolder, - PlayerAlbumCoverFragment.Callbacks { - +abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMainActivityFragment(layout), + Toolbar.OnMenuItemClickListener, PaletteColorHolder, PlayerAlbumCoverFragment.Callbacks { private var updateIsFavoriteTask: AsyncTask<*, *, *>? = null private var updateLyricsAsyncTask: AsyncTask<*, *, *>? = null @@ -264,11 +261,6 @@ abstract class AbsPlayerFragment(@LayoutRes layout: Int) : AbsMusicServiceFragme statusBarShadow?.hide() } - interface Callbacks { - - fun onPaletteColorChanged() - } - companion object { val TAG: String = AbsPlayerFragment::class.java.simpleName const val VISIBILITY_ANIM_DURATION: Long = 300 diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsRecyclerViewFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsRecyclerViewFragment.kt index cd5f1174..2ba05ce7 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsRecyclerViewFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsRecyclerViewFragment.kt @@ -23,8 +23,7 @@ abstract class AbsRecyclerViewFragment, LM : Recycle AppBarLayout.OnOffsetChangedListener { val libraryViewModel: LibraryViewModel by sharedViewModel() - - + override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) setHasOptionsMenu(true) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/genres/GenreDetailsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/genres/GenreDetailsFragment.kt index 13a96b9e..bb9fa8fb 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/genres/GenreDetailsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/genres/GenreDetailsFragment.kt @@ -10,7 +10,7 @@ import code.name.monkey.retromusic.R import code.name.monkey.retromusic.adapter.song.SongAdapter import code.name.monkey.retromusic.extensions.dipToPix import code.name.monkey.retromusic.extensions.extraNotNull -import code.name.monkey.retromusic.fragments.MainActivityFragment +import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment import code.name.monkey.retromusic.model.Genre import code.name.monkey.retromusic.model.Song import kotlinx.android.synthetic.main.fragment_playlist_detail.* @@ -18,7 +18,7 @@ import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.core.parameter.parametersOf import java.util.* -class GenreDetailsFragment : MainActivityFragment(R.layout.fragment_playlist_detail) { +class GenreDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playlist_detail) { private val detailsViewModel: GenreDetailsViewModel by viewModel { parametersOf(extraNotNull(EXTRA_GENRE).value) } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/home/HomeFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/home/HomeFragment.kt index 39ef69aa..6c0d9881 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/home/HomeFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/home/HomeFragment.kt @@ -30,7 +30,6 @@ import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment import code.name.monkey.retromusic.glide.ProfileBannerGlideRequest import code.name.monkey.retromusic.glide.UserProfileGlideRequest import code.name.monkey.retromusic.helper.MusicPlayerRemote -import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks import code.name.monkey.retromusic.loaders.SongLoader import code.name.monkey.retromusic.model.smartplaylist.HistoryPlaylist import code.name.monkey.retromusic.model.smartplaylist.LastAddedPlaylist @@ -44,12 +43,7 @@ import kotlinx.android.synthetic.main.home_content.* import org.koin.androidx.viewmodel.ext.android.sharedViewModel class HomeFragment : - AbsMainActivityFragment(if (PreferenceUtil.isHomeBanner) R.layout.fragment_banner_home else R.layout.fragment_home), - MainActivityFragmentCallbacks { - - override fun handleBackPress(): Boolean { - return false - } + AbsMainActivityFragment(if (PreferenceUtil.isHomeBanner) R.layout.fragment_banner_home else R.layout.fragment_home) { private val libraryViewModel: LibraryViewModel by sharedViewModel() diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/library/LibraryFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/library/LibraryFragment.kt index d0227df1..93859b58 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/library/LibraryFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/library/LibraryFragment.kt @@ -6,40 +6,17 @@ import android.view.MenuInflater import android.view.MenuItem import android.view.View import androidx.navigation.fragment.findNavController -import androidx.navigation.navOptions -import androidx.navigation.ui.AppBarConfiguration import code.name.monkey.appthemehelper.common.ATHToolbarActivity.getToolbarBackgroundColor import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper import code.name.monkey.retromusic.R import code.name.monkey.retromusic.extensions.findNavController -import code.name.monkey.retromusic.fragments.MainActivityFragment +import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment import code.name.monkey.retromusic.fragments.folder.FoldersFragment import code.name.monkey.retromusic.util.PreferenceUtil import com.google.android.material.appbar.AppBarLayout import kotlinx.android.synthetic.main.fragment_library.* -class LibraryFragment : MainActivityFragment(R.layout.fragment_library) { - private val navOptions by lazy { - navOptions { - launchSingleTop = true - anim { - enter = R.anim.retro_fragment_open_enter - exit = R.anim.retro_fragment_open_exit - popEnter = R.anim.retro_fragment_close_enter - popExit = R.anim.retro_fragment_close_exit - } - } - } - private val appBarConfiguration by lazy { - AppBarConfiguration( - setOf( - R.id.libraryFragment, - R.id.settingsFragment, - R.id.searchFragment - ) - ) - } - +class LibraryFragment : AbsMainActivityFragment(R.layout.fragment_library) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setHasOptionsMenu(true) @@ -50,18 +27,6 @@ class LibraryFragment : MainActivityFragment(R.layout.fragment_library) { private fun setupNavigationController() { val navController = findNavController(R.id.fragment_container) - val navOptions = navOptions { - launchSingleTop = true - anim { - enter = R.anim.retro_fragment_open_enter - exit = R.anim.retro_fragment_open_exit - popEnter = R.anim.retro_fragment_close_enter - popExit = R.anim.retro_fragment_close_exit - } - popUpTo(navController.graph.startDestination) { - inclusive = true - } - } mainActivity.getBottomNavigationView().setOnNavigationItemSelectedListener { var handled = false if (navController.graph.findNode(it.itemId) != null) { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/PlayerAlbumCoverFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/PlayerAlbumCoverFragment.kt index 9caeb699..be5d8c83 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/PlayerAlbumCoverFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/PlayerAlbumCoverFragment.kt @@ -18,6 +18,7 @@ import kotlinx.android.synthetic.main.fragment_player_album_cover.* class PlayerAlbumCoverFragment : AbsMusicServiceFragment(R.layout.fragment_player_album_cover), ViewPager.OnPageChangeListener { + private var callbacks: Callbacks? = null private var currentPosition: Int = 0 private val colorReceiver = object : AlbumCoverFragment.ColorReceiver { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlayerFragment.kt index 33aa882c..cca5df70 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlayerFragment.kt @@ -8,12 +8,13 @@ import android.widget.FrameLayout import android.widget.TextView import androidx.appcompat.widget.Toolbar import androidx.core.os.bundleOf -import androidx.navigation.findNavController import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper import code.name.monkey.retromusic.EXTRA_ARTIST_ID import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.extensions.findActivityNavController import code.name.monkey.retromusic.extensions.hide import code.name.monkey.retromusic.extensions.show +import code.name.monkey.retromusic.extensions.whichFragment import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment import code.name.monkey.retromusic.glide.ArtistGlideRequest @@ -151,7 +152,8 @@ class FullPlayerFragment : AbsPlayerFragment(R.layout.fragment_full), private fun setupArtist() { artistImage.setOnClickListener { - requireActivity().findNavController(R.id.fragment_container) + mainActivity.collapsePanel() + findActivityNavController(R.id.fragment_container) .navigate( R.id.artistDetailsFragment, bundleOf(EXTRA_ARTIST_ID to MusicPlayerRemote.currentSong.artistId) @@ -160,13 +162,10 @@ class FullPlayerFragment : AbsPlayerFragment(R.layout.fragment_full), } private fun setUpSubFragments() { - controlsFragment = - childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as FullPlaybackControlsFragment - - val playerAlbumCoverFragment = - childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment - playerAlbumCoverFragment.setCallbacks(this) - playerAlbumCoverFragment.removeSlideEffect() + controlsFragment = whichFragment(R.id.playbackControlsFragment) + val coverFragment: PlayerAlbumCoverFragment = whichFragment(R.id.playerAlbumCoverFragment) + coverFragment.setCallbacks(this) + coverFragment.removeSlideEffect() } override fun onShow() { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/playlists/PlaylistDetailsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/playlists/PlaylistDetailsFragment.kt index c3dba8cc..872128e6 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/playlists/PlaylistDetailsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/playlists/PlaylistDetailsFragment.kt @@ -13,7 +13,7 @@ import code.name.monkey.retromusic.adapter.song.OrderablePlaylistSongAdapter import code.name.monkey.retromusic.adapter.song.SongAdapter import code.name.monkey.retromusic.extensions.dipToPix import code.name.monkey.retromusic.extensions.extraNotNull -import code.name.monkey.retromusic.fragments.MainActivityFragment +import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment import code.name.monkey.retromusic.model.AbsCustomPlaylist import code.name.monkey.retromusic.model.Playlist import code.name.monkey.retromusic.model.Song @@ -21,11 +21,11 @@ import code.name.monkey.retromusic.util.PlaylistsUtil import com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator import com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager import com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils -import kotlinx.android.synthetic.main.activity_playlist_detail.* +import kotlinx.android.synthetic.main.fragment_playlist_detail.* import org.koin.androidx.viewmodel.ext.android.viewModel import org.koin.core.parameter.parametersOf -class PlaylistDetailsFragment : MainActivityFragment(R.layout.fragment_playlist_detail) { +class PlaylistDetailsFragment : AbsMainActivityFragment(R.layout.fragment_playlist_detail) { private val viewModel: PlaylistDetailsViewModel by viewModel { parametersOf(extraNotNull(EXTRA_PLAYLIST).value) } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/search/SearchFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/search/SearchFragment.kt index 75c1500f..a53f4e13 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/search/SearchFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/search/SearchFragment.kt @@ -18,15 +18,14 @@ import code.name.monkey.retromusic.R import code.name.monkey.retromusic.adapter.SearchAdapter import code.name.monkey.retromusic.extensions.accentColor import code.name.monkey.retromusic.extensions.showToast -import code.name.monkey.retromusic.fragments.MainActivityFragment +import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment import com.google.android.material.textfield.TextInputEditText import kotlinx.android.synthetic.main.fragment_search.* -import kotlinx.android.synthetic.main.fragment_search.view.* import org.koin.android.ext.android.inject import java.util.* import kotlin.collections.ArrayList -class SearchFragment : MainActivityFragment(R.layout.fragment_search), TextWatcher { +class SearchFragment : AbsMainActivityFragment(R.layout.fragment_search), TextWatcher { companion object { const val QUERY = "query" const val REQ_CODE_SPEECH_INPUT = 9001 @@ -41,6 +40,7 @@ class SearchFragment : MainActivityFragment(R.layout.fragment_search), TextWatch mainActivity.setSupportActionBar(toolbar) mainActivity.hideBottomNavigation() mainActivity.setBottomBarVisibility(View.GONE) + setupRecyclerView() setupSearchView() voiceSearch.setOnClickListener { startMicSearch() } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/settings/SettingsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/settings/SettingsFragment.kt index d1df247c..72355ec9 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/settings/SettingsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/settings/SettingsFragment.kt @@ -5,10 +5,10 @@ import android.view.View import androidx.navigation.NavController import code.name.monkey.retromusic.R import code.name.monkey.retromusic.extensions.findNavController -import code.name.monkey.retromusic.fragments.MainActivityFragment +import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment import kotlinx.android.synthetic.main.fragment_settings.* -class SettingsFragment : MainActivityFragment(R.layout.fragment_settings) { +class SettingsFragment : AbsMainActivityFragment(R.layout.fragment_settings) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) diff --git a/app/src/main/res/layout-land/fragment_album_details.xml b/app/src/main/res/layout-land/fragment_album_details.xml new file mode 100644 index 00000000..32d4c7f6 --- /dev/null +++ b/app/src/main/res/layout-land/fragment_album_details.xml @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout-land/fragment_artist_details.xml b/app/src/main/res/layout-land/fragment_artist_details.xml new file mode 100644 index 00000000..c697c814 --- /dev/null +++ b/app/src/main/res/layout-land/fragment_artist_details.xml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_album_details.xml b/app/src/main/res/layout/activity_album_details.xml index 56bff8c3..473a20ee 100755 --- a/app/src/main/res/layout/activity_album_details.xml +++ b/app/src/main/res/layout/activity_album_details.xml @@ -105,7 +105,7 @@ app:layout_constraintStart_toEndOf="@id/artistImage" app:layout_constraintTop_toTopOf="@id/artistImage" tools:ignore="MissingPrefix" - tools:text="@tools:sample/lorem/random" /> + tools:text="@tools:sample/full_names" /> + tools:text="@tools:sample/full_names" /> - diff --git a/app/src/main/res/layout/fragment_artist_details.xml b/app/src/main/res/layout/fragment_artist_details.xml index b757c277..09d2fe80 100644 --- a/app/src/main/res/layout/fragment_artist_details.xml +++ b/app/src/main/res/layout/fragment_artist_details.xml @@ -76,8 +76,7 @@ tools:srcCompat="@tools:sample/backgrounds/scenic" /> - - + - - diff --git a/app/src/main/res/navigation/library_graph.xml b/app/src/main/res/navigation/library_graph.xml index 9223239e..9749f4d2 100644 --- a/app/src/main/res/navigation/library_graph.xml +++ b/app/src/main/res/navigation/library_graph.xml @@ -8,7 +8,7 @@ + tools:layout="@layout/fragment_main_activity_recycler_view"/> + \ No newline at end of file diff --git a/app/src/main/res/transition/change_bounds.xml b/app/src/main/res/transition/change_bounds.xml index 8595f5a9..5da16fb1 100644 --- a/app/src/main/res/transition/change_bounds.xml +++ b/app/src/main/res/transition/change_bounds.xml @@ -1,3 +1,7 @@ - \ No newline at end of file + + + + + + \ No newline at end of file