From 1174cbb477e56b46b44ae65032db7a87d8f4944f Mon Sep 17 00:00:00 2001 From: h4h13 Date: Wed, 19 Feb 2020 00:41:26 +0530 Subject: [PATCH 1/5] WIP Removing library fragment --- .../retromusic/activities/MainActivity.kt | 346 +++++++++++++++++- .../fragments/base/AbsLibraryPagerFragment.kt | 7 +- .../AbsLibraryPagerRecyclerViewFragment.kt | 6 +- .../fragments/mainactivity/AlbumsFragment.kt | 13 +- .../fragments/mainactivity/ArtistsFragment.kt | 17 +- .../fragments/mainactivity/GenresFragment.kt | 11 +- .../mainactivity/PlayingQueueFragment.kt | 8 +- .../mainactivity/PlaylistsFragment.kt | 14 +- .../fragments/mainactivity/SongsFragment.kt | 18 +- .../monkey/retromusic/helper/SortOrder.kt | 11 +- .../MainActivityFragmentCallbacks.kt | 3 +- .../main/res/layout/activity_main_content.xml | 72 +++- 12 files changed, 484 insertions(+), 42 deletions(-) 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 01eb8532..0d12575d 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 @@ -1,33 +1,66 @@ package code.name.monkey.retromusic.activities +import android.app.ActivityOptions import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter import android.content.SharedPreferences +import android.content.res.ColorStateList +import android.graphics.Color import android.os.Bundle import android.provider.MediaStore import android.util.Log +import android.view.Menu +import android.view.MenuItem +import android.view.SubMenu import android.view.View import androidx.core.app.ActivityCompat import androidx.fragment.app.Fragment +import code.name.monkey.appthemehelper.util.ATHUtil +import code.name.monkey.appthemehelper.util.ATHUtil.resolveColor import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.R.drawable +import code.name.monkey.retromusic.R.id +import code.name.monkey.retromusic.R.layout +import code.name.monkey.retromusic.R.string import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity +import code.name.monkey.retromusic.dialogs.CreatePlaylistDialog.Companion.create +import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment +import code.name.monkey.retromusic.fragments.mainactivity.AlbumsFragment +import code.name.monkey.retromusic.fragments.mainactivity.ArtistsFragment +import code.name.monkey.retromusic.fragments.mainactivity.GenresFragment import code.name.monkey.retromusic.fragments.mainactivity.LibraryFragment +import code.name.monkey.retromusic.fragments.mainactivity.PlayingQueueFragment +import code.name.monkey.retromusic.fragments.mainactivity.PlaylistsFragment +import code.name.monkey.retromusic.fragments.mainactivity.SongsFragment import code.name.monkey.retromusic.fragments.mainactivity.folders.FoldersFragment import code.name.monkey.retromusic.fragments.mainactivity.home.BannerHomeFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.helper.SearchQueryHelper +import code.name.monkey.retromusic.helper.SortOrder.AlbumSortOrder +import code.name.monkey.retromusic.helper.SortOrder.ArtistSortOrder +import code.name.monkey.retromusic.helper.SortOrder.SongSortOrder +import code.name.monkey.retromusic.interfaces.CabHolder import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks import code.name.monkey.retromusic.loaders.AlbumLoader import code.name.monkey.retromusic.loaders.ArtistLoader import code.name.monkey.retromusic.loaders.PlaylistSongsLoader import code.name.monkey.retromusic.service.MusicService import code.name.monkey.retromusic.util.AppRater +import code.name.monkey.retromusic.util.NavigationUtil import code.name.monkey.retromusic.util.PreferenceUtil +import code.name.monkey.retromusic.util.RetroColorUtil +import code.name.monkey.retromusic.util.RetroUtil +import com.afollestad.materialcab.MaterialCab +import com.afollestad.materialcab.MaterialCab.Callback +import com.google.android.material.appbar.AppBarLayout.OnOffsetChangedListener +import kotlinx.android.synthetic.main.activity_main_content.appBarLayout +import kotlinx.android.synthetic.main.activity_main_content.toolbar +import kotlinx.android.synthetic.main.activity_main_content.toolbarContainer import java.util.ArrayList -class MainActivity : AbsSlidingMusicPanelActivity(), SharedPreferences.OnSharedPreferenceChangeListener { +class MainActivity : AbsSlidingMusicPanelActivity(), CabHolder, SharedPreferences.OnSharedPreferenceChangeListener { private lateinit var currentFragment: MainActivityFragmentCallbacks @@ -71,6 +104,23 @@ class MainActivity : AbsSlidingMusicPanelActivity(), SharedPreferences.OnSharedP checkShowChangelog() AppRater.appLaunched(this) + setupToolbar() + setBottomBarVisibility(View.VISIBLE) + } + + private fun setupToolbar() { + toolbar.setBackgroundColor(Color.TRANSPARENT) + toolbarContainer.backgroundTintList = + ColorStateList.valueOf(resolveColor(this, R.attr.colorSurface)) + setSupportActionBar(toolbar) + toolbar.setOnClickListener { + val options = ActivityOptions + .makeSceneTransitionAnimation( + this, toolbarContainer, + getString(R.string.transition_toolbar) + ) + NavigationUtil.goToSearch(this, options) + } } private fun checkShowChangelog() { @@ -238,12 +288,12 @@ class MainActivity : AbsSlidingMusicPanelActivity(), SharedPreferences.OnSharedP private fun selectedFragment(itemId: Int) { when (itemId) { - R.id.action_album, - R.id.action_artist, - R.id.action_playlist, - R.id.action_genre, - R.id.action_playing_queue, - R.id.action_song -> setCurrentFragment(LibraryFragment.newInstance(itemId), itemId.toString()) + R.id.action_album -> setCurrentFragment(AlbumsFragment.newInstance(), itemId.toString()) + R.id.action_artist -> setCurrentFragment(ArtistsFragment.newInstance(), itemId.toString()) + R.id.action_playlist -> setCurrentFragment(PlaylistsFragment.newInstance(), itemId.toString()) + R.id.action_genre -> setCurrentFragment(GenresFragment.newInstance(), itemId.toString()) + R.id.action_playing_queue -> setCurrentFragment(PlayingQueueFragment.newInstance(), itemId.toString()) + R.id.action_song -> setCurrentFragment(SongsFragment.newInstance(), itemId.toString()) R.id.action_home -> setCurrentFragment(BannerHomeFragment.newInstance(), BannerHomeFragment.TAG) else -> { setCurrentFragment(BannerHomeFragment.newInstance(), BannerHomeFragment.TAG) @@ -269,4 +319,286 @@ class MainActivity : AbsSlidingMusicPanelActivity(), SharedPreferences.OnSharedP private const val REQUEST_CODE_THEME = 9002 private const val PURCHASE_REQUEST = 101 } + + private lateinit var cab: MaterialCab + + fun getTotalAppBarScrollingRange(): Int { + return appBarLayout.totalScrollRange + } + + fun addOnAppBarOffsetChangedListener( + onOffsetChangedListener: OnOffsetChangedListener + ) { + appBarLayout.addOnOffsetChangedListener(onOffsetChangedListener) + } + + fun removeOnAppBarOffsetChangedListener( + onOffsetChangedListener: OnOffsetChangedListener + ) { + appBarLayout.removeOnOffsetChangedListener(onOffsetChangedListener) + } + + override fun openCab(menuRes: Int, callback: Callback): MaterialCab { + if (cab != null && cab.isActive()) { + cab.finish() + } + + cab = MaterialCab(this, R.id.cab_stub) + .setMenu(menuRes) + .setCloseDrawableRes(R.drawable.ic_close_white_24dp) + .setBackgroundColor( + RetroColorUtil.shiftBackgroundColorForLightText( + ATHUtil.resolveColor(this, R.attr.colorSurface) + ) + ) + .start(callback) + return cab + } + + private fun getCurrentFragment(): Fragment? { + return if (supportFragmentManager == null) { + SongsFragment.newInstance() + } else supportFragmentManager.findFragmentByTag(LibraryFragment.TAG) + } + + override fun onCreateOptionsMenu(menu: Menu?): Boolean { + menuInflater.inflate(R.menu.menu_main, menu) + val currentFragment: Fragment? = getCurrentFragment() + if (currentFragment is AbsLibraryPagerRecyclerViewCustomGridSizeFragment<*, *> + && currentFragment.isAdded() + ) { + + if (currentFragment is SongsFragment) { + menu!!.removeItem(id.action_grid_size) + menu.removeItem(id.action_layout_type) + } else { + val gridSizeItem = menu!!.findItem(id.action_grid_size) + if (RetroUtil.isLandscape()) { + gridSizeItem.setTitle(string.action_grid_size_land) + } + setUpGridSizeMenu(currentFragment, gridSizeItem.subMenu) + val layoutItem = menu.findItem(id.action_layout_type) + setupLayoutMenu(currentFragment, layoutItem.subMenu) + } + setUpSortOrderMenu(currentFragment, menu.findItem(id.action_sort_order).subMenu) + } else if (currentFragment is GenresFragment || currentFragment is PlayingQueueFragment) { + menu!!.removeItem(id.action_new_playlist) + menu.removeItem(id.action_layout_type) + menu.removeItem(id.action_grid_size) + menu.removeItem(id.action_sort_order) + } else { + menu!!.add(0, id.action_new_playlist, 0, string.new_playlist_title) + .setIcon(drawable.ic_playlist_add_white_24dp) + .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM) + menu.removeItem(id.action_grid_size) + menu.removeItem(id.action_layout_type) + } + return super.onCreateOptionsMenu(menu) + } + + private fun setUpGridSizeMenu( + fragment: AbsLibraryPagerRecyclerViewCustomGridSizeFragment<*, *>, + gridSizeMenu: SubMenu + ) { + when (fragment.getGridSize()) { + 1 -> gridSizeMenu.findItem(id.action_grid_size_1).isChecked = true + 2 -> gridSizeMenu.findItem(id.action_grid_size_2).isChecked = true + 3 -> gridSizeMenu.findItem(id.action_grid_size_3).isChecked = true + 4 -> gridSizeMenu.findItem(id.action_grid_size_4).isChecked = true + 5 -> gridSizeMenu.findItem(id.action_grid_size_5).isChecked = true + 6 -> gridSizeMenu.findItem(id.action_grid_size_6).isChecked = true + 7 -> gridSizeMenu.findItem(id.action_grid_size_7).isChecked = true + 8 -> gridSizeMenu.findItem(id.action_grid_size_8).isChecked = true + } + val maxGridSize = fragment.maxGridSize + if (maxGridSize < 8) { + gridSizeMenu.findItem(id.action_grid_size_8).isVisible = false + } + if (maxGridSize < 7) { + gridSizeMenu.findItem(id.action_grid_size_7).isVisible = false + } + if (maxGridSize < 6) { + gridSizeMenu.findItem(id.action_grid_size_6).isVisible = false + } + if (maxGridSize < 5) { + gridSizeMenu.findItem(id.action_grid_size_5).isVisible = false + } + if (maxGridSize < 4) { + gridSizeMenu.findItem(id.action_grid_size_4).isVisible = false + } + if (maxGridSize < 3) { + gridSizeMenu.findItem(id.action_grid_size_3).isVisible = false + } + } + + private fun setUpSortOrderMenu( + fragment: AbsLibraryPagerRecyclerViewCustomGridSizeFragment<*, *>, + sortOrderMenu: SubMenu + ) { + val currentSortOrder = fragment.getSortOrder() + sortOrderMenu.clear() + when (fragment) { + is AlbumsFragment -> { + sortOrderMenu.add(0, id.action_album_sort_order_asc, 0, string.sort_order_a_z).isChecked = + currentSortOrder == AlbumSortOrder.ALBUM_A_Z + sortOrderMenu.add(0, id.action_album_sort_order_desc, 1, string.sort_order_z_a).isChecked = + currentSortOrder == AlbumSortOrder.ALBUM_Z_A + sortOrderMenu.add(0, id.action_album_sort_order_artist, 2, string.sort_order_artist).isChecked = + currentSortOrder == AlbumSortOrder.ALBUM_ARTIST + sortOrderMenu.add(0, id.action_album_sort_order_year, 3, string.sort_order_year).isChecked = + currentSortOrder == AlbumSortOrder.ALBUM_YEAR + } + is ArtistsFragment -> { + sortOrderMenu.add(0, id.action_artist_sort_order_asc, 0, string.sort_order_a_z).isChecked = + currentSortOrder == ArtistSortOrder.ARTIST_A_Z + sortOrderMenu.add(0, id.action_artist_sort_order_desc, 1, string.sort_order_z_a).isChecked = + currentSortOrder == ArtistSortOrder.ARTIST_Z_A + } + is SongsFragment -> { + sortOrderMenu.add(0, id.action_song_sort_order_asc, 0, string.sort_order_a_z).isChecked = + currentSortOrder == SongSortOrder.SONG_A_Z + sortOrderMenu.add(0, id.action_song_sort_order_desc, 1, string.sort_order_z_a).isChecked = + currentSortOrder == SongSortOrder.SONG_Z_A + sortOrderMenu.add(0, id.action_song_sort_order_artist, 2, string.sort_order_artist).isChecked = + currentSortOrder == SongSortOrder.SONG_ARTIST + sortOrderMenu.add(0, id.action_song_sort_order_album, 3, string.sort_order_album).isChecked = + currentSortOrder == SongSortOrder.SONG_ALBUM + sortOrderMenu.add(0, id.action_song_sort_order_year, 4, string.sort_order_year).isChecked = + currentSortOrder == SongSortOrder.SONG_YEAR + sortOrderMenu.add(0, id.action_song_sort_order_date, 5, string.sort_order_date).isChecked = + currentSortOrder == SongSortOrder.SONG_DATE + sortOrderMenu.add(0, id.action_song_sort_order_composer, 6, string.sort_order_composer).isChecked = + currentSortOrder == SongSortOrder.COMPOSER + } + } + sortOrderMenu.setGroupCheckable(0, true, true) + } + + private fun setupLayoutMenu( + fragment: AbsLibraryPagerRecyclerViewCustomGridSizeFragment<*, *>, + subMenu: SubMenu + ) { + when (fragment.itemLayoutRes()) { + layout.item_card -> subMenu.findItem(id.action_layout_card).isChecked = true + layout.item_grid -> subMenu.findItem(id.action_layout_normal).isChecked = true + layout.item_card_color -> subMenu.findItem(id.action_layout_colored_card).isChecked = true + layout.item_grid_circle -> subMenu.findItem(id.action_layout_circular).isChecked = true + layout.image -> subMenu.findItem(id.action_layout_image).isChecked = true + layout.item_image_gradient -> subMenu.findItem(id.action_layout_gradient_image).isChecked = true + } + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + //if (pager == null) return false; + val currentFragment = getCurrentFragment() + if (currentFragment is AbsLibraryPagerRecyclerViewCustomGridSizeFragment<*, *>) { + if (handleGridSizeMenuItem(currentFragment, item)) { + return true + } + if (handleLayoutResType(currentFragment, item)) { + return true + } + if (handleSortOrderMenuItem(currentFragment, item)) { + return true + } + } + when (item.itemId) { + R.id.action_search -> { + val options = ActivityOptions + .makeSceneTransitionAnimation( + this, toolbarContainer, + getString(string.transition_toolbar) + ) + NavigationUtil.goToSearch(this, options) + } + R.id.action_new_playlist -> { + create().show(supportFragmentManager, "CREATE_PLAYLIST") + return true + } + } + return super.onOptionsItemSelected(item) + } + + private fun handleGridSizeMenuItem( + fragment: AbsLibraryPagerRecyclerViewCustomGridSizeFragment<*, *>, + item: MenuItem + ): Boolean { + var gridSize = 0 + when (item.itemId) { + id.action_grid_size_1 -> gridSize = 1 + id.action_grid_size_2 -> gridSize = 2 + id.action_grid_size_3 -> gridSize = 3 + id.action_grid_size_4 -> gridSize = 4 + id.action_grid_size_5 -> gridSize = 5 + id.action_grid_size_6 -> gridSize = 6 + id.action_grid_size_7 -> gridSize = 7 + id.action_grid_size_8 -> gridSize = 8 + } + if (gridSize > 0) { + item.isChecked = true + fragment.setAndSaveGridSize(gridSize) + return true + } + return false + } + + private fun handleLayoutResType( + fragment: AbsLibraryPagerRecyclerViewCustomGridSizeFragment<*, *>, + item: MenuItem + ): Boolean { + var layoutRes = -1 + when (item.itemId) { + id.action_layout_normal -> layoutRes = layout.item_grid + id.action_layout_card -> layoutRes = layout.item_card + id.action_layout_colored_card -> layoutRes = layout.item_card_color + id.action_layout_circular -> layoutRes = layout.item_grid_circle + id.action_layout_image -> layoutRes = layout.image + id.action_layout_gradient_image -> layoutRes = layout.item_image_gradient + } + if (layoutRes != -1) { + item.isChecked = true + fragment.setAndSaveLayoutRes(layoutRes) + return true + } + return false + } + + private fun handleSortOrderMenuItem( + fragment: AbsLibraryPagerRecyclerViewCustomGridSizeFragment<*, *>, item: MenuItem + ): Boolean { + var sortOrder: String? = null + when (fragment) { + is SongsFragment -> { + when (item.itemId) { + id.action_song_sort_order_asc -> sortOrder = SongSortOrder.SONG_A_Z + id.action_song_sort_order_desc -> sortOrder = SongSortOrder.SONG_Z_A + id.action_song_sort_order_artist -> sortOrder = SongSortOrder.SONG_ARTIST + id.action_song_sort_order_album -> sortOrder = SongSortOrder.SONG_ALBUM + id.action_song_sort_order_year -> sortOrder = SongSortOrder.SONG_YEAR + id.action_song_sort_order_date -> sortOrder = SongSortOrder.SONG_DATE + id.action_song_sort_order_composer -> sortOrder = SongSortOrder.COMPOSER + } + } + is AlbumsFragment -> { + when (item.itemId) { + id.action_album_sort_order_asc -> sortOrder = AlbumSortOrder.ALBUM_A_Z + id.action_album_sort_order_desc -> sortOrder = AlbumSortOrder.ALBUM_Z_A + id.action_album_sort_order_artist -> sortOrder = AlbumSortOrder.ALBUM_ARTIST + id.action_album_sort_order_year -> sortOrder = AlbumSortOrder.ALBUM_YEAR + } + } + is ArtistsFragment -> { + when (item.itemId) { + id.action_artist_sort_order_asc -> sortOrder = ArtistSortOrder.ARTIST_A_Z + id.action_artist_sort_order_desc -> sortOrder = ArtistSortOrder.ARTIST_Z_A + } + } + } + if (sortOrder != null) { + item.isChecked = true + fragment.setAndSaveSortOrder(sortOrder) + return true + } + return false + } } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsLibraryPagerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsLibraryPagerFragment.kt index c1ceaefc..d725202e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsLibraryPagerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsLibraryPagerFragment.kt @@ -1,13 +1,12 @@ package code.name.monkey.retromusic.fragments.base import android.os.Bundle -import code.name.monkey.retromusic.fragments.mainactivity.LibraryFragment +import code.name.monkey.retromusic.activities.MainActivity open class AbsLibraryPagerFragment : AbsMusicServiceFragment() { - - val libraryFragment: LibraryFragment - get() = parentFragment as LibraryFragment + val mainActivity: MainActivity + get() = requireActivity() as MainActivity override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsLibraryPagerRecyclerViewFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsLibraryPagerRecyclerViewFragment.kt index dd4c3bf9..f6047f1e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsLibraryPagerRecyclerViewFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsLibraryPagerRecyclerViewFragment.kt @@ -35,7 +35,7 @@ abstract class AbsLibraryPagerRecyclerViewFragment, override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - libraryFragment.addOnAppBarOffsetChangedListener(this) + mainActivity.addOnAppBarOffsetChangedListener(this) initLayoutManager() initAdapter() setUpRecyclerView() @@ -109,7 +109,7 @@ abstract class AbsLibraryPagerRecyclerViewFragment, container.paddingLeft, container.paddingTop, container.paddingRight, - libraryFragment.totalAppBarScrollingRange + i + mainActivity.getTotalAppBarScrollingRange() + i ) } @@ -136,7 +136,7 @@ abstract class AbsLibraryPagerRecyclerViewFragment, override fun onDestroyView() { super.onDestroyView() - libraryFragment.removeOnAppBarOffsetChangedListener(this) + mainActivity.removeOnAppBarOffsetChangedListener(this) } fun recyclerView(): RecyclerView { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/AlbumsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/AlbumsFragment.kt index 4790b261..a453356b 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/AlbumsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/AlbumsFragment.kt @@ -7,6 +7,7 @@ import code.name.monkey.retromusic.App import code.name.monkey.retromusic.R import code.name.monkey.retromusic.adapter.album.AlbumAdapter import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment +import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks import code.name.monkey.retromusic.model.Album import code.name.monkey.retromusic.mvp.presenter.AlbumsPresenter import code.name.monkey.retromusic.mvp.presenter.AlbumsView @@ -14,7 +15,7 @@ import code.name.monkey.retromusic.util.PreferenceUtil import javax.inject.Inject class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment(), - AlbumsView { + AlbumsView, MainActivityFragmentCallbacks { @Inject lateinit var albumsPresenter: AlbumsPresenter @@ -49,16 +50,16 @@ class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment(), - ArtistsView { + ArtistsView, MainActivityFragmentCallbacks { + + override fun handleBackPress(): Boolean { + return false + } override fun artists(artists: List) { adapter?.swapDataSet(artists) @@ -57,21 +62,21 @@ class ArtistsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment(), GenresView { +class GenresFragment : AbsLibraryPagerRecyclerViewFragment(), + GenresView, MainActivityFragmentCallbacks { + + override fun handleBackPress(): Boolean { + return false + } + override fun genres(genres: List) { adapter?.swapDataSet(genres) } @@ -40,7 +47,7 @@ class GenresFragment : AbsLibraryPagerRecyclerViewFragment() { +class PlayingQueueFragment : AbsLibraryPagerRecyclerViewFragment(), + MainActivityFragmentCallbacks { + + override fun handleBackPress(): Boolean { + return false + } private lateinit var wrappedAdapter: RecyclerView.Adapter<*> private var recyclerViewDragDropManager: RecyclerViewDragDropManager? = null diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/PlaylistsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/PlaylistsFragment.kt index 76a6721e..c7af01bb 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/PlaylistsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/PlaylistsFragment.kt @@ -9,12 +9,18 @@ import code.name.monkey.retromusic.App import code.name.monkey.retromusic.R import code.name.monkey.retromusic.adapter.playlist.PlaylistAdapter import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewFragment +import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks import code.name.monkey.retromusic.model.Playlist import code.name.monkey.retromusic.mvp.presenter.PlaylistView import code.name.monkey.retromusic.mvp.presenter.PlaylistsPresenter import javax.inject.Inject -class PlaylistsFragment : AbsLibraryPagerRecyclerViewFragment(), PlaylistView { +class PlaylistsFragment : AbsLibraryPagerRecyclerViewFragment(), PlaylistView, + MainActivityFragmentCallbacks { + + override fun handleBackPress(): Boolean { + return false + } @Inject lateinit var playlistsPresenter: PlaylistsPresenter @@ -38,8 +44,10 @@ class PlaylistsFragment : AbsLibraryPagerRecyclerViewFragment(), - SongView { + SongView, MainActivityFragmentCallbacks { @Inject lateinit var songPresenter: SongPresenter @@ -36,16 +37,16 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment - + android:layout_height="match_parent" + android:background="?colorSurface" + android:orientation="vertical"> + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 8a58021deba0d5c00a5a7b43a30a67b086d88f84 Mon Sep 17 00:00:00 2001 From: h4h13 Date: Wed, 19 Feb 2020 12:38:12 +0530 Subject: [PATCH 2/5] Removed library fragment --- .../retromusic/activities/LyricsActivity.kt | 1 - .../retromusic/activities/MainActivity.java | 708 ++++++++++++++++++ .../retromusic/activities/MainActivity.kt | 604 --------------- .../retromusic/adapter/ContributorAdapter.kt | 1 - .../monkey/retromusic/adapter/HomeAdapter.kt | 1 - .../dialogs/CreatePlaylistDialog.kt | 40 +- .../dialogs/OptionsSheetDialogFragment.kt | 8 +- .../monkey/retromusic/extensions/ListEx.kt | 32 - .../AbsLibraryPagerRecyclerViewFragment.kt | 2 +- .../fragments/mainactivity/AlbumsFragment.kt | 2 +- .../fragments/mainactivity/ArtistsFragment.kt | 2 +- .../fragments/mainactivity/GenresFragment.kt | 2 +- .../mainactivity/PlayingQueueFragment.kt | 2 +- .../mainactivity/PlaylistsFragment.kt | 1 + .../mainactivity/home/BannerHomeFragment.kt | 63 +- .../normal/PlayerPlaybackControlsFragment.kt | 2 +- .../player/peak/PeakPlayerControlFragment.kt | 2 - .../retromusic/helper/MusicPlayerRemote.kt | 8 +- .../retromusic/helper/SearchQueryHelper.kt | 58 +- .../monkey/retromusic/loaders/AlbumLoader.kt | 5 +- .../monkey/retromusic/loaders/ArtistLoader.kt | 24 +- .../retromusic/loaders/PlaylistSongsLoader.kt | 2 +- .../name/monkey/retromusic/model/Album.kt | 1 + .../preferences/MaterialListPreference.kt | 1 - .../name/monkey/retromusic/util/AppRater.kt | 45 +- .../retromusic/util/PreferenceUtil.java | 9 - .../res/layout-land/fragment_banner_home.xml | 179 ++--- .../main/res/layout-land/fragment_home.xml | 149 ++-- .../main/res/layout/activity_main_content.xml | 2 +- .../main/res/layout/fragment_banner_home.xml | 186 ++--- app/src/main/res/layout/fragment_home.xml | 143 ++-- 31 files changed, 1079 insertions(+), 1206 deletions(-) create mode 100644 app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java delete mode 100644 app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt delete mode 100644 app/src/main/java/code/name/monkey/retromusic/extensions/ListEx.kt diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/LyricsActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/LyricsActivity.kt index 6f06f626..80ef2287 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/LyricsActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/LyricsActivity.kt @@ -417,7 +417,6 @@ class LyricsActivity : AbsMusicServiceActivity(), View.OnClickListener, ViewPage private fun loadLRCLyrics() { lyricsView.resetView("Empty") val song = MusicPlayerRemote.currentSong - println("${song.title} ${song.artistName}") if (LyricUtil.isLrcFileExist(song.title, song.artistName)) { showLyricsLocal(LyricUtil.getLocalLyricFile(song.title, song.artistName)) } diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java new file mode 100644 index 00000000..478903d7 --- /dev/null +++ b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java @@ -0,0 +1,708 @@ +/* + * Copyright (c) 2020 Hemanth Savarala. + * + * Licensed under the GNU General Public License v3 + * + * This is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by + * the Free Software Foundation either version 3 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. + */ + +package code.name.monkey.retromusic.activities; + +import android.app.ActivityOptions; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.SharedPreferences; +import android.content.pm.PackageInfo; +import android.content.pm.PackageManager.NameNotFoundException; +import android.content.res.ColorStateList; +import android.graphics.Color; +import android.net.Uri; +import android.os.Bundle; +import android.provider.MediaStore; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.SubMenu; +import android.view.View; +import androidx.annotation.NonNull; +import androidx.appcompat.widget.Toolbar; +import androidx.core.app.ActivityCompat; +import androidx.fragment.app.Fragment; +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.activities.base.AbsSlidingMusicPanelActivity; +import code.name.monkey.retromusic.dialogs.CreatePlaylistDialog; +import code.name.monkey.retromusic.dialogs.OptionsSheetDialogFragment; +import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment; +import code.name.monkey.retromusic.fragments.mainactivity.AlbumsFragment; +import code.name.monkey.retromusic.fragments.mainactivity.ArtistsFragment; +import code.name.monkey.retromusic.fragments.mainactivity.GenresFragment; +import code.name.monkey.retromusic.fragments.mainactivity.PlayingQueueFragment; +import code.name.monkey.retromusic.fragments.mainactivity.PlaylistsFragment; +import code.name.monkey.retromusic.fragments.mainactivity.SongsFragment; +import code.name.monkey.retromusic.fragments.mainactivity.home.BannerHomeFragment; +import code.name.monkey.retromusic.helper.MusicPlayerRemote; +import code.name.monkey.retromusic.helper.SearchQueryHelper; +import code.name.monkey.retromusic.helper.SortOrder.AlbumSortOrder; +import code.name.monkey.retromusic.helper.SortOrder.ArtistSortOrder; +import code.name.monkey.retromusic.helper.SortOrder.SongSortOrder; +import code.name.monkey.retromusic.interfaces.CabHolder; +import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks; +import code.name.monkey.retromusic.loaders.AlbumLoader; +import code.name.monkey.retromusic.loaders.ArtistLoader; +import code.name.monkey.retromusic.loaders.PlaylistSongsLoader; +import code.name.monkey.retromusic.model.Song; +import code.name.monkey.retromusic.service.MusicService; +import code.name.monkey.retromusic.util.AppRater; +import code.name.monkey.retromusic.util.NavigationUtil; +import code.name.monkey.retromusic.util.PreferenceUtil; +import code.name.monkey.retromusic.util.RetroUtil; +import com.afollestad.materialcab.MaterialCab; +import com.afollestad.materialcab.MaterialCab.Callback; +import com.google.android.material.appbar.AppBarLayout; +import com.google.android.material.card.MaterialCardView; +import java.util.ArrayList; +import java.util.List; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Created by hemanths on 2020-02-19. + */ +public class MainActivity extends AbsSlidingMusicPanelActivity + implements CabHolder, SharedPreferences.OnSharedPreferenceChangeListener { + + public static final String TAG = MainActivity.class.getSimpleName(); + + public static final int APP_INTRO_REQUEST = 100; + + public static final String EXPAND_PANEL = "expand_panel"; + + @Nullable + MainActivityFragmentCallbacks currentFragment; + + private boolean blockRequestPermissions = false; + + private AppBarLayout mAppBarLayout; + + private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { + @Override + public void onReceive(final Context context, final Intent intent) { + String action = intent.getAction(); + if (action != null && action.equals(Intent.ACTION_SCREEN_OFF)) { + if (PreferenceUtil.getInstance(context).getLockScreen() && MusicPlayerRemote.isPlaying()) { + final Intent activity = new Intent(context, LockScreenActivity.class); + activity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + activity.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); + ActivityCompat.startActivity(context, activity, null); + } + } + } + }; + + private final IntentFilter mIntentFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF); + + private Toolbar mToolbar; + + private MaterialCardView mToolbarContainer; + + @Override + protected void onCreate(@Nullable final Bundle savedInstanceState) { + setDrawUnderStatusBar(); + super.onCreate(savedInstanceState); + setStatusbarColorAuto(); + setNavigationbarColorAuto(); + setLightNavigationBar(true); + setTaskDescriptionColorAuto(); + hideStatusBar(); + setBottomBarVisibility(View.VISIBLE); + + getBottomNavigationView().setSelectedItemId(PreferenceUtil.getInstance(this).getLastPage()); + getBottomNavigationView().setOnNavigationItemSelectedListener(item -> { + PreferenceUtil.getInstance(MainActivity.this).setLastPage(item.getItemId()); + selectedFragment(item.getItemId()); + return true; + }); + + if (savedInstanceState == null) { + selectedFragment(PreferenceUtil.getInstance(this).getLastPage()); + } else { + restoreCurrentFragment(); + } + + mToolbarContainer = findViewById(R.id.toolbarContainer); + mToolbar = findViewById(R.id.toolbar); + mAppBarLayout = findViewById(R.id.appBarLayout); + + checkShowChangelog(); + AppRater.appLaunched(this); + setupToolbar(); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + if (requestCode == APP_INTRO_REQUEST) { + blockRequestPermissions = false; + if (!hasPermissions()) { + requestPermissions(); + } + } + } + + @Override + protected void onResume() { + super.onResume(); + registerReceiver(mBroadcastReceiver, mIntentFilter); + PreferenceUtil.getInstance(this).registerOnSharedPreferenceChangedListener(this); + + if (getIntent().hasExtra(EXPAND_PANEL)) { + if (getIntent().getBooleanExtra(EXPAND_PANEL, false)) { + expandPanel(); + getIntent().putExtra(EXPAND_PANEL, false); + } + } + } + + @Override + public void onDestroy() { + super.onDestroy(); + unregisterReceiver(mBroadcastReceiver); + PreferenceUtil.getInstance(this).unregisterOnSharedPreferenceChangedListener(this); + } + + public void addOnAppBarOffsetChangedListener( + @NonNull AppBarLayout.OnOffsetChangedListener onOffsetChangedListener) { + mAppBarLayout.addOnOffsetChangedListener(onOffsetChangedListener); + } + + public int getTotalAppBarScrollingRange() { + return mAppBarLayout.getTotalScrollRange(); + } + + @Override + public boolean onCreateOptionsMenu(final Menu menu) { + getMenuInflater().inflate(R.menu.menu_main, menu); + if (isPlaylistPage()) { + menu.add(0, R.id.action_new_playlist, 0, R.string.new_playlist_title) + .setIcon(R.drawable.ic_playlist_add_white_24dp).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); + } + if (isHomePage()) { + menu.add(0, R.id.action_search, 0, getString(R.string.action_search)) + .setIcon(R.drawable.ic_mic_white_24dp).setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM); + } + Fragment fragment = getCurrentFragment(); + if (fragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment) { + AbsLibraryPagerRecyclerViewCustomGridSizeFragment currentFragment + = (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) fragment; + if (currentFragment instanceof SongsFragment) { + menu.removeItem(R.id.action_grid_size); + menu.removeItem(R.id.action_layout_type); + } else { + MenuItem gridSizeItem = menu.findItem(R.id.action_grid_size); + if (RetroUtil.isLandscape()) { + gridSizeItem.setTitle(R.string.action_grid_size_land); + } + setUpGridSizeMenu(currentFragment, gridSizeItem.getSubMenu()); + MenuItem layoutItem = menu.findItem(R.id.action_layout_type); + setupLayoutMenu(currentFragment, layoutItem.getSubMenu()); + } + setUpSortOrderMenu(currentFragment, menu.findItem(R.id.action_sort_order).getSubMenu()); + } else { + menu.removeItem(R.id.action_layout_type); + menu.removeItem(R.id.action_grid_size); + menu.removeItem(R.id.action_sort_order); + } + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(@NonNull final MenuItem item) { + Fragment fragment = getCurrentFragment(); + if (fragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment) { + AbsLibraryPagerRecyclerViewCustomGridSizeFragment currentFragment + = (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) fragment; + if (handleGridSizeMenuItem(currentFragment, item)) { + return true; + } + if (handleLayoutResType(currentFragment, item)) { + return true; + } + if (handleSortOrderMenuItem(currentFragment, item)) { + return true; + } + } + int id = item.getItemId(); + switch (id) { + case R.id.action_search: + ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this, mToolbarContainer, + getString(R.string.transition_toolbar)); + NavigationUtil.goToSearch(this, true, options); + break; + case R.id.action_new_playlist: + CreatePlaylistDialog.create().show(getSupportFragmentManager(), "CREATE_PLAYLIST"); + return true; + } + return super.onOptionsItemSelected(item); + } + + @Override + public boolean onPrepareOptionsMenu(final Menu menu) { + ToolbarContentTintHelper.handleOnPrepareOptionsMenu(this, mToolbar); + return super.onPrepareOptionsMenu(menu); + } + + @Override + public void onServiceConnected() { + super.onServiceConnected(); + handlePlaybackIntent(getIntent()); + } + + @Override + public void onSharedPreferenceChanged(final @NonNull SharedPreferences sharedPreferences, + final @NonNull String key) { + if (key.equals(PreferenceUtil.GENERAL_THEME) || key.equals(PreferenceUtil.BLACK_THEME) || + key.equals(PreferenceUtil.ADAPTIVE_COLOR_APP) || key.equals(PreferenceUtil.DOMINANT_COLOR) || + key.equals(PreferenceUtil.USER_NAME) || key.equals(PreferenceUtil.TOGGLE_FULL_SCREEN) || + key.equals(PreferenceUtil.TOGGLE_VOLUME) || key.equals(PreferenceUtil.ROUND_CORNERS) || + key.equals(PreferenceUtil.CAROUSEL_EFFECT) || key == PreferenceUtil.NOW_PLAYING_SCREEN_ID || + key == PreferenceUtil.TOGGLE_GENRE || key == PreferenceUtil.BANNER_IMAGE_PATH || + key == PreferenceUtil.PROFILE_IMAGE_PATH || key == PreferenceUtil.CIRCULAR_ALBUM_ART || + key == PreferenceUtil.KEEP_SCREEN_ON || key == PreferenceUtil.TOGGLE_SEPARATE_LINE || + key == PreferenceUtil.TOGGLE_HOME_BANNER || key == PreferenceUtil.TOGGLE_ADD_CONTROLS || + key == PreferenceUtil.ALBUM_COVER_STYLE || key == PreferenceUtil.HOME_ARTIST_GRID_STYLE || + key == PreferenceUtil.ALBUM_COVER_TRANSFORM || key == PreferenceUtil.DESATURATED_COLOR || + key == PreferenceUtil.TAB_TEXT_MODE || key == PreferenceUtil.LIBRARY_CATEGORIES + ) { + postRecreate(); + } + } + + @NotNull + @Override + public MaterialCab openCab(final int menuRes, @NotNull final Callback callback) { + return null; + } + + public void removeOnAppBarOffsetChangedListener( + @NonNull AppBarLayout.OnOffsetChangedListener onOffsetChangedListener) { + mAppBarLayout.removeOnOffsetChangedListener(onOffsetChangedListener); + } + + @NotNull + @Override + protected View createContentView() { + return wrapSlidingMusicPanel(R.layout.activity_main_content); + } + + private void checkShowChangelog() { + try { + final PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); + final int currentVersion = pInfo.versionCode; + if (currentVersion != PreferenceUtil.getInstance(this).getLastChangelogVersion()) { + startActivityForResult(new Intent(this, WhatsNewActivity.class), APP_INTRO_REQUEST); + } + } catch (NameNotFoundException e) { + e.printStackTrace(); + } + } + + @Nullable + private Fragment getCurrentFragment() { + return getSupportFragmentManager().findFragmentById(R.id.fragment_container); + } + + private boolean handleGridSizeMenuItem( + @NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, + @NonNull MenuItem item) { + int gridSize = 0; + switch (item.getItemId()) { + case R.id.action_grid_size_1: + gridSize = 1; + break; + case R.id.action_grid_size_2: + gridSize = 2; + break; + case R.id.action_grid_size_3: + gridSize = 3; + break; + case R.id.action_grid_size_4: + gridSize = 4; + break; + case R.id.action_grid_size_5: + gridSize = 5; + break; + case R.id.action_grid_size_6: + gridSize = 6; + break; + case R.id.action_grid_size_7: + gridSize = 7; + break; + case R.id.action_grid_size_8: + gridSize = 8; + break; + } + + if (gridSize > 0) { + item.setChecked(true); + fragment.setAndSaveGridSize(gridSize); + return true; + } + return false; + } + + private boolean handleLayoutResType( + final AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, + final MenuItem item) { + int layoutRes = -1; + switch (item.getItemId()) { + case R.id.action_layout_normal: + layoutRes = R.layout.item_grid; + break; + case R.id.action_layout_card: + layoutRes = R.layout.item_card; + break; + case R.id.action_layout_colored_card: + layoutRes = R.layout.item_card_color; + break; + case R.id.action_layout_circular: + layoutRes = R.layout.item_grid_circle; + break; + case R.id.action_layout_image: + layoutRes = R.layout.image; + break; + case R.id.action_layout_gradient_image: + layoutRes = R.layout.item_image_gradient; + break; + } + if (layoutRes != -1) { + item.setChecked(true); + fragment.setAndSaveLayoutRes(layoutRes); + return true; + } + return false; + } + + private void handlePlaybackIntent(@Nullable Intent intent) { + if (intent == null) { + return; + } + + Uri uri = intent.getData(); + String mimeType = intent.getType(); + boolean handled = false; + + if (intent.getAction() != null && intent.getAction() + .equals(MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH)) { + final List songs = SearchQueryHelper.getSongs(this, intent.getExtras()); + if (MusicPlayerRemote.getShuffleMode() == MusicService.SHUFFLE_MODE_SHUFFLE) { + MusicPlayerRemote.openAndShuffleQueue(songs, true); + } else { + MusicPlayerRemote.openQueue(songs, 0, true); + } + handled = true; + } + + if (uri != null && uri.toString().length() > 0) { + MusicPlayerRemote.playFromUri(uri); + handled = true; + } else if (MediaStore.Audio.Playlists.CONTENT_TYPE.equals(mimeType)) { + final int id = (int) parseIdFromIntent(intent, "playlistId", "playlist"); + if (id >= 0) { + int position = intent.getIntExtra("position", 0); + List songs = new ArrayList<>(PlaylistSongsLoader.getPlaylistSongList(this, id)); + MusicPlayerRemote.openQueue(songs, position, true); + handled = true; + } + } else if (MediaStore.Audio.Albums.CONTENT_TYPE.equals(mimeType)) { + final int id = (int) parseIdFromIntent(intent, "albumId", "album"); + if (id >= 0) { + int position = intent.getIntExtra("position", 0); + MusicPlayerRemote.openQueue(AlbumLoader.getAlbum(this, id).getSongs(), position, true); + handled = true; + } + } else if (MediaStore.Audio.Artists.CONTENT_TYPE.equals(mimeType)) { + final int id = (int) parseIdFromIntent(intent, "artistId", "artist"); + if (id >= 0) { + int position = intent.getIntExtra("position", 0); + MusicPlayerRemote.openQueue(ArtistLoader.getArtist(this, id).getSongs(), position, true); + handled = true; + } + } + if (handled) { + setIntent(new Intent()); + } + } + + private boolean handleSortOrderMenuItem( + @NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment + fragment, @NonNull MenuItem item) { + String sortOrder = null; + if (fragment instanceof AlbumsFragment) { + switch (item.getItemId()) { + case R.id.action_album_sort_order_asc: + sortOrder = AlbumSortOrder.ALBUM_A_Z; + break; + case R.id.action_album_sort_order_desc: + sortOrder = AlbumSortOrder.ALBUM_Z_A; + break; + case R.id.action_album_sort_order_artist: + sortOrder = AlbumSortOrder.ALBUM_ARTIST; + break; + case R.id.action_album_sort_order_year: + sortOrder = AlbumSortOrder.ALBUM_YEAR; + break; + } + } else if (fragment instanceof ArtistsFragment) { + switch (item.getItemId()) { + case R.id.action_artist_sort_order_asc: + sortOrder = ArtistSortOrder.ARTIST_A_Z; + break; + case R.id.action_artist_sort_order_desc: + sortOrder = ArtistSortOrder.ARTIST_Z_A; + break; + } + } else if (fragment instanceof SongsFragment) { + switch (item.getItemId()) { + case R.id.action_song_sort_order_asc: + sortOrder = SongSortOrder.SONG_A_Z; + break; + case R.id.action_song_sort_order_desc: + sortOrder = SongSortOrder.SONG_Z_A; + break; + case R.id.action_song_sort_order_artist: + sortOrder = SongSortOrder.SONG_ARTIST; + break; + case R.id.action_song_sort_order_album: + sortOrder = SongSortOrder.SONG_ALBUM; + break; + case R.id.action_song_sort_order_year: + sortOrder = SongSortOrder.SONG_YEAR; + break; + case R.id.action_song_sort_order_date: + sortOrder = SongSortOrder.SONG_DATE; + break; + case R.id.action_song_sort_order_composer: + sortOrder = SongSortOrder.COMPOSER; + break; + + } + } + + if (sortOrder != null) { + item.setChecked(true); + fragment.setAndSaveSortOrder(sortOrder); + return true; + } + + return false; + } + + private boolean isHomePage() { + return getSupportFragmentManager().findFragmentByTag(BannerHomeFragment.TAG) instanceof BannerHomeFragment; + } + + private boolean isPlaylistPage() { + return getSupportFragmentManager().findFragmentByTag(PlaylistsFragment.TAG) instanceof PlaylistsFragment; + } + + private long parseIdFromIntent(@NonNull Intent intent, String longKey, + String stringKey) { + long id = intent.getLongExtra(longKey, -1); + if (id < 0) { + String idString = intent.getStringExtra(stringKey); + if (idString != null) { + try { + id = Long.parseLong(idString); + } catch (NumberFormatException e) { + Log.e(TAG, e.getMessage()); + } + } + } + return id; + } + + private void restoreCurrentFragment() { + currentFragment = (MainActivityFragmentCallbacks) getSupportFragmentManager() + .findFragmentById(R.id.fragment_container); + } + + private void selectedFragment(final int itemId) { + switch (itemId) { + case R.id.action_album: + setCurrentFragment(AlbumsFragment.newInstance(), AlbumsFragment.TAG); + break; + case R.id.action_artist: + setCurrentFragment(ArtistsFragment.newInstance(), ArtistsFragment.TAG); + break; + case R.id.action_playlist: + setCurrentFragment(PlaylistsFragment.newInstance(), PlaylistsFragment.TAG); + break; + case R.id.action_genre: + setCurrentFragment(GenresFragment.newInstance(), GenresFragment.TAG); + break; + case R.id.action_playing_queue: + setCurrentFragment(PlayingQueueFragment.newInstance(), PlayingQueueFragment.TAG); + break; + case R.id.action_song: + setCurrentFragment(SongsFragment.newInstance(), SongsFragment.TAG); + break; + default: + case R.id.action_home: + setCurrentFragment(BannerHomeFragment.newInstance(), BannerHomeFragment.TAG); + break; + } + } + + private void setCurrentFragment(Fragment fragment, String tag) { + String currentTag = null; + if (getSupportFragmentManager().findFragmentByTag(tag) != null) { + currentTag = getSupportFragmentManager().findFragmentByTag(tag).getTag(); + } + + if (!tag.equals(currentTag)) { + getSupportFragmentManager().beginTransaction() + .replace(R.id.fragment_container, fragment, tag) + .commit(); + currentFragment = (MainActivityFragmentCallbacks) fragment; + } + } + + private void setUpGridSizeMenu(@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, + @NonNull SubMenu gridSizeMenu) { + + switch (fragment.getGridSize()) { + case 1: + gridSizeMenu.findItem(R.id.action_grid_size_1).setChecked(true); + break; + case 2: + gridSizeMenu.findItem(R.id.action_grid_size_2).setChecked(true); + break; + case 3: + gridSizeMenu.findItem(R.id.action_grid_size_3).setChecked(true); + break; + case 4: + gridSizeMenu.findItem(R.id.action_grid_size_4).setChecked(true); + break; + case 5: + gridSizeMenu.findItem(R.id.action_grid_size_5).setChecked(true); + break; + case 6: + gridSizeMenu.findItem(R.id.action_grid_size_6).setChecked(true); + break; + case 7: + gridSizeMenu.findItem(R.id.action_grid_size_7).setChecked(true); + break; + case 8: + gridSizeMenu.findItem(R.id.action_grid_size_8).setChecked(true); + break; + } + int maxGridSize = fragment.getMaxGridSize(); + if (maxGridSize < 8) { + gridSizeMenu.findItem(R.id.action_grid_size_8).setVisible(false); + } + if (maxGridSize < 7) { + gridSizeMenu.findItem(R.id.action_grid_size_7).setVisible(false); + } + if (maxGridSize < 6) { + gridSizeMenu.findItem(R.id.action_grid_size_6).setVisible(false); + } + if (maxGridSize < 5) { + gridSizeMenu.findItem(R.id.action_grid_size_5).setVisible(false); + } + if (maxGridSize < 4) { + gridSizeMenu.findItem(R.id.action_grid_size_4).setVisible(false); + } + if (maxGridSize < 3) { + gridSizeMenu.findItem(R.id.action_grid_size_3).setVisible(false); + } + } + + private void setUpSortOrderMenu( + @NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, + @NonNull SubMenu sortOrderMenu) { + String currentSortOrder = fragment.getSortOrder(); + sortOrderMenu.clear(); + + if (fragment instanceof AlbumsFragment) { + sortOrderMenu.add(0, R.id.action_album_sort_order_asc, 0, R.string.sort_order_a_z) + .setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_A_Z)); + sortOrderMenu.add(0, R.id.action_album_sort_order_desc, 1, R.string.sort_order_z_a) + .setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_Z_A)); + sortOrderMenu.add(0, R.id.action_album_sort_order_artist, 2, R.string.sort_order_artist) + .setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_ARTIST)); + sortOrderMenu.add(0, R.id.action_album_sort_order_year, 3, R.string.sort_order_year) + .setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_YEAR)); + } else if (fragment instanceof ArtistsFragment) { + sortOrderMenu.add(0, R.id.action_artist_sort_order_asc, 0, R.string.sort_order_a_z) + .setChecked(currentSortOrder.equals(ArtistSortOrder.ARTIST_A_Z)); + sortOrderMenu.add(0, R.id.action_artist_sort_order_desc, 1, R.string.sort_order_z_a) + .setChecked(currentSortOrder.equals(ArtistSortOrder.ARTIST_Z_A)); + } else if (fragment instanceof SongsFragment) { + sortOrderMenu.add(0, R.id.action_song_sort_order_asc, 0, R.string.sort_order_a_z) + .setChecked(currentSortOrder.equals(SongSortOrder.SONG_A_Z)); + sortOrderMenu.add(0, R.id.action_song_sort_order_desc, 1, R.string.sort_order_z_a) + .setChecked(currentSortOrder.equals(SongSortOrder.SONG_Z_A)); + sortOrderMenu.add(0, R.id.action_song_sort_order_artist, 2, R.string.sort_order_artist) + .setChecked(currentSortOrder.equals(SongSortOrder.SONG_ARTIST)); + sortOrderMenu.add(0, R.id.action_song_sort_order_album, 3, R.string.sort_order_album) + .setChecked(currentSortOrder.equals(SongSortOrder.SONG_ALBUM)); + sortOrderMenu.add(0, R.id.action_song_sort_order_year, 4, R.string.sort_order_year) + .setChecked(currentSortOrder.equals(SongSortOrder.SONG_YEAR)); + sortOrderMenu.add(0, R.id.action_song_sort_order_date, 5, R.string.sort_order_date) + .setChecked(currentSortOrder.equals(SongSortOrder.SONG_DATE)); + sortOrderMenu.add(0, R.id.action_song_sort_order_composer, 6, R.string.sort_order_composer) + .setChecked(currentSortOrder.equals(SongSortOrder.COMPOSER)); + } + + sortOrderMenu.setGroupCheckable(0, true, true); + } + + private void setupLayoutMenu( + @NonNull final AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, + @NonNull final SubMenu subMenu) { + switch (fragment.itemLayoutRes()) { + case R.layout.item_card: + subMenu.findItem(R.id.action_layout_card).setChecked(true); + break; + case R.layout.item_grid: + subMenu.findItem(R.id.action_layout_normal).setChecked(true); + break; + case R.layout.item_card_color: + subMenu.findItem(R.id.action_layout_colored_card).setChecked(true); + break; + case R.layout.item_grid_circle: + subMenu.findItem(R.id.action_layout_circular).setChecked(true); + break; + case R.layout.image: + subMenu.findItem(R.id.action_layout_image).setChecked(true); + break; + case R.layout.item_image_gradient: + subMenu.findItem(R.id.action_layout_gradient_image).setChecked(true); + break; + } + } + + private void setupToolbar() { + mToolbar.setBackgroundColor(Color.TRANSPARENT); + mToolbarContainer.setCardBackgroundColor( + ColorStateList.valueOf(ATHUtil.INSTANCE.resolveColor(this, R.attr.colorSurface))); + setSupportActionBar(mToolbar); + mToolbar.setOnClickListener(v -> { + ActivityOptions options = ActivityOptions + .makeSceneTransitionAnimation(this, mToolbarContainer, getString(R.string.transition_toolbar)); + NavigationUtil.goToSearch(this, options); + }); + mToolbar.setNavigationOnClickListener( + v -> OptionsSheetDialogFragment.newInstance().show(getSupportFragmentManager(), "Main_Menu")); + } +} 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 deleted file mode 100644 index 0d12575d..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt +++ /dev/null @@ -1,604 +0,0 @@ -package code.name.monkey.retromusic.activities - -import android.app.ActivityOptions -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter -import android.content.SharedPreferences -import android.content.res.ColorStateList -import android.graphics.Color -import android.os.Bundle -import android.provider.MediaStore -import android.util.Log -import android.view.Menu -import android.view.MenuItem -import android.view.SubMenu -import android.view.View -import androidx.core.app.ActivityCompat -import androidx.fragment.app.Fragment -import code.name.monkey.appthemehelper.util.ATHUtil -import code.name.monkey.appthemehelper.util.ATHUtil.resolveColor -import code.name.monkey.retromusic.R -import code.name.monkey.retromusic.R.drawable -import code.name.monkey.retromusic.R.id -import code.name.monkey.retromusic.R.layout -import code.name.monkey.retromusic.R.string -import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity -import code.name.monkey.retromusic.dialogs.CreatePlaylistDialog.Companion.create -import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment -import code.name.monkey.retromusic.fragments.mainactivity.AlbumsFragment -import code.name.monkey.retromusic.fragments.mainactivity.ArtistsFragment -import code.name.monkey.retromusic.fragments.mainactivity.GenresFragment -import code.name.monkey.retromusic.fragments.mainactivity.LibraryFragment -import code.name.monkey.retromusic.fragments.mainactivity.PlayingQueueFragment -import code.name.monkey.retromusic.fragments.mainactivity.PlaylistsFragment -import code.name.monkey.retromusic.fragments.mainactivity.SongsFragment -import code.name.monkey.retromusic.fragments.mainactivity.folders.FoldersFragment -import code.name.monkey.retromusic.fragments.mainactivity.home.BannerHomeFragment -import code.name.monkey.retromusic.helper.MusicPlayerRemote -import code.name.monkey.retromusic.helper.SearchQueryHelper -import code.name.monkey.retromusic.helper.SortOrder.AlbumSortOrder -import code.name.monkey.retromusic.helper.SortOrder.ArtistSortOrder -import code.name.monkey.retromusic.helper.SortOrder.SongSortOrder -import code.name.monkey.retromusic.interfaces.CabHolder -import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks -import code.name.monkey.retromusic.loaders.AlbumLoader -import code.name.monkey.retromusic.loaders.ArtistLoader -import code.name.monkey.retromusic.loaders.PlaylistSongsLoader -import code.name.monkey.retromusic.service.MusicService -import code.name.monkey.retromusic.util.AppRater -import code.name.monkey.retromusic.util.NavigationUtil -import code.name.monkey.retromusic.util.PreferenceUtil -import code.name.monkey.retromusic.util.RetroColorUtil -import code.name.monkey.retromusic.util.RetroUtil -import com.afollestad.materialcab.MaterialCab -import com.afollestad.materialcab.MaterialCab.Callback -import com.google.android.material.appbar.AppBarLayout.OnOffsetChangedListener -import kotlinx.android.synthetic.main.activity_main_content.appBarLayout -import kotlinx.android.synthetic.main.activity_main_content.toolbar -import kotlinx.android.synthetic.main.activity_main_content.toolbarContainer -import java.util.ArrayList - -class MainActivity : AbsSlidingMusicPanelActivity(), CabHolder, SharedPreferences.OnSharedPreferenceChangeListener { - - private lateinit var currentFragment: MainActivityFragmentCallbacks - - private var blockRequestPermissions: Boolean = false - - private val broadcastReceiver = object : BroadcastReceiver() { - override fun onReceive(context: Context, intent: Intent) { - val action = intent.action - if (action != null && action == Intent.ACTION_SCREEN_OFF) { - if (PreferenceUtil.getInstance(this@MainActivity).lockScreen && MusicPlayerRemote.isPlaying) { - val activity = Intent(context, LockScreenActivity::class.java) - activity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) - activity.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY) - ActivityCompat.startActivity(context, activity, null) - } - } - } - } - - override fun createContentView(): View { - return wrapSlidingMusicPanel(R.layout.activity_main_content) - } - - override fun onCreate( - savedInstanceState: Bundle? - ) { - setDrawUnderStatusBar() - super.onCreate(savedInstanceState) - getBottomNavigationView().selectedItemId = PreferenceUtil.getInstance(this).lastPage - getBottomNavigationView().setOnNavigationItemSelectedListener { - PreferenceUtil.getInstance(this).lastPage = it.itemId - selectedFragment(it.itemId) - true - } - - if (savedInstanceState == null) { - setMusicChooser(PreferenceUtil.getInstance(this).lastMusicChooser) - } else { - restoreCurrentFragment() - } - - checkShowChangelog() - AppRater.appLaunched(this) - setupToolbar() - setBottomBarVisibility(View.VISIBLE) - } - - private fun setupToolbar() { - toolbar.setBackgroundColor(Color.TRANSPARENT) - toolbarContainer.backgroundTintList = - ColorStateList.valueOf(resolveColor(this, R.attr.colorSurface)) - setSupportActionBar(toolbar) - toolbar.setOnClickListener { - val options = ActivityOptions - .makeSceneTransitionAnimation( - this, toolbarContainer, - getString(R.string.transition_toolbar) - ) - NavigationUtil.goToSearch(this, options) - } - } - - private fun checkShowChangelog() { - try { - val pInfo = packageManager.getPackageInfo(packageName, 0) - val currentVersion = pInfo.versionCode - if (currentVersion != PreferenceUtil.getInstance(this).lastChangelogVersion) { - startActivityForResult( - Intent(this, WhatsNewActivity::class.java), - APP_INTRO_REQUEST - ) - } - } catch (e: Throwable) { - e.printStackTrace() - } - } - - override fun onResume() { - super.onResume() - val screenOnOff = IntentFilter() - screenOnOff.addAction(Intent.ACTION_SCREEN_OFF) - registerReceiver(broadcastReceiver, screenOnOff) - - PreferenceUtil.getInstance(this).registerOnSharedPreferenceChangedListener(this) - - if (intent.hasExtra("expand")) { - if (intent.getBooleanExtra("expand", false)) { - expandPanel() - intent.putExtra("expand", false) - } - } - } - - override fun onDestroy() { - super.onDestroy() - unregisterReceiver(broadcastReceiver) - PreferenceUtil.getInstance(this).unregisterOnSharedPreferenceChangedListener(this) - } - - private fun setCurrentFragment(fragment: Fragment, tag: String) { - if (tag != supportFragmentManager.findFragmentById(R.id.fragment_container)?.tag) { - supportFragmentManager.beginTransaction() - .replace(R.id.fragment_container, fragment, tag).commit() - currentFragment = fragment as MainActivityFragmentCallbacks - } - } - - private fun restoreCurrentFragment() { - currentFragment = - supportFragmentManager.findFragmentById(R.id.fragment_container) as MainActivityFragmentCallbacks - } - - private fun handlePlaybackIntent(intent: Intent?) { - if (intent == null) { - return - } - val uri = intent.data - val mimeType = intent.type - var handled = false - if (intent.action != null && intent.action == MediaStore.INTENT_ACTION_MEDIA_PLAY_FROM_SEARCH) { - val songs = SearchQueryHelper.getSongs(this, intent.extras!!) - if (MusicPlayerRemote.shuffleMode == MusicService.SHUFFLE_MODE_SHUFFLE) { - MusicPlayerRemote.openAndShuffleQueue(songs, true) - } else { - MusicPlayerRemote.openQueue(songs, 0, true) - } - handled = true - } - - if (uri != null && uri.toString().isNotEmpty()) { - MusicPlayerRemote.playFromUri(uri) - handled = true - } else if (MediaStore.Audio.Playlists.CONTENT_TYPE == mimeType) { - val id = parseIdFromIntent(intent, "playlistId", "playlist").toInt() - if (id >= 0) { - val position = intent.getIntExtra("position", 0) - val songs = ArrayList(PlaylistSongsLoader.getPlaylistSongList(this, id)) - MusicPlayerRemote.openQueue(songs, position, true) - handled = true - } - } else if (MediaStore.Audio.Albums.CONTENT_TYPE == mimeType) { - val id = parseIdFromIntent(intent, "albumId", "album").toInt() - if (id >= 0) { - val position = intent.getIntExtra("position", 0) - MusicPlayerRemote.openQueue(AlbumLoader.getAlbum(this, id).songs!!, position, true) - handled = true - } - } else if (MediaStore.Audio.Artists.CONTENT_TYPE == mimeType) { - val id = parseIdFromIntent(intent, "artistId", "artist").toInt() - if (id >= 0) { - val position = intent.getIntExtra("position", 0) - MusicPlayerRemote.openQueue(ArtistLoader.getArtist(this, id).songs, position, true) - handled = true - } - } - if (handled) { - setIntent(Intent()) - } - } - - private fun parseIdFromIntent(intent: Intent, longKey: String, stringKey: String): Long { - var id = intent.getLongExtra(longKey, -1) - if (id < 0) { - val idString = intent.getStringExtra(stringKey) - if (idString != null) { - try { - id = java.lang.Long.parseLong(idString) - } catch (e: NumberFormatException) { - Log.e(TAG, e.message) - } - } - } - return id - } - - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - when (requestCode) { - APP_INTRO_REQUEST -> { - blockRequestPermissions = false - if (!hasPermissions()) { - requestPermissions() - } - } - REQUEST_CODE_THEME, APP_USER_INFO_REQUEST -> postRecreate() - PURCHASE_REQUEST -> { - if (resultCode == RESULT_OK) { - //checkSetUpPro(); - } - } - } - } - - override fun handleBackPress(): Boolean { - return super.handleBackPress() || currentFragment.handleBackPress() - } - - override fun onServiceConnected() { - super.onServiceConnected() - handlePlaybackIntent(intent) - } - - override fun requestPermissions() { - if (!blockRequestPermissions) { - super.requestPermissions() - } - } - - override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { - if (key == PreferenceUtil.GENERAL_THEME || key == PreferenceUtil.BLACK_THEME || - key == PreferenceUtil.ADAPTIVE_COLOR_APP || key == PreferenceUtil.DOMINANT_COLOR || - key == PreferenceUtil.USER_NAME || key == PreferenceUtil.TOGGLE_FULL_SCREEN || - key == PreferenceUtil.TOGGLE_VOLUME || key == PreferenceUtil.ROUND_CORNERS || - key == PreferenceUtil.CAROUSEL_EFFECT || key == PreferenceUtil.NOW_PLAYING_SCREEN_ID || - key == PreferenceUtil.TOGGLE_GENRE || key == PreferenceUtil.BANNER_IMAGE_PATH || - key == PreferenceUtil.PROFILE_IMAGE_PATH || key == PreferenceUtil.CIRCULAR_ALBUM_ART || - key == PreferenceUtil.KEEP_SCREEN_ON || key == PreferenceUtil.TOGGLE_SEPARATE_LINE || - key == PreferenceUtil.TOGGLE_HOME_BANNER || key == PreferenceUtil.TOGGLE_ADD_CONTROLS || - key == PreferenceUtil.ALBUM_COVER_STYLE || key == PreferenceUtil.HOME_ARTIST_GRID_STYLE || - key == PreferenceUtil.ALBUM_COVER_TRANSFORM || key == PreferenceUtil.DESATURATED_COLOR || - key == PreferenceUtil.TAB_TEXT_MODE || key == PreferenceUtil.LIBRARY_CATEGORIES - ) - postRecreate() - } - - private fun selectedFragment(itemId: Int) { - when (itemId) { - R.id.action_album -> setCurrentFragment(AlbumsFragment.newInstance(), itemId.toString()) - R.id.action_artist -> setCurrentFragment(ArtistsFragment.newInstance(), itemId.toString()) - R.id.action_playlist -> setCurrentFragment(PlaylistsFragment.newInstance(), itemId.toString()) - R.id.action_genre -> setCurrentFragment(GenresFragment.newInstance(), itemId.toString()) - R.id.action_playing_queue -> setCurrentFragment(PlayingQueueFragment.newInstance(), itemId.toString()) - R.id.action_song -> setCurrentFragment(SongsFragment.newInstance(), itemId.toString()) - R.id.action_home -> setCurrentFragment(BannerHomeFragment.newInstance(), BannerHomeFragment.TAG) - else -> { - setCurrentFragment(BannerHomeFragment.newInstance(), BannerHomeFragment.TAG) - } - } - } - - fun setMusicChooser(key: Int) { - PreferenceUtil.getInstance(this).lastMusicChooser = key - when (key) { - FOLDER -> setCurrentFragment(FoldersFragment.newInstance(this), FoldersFragment.TAG) - else -> selectedFragment(PreferenceUtil.getInstance(this).lastPage) - } - } - - companion object { - const val APP_INTRO_REQUEST = 2323 - const val HOME = 0 - const val FOLDER = 1 - const val LIBRARY = 2 - private const val TAG = "MainActivity" - private const val APP_USER_INFO_REQUEST = 9003 - private const val REQUEST_CODE_THEME = 9002 - private const val PURCHASE_REQUEST = 101 - } - - private lateinit var cab: MaterialCab - - fun getTotalAppBarScrollingRange(): Int { - return appBarLayout.totalScrollRange - } - - fun addOnAppBarOffsetChangedListener( - onOffsetChangedListener: OnOffsetChangedListener - ) { - appBarLayout.addOnOffsetChangedListener(onOffsetChangedListener) - } - - fun removeOnAppBarOffsetChangedListener( - onOffsetChangedListener: OnOffsetChangedListener - ) { - appBarLayout.removeOnOffsetChangedListener(onOffsetChangedListener) - } - - override fun openCab(menuRes: Int, callback: Callback): MaterialCab { - if (cab != null && cab.isActive()) { - cab.finish() - } - - cab = MaterialCab(this, R.id.cab_stub) - .setMenu(menuRes) - .setCloseDrawableRes(R.drawable.ic_close_white_24dp) - .setBackgroundColor( - RetroColorUtil.shiftBackgroundColorForLightText( - ATHUtil.resolveColor(this, R.attr.colorSurface) - ) - ) - .start(callback) - return cab - } - - private fun getCurrentFragment(): Fragment? { - return if (supportFragmentManager == null) { - SongsFragment.newInstance() - } else supportFragmentManager.findFragmentByTag(LibraryFragment.TAG) - } - - override fun onCreateOptionsMenu(menu: Menu?): Boolean { - menuInflater.inflate(R.menu.menu_main, menu) - val currentFragment: Fragment? = getCurrentFragment() - if (currentFragment is AbsLibraryPagerRecyclerViewCustomGridSizeFragment<*, *> - && currentFragment.isAdded() - ) { - - if (currentFragment is SongsFragment) { - menu!!.removeItem(id.action_grid_size) - menu.removeItem(id.action_layout_type) - } else { - val gridSizeItem = menu!!.findItem(id.action_grid_size) - if (RetroUtil.isLandscape()) { - gridSizeItem.setTitle(string.action_grid_size_land) - } - setUpGridSizeMenu(currentFragment, gridSizeItem.subMenu) - val layoutItem = menu.findItem(id.action_layout_type) - setupLayoutMenu(currentFragment, layoutItem.subMenu) - } - setUpSortOrderMenu(currentFragment, menu.findItem(id.action_sort_order).subMenu) - } else if (currentFragment is GenresFragment || currentFragment is PlayingQueueFragment) { - menu!!.removeItem(id.action_new_playlist) - menu.removeItem(id.action_layout_type) - menu.removeItem(id.action_grid_size) - menu.removeItem(id.action_sort_order) - } else { - menu!!.add(0, id.action_new_playlist, 0, string.new_playlist_title) - .setIcon(drawable.ic_playlist_add_white_24dp) - .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM) - menu.removeItem(id.action_grid_size) - menu.removeItem(id.action_layout_type) - } - return super.onCreateOptionsMenu(menu) - } - - private fun setUpGridSizeMenu( - fragment: AbsLibraryPagerRecyclerViewCustomGridSizeFragment<*, *>, - gridSizeMenu: SubMenu - ) { - when (fragment.getGridSize()) { - 1 -> gridSizeMenu.findItem(id.action_grid_size_1).isChecked = true - 2 -> gridSizeMenu.findItem(id.action_grid_size_2).isChecked = true - 3 -> gridSizeMenu.findItem(id.action_grid_size_3).isChecked = true - 4 -> gridSizeMenu.findItem(id.action_grid_size_4).isChecked = true - 5 -> gridSizeMenu.findItem(id.action_grid_size_5).isChecked = true - 6 -> gridSizeMenu.findItem(id.action_grid_size_6).isChecked = true - 7 -> gridSizeMenu.findItem(id.action_grid_size_7).isChecked = true - 8 -> gridSizeMenu.findItem(id.action_grid_size_8).isChecked = true - } - val maxGridSize = fragment.maxGridSize - if (maxGridSize < 8) { - gridSizeMenu.findItem(id.action_grid_size_8).isVisible = false - } - if (maxGridSize < 7) { - gridSizeMenu.findItem(id.action_grid_size_7).isVisible = false - } - if (maxGridSize < 6) { - gridSizeMenu.findItem(id.action_grid_size_6).isVisible = false - } - if (maxGridSize < 5) { - gridSizeMenu.findItem(id.action_grid_size_5).isVisible = false - } - if (maxGridSize < 4) { - gridSizeMenu.findItem(id.action_grid_size_4).isVisible = false - } - if (maxGridSize < 3) { - gridSizeMenu.findItem(id.action_grid_size_3).isVisible = false - } - } - - private fun setUpSortOrderMenu( - fragment: AbsLibraryPagerRecyclerViewCustomGridSizeFragment<*, *>, - sortOrderMenu: SubMenu - ) { - val currentSortOrder = fragment.getSortOrder() - sortOrderMenu.clear() - when (fragment) { - is AlbumsFragment -> { - sortOrderMenu.add(0, id.action_album_sort_order_asc, 0, string.sort_order_a_z).isChecked = - currentSortOrder == AlbumSortOrder.ALBUM_A_Z - sortOrderMenu.add(0, id.action_album_sort_order_desc, 1, string.sort_order_z_a).isChecked = - currentSortOrder == AlbumSortOrder.ALBUM_Z_A - sortOrderMenu.add(0, id.action_album_sort_order_artist, 2, string.sort_order_artist).isChecked = - currentSortOrder == AlbumSortOrder.ALBUM_ARTIST - sortOrderMenu.add(0, id.action_album_sort_order_year, 3, string.sort_order_year).isChecked = - currentSortOrder == AlbumSortOrder.ALBUM_YEAR - } - is ArtistsFragment -> { - sortOrderMenu.add(0, id.action_artist_sort_order_asc, 0, string.sort_order_a_z).isChecked = - currentSortOrder == ArtistSortOrder.ARTIST_A_Z - sortOrderMenu.add(0, id.action_artist_sort_order_desc, 1, string.sort_order_z_a).isChecked = - currentSortOrder == ArtistSortOrder.ARTIST_Z_A - } - is SongsFragment -> { - sortOrderMenu.add(0, id.action_song_sort_order_asc, 0, string.sort_order_a_z).isChecked = - currentSortOrder == SongSortOrder.SONG_A_Z - sortOrderMenu.add(0, id.action_song_sort_order_desc, 1, string.sort_order_z_a).isChecked = - currentSortOrder == SongSortOrder.SONG_Z_A - sortOrderMenu.add(0, id.action_song_sort_order_artist, 2, string.sort_order_artist).isChecked = - currentSortOrder == SongSortOrder.SONG_ARTIST - sortOrderMenu.add(0, id.action_song_sort_order_album, 3, string.sort_order_album).isChecked = - currentSortOrder == SongSortOrder.SONG_ALBUM - sortOrderMenu.add(0, id.action_song_sort_order_year, 4, string.sort_order_year).isChecked = - currentSortOrder == SongSortOrder.SONG_YEAR - sortOrderMenu.add(0, id.action_song_sort_order_date, 5, string.sort_order_date).isChecked = - currentSortOrder == SongSortOrder.SONG_DATE - sortOrderMenu.add(0, id.action_song_sort_order_composer, 6, string.sort_order_composer).isChecked = - currentSortOrder == SongSortOrder.COMPOSER - } - } - sortOrderMenu.setGroupCheckable(0, true, true) - } - - private fun setupLayoutMenu( - fragment: AbsLibraryPagerRecyclerViewCustomGridSizeFragment<*, *>, - subMenu: SubMenu - ) { - when (fragment.itemLayoutRes()) { - layout.item_card -> subMenu.findItem(id.action_layout_card).isChecked = true - layout.item_grid -> subMenu.findItem(id.action_layout_normal).isChecked = true - layout.item_card_color -> subMenu.findItem(id.action_layout_colored_card).isChecked = true - layout.item_grid_circle -> subMenu.findItem(id.action_layout_circular).isChecked = true - layout.image -> subMenu.findItem(id.action_layout_image).isChecked = true - layout.item_image_gradient -> subMenu.findItem(id.action_layout_gradient_image).isChecked = true - } - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - //if (pager == null) return false; - val currentFragment = getCurrentFragment() - if (currentFragment is AbsLibraryPagerRecyclerViewCustomGridSizeFragment<*, *>) { - if (handleGridSizeMenuItem(currentFragment, item)) { - return true - } - if (handleLayoutResType(currentFragment, item)) { - return true - } - if (handleSortOrderMenuItem(currentFragment, item)) { - return true - } - } - when (item.itemId) { - R.id.action_search -> { - val options = ActivityOptions - .makeSceneTransitionAnimation( - this, toolbarContainer, - getString(string.transition_toolbar) - ) - NavigationUtil.goToSearch(this, options) - } - R.id.action_new_playlist -> { - create().show(supportFragmentManager, "CREATE_PLAYLIST") - return true - } - } - return super.onOptionsItemSelected(item) - } - - private fun handleGridSizeMenuItem( - fragment: AbsLibraryPagerRecyclerViewCustomGridSizeFragment<*, *>, - item: MenuItem - ): Boolean { - var gridSize = 0 - when (item.itemId) { - id.action_grid_size_1 -> gridSize = 1 - id.action_grid_size_2 -> gridSize = 2 - id.action_grid_size_3 -> gridSize = 3 - id.action_grid_size_4 -> gridSize = 4 - id.action_grid_size_5 -> gridSize = 5 - id.action_grid_size_6 -> gridSize = 6 - id.action_grid_size_7 -> gridSize = 7 - id.action_grid_size_8 -> gridSize = 8 - } - if (gridSize > 0) { - item.isChecked = true - fragment.setAndSaveGridSize(gridSize) - return true - } - return false - } - - private fun handleLayoutResType( - fragment: AbsLibraryPagerRecyclerViewCustomGridSizeFragment<*, *>, - item: MenuItem - ): Boolean { - var layoutRes = -1 - when (item.itemId) { - id.action_layout_normal -> layoutRes = layout.item_grid - id.action_layout_card -> layoutRes = layout.item_card - id.action_layout_colored_card -> layoutRes = layout.item_card_color - id.action_layout_circular -> layoutRes = layout.item_grid_circle - id.action_layout_image -> layoutRes = layout.image - id.action_layout_gradient_image -> layoutRes = layout.item_image_gradient - } - if (layoutRes != -1) { - item.isChecked = true - fragment.setAndSaveLayoutRes(layoutRes) - return true - } - return false - } - - private fun handleSortOrderMenuItem( - fragment: AbsLibraryPagerRecyclerViewCustomGridSizeFragment<*, *>, item: MenuItem - ): Boolean { - var sortOrder: String? = null - when (fragment) { - is SongsFragment -> { - when (item.itemId) { - id.action_song_sort_order_asc -> sortOrder = SongSortOrder.SONG_A_Z - id.action_song_sort_order_desc -> sortOrder = SongSortOrder.SONG_Z_A - id.action_song_sort_order_artist -> sortOrder = SongSortOrder.SONG_ARTIST - id.action_song_sort_order_album -> sortOrder = SongSortOrder.SONG_ALBUM - id.action_song_sort_order_year -> sortOrder = SongSortOrder.SONG_YEAR - id.action_song_sort_order_date -> sortOrder = SongSortOrder.SONG_DATE - id.action_song_sort_order_composer -> sortOrder = SongSortOrder.COMPOSER - } - } - is AlbumsFragment -> { - when (item.itemId) { - id.action_album_sort_order_asc -> sortOrder = AlbumSortOrder.ALBUM_A_Z - id.action_album_sort_order_desc -> sortOrder = AlbumSortOrder.ALBUM_Z_A - id.action_album_sort_order_artist -> sortOrder = AlbumSortOrder.ALBUM_ARTIST - id.action_album_sort_order_year -> sortOrder = AlbumSortOrder.ALBUM_YEAR - } - } - is ArtistsFragment -> { - when (item.itemId) { - id.action_artist_sort_order_asc -> sortOrder = ArtistSortOrder.ARTIST_A_Z - id.action_artist_sort_order_desc -> sortOrder = ArtistSortOrder.ARTIST_Z_A - } - } - } - if (sortOrder != null) { - item.isChecked = true - fragment.setAndSaveSortOrder(sortOrder) - return true - } - return false - } -} diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/ContributorAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/ContributorAdapter.kt index 2042e3c5..d1e4c7de 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/ContributorAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/ContributorAdapter.kt @@ -67,7 +67,6 @@ class ContributorAdapter( internal fun bindData(contributor: Contributor) { title.text = contributor.name text.text = contributor.summary - println(contributor.profileImage) Glide.with(image.context).load(contributor.profileImage) .error(R.drawable.ic_account_white_24dp) .placeholder(R.drawable.ic_account_white_24dp).dontAnimate().into(image) diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/HomeAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/HomeAdapter.kt index cd86aa67..6819051c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/HomeAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/HomeAdapter.kt @@ -52,7 +52,6 @@ class HomeAdapter( } override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { - println("ViewType ${getItemViewType(position)}") when (getItemViewType(position)) { RECENT_ALBUMS -> { val viewHolder = holder as AlbumViewHolder diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/CreatePlaylistDialog.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/CreatePlaylistDialog.kt index 0ccb5a69..56318bfc 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/CreatePlaylistDialog.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/CreatePlaylistDialog.kt @@ -35,36 +35,35 @@ import com.afollestad.materialdialogs.customview.getCustomView import com.google.android.material.textfield.TextInputEditText import com.google.android.material.textfield.TextInputLayout - class CreatePlaylistDialog : DialogFragment() { private lateinit var playlistView: TextInputEditText private lateinit var actionNewPlaylistContainer: TextInputLayout override fun onCreateDialog( - savedInstanceState: Bundle? + savedInstanceState: Bundle? ): Dialog { val materialDialog = MaterialDialog(requireContext(), BottomSheet(LayoutMode.WRAP_CONTENT)) - .show { - cornerRadius(PreferenceUtil.getInstance(requireContext()).dialogCorner) - title(string.new_playlist_title) - customView(layout.dialog_playlist) - negativeButton(android.R.string.cancel) - positiveButton(string.create_action) { - if (activity == null) { - return@positiveButton - } - val songs = arguments?.getParcelableArrayList("songs") - ?: return@positiveButton + .show { + cornerRadius(PreferenceUtil.getInstance(requireContext()).dialogCorner) + title(string.new_playlist_title) + customView(layout.dialog_playlist) + negativeButton(android.R.string.cancel) + positiveButton(string.create_action) { + if (activity == null) { + return@positiveButton + } + val songs = arguments?.getParcelableArrayList("songs") + ?: return@positiveButton - if (playlistView.text.toString().trim { it <= ' ' }.isNotEmpty()) { - val playlistId = PlaylistsUtil.createPlaylist(requireContext(), playlistView.text.toString()) - if (playlistId != -1 && activity != null) { - PlaylistsUtil.addToPlaylist(requireContext(), songs, playlistId, true) - } + if (playlistView.text.toString().trim { it <= ' ' }.isNotEmpty()) { + val playlistId = PlaylistsUtil.createPlaylist(requireContext(), playlistView.text.toString()) + if (playlistId != -1 && activity != null) { + PlaylistsUtil.addToPlaylist(requireContext(), songs, playlistId, true) } } } + } val dialogView = materialDialog.getCustomView() playlistView = dialogView.findViewById(R.id.actionNewPlaylist) @@ -73,12 +72,14 @@ class CreatePlaylistDialog : DialogFragment() { MaterialUtil.setTint(actionNewPlaylistContainer, false) val playlistId = arguments!!.getLong(MediaStore.Audio.Playlists.Members.PLAYLIST_ID) - playlistView.appHandleColor().setText(PlaylistsUtil.getNameForPlaylist(requireContext(), playlistId), TextView.BufferType.EDITABLE) + playlistView.appHandleColor() + .setText(PlaylistsUtil.getNameForPlaylist(requireContext(), playlistId), TextView.BufferType.EDITABLE) return materialDialog } companion object { @JvmOverloads + @JvmStatic fun create(song: Song? = null): CreatePlaylistDialog { val list = ArrayList() if (song != null) { @@ -87,6 +88,7 @@ class CreatePlaylistDialog : DialogFragment() { return create(list) } + @JvmStatic fun create(songs: ArrayList): CreatePlaylistDialog { val dialog = CreatePlaylistDialog() val args = Bundle() diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/OptionsSheetDialogFragment.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/OptionsSheetDialogFragment.kt index 2467610c..780feb96 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/OptionsSheetDialogFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/OptionsSheetDialogFragment.kt @@ -37,8 +37,10 @@ class OptionsSheetDialogFragment : DialogFragment(), View.OnClickListener { override fun onClick(view: View) { val mainActivity = activity as MainActivity? ?: return when (view.id) { - R.id.actionFolders -> mainActivity.setMusicChooser(MainActivity.FOLDER) - R.id.actionLibrary -> mainActivity.setMusicChooser(MainActivity.LIBRARY) + R.id.actionFolders -> { + }//mainActivity.setMusicChooser(MainActivity.FOLDER) + R.id.actionLibrary -> { + }//mainActivity.setMusicChooser(MainActivity.LIBRARY) R.id.actionSettings -> NavigationUtil.goToSettings(mainActivity) R.id.actionDriveMode -> NavigationUtil.gotoDriveMode(mainActivity) R.id.actionRate -> NavigationUtil.goToPlayStore(mainActivity) @@ -105,6 +107,7 @@ class OptionsSheetDialogFragment : DialogFragment(), View.OnClickListener { @JvmField var FOLDER: Int = 1 + @JvmStatic fun newInstance(selectedId: Int): OptionsSheetDialogFragment { val bundle = Bundle() bundle.putInt(WHICH_ONE, selectedId) @@ -113,6 +116,7 @@ class OptionsSheetDialogFragment : DialogFragment(), View.OnClickListener { return fragment } + @JvmStatic fun newInstance(): OptionsSheetDialogFragment { return OptionsSheetDialogFragment() } diff --git a/app/src/main/java/code/name/monkey/retromusic/extensions/ListEx.kt b/app/src/main/java/code/name/monkey/retromusic/extensions/ListEx.kt deleted file mode 100644 index 8711599f..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/extensions/ListEx.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2019 Hemanth Savarala. - * - * Licensed under the GNU General Public License v3 - * - * This is free software: you can redistribute it and/or modify it under - * the terms of the GNU General Public License as published by - * the Free Software Foundation either version 3 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * See the GNU General Public License for more details. - */ - -package code.name.monkey.retromusic.extensions - -import code.name.monkey.retromusic.helper.MusicPlayerRemote -import code.name.monkey.retromusic.model.Song - -/** - * Created by hemanths on 2019-11-01. - */ - - -fun ArrayList.lastElement(): Boolean { - println("${this.size} ${this.indexOf(MusicPlayerRemote.currentSong)}") - return this.size - 1 == this.indexOf(MusicPlayerRemote.currentSong) -} - -fun ArrayList.fistElement(): Boolean { - return 0 == this.indexOf(MusicPlayerRemote.currentSong) -} diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsLibraryPagerRecyclerViewFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsLibraryPagerRecyclerViewFragment.kt index f6047f1e..b3e676ad 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsLibraryPagerRecyclerViewFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsLibraryPagerRecyclerViewFragment.kt @@ -109,7 +109,7 @@ abstract class AbsLibraryPagerRecyclerViewFragment, container.paddingLeft, container.paddingTop, container.paddingRight, - mainActivity.getTotalAppBarScrollingRange() + i + mainActivity.totalAppBarScrollingRange + i ) } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/AlbumsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/AlbumsFragment.kt index a453356b..4130925e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/AlbumsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/AlbumsFragment.kt @@ -118,7 +118,7 @@ class AlbumsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment) { - println(sections.size) homeAdapter.swapData(sections) } @@ -93,7 +81,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setStatusBarColorAuto(view) - toolbar = view.findViewById(R.id.toolbar) bannerImage?.setOnClickListener { val options = ActivityOptions.makeSceneTransitionAnimation( @@ -120,8 +107,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba NavigationUtil.goToPlaylistNew(requireActivity(), HistoryPlaylist(requireActivity())) } - setupToolbar() - userImage?.setOnClickListener { val options = ActivityOptions.makeSceneTransitionAnimation( mainActivity, @@ -143,24 +128,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba homePresenter.loadSections() } - private fun setupToolbar() { - toolbar.apply { - backgroundTintList = ColorStateList.valueOf(ATHUtil.resolveColor(requireContext(), R.attr.colorSurface)) - setNavigationIcon(R.drawable.ic_menu_white_24dp) - setOnClickListener { - val options = ActivityOptions.makeSceneTransitionAnimation( - mainActivity, - toolbarContainer, - getString(R.string.transition_toolbar) - ) - NavigationUtil.goToSearch(requireActivity(), options) - } - - } - mainActivity.setSupportActionBar(toolbar) - toolbar.setNavigationOnClickListener { showMainMenu(OptionsSheetDialogFragment.LIBRARY) } - } - override fun handleBackPress(): Boolean { return false } @@ -179,35 +146,6 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba emptyContainer.show() } - override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { - super.onCreateOptionsMenu(menu, inflater) - inflater.inflate(R.menu.menu_search, menu) - - ToolbarContentTintHelper.handleOnCreateOptionsMenu( - requireActivity(), - toolbar, - menu, - ATHToolbarActivity.getToolbarBackgroundColor(toolbar) - ) - } - - override fun onPrepareOptionsMenu(menu: Menu) { - super.onPrepareOptionsMenu(menu) - ToolbarContentTintHelper.handleOnPrepareOptionsMenu(requireActivity(), toolbar) - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - if (item.itemId == R.id.action_search) { - val options = ActivityOptions.makeSceneTransitionAnimation( - mainActivity, - toolbarContainer, - getString(R.string.transition_toolbar) - ) - NavigationUtil.goToSearch(requireActivity(), true, options) - } - return super.onOptionsItemSelected(item) - } - private fun getTimeOfTheDay() { val c = Calendar.getInstance() val timeOfDay = c.get(Calendar.HOUR_OF_DAY) @@ -250,6 +188,7 @@ class BannerHomeFragment : AbsMainActivityFragment(), MainActivityFragmentCallba const val TAG: String = "BannerHomeFragment" + @JvmStatic fun newInstance(): BannerHomeFragment { return BannerHomeFragment() } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/normal/PlayerPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/normal/PlayerPlaybackControlsFragment.kt index 4be53f6b..49653e2f 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/normal/PlayerPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/normal/PlayerPlaybackControlsFragment.kt @@ -265,7 +265,7 @@ class PlayerPlaybackControlsFragment : AbsPlayerControlsFragment(), OnSharedPref } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { - println(key) + if (key == PreferenceUtil.EXTRA_SONG_INFO) { if (activity != null) updateSong() } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/peak/PeakPlayerControlFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/peak/PeakPlayerControlFragment.kt index 8ca714c8..e3ceacf3 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/peak/PeakPlayerControlFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/peak/PeakPlayerControlFragment.kt @@ -152,14 +152,12 @@ class PeakPlayerControlFragment : AbsPlayerControlsFragment() { private fun setUpShuffleButton() { shuffleButton.setOnClickListener { - println("shuffleButton Click") MusicPlayerRemote.toggleShuffleMode() } } private fun setUpRepeatButton() { repeatButton.setOnClickListener { - println("repeatButton Click") MusicPlayerRemote.cycleRepeatMode() } } diff --git a/app/src/main/java/code/name/monkey/retromusic/helper/MusicPlayerRemote.kt b/app/src/main/java/code/name/monkey/retromusic/helper/MusicPlayerRemote.kt index 7fd9f598..49eb1fc7 100644 --- a/app/src/main/java/code/name/monkey/retromusic/helper/MusicPlayerRemote.kt +++ b/app/src/main/java/code/name/monkey/retromusic/helper/MusicPlayerRemote.kt @@ -44,7 +44,7 @@ object MusicPlayerRemote { val TAG: String = MusicPlayerRemote::class.java.simpleName private val mConnectionMap = WeakHashMap() var musicService: MusicService? = null - + @JvmStatic val isPlaying: Boolean get() = musicService != null && musicService!!.isPlaying @@ -91,7 +91,7 @@ object MusicPlayerRemote { get() = if (musicService != null) { musicService!!.repeatMode } else MusicService.REPEAT_MODE_NONE - + @JvmStatic val shuffleMode: Int get() = if (musicService != null) { musicService!!.shuffleMode @@ -207,6 +207,7 @@ object MusicPlayerRemote { /** * Async */ + @JvmStatic fun openQueue(queue: List, startPosition: Int, startPlaying: Boolean) { if (!tryToHandleOpenPlayingQueue(queue, startPosition, startPlaying) && musicService != null) { musicService?.openQueue(queue, startPosition, startPlaying) @@ -218,6 +219,7 @@ object MusicPlayerRemote { /** * Async */ + @JvmStatic fun openAndShuffleQueue(queue: List, startPlaying: Boolean) { var startPosition = 0 if (queue.isNotEmpty()) { @@ -388,7 +390,7 @@ object MusicPlayerRemote { } return false } - + @JvmStatic fun playFromUri(uri: Uri) { if (musicService != null) { diff --git a/app/src/main/java/code/name/monkey/retromusic/helper/SearchQueryHelper.kt b/app/src/main/java/code/name/monkey/retromusic/helper/SearchQueryHelper.kt index 88ae6f23..78ea3e6d 100644 --- a/app/src/main/java/code/name/monkey/retromusic/helper/SearchQueryHelper.kt +++ b/app/src/main/java/code/name/monkey/retromusic/helper/SearchQueryHelper.kt @@ -20,8 +20,7 @@ import android.os.Bundle import android.provider.MediaStore import code.name.monkey.retromusic.loaders.SongLoader import code.name.monkey.retromusic.model.Song -import java.util.* - +import java.util.ArrayList object SearchQueryHelper { private const val TITLE_SELECTION = "lower(" + MediaStore.Audio.AudioColumns.TITLE + ") = ?" @@ -29,7 +28,7 @@ object SearchQueryHelper { private const val ARTIST_SELECTION = "lower(" + MediaStore.Audio.AudioColumns.ARTIST + ") = ?" private const val AND = " AND " var songs = ArrayList() - + @JvmStatic fun getSongs(context: Context, extras: Bundle): ArrayList { val query = extras.getString(SearchManager.QUERY, null) val artistName = extras.getString(MediaStore.EXTRA_MEDIA_ARTIST, null) @@ -38,42 +37,79 @@ object SearchQueryHelper { var songs = ArrayList() if (artistName != null && albumName != null && titleName != null) { - songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, ARTIST_SELECTION + AND + ALBUM_SELECTION + AND + TITLE_SELECTION, arrayOf(artistName.toLowerCase(), albumName.toLowerCase(), titleName.toLowerCase()))) + songs = SongLoader.getSongs( + SongLoader.makeSongCursor( + context, + ARTIST_SELECTION + AND + ALBUM_SELECTION + AND + TITLE_SELECTION, + arrayOf(artistName.toLowerCase(), albumName.toLowerCase(), titleName.toLowerCase()) + ) + ) } if (songs.isNotEmpty()) { return songs } if (artistName != null && titleName != null) { - songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, ARTIST_SELECTION + AND + TITLE_SELECTION, arrayOf(artistName.toLowerCase(), titleName.toLowerCase()))) + songs = SongLoader.getSongs( + SongLoader.makeSongCursor( + context, + ARTIST_SELECTION + AND + TITLE_SELECTION, + arrayOf(artistName.toLowerCase(), titleName.toLowerCase()) + ) + ) } if (songs.isNotEmpty()) { return songs } if (albumName != null && titleName != null) { - songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, ALBUM_SELECTION + AND + TITLE_SELECTION, arrayOf(albumName.toLowerCase(), titleName.toLowerCase()))) + songs = SongLoader.getSongs( + SongLoader.makeSongCursor( + context, + ALBUM_SELECTION + AND + TITLE_SELECTION, + arrayOf(albumName.toLowerCase(), titleName.toLowerCase()) + ) + ) } if (songs.isNotEmpty()) { return songs } if (artistName != null) { - songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, ARTIST_SELECTION, arrayOf(artistName.toLowerCase()))) + songs = SongLoader.getSongs( + SongLoader.makeSongCursor( + context, + ARTIST_SELECTION, + arrayOf(artistName.toLowerCase()) + ) + ) } if (songs.isNotEmpty()) { return songs } if (albumName != null) { - songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, ALBUM_SELECTION, arrayOf(albumName.toLowerCase()))) + songs = SongLoader.getSongs( + SongLoader.makeSongCursor( + context, + ALBUM_SELECTION, + arrayOf(albumName.toLowerCase()) + ) + ) } if (songs.isNotEmpty()) { return songs } if (titleName != null) { - songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, TITLE_SELECTION, arrayOf(titleName.toLowerCase()))) + songs = SongLoader.getSongs( + SongLoader.makeSongCursor( + context, + TITLE_SELECTION, + arrayOf(titleName.toLowerCase()) + ) + ) } if (songs.isNotEmpty()) { return songs } - songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, ARTIST_SELECTION, arrayOf(query.toLowerCase()))) + songs = + SongLoader.getSongs(SongLoader.makeSongCursor(context, ARTIST_SELECTION, arrayOf(query.toLowerCase()))) if (songs.isNotEmpty()) { return songs @@ -87,6 +123,4 @@ object SearchQueryHelper { songs } else ArrayList() } - - } diff --git a/app/src/main/java/code/name/monkey/retromusic/loaders/AlbumLoader.kt b/app/src/main/java/code/name/monkey/retromusic/loaders/AlbumLoader.kt index 2865b620..d28fb1ae 100644 --- a/app/src/main/java/code/name/monkey/retromusic/loaders/AlbumLoader.kt +++ b/app/src/main/java/code/name/monkey/retromusic/loaders/AlbumLoader.kt @@ -19,8 +19,7 @@ import android.provider.MediaStore.Audio.AudioColumns import code.name.monkey.retromusic.model.Album import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.util.PreferenceUtil -import java.util.* -import kotlin.collections.ArrayList +import java.util.Comparator /** @@ -41,7 +40,7 @@ object AlbumLoader { ) return splitIntoAlbums(songs) } - + @JvmStatic fun getAlbum( context: Context, albumId: Int diff --git a/app/src/main/java/code/name/monkey/retromusic/loaders/ArtistLoader.kt b/app/src/main/java/code/name/monkey/retromusic/loaders/ArtistLoader.kt index e4ce09c8..cd994be1 100644 --- a/app/src/main/java/code/name/monkey/retromusic/loaders/ArtistLoader.kt +++ b/app/src/main/java/code/name/monkey/retromusic/loaders/ArtistLoader.kt @@ -20,27 +20,32 @@ import code.name.monkey.retromusic.model.Album import code.name.monkey.retromusic.model.Artist import code.name.monkey.retromusic.util.PreferenceUtil - object ArtistLoader { private fun getSongLoaderSortOrder(context: Context): String { - return PreferenceUtil.getInstance(context).artistSortOrder + ", " + PreferenceUtil.getInstance(context).artistAlbumSortOrder + ", " + PreferenceUtil.getInstance(context).albumSongSortOrder + return PreferenceUtil.getInstance(context).artistSortOrder + ", " + PreferenceUtil.getInstance(context).artistAlbumSortOrder + ", " + PreferenceUtil.getInstance( + context + ).albumSongSortOrder } fun getAllArtists(context: Context): ArrayList { - val songs = SongLoader.getSongs(SongLoader.makeSongCursor( + val songs = SongLoader.getSongs( + SongLoader.makeSongCursor( context, null, null, - getSongLoaderSortOrder(context)) + getSongLoaderSortOrder(context) + ) ) return splitIntoArtists(AlbumLoader.splitIntoAlbums(songs)) } fun getArtists(context: Context, query: String): ArrayList { - val songs = SongLoader.getSongs(SongLoader.makeSongCursor( + val songs = SongLoader.getSongs( + SongLoader.makeSongCursor( context, AudioColumns.ARTIST + " LIKE ?", arrayOf("%$query%"), - getSongLoaderSortOrder(context)) + getSongLoaderSortOrder(context) + ) ) return splitIntoArtists(AlbumLoader.splitIntoAlbums(songs)) } @@ -66,12 +71,15 @@ object ArtistLoader { return album } + @JvmStatic fun getArtist(context: Context, artistId: Int): Artist { - val songs = SongLoader.getSongs(SongLoader.makeSongCursor( + val songs = SongLoader.getSongs( + SongLoader.makeSongCursor( context, AudioColumns.ARTIST_ID + "=?", arrayOf(artistId.toString()), - getSongLoaderSortOrder(context)) + getSongLoaderSortOrder(context) + ) ) return Artist(AlbumLoader.splitIntoAlbums(songs)) } diff --git a/app/src/main/java/code/name/monkey/retromusic/loaders/PlaylistSongsLoader.kt b/app/src/main/java/code/name/monkey/retromusic/loaders/PlaylistSongsLoader.kt index 3073db67..c6a3c297 100644 --- a/app/src/main/java/code/name/monkey/retromusic/loaders/PlaylistSongsLoader.kt +++ b/app/src/main/java/code/name/monkey/retromusic/loaders/PlaylistSongsLoader.kt @@ -38,7 +38,7 @@ object PlaylistSongsLoader { return (playlist as? AbsCustomPlaylist)?.getSongs(context) ?: getPlaylistSongList(context, playlist.id) } - + @JvmStatic fun getPlaylistSongList(context: Context, playlistId: Int): ArrayList { val songs = arrayListOf() val cursor = makePlaylistSongCursor(context, playlistId) diff --git a/app/src/main/java/code/name/monkey/retromusic/model/Album.kt b/app/src/main/java/code/name/monkey/retromusic/model/Album.kt index f718d0f8..3796b900 100644 --- a/app/src/main/java/code/name/monkey/retromusic/model/Album.kt +++ b/app/src/main/java/code/name/monkey/retromusic/model/Album.kt @@ -17,6 +17,7 @@ package code.name.monkey.retromusic.model import java.util.ArrayList class Album { + val songs: ArrayList? val id: Int diff --git a/app/src/main/java/code/name/monkey/retromusic/preferences/MaterialListPreference.kt b/app/src/main/java/code/name/monkey/retromusic/preferences/MaterialListPreference.kt index 8c02e28b..76b937a9 100644 --- a/app/src/main/java/code/name/monkey/retromusic/preferences/MaterialListPreference.kt +++ b/app/src/main/java/code/name/monkey/retromusic/preferences/MaterialListPreference.kt @@ -124,7 +124,6 @@ class MaterialListPreferenceDialog : PreferenceDialogFragmentCompat() { fun newInstance(listPreference: ListPreference): MaterialListPreferenceDialog { val entries = listPreference.entries.toList() as ArrayList val entriesValues = listPreference.entryValues.toList() as ArrayList - println("List value: ${listPreference.value}") val position = listPreference.findIndexOfValue(listPreference.value) val args = Bundle() args.putString(ARG_KEY, listPreference.key) diff --git a/app/src/main/java/code/name/monkey/retromusic/util/AppRater.kt b/app/src/main/java/code/name/monkey/retromusic/util/AppRater.kt index 99903810..d7204fa6 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/AppRater.kt +++ b/app/src/main/java/code/name/monkey/retromusic/util/AppRater.kt @@ -34,7 +34,7 @@ object AppRater { private const val DAYS_UNTIL_PROMPT = 3//Min number of days private const val LAUNCHES_UNTIL_PROMPT = 5//Min number of launches - + @JvmStatic fun appLaunched(context: Context) { val prefs = context.getSharedPreferences(APP_RATING, 0) if (prefs.getBoolean(DO_NOT_SHOW_AGAIN, false)) { @@ -66,26 +66,31 @@ object AppRater { private fun showRateDialog(context: Context, editor: SharedPreferences.Editor) { MaterialDialog(context, BottomSheet(LayoutMode.WRAP_CONTENT)) - .show { + .show { - cornerRadius(PreferenceUtil.getInstance(context).dialogCorner) - title(text = "Rate this App") - message(text = "If you enjoy using Retro Music, please take a moment to rate it. Thanks for your support!") - positiveButton(R.string.app_name) { - context.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=${context.packageName}"))) - editor.putBoolean(DO_NOT_SHOW_AGAIN, true) - editor.commit() - dismiss() - } - negativeButton(text = "Later") { - dismiss() - } - neutralButton(text = " No thanks") { - editor.putBoolean(DO_NOT_SHOW_AGAIN, true) - editor.commit() - dismiss() - } - getActionButton(WhichButton.POSITIVE).updateTextColor(Color.RED) + cornerRadius(PreferenceUtil.getInstance(context).dialogCorner) + title(text = "Rate this App") + message(text = "If you enjoy using Retro Music, please take a moment to rate it. Thanks for your support!") + positiveButton(R.string.app_name) { + context.startActivity( + Intent( + Intent.ACTION_VIEW, + Uri.parse("market://details?id=${context.packageName}") + ) + ) + editor.putBoolean(DO_NOT_SHOW_AGAIN, true) + editor.commit() + dismiss() } + negativeButton(text = "Later") { + dismiss() + } + neutralButton(text = " No thanks") { + editor.putBoolean(DO_NOT_SHOW_AGAIN, true) + editor.commit() + dismiss() + } + getActionButton(WhichButton.POSITIVE).updateTextColor(Color.RED) + } } } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java index 8ca67846..0c033f63 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java @@ -29,7 +29,6 @@ import androidx.annotation.NonNull; import androidx.annotation.StyleRes; import androidx.viewpager.widget.ViewPager; import code.name.monkey.retromusic.R; -import code.name.monkey.retromusic.activities.MainActivity; import code.name.monkey.retromusic.fragments.AlbumCoverStyle; import code.name.monkey.retromusic.fragments.NowPlayingScreen; import code.name.monkey.retromusic.fragments.mainactivity.folders.FoldersFragment; @@ -585,14 +584,6 @@ public final class PreferenceUtil { return mPreferences.getInt(LAST_CHANGELOG_VERSION, -1); } - public final int getLastMusicChooser() { - return mPreferences.getInt(LAST_MUSIC_CHOOSER, MainActivity.HOME); - } - - public void setLastMusicChooser(int value) { - mPreferences.edit().putInt(LAST_MUSIC_CHOOSER, value).apply(); - } - public final int getLastPage() { return mPreferences.getInt(LAST_PAGE, R.id.action_song); } diff --git a/app/src/main/res/layout-land/fragment_banner_home.xml b/app/src/main/res/layout-land/fragment_banner_home.xml index f90e9a2c..99f27ab4 100644 --- a/app/src/main/res/layout-land/fragment_banner_home.xml +++ b/app/src/main/res/layout-land/fragment_banner_home.xml @@ -12,130 +12,89 @@ ~ See the GNU General Public License for more details. --> - + android:layout_marginStart="@dimen/toolbar_margin_horizontal" + android:layout_marginEnd="@dimen/toolbar_margin_horizontal" + app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"> - + android:layout_height="wrap_content" + android:orientation="vertical"> - - - - - - + android:layout_height="228dp" + app:cardCornerRadius="24dp" + app:cardUseCompatPadding="true"> - + android:layout_height="wrap_content"> - + android:layout_height="match_parent" + android:scaleType="centerCrop" + app:layout_collapseMode="parallax" + tools:ignore="ContentDescription" + tools:srcCompat="@tools:sample/backgrounds/scenic[9]" /> - + + + + + + + - + + - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + \ No newline at end of file diff --git a/app/src/main/res/layout-land/fragment_home.xml b/app/src/main/res/layout-land/fragment_home.xml index 017b2a7e..074b2f31 100644 --- a/app/src/main/res/layout-land/fragment_home.xml +++ b/app/src/main/res/layout-land/fragment_home.xml @@ -12,115 +12,64 @@ ~ See the GNU General Public License for more details. --> - + android:layout_marginStart="@dimen/toolbar_margin_horizontal" + android:layout_marginEnd="@dimen/toolbar_margin_horizontal" + app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"> - + android:layout_height="wrap_content"> - + - - - - - + android:layout_marginStart="16dp" + android:ellipsize="end" + android:text="@string/welcome" + app:layout_constraintStart_toEndOf="@+id/userImage" + app:layout_constraintTop_toTopOf="@+id/userImage" + tools:text="@tools:sample/lorem" /> - + - - + + - - - - - - - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main_content.xml b/app/src/main/res/layout/activity_main_content.xml index a22fce9a..6b20d393 100644 --- a/app/src/main/res/layout/activity_main_content.xml +++ b/app/src/main/res/layout/activity_main_content.xml @@ -46,7 +46,7 @@ android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="@dimen/toolbar_height" - android:background="?colorSurface" + android:background="?attr/colorSurface" app:navigationIcon="@drawable/ic_menu_white_24dp" app:popupTheme="?attr/toolbarPopupTheme" app:title="@string/action_search" diff --git a/app/src/main/res/layout/fragment_banner_home.xml b/app/src/main/res/layout/fragment_banner_home.xml index 7f3b395f..26ee8259 100644 --- a/app/src/main/res/layout/fragment_banner_home.xml +++ b/app/src/main/res/layout/fragment_banner_home.xml @@ -11,133 +11,97 @@ ~ 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="wrap_content" + app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"> - - - - - - + android:orientation="vertical"> - - + + + android:layout_height="wrap_content"> - - + android:layout_height="match_parent" + android:scaleType="centerCrop" + app:layout_collapseMode="parallax" + tools:ignore="ContentDescription" + tools:srcCompat="@tools:sample/backgrounds/scenic[9]" /> - - - + android:layout_height="52dp" + android:background="@drawable/shadow_up" + app:layout_constraintBottom_toBottomOf="parent" /> - + - + - - - - - + - - + + - - - - \ 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 2376a10c..4e075dd4 100755 --- a/app/src/main/res/layout/fragment_home.xml +++ b/app/src/main/res/layout/fragment_home.xml @@ -11,113 +11,62 @@ ~ 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="wrap_content" + app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior"> - - - + - - - + android:layout_marginStart="16dp" + android:ellipsize="end" + android:text="@string/welcome" + app:layout_constraintStart_toEndOf="@+id/userImage" + app:layout_constraintTop_toTopOf="@+id/userImage" + tools:text="@tools:sample/lorem" /> - - - - - - - + android:layout_marginStart="16dp" + android:padding="0dp" + android:textAppearance="@style/TextViewHeadline5" + android:textColor="?android:attr/textColorPrimary" + android:textStyle="bold" + app:layout_constraintBottom_toBottomOf="@+id/userImage" + app:layout_constraintStart_toEndOf="@+id/userImage" + app:layout_constraintTop_toBottomOf="@+id/text" + tools:text="@tools:sample/lorem" /> - + + - - - - - - - - - - - - \ No newline at end of file + \ No newline at end of file From d03d4e45055b2708293cc9cf284dad9c2251eb99 Mon Sep 17 00:00:00 2001 From: h4h13 Date: Wed, 19 Feb 2020 12:38:25 +0530 Subject: [PATCH 3/5] Removed library fragment --- .../mainactivity/LibraryFragment.java | 529 ------------------ 1 file changed, 529 deletions(-) delete mode 100644 app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/LibraryFragment.java diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/LibraryFragment.java b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/LibraryFragment.java deleted file mode 100644 index a63ed20e..00000000 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/LibraryFragment.java +++ /dev/null @@ -1,529 +0,0 @@ -package code.name.monkey.retromusic.fragments.mainactivity; - -import android.app.Activity; -import android.app.ActivityOptions; -import android.content.res.ColorStateList; -import android.graphics.Color; -import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuInflater; -import android.view.MenuItem; -import android.view.SubMenu; -import android.view.View; -import android.view.ViewGroup; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; -import androidx.appcompat.widget.Toolbar; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentManager; -import androidx.fragment.app.FragmentTransaction; -import code.name.monkey.appthemehelper.common.ATHToolbarActivity; -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.dialogs.CreatePlaylistDialog; -import code.name.monkey.retromusic.dialogs.OptionsSheetDialogFragment; -import code.name.monkey.retromusic.fragments.base.AbsLibraryPagerRecyclerViewCustomGridSizeFragment; -import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment; -import code.name.monkey.retromusic.helper.SortOrder.AlbumSortOrder; -import code.name.monkey.retromusic.helper.SortOrder.ArtistSortOrder; -import code.name.monkey.retromusic.helper.SortOrder.SongSortOrder; -import code.name.monkey.retromusic.interfaces.CabHolder; -import code.name.monkey.retromusic.interfaces.MainActivityFragmentCallbacks; -import code.name.monkey.retromusic.util.NavigationUtil; -import code.name.monkey.retromusic.util.RetroColorUtil; -import code.name.monkey.retromusic.util.RetroUtil; -import com.afollestad.materialcab.MaterialCab; -import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.card.MaterialCardView; -import org.jetbrains.annotations.NotNull; - -public class LibraryFragment extends AbsMainActivityFragment implements CabHolder, MainActivityFragmentCallbacks { - - public static final String TAG = "LibraryFragment"; - - private static final String CURRENT_TAB_ID = "current_tab_id"; - - private AppBarLayout appBarLayout; - - private MaterialCab cab; - - private FragmentManager fragmentManager; - - private Toolbar toolbar; - - private MaterialCardView toolbarContainer; - - @NonNull - public static Fragment newInstance(int tab) { - Bundle args = new Bundle(); - args.putInt(CURRENT_TAB_ID, tab); - LibraryFragment fragment = new LibraryFragment(); - fragment.setArguments(args); - return fragment; - } - - @NonNull - public static Fragment newInstance() { - return new LibraryFragment(); - } - - @Nullable - @Override - public View onCreateView(@NonNull LayoutInflater inflater, - @Nullable ViewGroup container, - @Nullable Bundle savedInstanceState) { - View view = inflater.inflate(R.layout.fragment_library, container, false); - appBarLayout = view.findViewById(R.id.appBarLayout); - toolbarContainer = view.findViewById(R.id.toolbarContainer); - toolbar = view.findViewById(R.id.toolbar); - return view; - } - - @Override - public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - super.onViewCreated(view, savedInstanceState); - setStatusBarColorAuto(view); - setupToolbar(); - inflateFragment(); - } - - - public void addOnAppBarOffsetChangedListener( - @NonNull AppBarLayout.OnOffsetChangedListener onOffsetChangedListener) { - appBarLayout.addOnOffsetChangedListener(onOffsetChangedListener); - } - - public int getTotalAppBarScrollingRange() { - return appBarLayout.getTotalScrollRange(); - } - - @Override - public boolean handleBackPress() { - if (cab != null && cab.isActive()) { - cab.finish(); - return true; - } - return false; - } - - @Override - public void onCreateOptionsMenu(@NotNull Menu menu, @NonNull MenuInflater inflater) { - super.onCreateOptionsMenu(menu, inflater); - inflater.inflate(R.menu.menu_main, menu); - - Fragment currentFragment = getCurrentFragment(); - if (currentFragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment - && currentFragment.isAdded()) { - AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment - = (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) currentFragment; - - if (fragment instanceof SongsFragment) { - menu.removeItem(R.id.action_grid_size); - menu.removeItem(R.id.action_layout_type); - } else { - MenuItem gridSizeItem = menu.findItem(R.id.action_grid_size); - if (RetroUtil.isLandscape()) { - gridSizeItem.setTitle(R.string.action_grid_size_land); - } - setUpGridSizeMenu(fragment, gridSizeItem.getSubMenu()); - MenuItem layoutItem = menu.findItem(R.id.action_layout_type); - setupLayoutMenu(fragment, layoutItem.getSubMenu()); - } - - setUpSortOrderMenu(fragment, menu.findItem(R.id.action_sort_order).getSubMenu()); - - } else if (currentFragment instanceof GenresFragment || currentFragment instanceof PlayingQueueFragment) { - menu.removeItem(R.id.action_new_playlist); - menu.removeItem(R.id.action_layout_type); - menu.removeItem(R.id.action_grid_size); - menu.removeItem(R.id.action_sort_order); - } else { - menu.add(0, R.id.action_new_playlist, 0, R.string.new_playlist_title) - .setIcon(R.drawable.ic_playlist_add_white_24dp).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM); - menu.removeItem(R.id.action_grid_size); - menu.removeItem(R.id.action_layout_type); - } - ToolbarContentTintHelper.handleOnCreateOptionsMenu(requireActivity(), toolbar, menu, - ATHToolbarActivity.getToolbarBackgroundColor(toolbar)); - } - - @Override - public boolean onOptionsItemSelected(@NonNull MenuItem item) { - //if (pager == null) return false; - Fragment currentFragment = getCurrentFragment(); - if (currentFragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment) { - AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment - = (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) currentFragment; - if (handleGridSizeMenuItem(fragment, item)) { - return true; - } - if (handleLayoutResType(fragment, item)) { - return true; - } - if (handleSortOrderMenuItem(fragment, item)) { - return true; - } - } - int id = item.getItemId(); - switch (id) { - case R.id.action_search: - ActivityOptions options = ActivityOptions - .makeSceneTransitionAnimation(getMainActivity(), toolbarContainer, - getString(R.string.transition_toolbar)); - NavigationUtil.goToSearch(getMainActivity(), options); - break; - case R.id.action_new_playlist: - CreatePlaylistDialog.Companion.create().show(getChildFragmentManager(), "CREATE_PLAYLIST"); - return true; - } - return super.onOptionsItemSelected(item); - } - - @Override - public void onPrepareOptionsMenu(@NonNull Menu menu) { - super.onPrepareOptionsMenu(menu); - Activity activity = getActivity(); - if (activity == null) { - return; - } - ToolbarContentTintHelper.handleOnPrepareOptionsMenu(activity, toolbar); - } - - @NonNull - @Override - public MaterialCab openCab(int menuRes, @NonNull MaterialCab.Callback callback) { - if (cab != null && cab.isActive()) { - cab.finish(); - } - - cab = new MaterialCab(getMainActivity(), R.id.cab_stub) - .setMenu(menuRes) - .setCloseDrawableRes(R.drawable.ic_close_white_24dp) - .setBackgroundColor( - RetroColorUtil.shiftBackgroundColorForLightText( - ATHUtil.INSTANCE.resolveColor(requireContext(), R.attr.colorSurface))) - .start(callback); - return cab; - } - - public void removeOnAppBarOffsetChangedListener( - @NonNull AppBarLayout.OnOffsetChangedListener onOffsetChangedListener) { - appBarLayout.removeOnOffsetChangedListener(onOffsetChangedListener); - } - - public void setTitle(@StringRes int name) { - toolbar.setTitle(getString(name)); - } - - private Fragment getCurrentFragment() { - if (fragmentManager == null) { - return SongsFragment.Companion.newInstance(); - } - return fragmentManager.findFragmentByTag(LibraryFragment.TAG); - } - - private boolean handleGridSizeMenuItem( - @NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, - @NonNull MenuItem item) { - int gridSize = 0; - switch (item.getItemId()) { - case R.id.action_grid_size_1: - gridSize = 1; - break; - case R.id.action_grid_size_2: - gridSize = 2; - break; - case R.id.action_grid_size_3: - gridSize = 3; - break; - case R.id.action_grid_size_4: - gridSize = 4; - break; - case R.id.action_grid_size_5: - gridSize = 5; - break; - case R.id.action_grid_size_6: - gridSize = 6; - break; - case R.id.action_grid_size_7: - gridSize = 7; - break; - case R.id.action_grid_size_8: - gridSize = 8; - break; - } - - if (gridSize > 0) { - item.setChecked(true); - fragment.setAndSaveGridSize(gridSize); - return true; - } - return false; - } - - private boolean handleLayoutResType( - final AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, - final MenuItem item) { - int layoutRes = -1; - switch (item.getItemId()) { - case R.id.action_layout_normal: - layoutRes = R.layout.item_grid; - break; - case R.id.action_layout_card: - layoutRes = R.layout.item_card; - break; - case R.id.action_layout_colored_card: - layoutRes = R.layout.item_card_color; - break; - case R.id.action_layout_circular: - layoutRes = R.layout.item_grid_circle; - break; - case R.id.action_layout_image: - layoutRes = R.layout.image; - break; - case R.id.action_layout_gradient_image: - layoutRes = R.layout.item_image_gradient; - break; - } - if (layoutRes != -1) { - item.setChecked(true); - fragment.setAndSaveLayoutRes(layoutRes); - return true; - } - return false; - } - - private boolean handleSortOrderMenuItem( - @NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment - fragment, @NonNull MenuItem item) { - String sortOrder = null; - if (fragment instanceof AlbumsFragment) { - switch (item.getItemId()) { - case R.id.action_album_sort_order_asc: - sortOrder = AlbumSortOrder.ALBUM_A_Z; - break; - case R.id.action_album_sort_order_desc: - sortOrder = AlbumSortOrder.ALBUM_Z_A; - break; - case R.id.action_album_sort_order_artist: - sortOrder = AlbumSortOrder.ALBUM_ARTIST; - break; - case R.id.action_album_sort_order_year: - sortOrder = AlbumSortOrder.ALBUM_YEAR; - break; - } - } else if (fragment instanceof ArtistsFragment) { - switch (item.getItemId()) { - case R.id.action_artist_sort_order_asc: - sortOrder = ArtistSortOrder.ARTIST_A_Z; - break; - case R.id.action_artist_sort_order_desc: - sortOrder = ArtistSortOrder.ARTIST_Z_A; - break; - } - } else if (fragment instanceof SongsFragment) { - switch (item.getItemId()) { - case R.id.action_song_sort_order_asc: - sortOrder = SongSortOrder.SONG_A_Z; - break; - case R.id.action_song_sort_order_desc: - sortOrder = SongSortOrder.SONG_Z_A; - break; - case R.id.action_song_sort_order_artist: - sortOrder = SongSortOrder.SONG_ARTIST; - break; - case R.id.action_song_sort_order_album: - sortOrder = SongSortOrder.SONG_ALBUM; - break; - case R.id.action_song_sort_order_year: - sortOrder = SongSortOrder.SONG_YEAR; - break; - case R.id.action_song_sort_order_date: - sortOrder = SongSortOrder.SONG_DATE; - break; - case R.id.action_song_sort_order_composer: - sortOrder = SongSortOrder.COMPOSER; - break; - - } - } - - if (sortOrder != null) { - item.setChecked(true); - fragment.setAndSaveSortOrder(sortOrder); - return true; - } - - return false; - } - - private void inflateFragment() { - if (getArguments() == null) { - selectedFragment(SongsFragment.Companion.newInstance()); - return; - } - switch (getArguments().getInt(CURRENT_TAB_ID)) { - default: - case R.id.action_song: - selectedFragment(SongsFragment.Companion.newInstance()); - break; - case R.id.action_album: - selectedFragment(AlbumsFragment.Companion.newInstance()); - break; - case R.id.action_artist: - selectedFragment(ArtistsFragment.Companion.newInstance()); - break; - case R.id.action_playlist: - selectedFragment(PlaylistsFragment.Companion.newInstance()); - break; - case R.id.action_genre: - selectedFragment(GenresFragment.Companion.newInstance()); - break; - case R.id.action_playing_queue: - selectedFragment(PlayingQueueFragment.Companion.newInstance()); - break; - } - } - - private void selectedFragment(Fragment fragment) { - fragmentManager = getChildFragmentManager(); - FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); - fragmentTransaction - .replace(R.id.fragmentContainer, fragment, LibraryFragment.TAG) - .commit(); - } - - private void setUpGridSizeMenu( - @NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, - @NonNull SubMenu gridSizeMenu) { - switch (fragment.getGridSize()) { - case 1: - gridSizeMenu.findItem(R.id.action_grid_size_1).setChecked(true); - break; - case 2: - gridSizeMenu.findItem(R.id.action_grid_size_2).setChecked(true); - break; - case 3: - gridSizeMenu.findItem(R.id.action_grid_size_3).setChecked(true); - break; - case 4: - gridSizeMenu.findItem(R.id.action_grid_size_4).setChecked(true); - break; - case 5: - gridSizeMenu.findItem(R.id.action_grid_size_5).setChecked(true); - break; - case 6: - gridSizeMenu.findItem(R.id.action_grid_size_6).setChecked(true); - break; - case 7: - gridSizeMenu.findItem(R.id.action_grid_size_7).setChecked(true); - break; - case 8: - gridSizeMenu.findItem(R.id.action_grid_size_8).setChecked(true); - break; - } - int maxGridSize = fragment.getMaxGridSize(); - if (maxGridSize < 8) { - gridSizeMenu.findItem(R.id.action_grid_size_8).setVisible(false); - } - if (maxGridSize < 7) { - gridSizeMenu.findItem(R.id.action_grid_size_7).setVisible(false); - } - if (maxGridSize < 6) { - gridSizeMenu.findItem(R.id.action_grid_size_6).setVisible(false); - } - if (maxGridSize < 5) { - gridSizeMenu.findItem(R.id.action_grid_size_5).setVisible(false); - } - if (maxGridSize < 4) { - gridSizeMenu.findItem(R.id.action_grid_size_4).setVisible(false); - } - if (maxGridSize < 3) { - gridSizeMenu.findItem(R.id.action_grid_size_3).setVisible(false); - } - } - - private void setUpSortOrderMenu( - @NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, - @NonNull SubMenu sortOrderMenu) { - String currentSortOrder = fragment.getSortOrder(); - sortOrderMenu.clear(); - - if (fragment instanceof AlbumsFragment) { - sortOrderMenu.add(0, R.id.action_album_sort_order_asc, 0, R.string.sort_order_a_z) - .setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_A_Z)); - sortOrderMenu.add(0, R.id.action_album_sort_order_desc, 1, R.string.sort_order_z_a) - .setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_Z_A)); - sortOrderMenu.add(0, R.id.action_album_sort_order_artist, 2, R.string.sort_order_artist) - .setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_ARTIST)); - sortOrderMenu.add(0, R.id.action_album_sort_order_year, 3, R.string.sort_order_year) - .setChecked(currentSortOrder.equals(AlbumSortOrder.ALBUM_YEAR)); - } else if (fragment instanceof ArtistsFragment) { - sortOrderMenu.add(0, R.id.action_artist_sort_order_asc, 0, R.string.sort_order_a_z) - .setChecked(currentSortOrder.equals(ArtistSortOrder.ARTIST_A_Z)); - sortOrderMenu.add(0, R.id.action_artist_sort_order_desc, 1, R.string.sort_order_z_a) - .setChecked(currentSortOrder.equals(ArtistSortOrder.ARTIST_Z_A)); - } else if (fragment instanceof SongsFragment) { - sortOrderMenu.add(0, R.id.action_song_sort_order_asc, 0, R.string.sort_order_a_z) - .setChecked(currentSortOrder.equals(SongSortOrder.SONG_A_Z)); - sortOrderMenu.add(0, R.id.action_song_sort_order_desc, 1, R.string.sort_order_z_a) - .setChecked(currentSortOrder.equals(SongSortOrder.SONG_Z_A)); - sortOrderMenu.add(0, R.id.action_song_sort_order_artist, 2, R.string.sort_order_artist) - .setChecked(currentSortOrder.equals(SongSortOrder.SONG_ARTIST)); - sortOrderMenu.add(0, R.id.action_song_sort_order_album, 3, R.string.sort_order_album) - .setChecked(currentSortOrder.equals(SongSortOrder.SONG_ALBUM)); - sortOrderMenu.add(0, R.id.action_song_sort_order_year, 4, R.string.sort_order_year) - .setChecked(currentSortOrder.equals(SongSortOrder.SONG_YEAR)); - sortOrderMenu.add(0, R.id.action_song_sort_order_date, 5, R.string.sort_order_date) - .setChecked(currentSortOrder.equals(SongSortOrder.SONG_DATE)); - sortOrderMenu.add(0, R.id.action_song_sort_order_composer, 6, R.string.sort_order_composer) - .setChecked(currentSortOrder.equals(SongSortOrder.COMPOSER)); - } - - sortOrderMenu.setGroupCheckable(0, true, true); - } - - private void setupLayoutMenu( - @NonNull final AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, - @NonNull final SubMenu subMenu) { - switch (fragment.itemLayoutRes()) { - case R.layout.item_card: - subMenu.findItem(R.id.action_layout_card).setChecked(true); - break; - case R.layout.item_grid: - subMenu.findItem(R.id.action_layout_normal).setChecked(true); - break; - case R.layout.item_card_color: - subMenu.findItem(R.id.action_layout_colored_card).setChecked(true); - break; - case R.layout.item_grid_circle: - subMenu.findItem(R.id.action_layout_circular).setChecked(true); - break; - case R.layout.image: - subMenu.findItem(R.id.action_layout_image).setChecked(true); - break; - case R.layout.item_image_gradient: - subMenu.findItem(R.id.action_layout_gradient_image).setChecked(true); - break; - } - } - - private void setupToolbar() { - toolbar.setBackgroundColor(Color.TRANSPARENT); - toolbarContainer.setCardBackgroundColor( - ColorStateList.valueOf(ATHUtil.INSTANCE.resolveColor(requireContext(), R.attr.colorSurface))); - toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp); - toolbar.setOnClickListener(v -> { - ActivityOptions options = ActivityOptions - .makeSceneTransitionAnimation(getMainActivity(), toolbarContainer, - getString(R.string.transition_toolbar)); - NavigationUtil.goToSearch(getMainActivity(), options); - }); - getMainActivity().setSupportActionBar(toolbar); - toolbar.setNavigationOnClickListener(v -> showMainMenu(OptionsSheetDialogFragment.LIBRARY)); - ToolbarContentTintHelper.colorBackButton(toolbar); - } -} \ No newline at end of file From f11c392b8ddb723cfe81a6fbcdf30cc7b70e5868 Mon Sep 17 00:00:00 2001 From: h4h13 Date: Wed, 19 Feb 2020 13:23:53 +0530 Subject: [PATCH 4/5] Removed library fragment --- .../retromusic/activities/MainActivity.java | 85 ++++++++--- .../dialogs/OptionsSheetDialogFragment.kt | 6 +- .../mainactivity/folders/FoldersFragment.java | 59 +------- .../retromusic/util/PreferenceUtil.java | 9 ++ app/src/main/res/layout/fragment_folder.xml | 132 +++++------------- 5 files changed, 118 insertions(+), 173 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java index 478903d7..f39c1660 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java +++ b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java @@ -49,6 +49,7 @@ import code.name.monkey.retromusic.fragments.mainactivity.GenresFragment; import code.name.monkey.retromusic.fragments.mainactivity.PlayingQueueFragment; import code.name.monkey.retromusic.fragments.mainactivity.PlaylistsFragment; import code.name.monkey.retromusic.fragments.mainactivity.SongsFragment; +import code.name.monkey.retromusic.fragments.mainactivity.folders.FoldersFragment; import code.name.monkey.retromusic.fragments.mainactivity.home.BannerHomeFragment; import code.name.monkey.retromusic.helper.MusicPlayerRemote; import code.name.monkey.retromusic.helper.SearchQueryHelper; @@ -65,6 +66,7 @@ import code.name.monkey.retromusic.service.MusicService; import code.name.monkey.retromusic.util.AppRater; import code.name.monkey.retromusic.util.NavigationUtil; import code.name.monkey.retromusic.util.PreferenceUtil; +import code.name.monkey.retromusic.util.RetroColorUtil; import code.name.monkey.retromusic.util.RetroUtil; import com.afollestad.materialcab.MaterialCab; import com.afollestad.materialcab.MaterialCab.Callback; @@ -92,6 +94,8 @@ public class MainActivity extends AbsSlidingMusicPanelActivity private boolean blockRequestPermissions = false; + private MaterialCab cab; + private AppBarLayout mAppBarLayout; private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @@ -134,7 +138,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity }); if (savedInstanceState == null) { - selectedFragment(PreferenceUtil.getInstance(this).getLastPage()); + setMusicChooser(PreferenceUtil.getInstance(this).getLastMusicChooser()); } else { restoreCurrentFragment(); } @@ -189,6 +193,15 @@ public class MainActivity extends AbsSlidingMusicPanelActivity return mAppBarLayout.getTotalScrollRange(); } + @Override + public boolean handleBackPress() { + if (cab != null && cab.isActive()) { + cab.finish(); + return true; + } + return super.handleBackPress() || (currentFragment != null && currentFragment.handleBackPress()); + } + @Override public boolean onCreateOptionsMenu(final Menu menu) { getMenuInflater().inflate(R.menu.menu_main, menu); @@ -275,7 +288,7 @@ public class MainActivity extends AbsSlidingMusicPanelActivity key.equals(PreferenceUtil.USER_NAME) || key.equals(PreferenceUtil.TOGGLE_FULL_SCREEN) || key.equals(PreferenceUtil.TOGGLE_VOLUME) || key.equals(PreferenceUtil.ROUND_CORNERS) || key.equals(PreferenceUtil.CAROUSEL_EFFECT) || key == PreferenceUtil.NOW_PLAYING_SCREEN_ID || - key == PreferenceUtil.TOGGLE_GENRE || key == PreferenceUtil.BANNER_IMAGE_PATH || + key == PreferenceUtil.TOGGLE_GENRE || key.equals(PreferenceUtil.BANNER_IMAGE_PATH) || key == PreferenceUtil.PROFILE_IMAGE_PATH || key == PreferenceUtil.CIRCULAR_ALBUM_ART || key == PreferenceUtil.KEEP_SCREEN_ON || key == PreferenceUtil.TOGGLE_SEPARATE_LINE || key == PreferenceUtil.TOGGLE_HOME_BANNER || key == PreferenceUtil.TOGGLE_ADD_CONTROLS || @@ -290,7 +303,17 @@ public class MainActivity extends AbsSlidingMusicPanelActivity @NotNull @Override public MaterialCab openCab(final int menuRes, @NotNull final Callback callback) { - return null; + if (cab != null && cab.isActive()) { + cab.finish(); + } + cab = new MaterialCab(this, R.id.cab_stub) + .setMenu(menuRes) + .setCloseDrawableRes(R.drawable.ic_close_white_24dp) + .setBackgroundColor( + RetroColorUtil.shiftBackgroundColorForLightText( + ATHUtil.INSTANCE.resolveColor(this, R.attr.colorSurface))) + .start(callback); + return cab; } public void removeOnAppBarOffsetChangedListener( @@ -298,12 +321,42 @@ public class MainActivity extends AbsSlidingMusicPanelActivity mAppBarLayout.removeOnOffsetChangedListener(onOffsetChangedListener); } + public void setCurrentFragment(Fragment fragment, String tag) { + String currentTag = null; + if (getSupportFragmentManager().findFragmentByTag(tag) != null) { + currentTag = getSupportFragmentManager().findFragmentByTag(tag).getTag(); + } + + if (!tag.equals(currentTag)) { + getSupportFragmentManager().beginTransaction() + .replace(R.id.fragment_container, fragment, tag) + .commit(); + currentFragment = (MainActivityFragmentCallbacks) fragment; + } + } + + public void setMusicChooser(final int option) { + PreferenceUtil.getInstance(this).setLastMusicChooser(option); + if (option == OptionsSheetDialogFragment.FOLDER) { + setCurrentFragment(FoldersFragment.newInstance(this), FoldersFragment.TAG); + } else { + selectedFragment(PreferenceUtil.getInstance(this).getLastPage()); + } + } + @NotNull @Override protected View createContentView() { return wrapSlidingMusicPanel(R.layout.activity_main_content); } + @Override + protected void requestPermissions() { + if (!blockRequestPermissions) { + super.requestPermissions(); + } + } + private void checkShowChangelog() { try { final PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); @@ -563,20 +616,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity } } - private void setCurrentFragment(Fragment fragment, String tag) { - String currentTag = null; - if (getSupportFragmentManager().findFragmentByTag(tag) != null) { - currentTag = getSupportFragmentManager().findFragmentByTag(tag).getTag(); - } - - if (!tag.equals(currentTag)) { - getSupportFragmentManager().beginTransaction() - .replace(R.id.fragment_container, fragment, tag) - .commit(); - currentFragment = (MainActivityFragmentCallbacks) fragment; - } - } - private void setUpGridSizeMenu(@NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, @NonNull SubMenu gridSizeMenu) { @@ -702,7 +741,17 @@ public class MainActivity extends AbsSlidingMusicPanelActivity .makeSceneTransitionAnimation(this, mToolbarContainer, getString(R.string.transition_toolbar)); NavigationUtil.goToSearch(this, options); }); + mToolbar.setNavigationOnClickListener( - v -> OptionsSheetDialogFragment.newInstance().show(getSupportFragmentManager(), "Main_Menu")); + v -> { + Fragment fragment = getCurrentFragment(); + if (fragment instanceof FoldersFragment) { + OptionsSheetDialogFragment.newInstance(OptionsSheetDialogFragment.FOLDER) + .show(getSupportFragmentManager(), "Main_Menu"); + } else { + OptionsSheetDialogFragment.newInstance(OptionsSheetDialogFragment.LIBRARY) + .show(getSupportFragmentManager(), "Main_Menu"); + } + }); } } diff --git a/app/src/main/java/code/name/monkey/retromusic/dialogs/OptionsSheetDialogFragment.kt b/app/src/main/java/code/name/monkey/retromusic/dialogs/OptionsSheetDialogFragment.kt index 780feb96..0c06a8f4 100644 --- a/app/src/main/java/code/name/monkey/retromusic/dialogs/OptionsSheetDialogFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/dialogs/OptionsSheetDialogFragment.kt @@ -37,10 +37,8 @@ class OptionsSheetDialogFragment : DialogFragment(), View.OnClickListener { override fun onClick(view: View) { val mainActivity = activity as MainActivity? ?: return when (view.id) { - R.id.actionFolders -> { - }//mainActivity.setMusicChooser(MainActivity.FOLDER) - R.id.actionLibrary -> { - }//mainActivity.setMusicChooser(MainActivity.LIBRARY) + R.id.actionFolders -> mainActivity.setMusicChooser(FOLDER) + R.id.actionLibrary -> mainActivity.setMusicChooser(LIBRARY) R.id.actionSettings -> NavigationUtil.goToSettings(mainActivity) R.id.actionDriveMode -> NavigationUtil.gotoDriveMode(mainActivity) R.id.actionRate -> NavigationUtil.goToPlayStore(mainActivity) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/folders/FoldersFragment.java b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/folders/FoldersFragment.java index 1ddef96f..9d6c30ba 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/folders/FoldersFragment.java +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/folders/FoldersFragment.java @@ -1,9 +1,7 @@ package code.name.monkey.retromusic.fragments.mainactivity.folders; -import android.app.ActivityOptions; import android.app.Dialog; import android.content.Context; -import android.content.res.ColorStateList; import android.media.MediaScannerConnection; import android.os.Bundle; import android.os.Environment; @@ -20,18 +18,14 @@ import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.widget.Toolbar; import androidx.loader.app.LoaderManager; import androidx.loader.content.Loader; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; import code.name.monkey.appthemehelper.ThemeStore; -import code.name.monkey.appthemehelper.common.ATHToolbarActivity; 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.dialogs.OptionsSheetDialogFragment; import code.name.monkey.retromusic.fragments.base.AbsMainActivityFragment; import code.name.monkey.retromusic.helper.MusicPlayerRemote; import code.name.monkey.retromusic.helper.menu.SongMenuHelper; @@ -43,17 +37,13 @@ import code.name.monkey.retromusic.misc.DialogAsyncTask; import code.name.monkey.retromusic.misc.UpdateToastMediaScannerCompletionListener; import code.name.monkey.retromusic.misc.WrappedAsyncTaskLoader; import code.name.monkey.retromusic.model.Song; -import code.name.monkey.retromusic.util.DensityUtil; import code.name.monkey.retromusic.util.FileUtil; -import code.name.monkey.retromusic.util.NavigationUtil; import code.name.monkey.retromusic.util.PreferenceUtil; import code.name.monkey.retromusic.util.RetroColorUtil; import code.name.monkey.retromusic.util.ThemedFastScroller; import code.name.monkey.retromusic.views.BreadCrumbLayout; import code.name.monkey.retromusic.views.ScrollingViewOnApplyWindowInsetsListener; import com.afollestad.materialcab.MaterialCab; -import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.card.MaterialCardView; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.snackbar.Snackbar; import java.io.File; @@ -71,7 +61,7 @@ import me.zhanghai.android.fastscroll.FastScroller; public class FoldersFragment extends AbsMainActivityFragment implements MainActivityFragmentCallbacks, CabHolder, BreadCrumbLayout.SelectionCallback, SongFileAdapter.Callbacks, - AppBarLayout.OnOffsetChangedListener, LoaderManager.LoaderCallbacks> { + LoaderManager.LoaderCallbacks> { public static class ListPathsAsyncTask extends ListingFilesDialogAsyncTask { @@ -327,8 +317,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements private SongFileAdapter adapter; - private AppBarLayout appBarLayout; - private BreadCrumbLayout breadCrumbs; private MaterialCab cab; @@ -350,9 +338,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements private RecyclerView recyclerView; - private Toolbar toolbar; - - private MaterialCardView toolbarContainer; public static File getDefaultStartDirectory() { File musicDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC); @@ -434,12 +419,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements } - @Override - public void onDestroyView() { - appBarLayout.removeOnOffsetChangedListener(this); - super.onDestroyView(); - } - @Override public boolean handleBackPress() { if (cab != null && cab.isActive()) { @@ -463,8 +442,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); inflater.inflate(R.menu.menu_folders, menu); - ToolbarContentTintHelper.handleOnCreateOptionsMenu(getActivity(), toolbar, menu, - ATHToolbarActivity.getToolbarBackgroundColor(toolbar)); } @Override @@ -590,13 +567,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements .execute(new ListSongsAsyncTask.LoadingInfo(files, AUDIO_FILE_FILTER, getFileComparator())); } - @Override - public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) { - recyclerView.setPadding(recyclerView.getPaddingLeft(), recyclerView.getPaddingTop(), - recyclerView.getPaddingRight(), DensityUtil.dip2px(requireContext(), 52f) + - this.appBarLayout.getTotalScrollRange() + verticalOffset); - } - @Override public boolean onOptionsItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { @@ -617,11 +587,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements return super.onOptionsItemSelected(item); } - @Override - public void onPrepareOptionsMenu(Menu menu) { - super.onPrepareOptionsMenu(menu); - ToolbarContentTintHelper.handleOnPrepareOptionsMenu(getActivity(), toolbar); - } @NonNull @Override @@ -661,11 +626,8 @@ public class FoldersFragment extends AbsMainActivityFragment implements private void initViews(View view) { coordinatorLayout = view.findViewById(R.id.coordinatorLayout); - toolbarContainer = view.findViewById(R.id.toolbarContainer); recyclerView = view.findViewById(R.id.recyclerView); - appBarLayout = view.findViewById(R.id.appBarLayout); breadCrumbs = view.findViewById(R.id.breadCrumbs); - toolbar = view.findViewById(R.id.toolbar); empty = view.findViewById(android.R.id.empty); emojiText = view.findViewById(R.id.emptyEmoji); } @@ -703,7 +665,7 @@ public class FoldersFragment extends AbsMainActivityFragment implements } private void setUpAdapter() { - adapter = new SongFileAdapter(getMainActivity(), new LinkedList(), R.layout.item_list, + adapter = new SongFileAdapter(getMainActivity(), new LinkedList<>(), R.layout.item_list, this, this); adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { @Override @@ -717,26 +679,10 @@ public class FoldersFragment extends AbsMainActivityFragment implements } private void setUpAppbarColor() { - int primaryColor = ATHUtil.INSTANCE.resolveColor(requireContext(), R.attr.colorSurface); - getMainActivity().setSupportActionBar(toolbar); - toolbar.setBackgroundTintList(ColorStateList.valueOf(primaryColor)); - toolbarContainer.setCardBackgroundColor(ColorStateList.valueOf(primaryColor)); - toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp); - toolbar.setNavigationOnClickListener(v -> { - showMainMenu(OptionsSheetDialogFragment.FOLDER); - }); breadCrumbs.setActivatedContentColor( ATHUtil.INSTANCE.resolveColor(requireContext(), android.R.attr.textColorPrimary)); breadCrumbs.setDeactivatedContentColor( ATHUtil.INSTANCE.resolveColor(requireContext(), android.R.attr.textColorSecondary)); - appBarLayout.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> getMainActivity() - .setLightStatusbar(!ATHUtil.INSTANCE.isWindowBackgroundDark(requireContext()))); - toolbar.setOnClickListener(v -> { - ActivityOptions options = ActivityOptions - .makeSceneTransitionAnimation(getMainActivity(), toolbarContainer, - getString(R.string.transition_toolbar)); - NavigationUtil.goToSearch(getMainActivity(), options); - }); } private void setUpBreadCrumbs() { @@ -745,7 +691,6 @@ public class FoldersFragment extends AbsMainActivityFragment implements private void setUpRecyclerView() { recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); - appBarLayout.addOnOffsetChangedListener(this); FastScroller fastScroller = ThemedFastScroller.INSTANCE.create(recyclerView); recyclerView.setOnApplyWindowInsetsListener( new ScrollingViewOnApplyWindowInsetsListener(recyclerView, fastScroller)); diff --git a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java index 0c033f63..f6eb9e29 100644 --- a/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/PreferenceUtil.java @@ -29,6 +29,7 @@ import androidx.annotation.NonNull; import androidx.annotation.StyleRes; import androidx.viewpager.widget.ViewPager; import code.name.monkey.retromusic.R; +import code.name.monkey.retromusic.dialogs.OptionsSheetDialogFragment; import code.name.monkey.retromusic.fragments.AlbumCoverStyle; import code.name.monkey.retromusic.fragments.NowPlayingScreen; import code.name.monkey.retromusic.fragments.mainactivity.folders.FoldersFragment; @@ -584,6 +585,14 @@ public final class PreferenceUtil { return mPreferences.getInt(LAST_CHANGELOG_VERSION, -1); } + public final int getLastMusicChooser() { + return mPreferences.getInt(LAST_MUSIC_CHOOSER, OptionsSheetDialogFragment.LIBRARY); + } + + public void setLastMusicChooser(int value) { + mPreferences.edit().putInt(LAST_MUSIC_CHOOSER, value).apply(); + } + public final int getLastPage() { return mPreferences.getInt(LAST_PAGE, R.id.action_song); } diff --git a/app/src/main/res/layout/fragment_folder.xml b/app/src/main/res/layout/fragment_folder.xml index 91f06b7e..df1ed7fc 100644 --- a/app/src/main/res/layout/fragment_folder.xml +++ b/app/src/main/res/layout/fragment_folder.xml @@ -1,80 +1,53 @@ - + android:background="?attr/colorSurface"> - + android:layout_gravity="center" + android:gravity="center" + android:orientation="vertical" + android:visibility="gone" + tools:visibility="visible"> - + - + + - + android:orientation="vertical"> - - - - - - - - - - - - - - - - - + android:layout_height="@dimen/tab_height" + android:paddingStart="60dp" + android:paddingEnd="8dp" + app:layout_collapseMode="pin" /> - - - - - - - - - \ No newline at end of file + + \ No newline at end of file From 94ce6e86e824da6c14723378ad9a56c528203a19 Mon Sep 17 00:00:00 2001 From: h4h13 Date: Thu, 20 Feb 2020 20:39:47 +0530 Subject: [PATCH 5/5] Added song count and other quick actions --- .../retromusic/activities/MainActivity.java | 1 - .../adapter/song/AbsOffsetSongAdapter.kt | 3 +- .../adapter/song/ShuffleButtonSongAdapter.kt | 85 ++++++++++++++++--- .../fragments/mainactivity/SongsFragment.kt | 12 ++- .../retromusic/util/PreferenceUtil.java | 4 +- .../main/res/drawable/popup_background.xml | 18 ++++ .../res/layout/item_list_quick_actions.xml | 46 ++++++---- app/src/main/res/menu/menu_grid_options.xml | 28 ++++++ app/src/main/res/menu/menu_song_sort.xml | 37 ++++++++ app/src/main/res/values-night-v27/styles.xml | 2 + app/src/main/res/values-night/styles.xml | 1 + .../main/res/values-v27/styles_parents.xml | 6 ++ app/src/main/res/values/strings.xml | 6 +- app/src/main/res/values/styles.xml | 4 + app/src/main/res/values/styles_parents.xml | 8 ++ 15 files changed, 226 insertions(+), 35 deletions(-) create mode 100644 app/src/main/res/drawable/popup_background.xml create mode 100644 app/src/main/res/menu/menu_grid_options.xml create mode 100644 app/src/main/res/menu/menu_song_sort.xml diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java index f39c1660..53bae439 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java +++ b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.java @@ -547,7 +547,6 @@ public class MainActivity extends AbsSlidingMusicPanelActivity case R.id.action_song_sort_order_composer: sortOrder = SongSortOrder.COMPOSER; break; - } } diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/song/AbsOffsetSongAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/song/AbsOffsetSongAdapter.kt index 89d3e511..5d216fff 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/song/AbsOffsetSongAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/song/AbsOffsetSongAdapter.kt @@ -19,8 +19,7 @@ abstract class AbsOffsetSongAdapter( override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SongAdapter.ViewHolder { if (viewType == OFFSET_ITEM) { - val view = LayoutInflater.from(activity) - .inflate(R.layout.item_list_quick_actions, parent, false) + val view = LayoutInflater.from(activity).inflate(R.layout.item_list_quick_actions, parent, false) return createViewHolder(view) } return super.onCreateViewHolder(parent, viewType) diff --git a/app/src/main/java/code/name/monkey/retromusic/adapter/song/ShuffleButtonSongAdapter.kt b/app/src/main/java/code/name/monkey/retromusic/adapter/song/ShuffleButtonSongAdapter.kt index 4f3935ad..801fd1ab 100644 --- a/app/src/main/java/code/name/monkey/retromusic/adapter/song/ShuffleButtonSongAdapter.kt +++ b/app/src/main/java/code/name/monkey/retromusic/adapter/song/ShuffleButtonSongAdapter.kt @@ -1,12 +1,16 @@ package code.name.monkey.retromusic.adapter.song import android.view.View +import android.widget.PopupMenu import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.widget.AppCompatImageView import code.name.monkey.retromusic.R import code.name.monkey.retromusic.helper.MusicPlayerRemote +import code.name.monkey.retromusic.helper.SortOrder.SongSortOrder import code.name.monkey.retromusic.interfaces.CabHolder import code.name.monkey.retromusic.model.Song -import com.google.android.material.button.MaterialButton +import code.name.monkey.retromusic.util.PreferenceUtil +import com.google.android.material.textview.MaterialTextView class ShuffleButtonSongAdapter( activity: AppCompatActivity, @@ -22,24 +26,83 @@ class ShuffleButtonSongAdapter( override fun onBindViewHolder(holder: SongAdapter.ViewHolder, position: Int) { if (holder.itemViewType == OFFSET_ITEM) { val viewHolder = holder as ViewHolder - viewHolder.playAction?.let { - it.setOnClickListener { - MusicPlayerRemote.openQueue(dataSet, 0, true) - } + viewHolder.playAction?.setOnClickListener { + MusicPlayerRemote.openQueue(dataSet, 0, true) } - viewHolder.shuffleAction?.let { - it.setOnClickListener { - MusicPlayerRemote.openAndShuffleQueue(dataSet, true) - } + viewHolder.shuffleAction?.setOnClickListener { + MusicPlayerRemote.openAndShuffleQueue(dataSet, true) + } + val songCount = activity.resources.getQuantityString(R.plurals.songCount, dataSet.size, dataSet.size) + viewHolder.songCount?.text = songCount + viewHolder.sortAction?.setOnClickListener { + showSortPopupMenu(it) } } else { super.onBindViewHolder(holder, position - 1) } } + private fun showGridPopupMenu(view: View) { + val popupMenu = PopupMenu(activity, view) + popupMenu.menuInflater.inflate(R.menu.menu_grid_options, popupMenu.menu) + popupMenu.setOnMenuItemClickListener { + when (it.itemId) { + R.id.action_grid_size_1 -> { + PreferenceUtil.getInstance(activity).setSongGridSize(1) + } + R.id.action_grid_size_2 -> { + PreferenceUtil.getInstance(activity).setSongGridSize(2) + } + R.id.action_grid_size_3 -> { + PreferenceUtil.getInstance(activity).setSongGridSize(3) + } + R.id.action_grid_size_4 -> { + PreferenceUtil.getInstance(activity).setSongGridSize(4) + } + + } + return@setOnMenuItemClickListener true + } + popupMenu.show() + } + + private fun showSortPopupMenu(view: View) { + val popupMenu = PopupMenu(activity, view) + popupMenu.menuInflater.inflate(R.menu.menu_song_sort, popupMenu.menu) + popupMenu.setOnMenuItemClickListener { + when (it.itemId) { + R.id.action_song_sort_order_asc -> { + PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_A_Z + } + R.id.action_song_sort_order_desc -> { + PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_Z_A + } + R.id.action_song_sort_order_artist -> { + PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_ARTIST + } + R.id.action_song_sort_order_album -> { + PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_ALBUM + } + R.id.action_song_sort_order_date -> { + PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_DATE + } + R.id.action_song_sort_order_composer -> { + PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.COMPOSER + } + R.id.action_song_sort_order_year -> { + PreferenceUtil.getInstance(activity).songSortOrder = SongSortOrder.SONG_YEAR + } + } + return@setOnMenuItemClickListener true + } + popupMenu.show() + } + inner class ViewHolder(itemView: View) : AbsOffsetSongAdapter.ViewHolder(itemView) { - val playAction: MaterialButton? = itemView.findViewById(R.id.playAction) - val shuffleAction: MaterialButton? = itemView.findViewById(R.id.shuffleAction) + val playAction: AppCompatImageView? = itemView.findViewById(R.id.playAction) + val shuffleAction: AppCompatImageView? = itemView.findViewById(R.id.shuffleAction) + val sortAction: AppCompatImageView? = itemView.findViewById(R.id.sortAction) + val songCount: MaterialTextView? = itemView.findViewById(R.id.songCount) override fun onClick(v: View?) { if (itemViewType == OFFSET_ITEM) { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/SongsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/SongsFragment.kt index 66529505..b2ceea28 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/SongsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/mainactivity/SongsFragment.kt @@ -1,5 +1,7 @@ package code.name.monkey.retromusic.fragments.mainactivity +import android.content.SharedPreferences +import android.content.SharedPreferences.OnSharedPreferenceChangeListener import android.os.Bundle import android.view.View import androidx.annotation.LayoutRes @@ -18,7 +20,7 @@ import java.util.ArrayList import javax.inject.Inject class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment(), - SongView, MainActivityFragmentCallbacks { + SongView, MainActivityFragmentCallbacks, OnSharedPreferenceChangeListener { @Inject lateinit var songPresenter: SongPresenter @@ -82,11 +84,13 @@ class SongsFragment : AbsLibraryPagerRecyclerViewCustomGridSizeFragment + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/item_list_quick_actions.xml b/app/src/main/res/layout/item_list_quick_actions.xml index 5e53b9f7..4e67689a 100644 --- a/app/src/main/res/layout/item_list_quick_actions.xml +++ b/app/src/main/res/layout/item_list_quick_actions.xml @@ -14,32 +14,44 @@ + android:paddingStart="16dp" + android:paddingEnd="0dp"> - + android:textAppearance="@style/TextViewSubtitle1" + android:textStyle="bold" /> - + android:layout_weight="0" + android:background="?attr/roundSelector" + android:padding="16dp" + app:srcCompat="@drawable/ic_shuffle_white_24dp" + app:tint="?attr/colorControlNormal" + tools:tint="@color/black_color" /> + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_grid_options.xml b/app/src/main/res/menu/menu_grid_options.xml new file mode 100644 index 00000000..156927e6 --- /dev/null +++ b/app/src/main/res/menu/menu_grid_options.xml @@ -0,0 +1,28 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_song_sort.xml b/app/src/main/res/menu/menu_song_sort.xml new file mode 100644 index 00000000..b6126f42 --- /dev/null +++ b/app/src/main/res/menu/menu_song_sort.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-night-v27/styles.xml b/app/src/main/res/values-night-v27/styles.xml index 16bbd391..accac239 100644 --- a/app/src/main/res/values-night-v27/styles.xml +++ b/app/src/main/res/values-night-v27/styles.xml @@ -34,5 +34,7 @@ false @color/darkColorSurface + @style/RetroPopupTheme + @style/RetroPopupTheme \ No newline at end of file diff --git a/app/src/main/res/values-night/styles.xml b/app/src/main/res/values-night/styles.xml index e53f21ee..0f585cd0 100644 --- a/app/src/main/res/values-night/styles.xml +++ b/app/src/main/res/values-night/styles.xml @@ -34,5 +34,6 @@ @color/darkColorPrimary @color/darkColorSurface + @style/RetroPopupTheme \ No newline at end of file diff --git a/app/src/main/res/values-v27/styles_parents.xml b/app/src/main/res/values-v27/styles_parents.xml index 0d326447..95975838 100644 --- a/app/src/main/res/values-v27/styles_parents.xml +++ b/app/src/main/res/values-v27/styles_parents.xml @@ -31,6 +31,8 @@ @drawable/rect_selector @style/Widget.ActionButton.Overflow true + @style/RetroPopupTheme + @style/RetroPopupTheme \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c257950f..b26236b0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -307,7 +307,7 @@ 7 8 - + Grid style Hinge @@ -827,4 +827,8 @@ Retro Music Player Pro Free + + %d Song + %d Songs + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index ed8fb9cd..0976e75a 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -184,4 +184,8 @@ @android:color/transparent + diff --git a/app/src/main/res/values/styles_parents.xml b/app/src/main/res/values/styles_parents.xml index 6ac2764d..0b9290a7 100644 --- a/app/src/main/res/values/styles_parents.xml +++ b/app/src/main/res/values/styles_parents.xml @@ -17,6 +17,8 @@ @drawable/round_selector @drawable/rect_selector @style/Widget.ActionButton.Overflow + @style/RetroPopupTheme + @style/RetroPopupTheme