diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt index 6eb4cc73..2d4023d9 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt @@ -8,11 +8,13 @@ import android.os.Bundle import android.provider.MediaStore import android.view.View import androidx.lifecycle.lifecycleScope +import androidx.navigation.ui.NavigationUI import code.name.monkey.retromusic.* import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity import code.name.monkey.retromusic.extensions.findNavController import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.helper.SearchQueryHelper.getSongs +import code.name.monkey.retromusic.model.CategoryInfo import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.repository.PlaylistSongsLoader import code.name.monkey.retromusic.service.MusicService @@ -45,6 +47,25 @@ class MainActivity : AbsSlidingMusicPanelActivity(), OnSharedPreferenceChangeLis hideStatusBar() AppRater.appLaunched(this) updateTabs() + + //NavigationUI.setupWithNavController(getBottomNavigationView(), findNavController(R.id.fragment_container)) + setupNavigationController() + } + + private fun setupNavigationController() { + val navController = findNavController(R.id.fragment_container) + val navInflater = navController.navInflater + val navGraph = navInflater.inflate(R.navigation.main_graph) + + val categoryInfo: CategoryInfo = PreferenceUtil.libraryCategory.first { it.visible } + if (categoryInfo.visible) { + navGraph.startDestination = categoryInfo.category.id + } + navController.graph = navGraph + NavigationUI.setupWithNavController(getBottomNavigationView(), navController) + navController.addOnDestinationChangedListener { _, _, _ -> + //appBarLayout.setExpanded(true, true) + } } override fun onSupportNavigateUp(): Boolean = 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 d3ff1601..96c5b9d8 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 @@ -16,7 +16,6 @@ import code.name.monkey.retromusic.helper.SortOrder import code.name.monkey.retromusic.helper.SortOrder.AlbumSortOrder import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.RetroUtil -import com.google.android.material.transition.platform.MaterialFadeThrough class AlbumsFragment : AbsRecyclerViewCustomGridSizeFragment(), @@ -110,6 +109,7 @@ class AlbumsFragment : AbsRecyclerViewCustomGridSizeFragment(), @@ -102,6 +101,7 @@ class ArtistsFragment : AbsRecyclerViewCustomGridSizeFragment, LM : RecyclerView.LayoutManager> : - AbsMusicServiceFragment(R.layout.fragment_main_activity_recycler_view), + AbsMainActivityFragment(R.layout.fragment_main_recycler), AppBarLayout.OnOffsetChangedListener { val libraryViewModel: LibraryViewModel by sharedViewModel() @@ -36,9 +43,30 @@ abstract class AbsRecyclerViewFragment, LM : Recycle override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + libraryViewModel.setPanelState(NowPlayingPanelState.COLLAPSED_WITH) + mainActivity.setSupportActionBar(toolbar) + mainActivity.supportActionBar?.title = null initLayoutManager() initAdapter() setUpRecyclerView() + setupTitle() + } + + private fun setupTitle() { + toolbar.setNavigationOnClickListener { + findNavController().navigate( + R.id.searchFragment, + null, + navOptions + ) + } + val color = ThemeStore.accentColor(requireContext()) + val hexColor = String.format("#%06X", 0xFFFFFF and color) + val appName = HtmlCompat.fromHtml( + "Retro Music", + HtmlCompat.FROM_HTML_MODE_COMPACT + ) + appNameText.text = appName } private fun setUpRecyclerView() { @@ -78,7 +106,7 @@ abstract class AbsRecyclerViewFragment, LM : Recycle return String(Character.toChars(unicode)) } - private fun checkIsEmpty() { + private fun checkIsEmpty() { emptyText.setText(emptyMessage) empty.visibility = if (adapter!!.itemCount == 0) View.VISIBLE else View.GONE } @@ -138,4 +166,39 @@ abstract class AbsRecyclerViewFragment, LM : Recycle fun recyclerView(): RecyclerView { return recyclerView } + + override fun onPrepareOptionsMenu(menu: Menu) { + super.onPrepareOptionsMenu(menu) + ToolbarContentTintHelper.handleOnPrepareOptionsMenu(requireActivity(), toolbar) + } + + override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { + super.onCreateOptionsMenu(menu, inflater) + inflater.inflate(R.menu.menu_main, menu) + ToolbarContentTintHelper.handleOnCreateOptionsMenu( + requireContext(), + toolbar, + menu, + ATHToolbarActivity.getToolbarBackgroundColor(toolbar) + ) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.action_settings -> findNavController().navigate( + R.id.settingsActivity, + null, + navOptions + ) + R.id.action_import_playlist -> ImportPlaylistDialog().show( + childFragmentManager, + "ImportPlaylist" + ) + R.id.action_add_to_playlist -> CreatePlaylistDialog.create(emptyList()).show( + childFragmentManager, + "ShowCreatePlaylistDialog" + ) + } + return super.onOptionsItemSelected(item) + } } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/folder/FoldersFragment.java b/app/src/main/java/code/name/monkey/retromusic/fragments/folder/FoldersFragment.java index 329172b7..ad0a4b7a 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/folder/FoldersFragment.java +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/folder/FoldersFragment.java @@ -20,6 +20,7 @@ import android.media.MediaScannerConnection; import android.os.Bundle; import android.os.Environment; import android.text.Html; +import android.text.Spanned; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -34,8 +35,11 @@ import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.appcompat.widget.Toolbar; +import androidx.core.text.HtmlCompat; import androidx.loader.app.LoaderManager; import androidx.loader.content.Loader; +import androidx.navigation.Navigation; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -57,6 +61,7 @@ import java.util.List; import code.name.monkey.appthemehelper.ThemeStore; import code.name.monkey.appthemehelper.util.ATHUtil; +import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper; import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.adapter.SongFileAdapter; import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment; @@ -79,6 +84,8 @@ import code.name.monkey.retromusic.views.BreadCrumbLayout; import code.name.monkey.retromusic.views.ScrollingViewOnApplyWindowInsetsListener; import me.zhanghai.android.fastscroll.FastScroller; +import static code.name.monkey.appthemehelper.common.ATHToolbarActivity.getToolbarBackgroundColor; + public class FoldersFragment extends AbsMainActivityFragment implements IMainActivityFragmentCallbacks, ICabHolder, @@ -95,6 +102,8 @@ public class FoldersFragment extends AbsMainActivityFragment implements private static final String CRUMBS = "crumbs"; private static final int LOADER_ID = 5; private SongFileAdapter adapter; + private Toolbar toolbar; + private TextView appNameText; private BreadCrumbLayout breadCrumbs; private MaterialCab cab; private View coordinatorLayout; @@ -154,11 +163,27 @@ public class FoldersFragment extends AbsMainActivityFragment implements @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + getMainActivity().setSupportActionBar(toolbar); + getMainActivity().getSupportActionBar().setTitle(null); setStatusBarColorAuto(view); setUpAppbarColor(); setUpBreadCrumbs(); setUpRecyclerView(); setUpAdapter(); + setUpTitle(); + } + + private void setUpTitle() { + toolbar.setNavigationOnClickListener(v -> + Navigation.findNavController(v).navigate(R.id.searchFragment, null, getNavOptions()) + ); + int color = ThemeStore.Companion.accentColor(requireContext()); + String hexColor = String.format("#%06X", 0xFFFFFF & color); + Spanned appName = HtmlCompat.fromHtml( + "Retro Music", + HtmlCompat.FROM_HTML_MODE_COMPACT + ); + appNameText.setText(appName); } @Override @@ -329,6 +354,12 @@ public class FoldersFragment extends AbsMainActivityFragment implements .execute(new ListSongsAsyncTask.LoadingInfo(files, AUDIO_FILE_FILTER, getFileComparator())); } + @Override + public void onPrepareOptionsMenu(@NonNull Menu menu) { + super.onPrepareOptionsMenu(menu); + ToolbarContentTintHelper.handleOnPrepareOptionsMenu(requireActivity(), toolbar); + } + @Override public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); @@ -337,6 +368,12 @@ public class FoldersFragment extends AbsMainActivityFragment implements menu.removeItem(R.id.action_grid_size); menu.removeItem(R.id.action_layout_type); menu.removeItem(R.id.action_sort_order); + ToolbarContentTintHelper.handleOnCreateOptionsMenu( + requireContext(), + toolbar, + menu, + getToolbarBackgroundColor(toolbar) + ); } @Override @@ -420,6 +457,8 @@ public class FoldersFragment extends AbsMainActivityFragment implements breadCrumbs = view.findViewById(R.id.breadCrumbs); empty = view.findViewById(android.R.id.empty); emojiText = view.findViewById(R.id.emptyEmoji); + toolbar = view.findViewById(R.id.toolbar); + appNameText = view.findViewById(R.id.appNameText); } private void saveScrollPosition() { 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 60f5b707..905c30e4 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 @@ -18,16 +18,24 @@ import android.app.ActivityOptions import android.os.Bundle import android.view.Menu import android.view.MenuInflater +import android.view.MenuItem import android.view.MenuItem.SHOW_AS_ACTION_IF_ROOM import android.view.View import androidx.core.os.bundleOf +import androidx.core.text.HtmlCompat import androidx.lifecycle.Observer +import androidx.navigation.fragment.findNavController import androidx.recyclerview.widget.LinearLayoutManager +import code.name.monkey.appthemehelper.ThemeStore +import code.name.monkey.appthemehelper.common.ATHToolbarActivity +import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper import code.name.monkey.retromusic.HISTORY_PLAYLIST import code.name.monkey.retromusic.LAST_ADDED_PLAYLIST import code.name.monkey.retromusic.R import code.name.monkey.retromusic.TOP_PLAYED_PLAYLIST import code.name.monkey.retromusic.adapter.HomeAdapter +import code.name.monkey.retromusic.dialogs.CreatePlaylistDialog +import code.name.monkey.retromusic.dialogs.ImportPlaylistDialog import code.name.monkey.retromusic.extensions.findActivityNavController import code.name.monkey.retromusic.fragments.LibraryViewModel import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment @@ -36,7 +44,6 @@ import code.name.monkey.retromusic.glide.UserProfileGlideRequest import code.name.monkey.retromusic.util.NavigationUtil import code.name.monkey.retromusic.util.PreferenceUtil import com.bumptech.glide.Glide -import com.google.android.material.transition.platform.MaterialFadeThrough import kotlinx.android.synthetic.main.abs_playlists.* import kotlinx.android.synthetic.main.fragment_banner_home.* import kotlinx.android.synthetic.main.home_content.* @@ -48,6 +55,8 @@ class HomeFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) + mainActivity.setSupportActionBar(toolbar) + mainActivity.supportActionBar?.title = null setStatusBarColorAuto(view) bannerImage?.setOnClickListener { val options = ActivityOptions.makeSceneTransitionAnimation( @@ -104,6 +113,24 @@ class HomeFragment : }) loadProfile() + setupTitle() + } + + private fun setupTitle() { + toolbar.setNavigationOnClickListener { + findNavController().navigate( + R.id.searchFragment, + null, + navOptions + ) + } + val color = ThemeStore.accentColor(requireContext()) + val hexColor = String.format("#%06X", 0xFFFFFF and color) + val appName = HtmlCompat.fromHtml( + "Retro Music", + HtmlCompat.FROM_HTML_MODE_COMPACT + ) + appNameText.text = appName } private fun loadProfile() { @@ -121,10 +148,17 @@ class HomeFragment : override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { super.onCreateOptionsMenu(menu, inflater) + inflater.inflate(R.menu.menu_main, menu) menu.removeItem(R.id.action_grid_size) menu.removeItem(R.id.action_layout_type) menu.removeItem(R.id.action_sort_order) menu.findItem(R.id.action_settings).setShowAsAction(SHOW_AS_ACTION_IF_ROOM) + ToolbarContentTintHelper.handleOnCreateOptionsMenu( + requireContext(), + toolbar, + menu, + ATHToolbarActivity.getToolbarBackgroundColor(toolbar) + ) } companion object { @@ -136,4 +170,28 @@ class HomeFragment : return HomeFragment() } } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.action_settings -> findNavController().navigate( + R.id.settingsActivity, + null, + navOptions + ) + R.id.action_import_playlist -> ImportPlaylistDialog().show( + childFragmentManager, + "ImportPlaylist" + ) + R.id.action_add_to_playlist -> CreatePlaylistDialog.create(emptyList()).show( + childFragmentManager, + "ShowCreatePlaylistDialog" + ) + } + return super.onOptionsItemSelected(item) + } + + override fun onPrepareOptionsMenu(menu: Menu) { + super.onPrepareOptionsMenu(menu) + ToolbarContentTintHelper.handleOnPrepareOptionsMenu(requireActivity(), toolbar) + } } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/playlists/PlaylistsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/playlists/PlaylistsFragment.kt index 326e530c..9744cb8e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/playlists/PlaylistsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/playlists/PlaylistsFragment.kt @@ -11,7 +11,6 @@ import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper import code.name.monkey.retromusic.R import code.name.monkey.retromusic.adapter.playlist.PlaylistAdapter import code.name.monkey.retromusic.fragments.base.AbsRecyclerViewFragment -import com.google.android.material.transition.platform.MaterialFadeThrough import kotlinx.android.synthetic.main.fragment_library.* class PlaylistsFragment : AbsRecyclerViewFragment() { @@ -47,12 +46,12 @@ class PlaylistsFragment : AbsRecyclerViewFragment + app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior" /> diff --git a/app/src/main/res/layout/fragment_banner_home.xml b/app/src/main/res/layout/fragment_banner_home.xml index 11778e7e..6db41162 100644 --- a/app/src/main/res/layout/fragment_banner_home.xml +++ b/app/src/main/res/layout/fragment_banner_home.xml @@ -11,100 +11,142 @@ ~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ~ See the GNU General Public License for more details. --> - + android:layout_height="match_parent"> - + app:liftOnScroll="true"> - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + app:layout_scrollFlags="scroll|enterAlways"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_folder.xml b/app/src/main/res/layout/fragment_folder.xml index ffe3abd5..c366f24e 100644 --- a/app/src/main/res/layout/fragment_folder.xml +++ b/app/src/main/res/layout/fragment_folder.xml @@ -1,63 +1,106 @@ - + android:layout_height="match_parent"> - + app:liftOnScroll="true"> - + app:layout_scrollFlags="scroll|enterAlways"> - + + + + + + + + + + + - + android:gravity="center" + android:orientation="vertical" + android:visibility="gone" + tools:visibility="visible"> - + - + + - + android:orientation="vertical"> - - \ No newline at end of file + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_home.xml b/app/src/main/res/layout/fragment_home.xml index 1233a2a5..2ccb2849 100755 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -11,66 +11,108 @@ ~ without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. ~ See the GNU General Public License for more details. --> - + android:layout_height="match_parent"> - + android:layout_height="wrap_content" + app:liftOnScroll="true"> - - - + app:layout_scrollFlags="scroll|enterAlways"> - + - - + + - \ No newline at end of file + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_main_recycler.xml b/app/src/main/res/layout/fragment_main_recycler.xml new file mode 100644 index 00000000..9342abdf --- /dev/null +++ b/app/src/main/res/layout/fragment_main_recycler.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/navigation/main_graph.xml b/app/src/main/res/navigation/main_graph.xml index bd9c0e75..ad6626bf 100644 --- a/app/src/main/res/navigation/main_graph.xml +++ b/app/src/main/res/navigation/main_graph.xml @@ -3,7 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/retro_graph" - app:startDestination="@id/libraryFragment"> + app:startDestination="@id/action_home"> + + + + + + + + + + + + + + + + + \ No newline at end of file