From 813fb8607303db8560897d426ed273b8af59e774 Mon Sep 17 00:00:00 2001 From: h4h13 Date: Mon, 6 Jan 2020 08:42:32 +0530 Subject: [PATCH] Added song track info --- .../activities/AlbumDetailsActivity.kt | 7 + .../retromusic/activities/MainActivity.kt | 3 + .../fragments/base/AbsMusicServiceFragment.kt | 39 +- .../base/AbsPlayerControlsFragment.kt | 27 +- .../mainactivity/LibraryFragment.java | 408 +++++----- .../player/adaptive/AdaptiveFragment.kt | 20 +- .../AdaptivePlaybackControlsFragment.kt | 50 +- .../blur/BlurPlaybackControlsFragment.kt | 75 +- .../player/blur/BlurPlayerFragment.kt | 47 +- .../fragments/player/card/CardFragment.kt | 17 +- .../card/CardPlaybackControlsFragment.kt | 40 +- .../player/cardblur/CardBlurFragment.kt | 45 +- .../CardBlurPlaybackControlsFragment.kt | 55 +- .../color/ColorPlaybackControlsFragment.kt | 14 +- .../fragments/player/fit/FitFragment.kt | 27 +- .../player/fit/FitPlaybackControlsFragment.kt | 93 ++- .../flat/FlatPlaybackControlsFragment.kt | 47 +- .../player/flat/FlatPlayerFragment.kt | 30 +- .../full/FullPlaybackControlsFragment.kt | 54 +- .../player/full/FullPlayerFragment.kt | 37 +- .../material/MaterialControlsFragment.kt | 47 +- .../player/material/MaterialFragment.kt | 28 +- .../normal/PlayerPlaybackControlsFragment.kt | 26 +- .../player/peak/PeakPlayerControlFragment.kt | 34 +- .../player/peak/PeakPlayerFragment.kt | 42 +- .../plain/PlainPlaybackControlsFragment.kt | 16 + .../player/plain/PlainPlayerFragment.kt | 29 +- .../simple/SimplePlaybackControlsFragment.kt | 48 +- .../player/simple/SimplePlayerFragment.kt | 27 +- .../tiny/TinyPlaybackControlsFragment.kt | 25 +- .../player/tiny/TinyPlayerFragment.kt | 32 +- .../retromusic/util/PreferenceUtil.java | 9 +- .../monkey/retromusic/util/RetroUtil.java | 123 +-- .../fragment_player_playback_controls.xml | 21 +- .../res/layout/fragment_adaptive_player.xml | 1 - ...ment_adaptive_player_playback_controls.xml | 15 + ...fragment_blur_player_playback_controls.xml | 385 ++++----- ...ent_card_blur_player_playback_controls.xml | 14 + ...fragment_card_player_playback_controls.xml | 223 ++--- ...ragment_color_player_playback_controls.xml | 169 ++-- .../layout/fragment_fit_playback_controls.xml | 292 ++++--- ...fragment_flat_player_playback_controls.xml | 28 +- .../layout/fragment_full_player_controls.xml | 21 +- app/src/main/res/layout/fragment_library.xml | 2 +- .../fragment_material_playback_controls.xml | 19 +- .../main/res/layout/fragment_peak_player.xml | 25 +- .../fragment_plain_controls_fragment.xml | 19 +- .../fragment_player_playback_controls.xml | 20 +- .../fragment_simple_controls_fragment.xml | 21 +- .../main/res/layout/fragment_tiny_player.xml | 29 +- app/src/main/res/layout/item_album_card.xml | 1 + app/src/main/res/layout/media_button.xml | 86 +- app/src/main/res/values/strings.xml | 12 +- app/src/main/res/xml/pref_ui.xml | 6 +- .../util/ToolbarContentTintHelper.java | 765 +++++++++--------- 55 files changed, 2267 insertions(+), 1528 deletions(-) diff --git a/app/src/main/java/code/name/monkey/retromusic/activities/AlbumDetailsActivity.kt b/app/src/main/java/code/name/monkey/retromusic/activities/AlbumDetailsActivity.kt index faed5b25..7481452e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/AlbumDetailsActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/AlbumDetailsActivity.kt @@ -16,6 +16,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import code.name.monkey.appthemehelper.ThemeStore import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.MaterialUtil +import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper import code.name.monkey.retromusic.App import code.name.monkey.retromusic.R import code.name.monkey.retromusic.activities.base.AbsSlidingMusicPanelActivity @@ -268,6 +269,12 @@ class AlbumDetailsActivity : AbsSlidingMusicPanelActivity(), AlbumDetailsView, C menuInflater.inflate(R.menu.menu_album_detail, menu) val sortOrder = menu.findItem(R.id.action_sort_order) setUpSortOrderMenu(sortOrder.subMenu) + ToolbarContentTintHelper.handleOnCreateOptionsMenu( + this, + toolbar, + menu, + getToolbarBackgroundColor(toolbar) + ) return super.onCreateOptionsMenu(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 index 79562a3f..01ad928e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt +++ b/app/src/main/java/code/name/monkey/retromusic/activities/MainActivity.kt @@ -8,9 +8,11 @@ import android.content.SharedPreferences import android.os.Bundle import android.provider.MediaStore import android.util.Log +import android.view.Menu import android.view.View import androidx.core.app.ActivityCompat import androidx.fragment.app.Fragment +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.fragments.mainactivity.LibraryFragment @@ -249,6 +251,7 @@ class MainActivity : AbsSlidingMusicPanelActivity(), SharedPreferences.OnSharedP } } + companion object { const val APP_INTRO_REQUEST = 2323 const val HOME = 0 diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMusicServiceFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMusicServiceFragment.kt index ddc847af..710e5fa8 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMusicServiceFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsMusicServiceFragment.kt @@ -1,11 +1,19 @@ package code.name.monkey.retromusic.fragments.base import android.content.Context +import android.net.Uri import android.os.Bundle import android.view.View +import android.webkit.MimeTypeMap import androidx.fragment.app.Fragment import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity import code.name.monkey.retromusic.interfaces.MusicServiceEventListener +import code.name.monkey.retromusic.model.Song +import code.name.monkey.retromusic.util.RetroUtil +import org.jaudiotagger.audio.AudioFileIO +import java.io.File +import java.net.URLEncoder +import java.util.Locale /** * Created by hemanths on 18/08/17. @@ -33,7 +41,6 @@ open class AbsMusicServiceFragment : Fragment(), MusicServiceEventListener { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) playerActivity?.addMusicServiceEventListener(this) - } override fun onDestroyView() { @@ -42,34 +49,50 @@ open class AbsMusicServiceFragment : Fragment(), MusicServiceEventListener { } override fun onPlayingMetaChanged() { - } override fun onServiceConnected() { - } override fun onServiceDisconnected() { - } override fun onQueueChanged() { - } override fun onPlayStateChanged() { - } override fun onRepeatModeChanged() { - } override fun onShuffleModeChanged() { - } override fun onMediaStoreChanged() { + } + fun getSongInfo(song: Song): String { + val file = File(song.data) + if (file.exists()) { + val audioHeader = AudioFileIO.read(File(song.data)).audioHeader + val string: StringBuilder = StringBuilder() + val uriFile = Uri.fromFile(file) + string.append(getMimeType(uriFile.toString())).append(" • ") + string.append(audioHeader.bitRate).append(" kb/s").append(" • ") + string.append(RetroUtil.frequencyCount(audioHeader.sampleRate.toInt())).append(" kHz") + return string.toString() + } + return "-" + } + + private fun getMimeType(url: String): String? { + var type: String? = MimeTypeMap.getFileExtensionFromUrl( + URLEncoder.encode(url, "utf-8") + ).toUpperCase(Locale.getDefault()) + if (type == null) { + type = url.substring(url.lastIndexOf(".") + 1) + } + return type } } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerControlsFragment.kt index e112ed75..85017dbd 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/base/AbsPlayerControlsFragment.kt @@ -9,7 +9,6 @@ import code.name.monkey.retromusic.fragments.VolumeFragment import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper import code.name.monkey.retromusic.util.PreferenceUtil - /** * Created by hemanths on 24/09/17. */ @@ -38,18 +37,18 @@ abstract class AbsPlayerControlsFragment : AbsMusicServiceFragment(), MusicProgr pivotY = (view.height / 2).toFloat() animate().setDuration(200) - .setInterpolator(DecelerateInterpolator()) - .scaleX(1.1f) - .scaleY(1.1f) - .withEndAction { - animate().setDuration(200) - .setInterpolator(AccelerateInterpolator()) - .scaleX(1f) - .scaleY(1f) - .alpha(1f) - .start() - } - .start() + .setInterpolator(DecelerateInterpolator()) + .scaleX(1.1f) + .scaleY(1.1f) + .withEndAction { + animate().setDuration(200) + .setInterpolator(AccelerateInterpolator()) + .scaleX(1f) + .scaleY(1f) + .alpha(1f) + .start() + } + .start() } } @@ -71,6 +70,4 @@ abstract class AbsPlayerControlsFragment : AbsMusicServiceFragment(), MusicProgr companion object { const val SLIDER_ANIMATION_TIME: Long = 400 } - - } 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 index e62659bb..807b708f 100644 --- 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 @@ -11,7 +11,6 @@ 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; @@ -19,13 +18,6 @@ import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; - -import com.afollestad.materialcab.MaterialCab; -import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.card.MaterialCardView; - -import org.jetbrains.annotations.NotNull; - import code.name.monkey.appthemehelper.common.ATHToolbarActivity; import code.name.monkey.appthemehelper.util.ATHUtil; import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper; @@ -40,21 +32,29 @@ 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 io.reactivex.disposables.CompositeDisposable; +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 Toolbar toolbar; private AppBarLayout appBarLayout; - private MaterialCardView toolbarContainer; private MaterialCab cab; - private FragmentManager fragmentManager; + private CompositeDisposable disposable; + private FragmentManager fragmentManager; + + private Toolbar toolbar; + + private MaterialCardView toolbarContainer; @NonNull public static Fragment newInstance(int tab) { @@ -70,17 +70,11 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde return new LibraryFragment(); } - @Override - public void onDestroyView() { - super.onDestroyView(); - disposable.dispose(); - } - @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, - @Nullable ViewGroup container, - @Nullable Bundle savedInstanceState) { + @Nullable ViewGroup container, + @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_library, container, false); disposable = new CompositeDisposable(); appBarLayout = view.findViewById(R.id.appBarLayout); @@ -89,23 +83,6 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde return view; } - public void setTitle(@StringRes int name) { - toolbar.setTitle(getString(name)); - } - - public void addOnAppBarOffsetChangedListener(@NonNull AppBarLayout.OnOffsetChangedListener onOffsetChangedListener) { - appBarLayout.addOnOffsetChangedListener(onOffsetChangedListener); - } - - public void removeOnAppBarOffsetChangedListener(@NonNull AppBarLayout.OnOffsetChangedListener onOffsetChangedListener) { - appBarLayout.removeOnOffsetChangedListener(onOffsetChangedListener); - } - - public int getTotalAppBarScrollingRange() { - return appBarLayout.getTotalScrollRange(); - } - - @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); @@ -114,53 +91,19 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde inflateFragment(); } - 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; - } + @Override + public void onDestroyView() { + super.onDestroyView(); + disposable.dispose(); } - @SuppressWarnings("ConstantConditions") - private void setupToolbar() { - toolbar.setBackgroundTintList(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); - //toolbar.setTitleTextColor(ATHUtil.INSTANCE.resolveColor(requireContext(), R.attr.colorOnSecondary)); + public void addOnAppBarOffsetChangedListener( + @NonNull AppBarLayout.OnOffsetChangedListener onOffsetChangedListener) { + appBarLayout.addOnOffsetChangedListener(onOffsetChangedListener); } - private Fragment getCurrentFragment() { - if (fragmentManager == null) { - return SongsFragment.Companion.newInstance(); - } - return fragmentManager.findFragmentByTag(LibraryFragment.TAG); + public int getTotalAppBarScrollingRange() { + return appBarLayout.getTotalScrollRange(); } @Override @@ -172,31 +115,6 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde return false; } - private void selectedFragment(Fragment fragment) { - fragmentManager = getChildFragmentManager(); - FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); - fragmentTransaction - .replace(R.id.fragmentContainer, fragment, LibraryFragment.TAG) - .commit(); - } - - @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; - } - - @Override public void onCreateOptionsMenu(@NotNull Menu menu, @NonNull MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); @@ -205,7 +123,8 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde Fragment currentFragment = getCurrentFragment(); if (currentFragment instanceof AbsLibraryPagerRecyclerViewCustomGridSizeFragment && currentFragment.isAdded()) { - AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment = (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) currentFragment; + AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment + = (AbsLibraryPagerRecyclerViewCustomGridSizeFragment) currentFragment; MenuItem gridSizeItem = menu.findItem(R.id.action_grid_size); if (RetroUtil.isLandscape()) { @@ -220,10 +139,41 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde 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.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); } - ToolbarContentTintHelper.handleOnCreateOptionsMenu(requireActivity(), toolbar, menu, ATHToolbarActivity.getToolbarBackgroundColor(toolbar)); + 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 (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 @@ -236,45 +186,76 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde ToolbarContentTintHelper.handleOnPrepareOptionsMenu(activity, toolbar); } - - 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(SortOrder.AlbumSortOrder.ALBUM_A_Z)); - sortOrderMenu.add(0, R.id.action_album_sort_order_desc, 1, R.string.sort_order_z_a) - .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_Z_A)); - sortOrderMenu.add(0, R.id.action_album_sort_order_artist, 2, R.string.sort_order_artist) - .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_ARTIST)); - sortOrderMenu.add(0, R.id.action_album_sort_order_year, 3, R.string.sort_order_year) - .setChecked(currentSortOrder.equals(SortOrder.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(SortOrder.ArtistSortOrder.ARTIST_A_Z)); - sortOrderMenu.add(0, R.id.action_artist_sort_order_desc, 1, R.string.sort_order_z_a) - .setChecked(currentSortOrder.equals(SortOrder.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(SortOrder.SongSortOrder.SONG_A_Z)); - sortOrderMenu.add(0, R.id.action_song_sort_order_desc, 1, R.string.sort_order_z_a) - .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_Z_A)); - sortOrderMenu.add(0, R.id.action_song_sort_order_artist, 2, R.string.sort_order_artist) - .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_ARTIST)); - sortOrderMenu.add(0, R.id.action_song_sort_order_album, 3, R.string.sort_order_album) - .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_ALBUM)); - sortOrderMenu.add(0, R.id.action_song_sort_order_year, 4, R.string.sort_order_year) - .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_YEAR)); - sortOrderMenu.add(0, R.id.action_song_sort_order_date, 5, R.string.sort_order_date) - .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_DATE)); - sortOrderMenu.add(0, R.id.action_song_sort_order_composer, 6, R.string.sort_order_composer) - .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.COMPOSER)); + @NonNull + @Override + public MaterialCab openCab(int menuRes, @NonNull MaterialCab.Callback callback) { + if (cab != null && cab.isActive()) { + cab.finish(); } - sortOrderMenu.setGroupCheckable(0, true, true); + 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 handleSortOrderMenuItem( @@ -341,33 +322,41 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde return false; } - - @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 (handleSortOrderMenuItem(fragment, item)) { - return true; - } + private void inflateFragment() { + if (getArguments() == null) { + selectedFragment(SongsFragment.Companion.newInstance()); + return; } - 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); + 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; - case R.id.action_new_playlist: - CreatePlaylistDialog.Companion.create().show(getChildFragmentManager(), "CREATE_PLAYLIST"); - return true; } - return super.onOptionsItemSelected(item); } + 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, @@ -419,43 +408,60 @@ public class LibraryFragment extends AbsMainActivityFragment implements CabHolde } } + private void setUpSortOrderMenu( + @NonNull AbsLibraryPagerRecyclerViewCustomGridSizeFragment fragment, + @NonNull SubMenu sortOrderMenu) { + String currentSortOrder = fragment.getSortOrder(); + sortOrderMenu.clear(); - 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 (fragment instanceof AlbumsFragment) { + sortOrderMenu.add(0, R.id.action_album_sort_order_asc, 0, R.string.sort_order_a_z) + .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_A_Z)); + sortOrderMenu.add(0, R.id.action_album_sort_order_desc, 1, R.string.sort_order_z_a) + .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_Z_A)); + sortOrderMenu.add(0, R.id.action_album_sort_order_artist, 2, R.string.sort_order_artist) + .setChecked(currentSortOrder.equals(SortOrder.AlbumSortOrder.ALBUM_ARTIST)); + sortOrderMenu.add(0, R.id.action_album_sort_order_year, 3, R.string.sort_order_year) + .setChecked(currentSortOrder.equals(SortOrder.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(SortOrder.ArtistSortOrder.ARTIST_A_Z)); + sortOrderMenu.add(0, R.id.action_artist_sort_order_desc, 1, R.string.sort_order_z_a) + .setChecked(currentSortOrder.equals(SortOrder.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(SortOrder.SongSortOrder.SONG_A_Z)); + sortOrderMenu.add(0, R.id.action_song_sort_order_desc, 1, R.string.sort_order_z_a) + .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_Z_A)); + sortOrderMenu.add(0, R.id.action_song_sort_order_artist, 2, R.string.sort_order_artist) + .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_ARTIST)); + sortOrderMenu.add(0, R.id.action_song_sort_order_album, 3, R.string.sort_order_album) + .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_ALBUM)); + sortOrderMenu.add(0, R.id.action_song_sort_order_year, 4, R.string.sort_order_year) + .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_YEAR)); + sortOrderMenu.add(0, R.id.action_song_sort_order_date, 5, R.string.sort_order_date) + .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.SONG_DATE)); + sortOrderMenu.add(0, R.id.action_song_sort_order_composer, 6, R.string.sort_order_composer) + .setChecked(currentSortOrder.equals(SortOrder.SongSortOrder.COMPOSER)); } - if (gridSize > 0) { - item.setChecked(true); - fragment.setAndSaveGridSize(gridSize); - return true; - } - return false; + sortOrderMenu.setGroupCheckable(0, true, true); + } + + @SuppressWarnings("ConstantConditions") + private void setupToolbar() { + toolbar.setBackgroundTintList( + 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); + //toolbar.setTitleTextColor(ATHUtil.INSTANCE.resolveColor(requireContext(), R.attr.colorOnSecondary)); } } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/adaptive/AdaptiveFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/adaptive/AdaptiveFragment.kt index e8268f23..37a0046a 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/adaptive/AdaptiveFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/adaptive/AdaptiveFragment.kt @@ -18,7 +18,7 @@ import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.model.lyrics.AbsSynchronizedLyrics import code.name.monkey.retromusic.model.lyrics.Lyrics -import kotlinx.android.synthetic.main.fragment_adaptive_player.* +import kotlinx.android.synthetic.main.fragment_adaptive_player.playerToolbar class AdaptiveFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Callback { @@ -53,7 +53,10 @@ class AdaptiveFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Call lyricsLine1.visibility = View.VISIBLE lyricsLine2.visibility = View.VISIBLE - lyricsLine2.measure(View.MeasureSpec.makeMeasureSpec(lyricsLine2.measuredWidth, View.MeasureSpec.EXACTLY), View.MeasureSpec.UNSPECIFIED) + lyricsLine2.measure( + View.MeasureSpec.makeMeasureSpec(lyricsLine2.measuredWidth, View.MeasureSpec.EXACTLY), + View.MeasureSpec.UNSPECIFIED + ) val h: Float = lyricsLine2.measuredHeight.toFloat() lyricsLine1.alpha = 1f @@ -130,8 +133,10 @@ class AdaptiveFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Call } private fun setUpSubFragments() { - playbackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as AdaptivePlaybackControlsFragment - val playerAlbumCoverFragment = childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment + playbackControlsFragment = + childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as AdaptivePlaybackControlsFragment + val playerAlbumCoverFragment = + childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment playerAlbumCoverFragment.apply { removeSlideEffect() setCallbacks(this@AdaptiveFragment) @@ -184,7 +189,11 @@ class AdaptiveFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Call playbackControlsFragment.setDark(color) lastColor = color callbacks?.onPaletteColorChanged() - ToolbarContentTintHelper.colorizeToolbar(playerToolbar, ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), requireActivity()) + ToolbarContentTintHelper.colorizeToolbar( + playerToolbar, + ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), + requireActivity() + ) } override fun onShow() { @@ -206,5 +215,4 @@ class AdaptiveFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Call override val paletteColor: Int get() = lastColor - } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/adaptive/AdaptivePlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/adaptive/AdaptivePlaybackControlsFragment.kt index d68cb7e5..c858e535 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/adaptive/AdaptivePlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/adaptive/AdaptivePlaybackControlsFragment.kt @@ -14,17 +14,26 @@ import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialValueHelper import code.name.monkey.appthemehelper.util.TintHelper import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.extensions.hide import code.name.monkey.retromusic.extensions.ripAlpha +import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper import code.name.monkey.retromusic.helper.PlayPauseButtonOnClickHandler import code.name.monkey.retromusic.misc.SimpleOnSeekbarChangeListener import code.name.monkey.retromusic.service.MusicService -import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.ViewUtil -import kotlinx.android.synthetic.main.fragment_adaptive_player_playback_controls.* +import kotlinx.android.synthetic.main.fragment_adaptive_player_playback_controls.nextButton +import kotlinx.android.synthetic.main.fragment_adaptive_player_playback_controls.playPauseButton +import kotlinx.android.synthetic.main.fragment_adaptive_player_playback_controls.previousButton +import kotlinx.android.synthetic.main.fragment_adaptive_player_playback_controls.progressSlider +import kotlinx.android.synthetic.main.fragment_adaptive_player_playback_controls.repeatButton +import kotlinx.android.synthetic.main.fragment_adaptive_player_playback_controls.shuffleButton +import kotlinx.android.synthetic.main.fragment_adaptive_player_playback_controls.songCurrentProgress +import kotlinx.android.synthetic.main.fragment_adaptive_player_playback_controls.songInfo +import kotlinx.android.synthetic.main.fragment_adaptive_player_playback_controls.songTotalTime class AdaptivePlaybackControlsFragment : AbsPlayerControlsFragment() { @@ -37,8 +46,10 @@ class AdaptivePlaybackControlsFragment : AbsPlayerControlsFragment() { progressViewUpdateHelper = MusicProgressViewUpdateHelper(this) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { return inflater.inflate(R.layout.fragment_adaptive_player_playback_controls, container, false) } @@ -56,6 +67,14 @@ class AdaptivePlaybackControlsFragment : AbsPlayerControlsFragment() { } } + private fun updateSong() { + if (PreferenceUtil.getInstance(requireContext()).isSongInfo) { + songInfo?.text = getSongInfo(MusicPlayerRemote.currentSong) + } else { + songInfo?.hide() + } + } + override fun onResume() { super.onResume() progressViewUpdateHelper!!.start() @@ -66,10 +85,16 @@ class AdaptivePlaybackControlsFragment : AbsPlayerControlsFragment() { progressViewUpdateHelper!!.stop() } + override fun onPlayingMetaChanged() { + super.onPlayingMetaChanged() + updateSong() + } + override fun onServiceConnected() { updatePlayPauseDrawableState() updateRepeatState() updateShuffleState() + updateSong() } override fun onPlayStateChanged() { @@ -104,7 +129,11 @@ class AdaptivePlaybackControlsFragment : AbsPlayerControlsFragment() { ThemeStore.accentColor(context!!) }.ripAlpha() - TintHelper.setTintAuto(playPauseButton, MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(colorFinal)), false) + TintHelper.setTintAuto( + playPauseButton, + MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(colorFinal)), + false + ) TintHelper.setTintAuto(playPauseButton, colorFinal, true) ViewUtil.setProgressDrawable(progressSlider, colorFinal, true) volumeFragment?.setTintable(colorFinal) @@ -151,7 +180,10 @@ class AdaptivePlaybackControlsFragment : AbsPlayerControlsFragment() { override fun updateShuffleState() { when (MusicPlayerRemote.shuffleMode) { - MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter( + lastPlaybackControlsColor, + PorterDuff.Mode.SRC_IN + ) else -> shuffleButton.setColorFilter(lastDisabledPlaybackControlsColor, PorterDuff.Mode.SRC_IN) } } @@ -202,8 +234,10 @@ class AdaptivePlaybackControlsFragment : AbsPlayerControlsFragment() { override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { if (fromUser) { MusicPlayerRemote.seekTo(progress) - onUpdateProgressViews(MusicPlayerRemote.songProgressMillis, - MusicPlayerRemote.songDurationMillis) + onUpdateProgressViews( + MusicPlayerRemote.songProgressMillis, + MusicPlayerRemote.songDurationMillis + ) } } }) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/blur/BlurPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/blur/BlurPlaybackControlsFragment.kt index f4d00709..b9052729 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/blur/BlurPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/blur/BlurPlaybackControlsFragment.kt @@ -16,6 +16,7 @@ import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialValueHelper import code.name.monkey.appthemehelper.util.TintHelper import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.extensions.hide import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper @@ -23,7 +24,18 @@ import code.name.monkey.retromusic.helper.PlayPauseButtonOnClickHandler import code.name.monkey.retromusic.misc.SimpleOnSeekbarChangeListener import code.name.monkey.retromusic.service.MusicService import code.name.monkey.retromusic.util.MusicUtil -import kotlinx.android.synthetic.main.fragment_blur_player_playback_controls.* +import code.name.monkey.retromusic.util.PreferenceUtil +import kotlinx.android.synthetic.main.fragment_blur_player_playback_controls.nextButton +import kotlinx.android.synthetic.main.fragment_blur_player_playback_controls.playPauseButton +import kotlinx.android.synthetic.main.fragment_blur_player_playback_controls.previousButton +import kotlinx.android.synthetic.main.fragment_blur_player_playback_controls.progressSlider +import kotlinx.android.synthetic.main.fragment_blur_player_playback_controls.repeatButton +import kotlinx.android.synthetic.main.fragment_blur_player_playback_controls.shuffleButton +import kotlinx.android.synthetic.main.fragment_blur_player_playback_controls.songCurrentProgress +import kotlinx.android.synthetic.main.fragment_blur_player_playback_controls.songInfo +import kotlinx.android.synthetic.main.fragment_blur_player_playback_controls.songTotalTime +import kotlinx.android.synthetic.main.fragment_blur_player_playback_controls.text +import kotlinx.android.synthetic.main.fragment_blur_player_playback_controls.title class BlurPlaybackControlsFragment : AbsPlayerControlsFragment() { @@ -36,9 +48,10 @@ class BlurPlaybackControlsFragment : AbsPlayerControlsFragment() { progressViewUpdateHelper = MusicProgressViewUpdateHelper(this) } - override fun onCreateView(inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? ): View? { return inflater.inflate(R.layout.fragment_blur_player_playback_controls, container, false) } @@ -63,6 +76,12 @@ class BlurPlaybackControlsFragment : AbsPlayerControlsFragment() { val song = MusicPlayerRemote.currentSong title.text = song.title text.text = "${song.artistName} • ${song.albumName}" + + if (PreferenceUtil.getInstance(requireContext()).isSongInfo) { + songInfo?.text = getSongInfo(song) + } else { + songInfo?.hide() + } } override fun onResume() { @@ -120,7 +139,11 @@ class BlurPlaybackControlsFragment : AbsPlayerControlsFragment() { } private fun setFabColor(i: Int) { - TintHelper.setTintAuto(playPauseButton, MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(i)), false) + TintHelper.setTintAuto( + playPauseButton, + MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(i)), + false + ) TintHelper.setTintAuto(playPauseButton, i, true) } @@ -161,7 +184,10 @@ class BlurPlaybackControlsFragment : AbsPlayerControlsFragment() { override fun updateShuffleState() { when (MusicPlayerRemote.shuffleMode) { - MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter( + lastPlaybackControlsColor, + PorterDuff.Mode.SRC_IN + ) else -> shuffleButton.setColorFilter(lastDisabledPlaybackControlsColor, PorterDuff.Mode.SRC_IN) } } @@ -189,11 +215,11 @@ class BlurPlaybackControlsFragment : AbsPlayerControlsFragment() { public override fun show() { playPauseButton!!.animate() - .scaleX(1f) - .scaleY(1f) - .rotation(360f) - .setInterpolator(DecelerateInterpolator()) - .start() + .scaleX(1f) + .scaleY(1f) + .rotation(360f) + .setInterpolator(DecelerateInterpolator()) + .start() } public override fun hide() { @@ -211,8 +237,10 @@ class BlurPlaybackControlsFragment : AbsPlayerControlsFragment() { override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { if (fromUser) { MusicPlayerRemote.seekTo(progress) - onUpdateProgressViews(MusicPlayerRemote.songProgressMillis, - MusicPlayerRemote.songDurationMillis) + onUpdateProgressViews( + MusicPlayerRemote.songProgressMillis, + MusicPlayerRemote.songDurationMillis + ) } } }) @@ -228,20 +256,19 @@ class BlurPlaybackControlsFragment : AbsPlayerControlsFragment() { pivotY = (height / 2).toFloat() animate().setDuration(200) - .setInterpolator(DecelerateInterpolator()) - .scaleX(1.1f) - .scaleY(1.1f) - .withEndAction { - animate().setDuration(200) - .setInterpolator(AccelerateInterpolator()) - .scaleX(1f) - .scaleY(1f) - .alpha(1f).start() - }.start() + .setInterpolator(DecelerateInterpolator()) + .scaleX(1.1f) + .scaleY(1.1f) + .withEndAction { + animate().setDuration(200) + .setInterpolator(AccelerateInterpolator()) + .scaleX(1f) + .scaleY(1f) + .alpha(1f).start() + }.start() } } - override fun onUpdateProgressViews(progress: Int, total: Int) { progressSlider.max = total diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/blur/BlurPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/blur/BlurPlayerFragment.kt index 856ef431..dd5c3cd3 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/blur/BlurPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/blur/BlurPlayerFragment.kt @@ -19,7 +19,8 @@ import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.util.PreferenceUtil import com.bumptech.glide.Glide -import kotlinx.android.synthetic.main.fragment_blur.* +import kotlinx.android.synthetic.main.fragment_blur.colorBackground +import kotlinx.android.synthetic.main.fragment_blur.playerToolbar class BlurPlayerFragment : AbsPlayerFragment(), SharedPreferences.OnSharedPreferenceChangeListener { @@ -31,9 +32,10 @@ class BlurPlayerFragment : AbsPlayerFragment(), SharedPreferences.OnSharedPrefer private var lastColor: Int = 0 - - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { return inflater.inflate(R.layout.fragment_blur, container, false) } @@ -44,8 +46,10 @@ class BlurPlayerFragment : AbsPlayerFragment(), SharedPreferences.OnSharedPrefer } private fun setUpSubFragments() { - playbackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as BlurPlaybackControlsFragment - val playerAlbumCoverFragment = childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment + playbackControlsFragment = + childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as BlurPlaybackControlsFragment + val playerAlbumCoverFragment = + childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment playerAlbumCoverFragment.setCallbacks(this) } @@ -76,11 +80,9 @@ class BlurPlayerFragment : AbsPlayerFragment(), SharedPreferences.OnSharedPrefer } override fun onShow() { - } override fun onHide() { - } override fun onBackPressed(): Boolean { @@ -94,24 +96,23 @@ class BlurPlayerFragment : AbsPlayerFragment(), SharedPreferences.OnSharedPrefer override val paletteColor: Int get() = lastColor - private fun updateBlur() { val blurAmount = PreferenceManager.getDefaultSharedPreferences(requireContext()) - .getInt(PreferenceUtil.NEW_BLUR_AMOUNT, 25) + .getInt(PreferenceUtil.NEW_BLUR_AMOUNT, 25) colorBackground!!.clearColorFilter() SongGlideRequest.Builder.from(Glide.with(requireActivity()), MusicPlayerRemote.currentSong) - .checkIgnoreMediaStore(requireContext()) - .generatePalette(requireContext()).build() - .transform(BlurTransformation.Builder(requireContext()).blurRadius(blurAmount.toFloat()).build()) - //.centerCrop() - //.override(320, 480) - .into(object : RetroMusicColoredTarget(colorBackground) { - override fun onColorReady(color: Int) { - if (color == defaultFooterColor) { - colorBackground!!.setColorFilter(color) - } + .checkIgnoreMediaStore(requireContext()) + .generatePalette(requireContext()).build() + .transform(BlurTransformation.Builder(requireContext()).blurRadius(blurAmount.toFloat()).build()) + //.centerCrop() + //.override(320, 480) + .into(object : RetroMusicColoredTarget(colorBackground) { + override fun onColorReady(color: Int) { + if (color == defaultFooterColor) { + colorBackground!!.setColorFilter(color) } - }) + } + }) } override fun onServiceConnected() { @@ -131,7 +132,8 @@ class BlurPlayerFragment : AbsPlayerFragment(), SharedPreferences.OnSharedPrefer override fun onDestroyView() { super.onDestroyView() - PreferenceManager.getDefaultSharedPreferences(requireContext()).unregisterOnSharedPreferenceChangeListener(this) + PreferenceManager.getDefaultSharedPreferences(requireContext()) + .unregisterOnSharedPreferenceChangeListener(this) } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { @@ -139,6 +141,5 @@ class BlurPlayerFragment : AbsPlayerFragment(), SharedPreferences.OnSharedPrefer updateBlur() } } - } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/card/CardFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/card/CardFragment.kt index e1767503..91f9cea7 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/card/CardFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/card/CardFragment.kt @@ -13,7 +13,7 @@ import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment import code.name.monkey.retromusic.fragments.player.normal.PlayerFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.model.Song -import kotlinx.android.synthetic.main.fragment_card_player.* +import kotlinx.android.synthetic.main.fragment_card_player.playerToolbar class CardFragment : AbsPlayerFragment() { override fun playerToolbar(): Toolbar { @@ -62,8 +62,10 @@ class CardFragment : AbsPlayerFragment() { toggleFavorite(MusicPlayerRemote.currentSong) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { return inflater.inflate(R.layout.fragment_card_player, container, false) } @@ -75,8 +77,10 @@ class CardFragment : AbsPlayerFragment() { } private fun setUpSubFragments() { - playbackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as CardPlaybackControlsFragment - val playerAlbumCoverFragment = childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment + playbackControlsFragment = + childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as CardPlaybackControlsFragment + val playerAlbumCoverFragment = + childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment playerAlbumCoverFragment.setCallbacks(this) playerAlbumCoverFragment.removeSlideEffect() } @@ -87,7 +91,6 @@ class CardFragment : AbsPlayerFragment() { playerToolbar.setOnMenuItemClickListener(this) ToolbarContentTintHelper.colorizeToolbar(playerToolbar, Color.WHITE, activity) - } override fun onServiceConnected() { @@ -107,6 +110,4 @@ class CardFragment : AbsPlayerFragment() { return fragment } } - - } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/card/CardPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/card/CardPlaybackControlsFragment.kt index 5d0fa98c..f3d8e093 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/card/CardPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/card/CardPlaybackControlsFragment.kt @@ -14,6 +14,7 @@ import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialValueHelper import code.name.monkey.appthemehelper.util.TintHelper import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.extensions.hide import code.name.monkey.retromusic.extensions.ripAlpha import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote @@ -23,8 +24,18 @@ import code.name.monkey.retromusic.misc.SimpleOnSeekbarChangeListener import code.name.monkey.retromusic.service.MusicService import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.PreferenceUtil -import kotlinx.android.synthetic.main.fragment_card_player_playback_controls.* -import kotlinx.android.synthetic.main.media_button.* +import kotlinx.android.synthetic.main.fragment_card_player_playback_controls.image +import kotlinx.android.synthetic.main.fragment_card_player_playback_controls.progressSlider +import kotlinx.android.synthetic.main.fragment_card_player_playback_controls.songCurrentProgress +import kotlinx.android.synthetic.main.fragment_card_player_playback_controls.songInfo +import kotlinx.android.synthetic.main.fragment_card_player_playback_controls.songTotalTime +import kotlinx.android.synthetic.main.fragment_card_player_playback_controls.text +import kotlinx.android.synthetic.main.fragment_card_player_playback_controls.title +import kotlinx.android.synthetic.main.media_button.nextButton +import kotlinx.android.synthetic.main.media_button.playPauseButton +import kotlinx.android.synthetic.main.media_button.previousButton +import kotlinx.android.synthetic.main.media_button.repeatButton +import kotlinx.android.synthetic.main.media_button.shuffleButton class CardPlaybackControlsFragment : AbsPlayerControlsFragment() { @@ -32,14 +43,15 @@ class CardPlaybackControlsFragment : AbsPlayerControlsFragment() { private var lastDisabledPlaybackControlsColor: Int = 0 private var progressViewUpdateHelper: MusicProgressViewUpdateHelper? = null - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) progressViewUpdateHelper = MusicProgressViewUpdateHelper(this) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { return inflater.inflate(R.layout.fragment_card_player_playback_controls, container, false) } @@ -64,6 +76,11 @@ class CardPlaybackControlsFragment : AbsPlayerControlsFragment() { title.text = song.title text.text = song.artistName + if (PreferenceUtil.getInstance(requireContext()).isSongInfo) { + songInfo?.text = getSongInfo(MusicPlayerRemote.currentSong) + } else { + songInfo?.hide() + } } override fun onResume() { @@ -116,18 +133,20 @@ class CardPlaybackControlsFragment : AbsPlayerControlsFragment() { updatePlayPauseColor() updateProgressTextColor() - val colorFinal = if (PreferenceUtil.getInstance(requireContext()).adaptiveColor) { color } else { ThemeStore.accentColor(context!!).ripAlpha() } image.setColorFilter(colorFinal, PorterDuff.Mode.SRC_IN) - TintHelper.setTintAuto(playPauseButton, MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(colorFinal)), false) + TintHelper.setTintAuto( + playPauseButton, + MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(colorFinal)), + false + ) TintHelper.setTintAuto(playPauseButton, colorFinal, true) volumeFragment?.setTintable(colorFinal) - } private fun updatePlayPauseColor() { @@ -171,7 +190,10 @@ class CardPlaybackControlsFragment : AbsPlayerControlsFragment() { override fun updateShuffleState() { when (MusicPlayerRemote.shuffleMode) { - MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter( + lastPlaybackControlsColor, + PorterDuff.Mode.SRC_IN + ) else -> shuffleButton.setColorFilter(lastDisabledPlaybackControlsColor, PorterDuff.Mode.SRC_IN) } } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/cardblur/CardBlurFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/cardblur/CardBlurFragment.kt index 645306a8..5ff6e16c 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/cardblur/CardBlurFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/cardblur/CardBlurFragment.kt @@ -20,7 +20,8 @@ import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.util.PreferenceUtil import com.bumptech.glide.Glide -import kotlinx.android.synthetic.main.fragment_card_blur_player.* +import kotlinx.android.synthetic.main.fragment_card_blur_player.colorBackground +import kotlinx.android.synthetic.main.fragment_card_blur_player.playerToolbar class CardBlurFragment : AbsPlayerFragment(), SharedPreferences.OnSharedPreferenceChangeListener { override fun playerToolbar(): Toolbar { @@ -32,7 +33,6 @@ class CardBlurFragment : AbsPlayerFragment(), SharedPreferences.OnSharedPreferen get() = lastColor private lateinit var playbackControlsFragment: CardBlurPlaybackControlsFragment - override fun onShow() { playbackControlsFragment.show() } @@ -71,9 +71,10 @@ class CardBlurFragment : AbsPlayerFragment(), SharedPreferences.OnSharedPreferen toggleFavorite(MusicPlayerRemote.currentSong) } - - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { return inflater.inflate(R.layout.fragment_card_blur_player, container, false) } @@ -85,13 +86,14 @@ class CardBlurFragment : AbsPlayerFragment(), SharedPreferences.OnSharedPreferen } private fun setUpSubFragments() { - playbackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as CardBlurPlaybackControlsFragment - val playerAlbumCoverFragment = childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment? + playbackControlsFragment = + childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as CardBlurPlaybackControlsFragment + val playerAlbumCoverFragment = + childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment? if (playerAlbumCoverFragment != null) { playerAlbumCoverFragment.setCallbacks(this) playerAlbumCoverFragment.removeEffect() } - } private fun setUpPlayerToolbar() { @@ -126,21 +128,21 @@ class CardBlurFragment : AbsPlayerFragment(), SharedPreferences.OnSharedPreferen private fun updateBlur() { val blurAmount = PreferenceManager.getDefaultSharedPreferences(requireContext()) - .getInt(PreferenceUtil.NEW_BLUR_AMOUNT, 25) + .getInt(PreferenceUtil.NEW_BLUR_AMOUNT, 25) colorBackground!!.clearColorFilter() SongGlideRequest.Builder.from(Glide.with(requireActivity()), MusicPlayerRemote.currentSong) - .checkIgnoreMediaStore(requireContext()) - .generatePalette(requireContext()).build() - .transform(BlurTransformation.Builder(requireContext()).blurRadius(blurAmount.toFloat()).build()) - //.centerCrop() - //.override(320, 480) - .into(object : RetroMusicColoredTarget(colorBackground) { - override fun onColorReady(color: Int) { - if (color == defaultFooterColor) { - colorBackground!!.setColorFilter(color) - } + .checkIgnoreMediaStore(requireContext()) + .generatePalette(requireContext()).build() + .transform(BlurTransformation.Builder(requireContext()).blurRadius(blurAmount.toFloat()).build()) + //.centerCrop() + //.override(320, 480) + .into(object : RetroMusicColoredTarget(colorBackground) { + override fun onColorReady(color: Int) { + if (color == defaultFooterColor) { + colorBackground!!.setColorFilter(color) } - }) + } + }) } override fun onResume() { @@ -150,7 +152,8 @@ class CardBlurFragment : AbsPlayerFragment(), SharedPreferences.OnSharedPreferen override fun onDestroyView() { super.onDestroyView() - PreferenceManager.getDefaultSharedPreferences(requireContext()).unregisterOnSharedPreferenceChangeListener(this) + PreferenceManager.getDefaultSharedPreferences(requireContext()) + .unregisterOnSharedPreferenceChangeListener(this) } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/cardblur/CardBlurPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/cardblur/CardBlurPlaybackControlsFragment.kt index 873eef27..4c0988fb 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/cardblur/CardBlurPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/cardblur/CardBlurPlaybackControlsFragment.kt @@ -14,6 +14,7 @@ import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialValueHelper import code.name.monkey.appthemehelper.util.TintHelper import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.extensions.hide import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper @@ -21,10 +22,17 @@ import code.name.monkey.retromusic.helper.PlayPauseButtonOnClickHandler import code.name.monkey.retromusic.misc.SimpleOnSeekbarChangeListener import code.name.monkey.retromusic.service.MusicService import code.name.monkey.retromusic.util.MusicUtil +import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.ViewUtil -import kotlinx.android.synthetic.main.fragment_card_blur_player_playback_controls.* -import kotlinx.android.synthetic.main.media_button.* - +import kotlinx.android.synthetic.main.fragment_card_blur_player_playback_controls.progressSlider +import kotlinx.android.synthetic.main.fragment_card_blur_player_playback_controls.songCurrentProgress +import kotlinx.android.synthetic.main.fragment_card_blur_player_playback_controls.songInfo +import kotlinx.android.synthetic.main.fragment_card_blur_player_playback_controls.songTotalTime +import kotlinx.android.synthetic.main.media_button.nextButton +import kotlinx.android.synthetic.main.media_button.playPauseButton +import kotlinx.android.synthetic.main.media_button.previousButton +import kotlinx.android.synthetic.main.media_button.repeatButton +import kotlinx.android.synthetic.main.media_button.shuffleButton class CardBlurPlaybackControlsFragment : AbsPlayerControlsFragment() { @@ -32,14 +40,15 @@ class CardBlurPlaybackControlsFragment : AbsPlayerControlsFragment() { private var lastDisabledPlaybackControlsColor: Int = 0 private lateinit var progressViewUpdateHelper: MusicProgressViewUpdateHelper - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) progressViewUpdateHelper = MusicProgressViewUpdateHelper(this) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { return inflater.inflate(R.layout.fragment_card_blur_player_playback_controls, container, false) } @@ -62,7 +71,6 @@ class CardBlurPlaybackControlsFragment : AbsPlayerControlsFragment() { volumeFragment?.tintWhiteColor() } - private fun setUpPlayPauseFab() { playPauseButton.apply { TintHelper.setTintAuto(this, Color.WHITE, true) @@ -78,14 +86,12 @@ class CardBlurPlaybackControlsFragment : AbsPlayerControlsFragment() { } } - private fun updateProgressTextColor() { val color = MaterialValueHelper.getPrimaryTextColor(context, false) songTotalTime.setTextColor(color) songCurrentProgress.setTextColor(color) } - override fun onResume() { super.onResume() progressViewUpdateHelper.start() @@ -100,6 +106,15 @@ class CardBlurPlaybackControlsFragment : AbsPlayerControlsFragment() { updatePlayPauseDrawableState() updateRepeatState() updateShuffleState() + updateSong() + } + + private fun updateSong() { + if (PreferenceUtil.getInstance(requireContext()).isSongInfo) { + songInfo?.text = getSongInfo(MusicPlayerRemote.currentSong) + } else { + songInfo?.hide() + } } override fun onPlayStateChanged() { @@ -139,7 +154,10 @@ class CardBlurPlaybackControlsFragment : AbsPlayerControlsFragment() { override fun updateShuffleState() { when (MusicPlayerRemote.shuffleMode) { - MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter( + lastPlaybackControlsColor, + PorterDuff.Mode.SRC_IN + ) else -> shuffleButton.setColorFilter(lastDisabledPlaybackControlsColor, PorterDuff.Mode.SRC_IN) } } @@ -167,11 +185,11 @@ class CardBlurPlaybackControlsFragment : AbsPlayerControlsFragment() { public override fun show() { playPauseButton!!.animate() - .scaleX(1f) - .scaleY(1f) - .rotation(360f) - .setInterpolator(DecelerateInterpolator()) - .start() + .scaleX(1f) + .scaleY(1f) + .rotation(360f) + .setInterpolator(DecelerateInterpolator()) + .start() } public override fun hide() { @@ -189,14 +207,15 @@ class CardBlurPlaybackControlsFragment : AbsPlayerControlsFragment() { override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { if (fromUser) { MusicPlayerRemote.seekTo(progress) - onUpdateProgressViews(MusicPlayerRemote.songProgressMillis, - MusicPlayerRemote.songDurationMillis) + onUpdateProgressViews( + MusicPlayerRemote.songProgressMillis, + MusicPlayerRemote.songDurationMillis + ) } } }) } - override fun onUpdateProgressViews(progress: Int, total: Int) { progressSlider.max = total diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/color/ColorPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/color/ColorPlaybackControlsFragment.kt index 4c97e4fb..86a17969 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/color/ColorPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/color/ColorPlaybackControlsFragment.kt @@ -13,6 +13,7 @@ import android.widget.SeekBar import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.TintHelper import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.extensions.hide import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper @@ -20,6 +21,7 @@ import code.name.monkey.retromusic.helper.PlayPauseButtonOnClickHandler import code.name.monkey.retromusic.misc.SimpleOnSeekbarChangeListener import code.name.monkey.retromusic.service.MusicService import code.name.monkey.retromusic.util.MusicUtil +import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.ViewUtil import kotlinx.android.synthetic.main.fragment_color_player_playback_controls.nextButton import kotlinx.android.synthetic.main.fragment_color_player_playback_controls.playPauseButton @@ -28,6 +30,7 @@ import kotlinx.android.synthetic.main.fragment_color_player_playback_controls.pr import kotlinx.android.synthetic.main.fragment_color_player_playback_controls.repeatButton import kotlinx.android.synthetic.main.fragment_color_player_playback_controls.shuffleButton import kotlinx.android.synthetic.main.fragment_color_player_playback_controls.songCurrentProgress +import kotlinx.android.synthetic.main.fragment_color_player_playback_controls.songInfo import kotlinx.android.synthetic.main.fragment_color_player_playback_controls.songTotalTime import kotlinx.android.synthetic.main.fragment_color_player_playback_controls.text import kotlinx.android.synthetic.main.fragment_color_player_playback_controls.title @@ -68,6 +71,12 @@ class ColorPlaybackControlsFragment : AbsPlayerControlsFragment() { val song = MusicPlayerRemote.currentSong title.text = song.title text.text = song.artistName + + if (PreferenceUtil.getInstance(requireContext()).isSongInfo) { + songInfo?.text = getSongInfo(song) + } else { + songInfo?.hide() + } } override fun onServiceConnected() { @@ -104,8 +113,9 @@ class ColorPlaybackControlsFragment : AbsPlayerControlsFragment() { lastPlaybackControlsColor = color lastDisabledPlaybackControlsColor = ColorUtil.withAlpha(color, 0.5f) - title!!.setTextColor(lastPlaybackControlsColor) - text!!.setTextColor(lastDisabledPlaybackControlsColor) + title.setTextColor(lastPlaybackControlsColor) + text.setTextColor(lastDisabledPlaybackControlsColor) + songInfo.setTextColor(lastDisabledPlaybackControlsColor) ViewUtil.setProgressDrawable(progressSlider, lastPlaybackControlsColor, true) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/fit/FitFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/fit/FitFragment.kt index 06e98ade..64bf03b6 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/fit/FitFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/fit/FitFragment.kt @@ -12,8 +12,7 @@ import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.model.Song -import kotlinx.android.synthetic.main.fragment_fit.* - +import kotlinx.android.synthetic.main.fragment_fit.playerToolbar class FitFragment : AbsPlayerFragment() { override fun playerToolbar(): Toolbar { @@ -47,7 +46,11 @@ class FitFragment : AbsPlayerFragment() { playbackControlsFragment.setDark(color) lastColor = color callbacks?.onPaletteColorChanged() - ToolbarContentTintHelper.colorizeToolbar(playerToolbar, ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), requireActivity()) + ToolbarContentTintHelper.colorizeToolbar( + playerToolbar, + ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), + requireActivity() + ) } override fun toggleFavorite(song: Song) { @@ -61,8 +64,10 @@ class FitFragment : AbsPlayerFragment() { toggleFavorite(MusicPlayerRemote.currentSong) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { return inflater.inflate(R.layout.fragment_fit, container, false) } @@ -74,8 +79,10 @@ class FitFragment : AbsPlayerFragment() { } private fun setUpSubFragments() { - playbackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as FitPlaybackControlsFragment - val playerAlbumCoverFragment: PlayerAlbumCoverFragment = childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment + playbackControlsFragment = + childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as FitPlaybackControlsFragment + val playerAlbumCoverFragment: PlayerAlbumCoverFragment = + childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment playerAlbumCoverFragment.setCallbacks(this) playerAlbumCoverFragment.removeEffect() } @@ -85,7 +92,11 @@ class FitFragment : AbsPlayerFragment() { inflateMenu(R.menu.menu_player) setNavigationOnClickListener { requireActivity().onBackPressed() } setOnMenuItemClickListener(this@FitFragment) - ToolbarContentTintHelper.colorizeToolbar(this, ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), requireActivity()) + ToolbarContentTintHelper.colorizeToolbar( + this, + ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), + requireActivity() + ) } } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/fit/FitPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/fit/FitPlaybackControlsFragment.kt index 3a968c2d..63edd157 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/fit/FitPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/fit/FitPlaybackControlsFragment.kt @@ -3,19 +3,40 @@ package code.name.monkey.retromusic.fragments.player.fit import android.animation.ObjectAnimator import android.graphics.PorterDuff import android.os.Bundle -import android.view.* -import android.view.animation.* +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.view.animation.AccelerateInterpolator +import android.view.animation.DecelerateInterpolator +import android.view.animation.LinearInterpolator import android.widget.SeekBar import code.name.monkey.appthemehelper.ThemeStore -import code.name.monkey.appthemehelper.util.* +import code.name.monkey.appthemehelper.util.ATHUtil +import code.name.monkey.appthemehelper.util.ColorUtil +import code.name.monkey.appthemehelper.util.MaterialValueHelper +import code.name.monkey.appthemehelper.util.TintHelper import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.extensions.hide import code.name.monkey.retromusic.extensions.ripAlpha import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment -import code.name.monkey.retromusic.helper.* +import code.name.monkey.retromusic.helper.MusicPlayerRemote +import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper +import code.name.monkey.retromusic.helper.PlayPauseButtonOnClickHandler import code.name.monkey.retromusic.misc.SimpleOnSeekbarChangeListener import code.name.monkey.retromusic.service.MusicService -import code.name.monkey.retromusic.util.* -import kotlinx.android.synthetic.main.fragment_player_playback_controls.* +import code.name.monkey.retromusic.util.MusicUtil +import code.name.monkey.retromusic.util.PreferenceUtil +import kotlinx.android.synthetic.main.fragment_fit_playback_controls.nextButton +import kotlinx.android.synthetic.main.fragment_fit_playback_controls.playPauseButton +import kotlinx.android.synthetic.main.fragment_fit_playback_controls.previousButton +import kotlinx.android.synthetic.main.fragment_fit_playback_controls.progressSlider +import kotlinx.android.synthetic.main.fragment_fit_playback_controls.repeatButton +import kotlinx.android.synthetic.main.fragment_fit_playback_controls.shuffleButton +import kotlinx.android.synthetic.main.fragment_fit_playback_controls.songCurrentProgress +import kotlinx.android.synthetic.main.fragment_fit_playback_controls.songInfo +import kotlinx.android.synthetic.main.fragment_fit_playback_controls.songTotalTime +import kotlinx.android.synthetic.main.fragment_fit_playback_controls.text +import kotlinx.android.synthetic.main.fragment_fit_playback_controls.title class FitPlaybackControlsFragment : AbsPlayerControlsFragment() { @@ -24,14 +45,15 @@ class FitPlaybackControlsFragment : AbsPlayerControlsFragment() { private var lastDisabledPlaybackControlsColor: Int = 0 private lateinit var progressViewUpdateHelper: MusicProgressViewUpdateHelper - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) progressViewUpdateHelper = MusicProgressViewUpdateHelper(this) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { return inflater.inflate(R.layout.fragment_fit_playback_controls, container, false) } @@ -57,6 +79,11 @@ class FitPlaybackControlsFragment : AbsPlayerControlsFragment() { val song = MusicPlayerRemote.currentSong title.text = song.title text.text = song.artistName + if (PreferenceUtil.getInstance(requireContext()).isSongInfo) { + songInfo?.text = getSongInfo(song) + } else { + songInfo?.hide() + } } override fun onResume() { @@ -118,7 +145,11 @@ class FitPlaybackControlsFragment : AbsPlayerControlsFragment() { } private fun setFabColor(i: Int) { - TintHelper.setTintAuto(playPauseButton, MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(i)), false) + TintHelper.setTintAuto( + playPauseButton, + MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(i)), + false + ) TintHelper.setTintAuto(playPauseButton, i, true) } @@ -159,7 +190,10 @@ class FitPlaybackControlsFragment : AbsPlayerControlsFragment() { override fun updateShuffleState() { when (MusicPlayerRemote.shuffleMode) { - MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter( + lastPlaybackControlsColor, + PorterDuff.Mode.SRC_IN + ) else -> shuffleButton.setColorFilter(lastDisabledPlaybackControlsColor, PorterDuff.Mode.SRC_IN) } } @@ -187,11 +221,11 @@ class FitPlaybackControlsFragment : AbsPlayerControlsFragment() { public override fun show() { playPauseButton!!.animate() - .scaleX(1f) - .scaleY(1f) - .rotation(360f) - .setInterpolator(DecelerateInterpolator()) - .start() + .scaleX(1f) + .scaleY(1f) + .rotation(360f) + .setInterpolator(DecelerateInterpolator()) + .start() } public override fun hide() { @@ -209,8 +243,10 @@ class FitPlaybackControlsFragment : AbsPlayerControlsFragment() { override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { if (fromUser) { MusicPlayerRemote.seekTo(progress) - onUpdateProgressViews(MusicPlayerRemote.songProgressMillis, - MusicPlayerRemote.songDurationMillis) + onUpdateProgressViews( + MusicPlayerRemote.songProgressMillis, + MusicPlayerRemote.songDurationMillis + ) } } }) @@ -226,16 +262,16 @@ class FitPlaybackControlsFragment : AbsPlayerControlsFragment() { pivotY = (height / 2).toFloat() animate().setDuration(200) - .setInterpolator(DecelerateInterpolator()) - .scaleX(1.1f) - .scaleY(1.1f) - .withEndAction { - animate().setDuration(200) - .setInterpolator(AccelerateInterpolator()) - .scaleX(1f) - .scaleY(1f) - .alpha(1f).start() - }.start() + .setInterpolator(DecelerateInterpolator()) + .scaleX(1.1f) + .scaleY(1.1f) + .withEndAction { + animate().setDuration(200) + .setInterpolator(AccelerateInterpolator()) + .scaleX(1f) + .scaleY(1f) + .alpha(1f).start() + }.start() } } @@ -250,5 +286,4 @@ class FitPlaybackControlsFragment : AbsPlayerControlsFragment() { songTotalTime.text = MusicUtil.getReadableDurationString(total.toLong()) songCurrentProgress.text = MusicUtil.getReadableDurationString(progress.toLong()) } - } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/flat/FlatPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/flat/FlatPlaybackControlsFragment.kt index 9acafa18..3db06f45 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/flat/FlatPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/flat/FlatPlaybackControlsFragment.kt @@ -15,6 +15,7 @@ import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialValueHelper import code.name.monkey.appthemehelper.util.TintHelper import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.extensions.hide import code.name.monkey.retromusic.extensions.ripAlpha import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote @@ -26,7 +27,15 @@ import code.name.monkey.retromusic.service.MusicService import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.ViewUtil -import kotlinx.android.synthetic.main.fragment_flat_player_playback_controls.* +import kotlinx.android.synthetic.main.fragment_flat_player_playback_controls.playPauseButton +import kotlinx.android.synthetic.main.fragment_flat_player_playback_controls.progressSlider +import kotlinx.android.synthetic.main.fragment_flat_player_playback_controls.repeatButton +import kotlinx.android.synthetic.main.fragment_flat_player_playback_controls.shuffleButton +import kotlinx.android.synthetic.main.fragment_flat_player_playback_controls.songCurrentProgress +import kotlinx.android.synthetic.main.fragment_flat_player_playback_controls.songInfo +import kotlinx.android.synthetic.main.fragment_flat_player_playback_controls.songTotalTime +import kotlinx.android.synthetic.main.fragment_flat_player_playback_controls.text +import kotlinx.android.synthetic.main.fragment_flat_player_playback_controls.title class FlatPlaybackControlsFragment : AbsPlayerControlsFragment(), Callback { @@ -34,14 +43,15 @@ class FlatPlaybackControlsFragment : AbsPlayerControlsFragment(), Callback { private var lastDisabledPlaybackControlsColor: Int = 0 private lateinit var progressViewUpdateHelper: MusicProgressViewUpdateHelper - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) progressViewUpdateHelper = MusicProgressViewUpdateHelper(this) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { return inflater.inflate(R.layout.fragment_flat_player_playback_controls, container, false) } @@ -76,13 +86,12 @@ class FlatPlaybackControlsFragment : AbsPlayerControlsFragment(), Callback { public override fun show() { playPauseButton!!.animate() - .scaleX(1f) - .scaleY(1f) - .setInterpolator(DecelerateInterpolator()) - .start() + .scaleX(1f) + .scaleY(1f) + .setInterpolator(DecelerateInterpolator()) + .start() } - public override fun hide() { playPauseButton!!.apply { scaleX = 0f @@ -130,6 +139,8 @@ class FlatPlaybackControlsFragment : AbsPlayerControlsFragment(), Callback { title.setTextColor(colorPrimary) text.setBackgroundColor(darkColor) text.setTextColor(colorSecondary) + songInfo.setBackgroundColor(darkColor) + songInfo.setTextColor(colorSecondary) } override fun onServiceConnected() { @@ -172,7 +183,11 @@ class FlatPlaybackControlsFragment : AbsPlayerControlsFragment(), Callback { val song = MusicPlayerRemote.currentSong title.text = song.title text.text = song.artistName - + if (PreferenceUtil.getInstance(requireContext()).isSongInfo) { + songInfo?.text = getSongInfo(song) + } else { + songInfo?.hide() + } } override fun setUpProgressSlider() { @@ -180,8 +195,10 @@ class FlatPlaybackControlsFragment : AbsPlayerControlsFragment(), Callback { override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { if (fromUser) { MusicPlayerRemote.seekTo(progress) - onUpdateProgressViews(MusicPlayerRemote.songProgressMillis, - MusicPlayerRemote.songDurationMillis) + onUpdateProgressViews( + MusicPlayerRemote.songProgressMillis, + MusicPlayerRemote.songDurationMillis + ) } } }) @@ -222,9 +239,11 @@ class FlatPlaybackControlsFragment : AbsPlayerControlsFragment(), Callback { override fun updateShuffleState() { when (MusicPlayerRemote.shuffleMode) { - MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter( + lastPlaybackControlsColor, + PorterDuff.Mode.SRC_IN + ) else -> shuffleButton.setColorFilter(lastDisabledPlaybackControlsColor, PorterDuff.Mode.SRC_IN) } } - } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/flat/FlatPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/flat/FlatPlayerFragment.kt index 50fd971f..8c3155fb 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/flat/FlatPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/flat/FlatPlayerFragment.kt @@ -20,7 +20,8 @@ import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.ViewUtil import code.name.monkey.retromusic.views.DrawableGradient -import kotlinx.android.synthetic.main.fragment_flat_player.* +import kotlinx.android.synthetic.main.fragment_flat_player.colorGradientBackground +import kotlinx.android.synthetic.main.fragment_flat_player.playerToolbar class FlatPlayerFragment : AbsPlayerFragment() { override fun playerToolbar(): Toolbar { @@ -34,8 +35,10 @@ class FlatPlayerFragment : AbsPlayerFragment() { get() = lastColor private fun setUpSubFragments() { - flatPlaybackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as FlatPlaybackControlsFragment - val playerAlbumCoverFragment = childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment + flatPlaybackControlsFragment = + childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as FlatPlaybackControlsFragment + val playerAlbumCoverFragment = + childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment playerAlbumCoverFragment.setCallbacks(this) } @@ -43,7 +46,11 @@ class FlatPlayerFragment : AbsPlayerFragment() { playerToolbar.inflateMenu(R.menu.menu_player) playerToolbar.setNavigationOnClickListener { _ -> requireActivity().onBackPressed() } playerToolbar.setOnMenuItemClickListener(this) - ToolbarContentTintHelper.colorizeToolbar(playerToolbar, ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), requireActivity()) + ToolbarContentTintHelper.colorizeToolbar( + playerToolbar, + ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), + requireActivity() + ) } private fun colorize(i: Int) { @@ -53,16 +60,20 @@ class FlatPlayerFragment : AbsPlayerFragment() { valueAnimator = ValueAnimator.ofObject(ArgbEvaluator(), android.R.color.transparent, i) valueAnimator!!.addUpdateListener { animation -> - val drawable = DrawableGradient(GradientDrawable.Orientation.TOP_BOTTOM, - intArrayOf(animation.animatedValue as Int, android.R.color.transparent), 0) + val drawable = DrawableGradient( + GradientDrawable.Orientation.TOP_BOTTOM, + intArrayOf(animation.animatedValue as Int, android.R.color.transparent), 0 + ) colorGradientBackground?.background = drawable } valueAnimator!!.setDuration(ViewUtil.RETRO_MUSIC_ANIM_TIME.toLong()).start() } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { return inflater.inflate(R.layout.fragment_flat_player, container, false) } @@ -70,7 +81,6 @@ class FlatPlayerFragment : AbsPlayerFragment() { super.onViewCreated(view, savedInstanceState) setUpPlayerToolbar() setUpSubFragments() - } override fun onShow() { @@ -109,12 +119,10 @@ class FlatPlayerFragment : AbsPlayerFragment() { } } - override fun onFavoriteToggled() { toggleFavorite(MusicPlayerRemote.currentSong) } - override fun toggleFavorite(song: Song) { super.toggleFavorite(song) if (song.id == MusicPlayerRemote.currentSong.id) { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlaybackControlsFragment.kt index 0aae7ae7..fc2ef704 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlaybackControlsFragment.kt @@ -21,6 +21,7 @@ import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialValueHelper import code.name.monkey.appthemehelper.util.TintHelper import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.extensions.hide import code.name.monkey.retromusic.extensions.ripAlpha import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote @@ -32,7 +33,19 @@ import code.name.monkey.retromusic.service.MusicService import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.ViewUtil -import kotlinx.android.synthetic.main.fragment_full_player_controls.* +import kotlinx.android.synthetic.main.fragment_full_player_controls.nextButton +import kotlinx.android.synthetic.main.fragment_full_player_controls.playPauseButton +import kotlinx.android.synthetic.main.fragment_full_player_controls.playerMenu +import kotlinx.android.synthetic.main.fragment_full_player_controls.previousButton +import kotlinx.android.synthetic.main.fragment_full_player_controls.progressSlider +import kotlinx.android.synthetic.main.fragment_full_player_controls.repeatButton +import kotlinx.android.synthetic.main.fragment_full_player_controls.shuffleButton +import kotlinx.android.synthetic.main.fragment_full_player_controls.songCurrentProgress +import kotlinx.android.synthetic.main.fragment_full_player_controls.songFavourite +import kotlinx.android.synthetic.main.fragment_full_player_controls.songInfo +import kotlinx.android.synthetic.main.fragment_full_player_controls.songTotalTime +import kotlinx.android.synthetic.main.fragment_full_player_controls.text +import kotlinx.android.synthetic.main.fragment_full_player_controls.title /** * Created by hemanths on 20/09/17. @@ -49,13 +62,14 @@ class FullPlaybackControlsFragment : AbsPlayerControlsFragment(), PopupMenu.OnMe progressViewUpdateHelper = MusicProgressViewUpdateHelper(this) } - override fun onCreateView(inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { return inflater.inflate(R.layout.fragment_full_player_controls, container, false) } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setUpMusicControllers() @@ -90,13 +104,12 @@ class FullPlaybackControlsFragment : AbsPlayerControlsFragment(), PopupMenu.OnMe public override fun show() { playPauseButton!!.animate() - .scaleX(1f) - .scaleY(1f) - .setInterpolator(DecelerateInterpolator()) - .start() + .scaleX(1f) + .scaleY(1f) + .setInterpolator(DecelerateInterpolator()) + .start() } - public override fun hide() { playPauseButton.apply { scaleX = 0f @@ -120,12 +133,16 @@ class FullPlaybackControlsFragment : AbsPlayerControlsFragment(), PopupMenu.OnMe ViewUtil.setProgressDrawable(progressSlider, colorFinal, true) playPauseButton.backgroundTintList = ColorStateList.valueOf(colorFinal) - playPauseButton.imageTintList = ColorStateList.valueOf(MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(colorFinal))) + playPauseButton.imageTintList = ColorStateList.valueOf( + MaterialValueHelper.getPrimaryTextColor( + context, + ColorUtil.isColorLight(colorFinal) + ) + ) updateRepeatState() updateShuffleState() updatePrevNextColor() - } override fun onServiceConnected() { @@ -140,6 +157,11 @@ class FullPlaybackControlsFragment : AbsPlayerControlsFragment(), PopupMenu.OnMe title.text = song.title text.text = song.artistName updateIsFavorite() + if (PreferenceUtil.getInstance(requireContext()).isSongInfo) { + songInfo?.text = getSongInfo(song) + } else { + songInfo?.hide() + } } override fun onPlayingMetaChanged() { @@ -199,7 +221,6 @@ class FullPlaybackControlsFragment : AbsPlayerControlsFragment(), PopupMenu.OnMe previousButton.setOnClickListener { MusicPlayerRemote.back() } } - private fun updatePrevNextColor() { nextButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) previousButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) @@ -216,7 +237,6 @@ class FullPlaybackControlsFragment : AbsPlayerControlsFragment(), PopupMenu.OnMe }) } - override fun onRepeatModeChanged() { updateRepeatState() } @@ -231,7 +251,10 @@ class FullPlaybackControlsFragment : AbsPlayerControlsFragment(), PopupMenu.OnMe override fun updateShuffleState() { when (MusicPlayerRemote.shuffleMode) { - MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter( + lastPlaybackControlsColor, + PorterDuff.Mode.SRC_IN + ) else -> shuffleButton.setColorFilter(lastDisabledPlaybackControlsColor, PorterDuff.Mode.SRC_IN) } } @@ -306,5 +329,4 @@ class FullPlaybackControlsFragment : AbsPlayerControlsFragment(), PopupMenu.OnMe fun onFavoriteToggled() { toggleFavorite(MusicPlayerRemote.currentSong) } - } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlayerFragment.kt index 798410ba..1261781b 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/full/FullPlayerFragment.kt @@ -25,7 +25,10 @@ import code.name.monkey.retromusic.model.lyrics.Lyrics import code.name.monkey.retromusic.util.NavigationUtil import com.bumptech.glide.Glide import io.reactivex.disposables.CompositeDisposable -import kotlinx.android.synthetic.main.fragment_full.* +import kotlinx.android.synthetic.main.fragment_full.artistImage +import kotlinx.android.synthetic.main.fragment_full.nextSong +import kotlinx.android.synthetic.main.fragment_full.nextSongLabel +import kotlinx.android.synthetic.main.fragment_full.playerToolbar import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -63,7 +66,10 @@ class FullPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Ca lyricsLine1.visibility = View.VISIBLE lyricsLine2.visibility = View.VISIBLE - lyricsLine2.measure(View.MeasureSpec.makeMeasureSpec(lyricsLine2.measuredWidth, View.MeasureSpec.EXACTLY), View.MeasureSpec.UNSPECIFIED) + lyricsLine2.measure( + View.MeasureSpec.makeMeasureSpec(lyricsLine2.measuredWidth, View.MeasureSpec.EXACTLY), + View.MeasureSpec.UNSPECIFIED + ) val h: Float = lyricsLine2.measuredHeight.toFloat() lyricsLine1.alpha = 1f @@ -125,8 +131,10 @@ class FullPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Ca } } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { return inflater.inflate(R.layout.fragment_full, container, false) } @@ -152,19 +160,19 @@ class FullPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Ca } private fun setUpSubFragments() { - fullPlaybackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as FullPlaybackControlsFragment + fullPlaybackControlsFragment = + childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as FullPlaybackControlsFragment - val playerAlbumCoverFragment = childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment + val playerAlbumCoverFragment = + childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment playerAlbumCoverFragment.setCallbacks(this) playerAlbumCoverFragment.removeSlideEffect() } override fun onShow() { - } override fun onHide() { - } override fun onBackPressed(): Boolean { @@ -219,13 +227,12 @@ class FullPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Ca val artist = ArtistLoader.getArtist(requireContext(), MusicPlayerRemote.currentSong.artistId) withContext(Dispatchers.Main) { ArtistGlideRequest.Builder.from(Glide.with(requireContext()), artist) - .generatePalette(requireContext()) - .build() - .into(object : RetroMusicColoredTarget(artistImage) { - override fun onColorReady(color: Int) { - - } - }) + .generatePalette(requireContext()) + .build() + .into(object : RetroMusicColoredTarget(artistImage) { + override fun onColorReady(color: Int) { + } + }) } } } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/material/MaterialControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/material/MaterialControlsFragment.kt index 247ae1ce..7318c66e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/material/MaterialControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/material/MaterialControlsFragment.kt @@ -13,6 +13,7 @@ import code.name.monkey.appthemehelper.util.ATHUtil import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialValueHelper import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.extensions.hide import code.name.monkey.retromusic.extensions.ripAlpha import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote @@ -23,7 +24,17 @@ import code.name.monkey.retromusic.service.MusicService import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.ViewUtil -import kotlinx.android.synthetic.main.fragment_material_playback_controls.* +import kotlinx.android.synthetic.main.fragment_material_playback_controls.nextButton +import kotlinx.android.synthetic.main.fragment_material_playback_controls.playPauseButton +import kotlinx.android.synthetic.main.fragment_material_playback_controls.previousButton +import kotlinx.android.synthetic.main.fragment_material_playback_controls.progressSlider +import kotlinx.android.synthetic.main.fragment_material_playback_controls.repeatButton +import kotlinx.android.synthetic.main.fragment_material_playback_controls.shuffleButton +import kotlinx.android.synthetic.main.fragment_material_playback_controls.songCurrentProgress +import kotlinx.android.synthetic.main.fragment_material_playback_controls.songInfo +import kotlinx.android.synthetic.main.fragment_material_playback_controls.songTotalTime +import kotlinx.android.synthetic.main.fragment_material_playback_controls.text +import kotlinx.android.synthetic.main.fragment_material_playback_controls.title /** * @author Hemanth S (h4h13). @@ -34,14 +45,15 @@ class MaterialControlsFragment : AbsPlayerControlsFragment() { private var lastDisabledPlaybackControlsColor: Int = 0 private lateinit var progressViewUpdateHelper: MusicProgressViewUpdateHelper - override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) progressViewUpdateHelper = MusicProgressViewUpdateHelper(this) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { return inflater.inflate(R.layout.fragment_material_playback_controls, container, false) } @@ -56,6 +68,12 @@ class MaterialControlsFragment : AbsPlayerControlsFragment() { val song = MusicPlayerRemote.currentSong title.text = song.title text.text = song.artistName + + if (PreferenceUtil.getInstance(requireContext()).isSongInfo) { + songInfo?.text = getSongInfo(song) + } else { + songInfo?.hide() + } } override fun onResume() { @@ -96,10 +114,12 @@ class MaterialControlsFragment : AbsPlayerControlsFragment() { val colorBg = ATHUtil.resolveColor(requireContext(), android.R.attr.colorBackground) if (ColorUtil.isColorLight(colorBg)) { lastPlaybackControlsColor = MaterialValueHelper.getSecondaryTextColor(requireContext(), true) - lastDisabledPlaybackControlsColor = MaterialValueHelper.getSecondaryDisabledTextColor(requireContext(), true) + lastDisabledPlaybackControlsColor = + MaterialValueHelper.getSecondaryDisabledTextColor(requireContext(), true) } else { lastPlaybackControlsColor = MaterialValueHelper.getPrimaryTextColor(requireContext(), false) - lastDisabledPlaybackControlsColor = MaterialValueHelper.getPrimaryDisabledTextColor(requireContext(), false) + lastDisabledPlaybackControlsColor = + MaterialValueHelper.getPrimaryDisabledTextColor(requireContext(), false) } updateRepeatState() @@ -133,7 +153,7 @@ class MaterialControlsFragment : AbsPlayerControlsFragment() { if (MusicPlayerRemote.isPlaying) { playPauseButton.setImageResource(R.drawable.ic_pause_white_64dp) } else { - playPauseButton.setImageResource(R.drawable.ic_play_arrow_white_64dp); + playPauseButton.setImageResource(R.drawable.ic_play_arrow_white_64dp) } } @@ -162,7 +182,10 @@ class MaterialControlsFragment : AbsPlayerControlsFragment() { override fun updateShuffleState() { when (MusicPlayerRemote.shuffleMode) { - MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter( + lastPlaybackControlsColor, + PorterDuff.Mode.SRC_IN + ) else -> shuffleButton.setColorFilter(lastDisabledPlaybackControlsColor, PorterDuff.Mode.SRC_IN) } } @@ -189,11 +212,9 @@ class MaterialControlsFragment : AbsPlayerControlsFragment() { } public override fun show() { - } public override fun hide() { - } override fun setUpProgressSlider() { @@ -201,8 +222,10 @@ class MaterialControlsFragment : AbsPlayerControlsFragment() { override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) { if (fromUser) { MusicPlayerRemote.seekTo(progress) - onUpdateProgressViews(MusicPlayerRemote.songProgressMillis, - MusicPlayerRemote.songDurationMillis) + onUpdateProgressViews( + MusicPlayerRemote.songProgressMillis, + MusicPlayerRemote.songDurationMillis + ) } } }) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/material/MaterialFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/material/MaterialFragment.kt index 9a548fd6..eb4f5834 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/material/MaterialFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/material/MaterialFragment.kt @@ -13,12 +13,13 @@ import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment import code.name.monkey.retromusic.fragments.player.normal.PlayerFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.model.Song -import kotlinx.android.synthetic.main.fragment_material.* +import kotlinx.android.synthetic.main.fragment_material.playerToolbar /** * @author Hemanth S (h4h13). */ class MaterialFragment : AbsPlayerFragment() { + override fun playerToolbar(): Toolbar { return playerToolbar } @@ -52,7 +53,11 @@ class MaterialFragment : AbsPlayerFragment() { lastColor = color callbacks?.onPaletteColorChanged() - ToolbarContentTintHelper.colorizeToolbar(playerToolbar, ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), requireActivity()) + ToolbarContentTintHelper.colorizeToolbar( + playerToolbar, + ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), + requireActivity() + ) } override fun toggleFavorite(song: Song) { @@ -66,8 +71,10 @@ class MaterialFragment : AbsPlayerFragment() { toggleFavorite(MusicPlayerRemote.currentSong) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { return inflater.inflate(R.layout.fragment_material, container, false) } @@ -75,12 +82,13 @@ class MaterialFragment : AbsPlayerFragment() { super.onViewCreated(view, savedInstanceState) setUpSubFragments() setUpPlayerToolbar() - } private fun setUpSubFragments() { - playbackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as MaterialControlsFragment - val playerAlbumCoverFragment = childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment + playbackControlsFragment = + childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as MaterialControlsFragment + val playerAlbumCoverFragment = + childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment playerAlbumCoverFragment.setCallbacks(this) } @@ -89,7 +97,11 @@ class MaterialFragment : AbsPlayerFragment() { inflateMenu(R.menu.menu_player) setNavigationOnClickListener { requireActivity().onBackPressed() } setOnMenuItemClickListener(this@MaterialFragment) - ToolbarContentTintHelper.colorizeToolbar(this, ATHUtil.resolveColor(context, R.attr.colorControlNormal), requireActivity()) + ToolbarContentTintHelper.colorizeToolbar( + this, + ATHUtil.resolveColor(context, R.attr.colorControlNormal), + requireActivity() + ) } } 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 1576e72a..125476e4 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 @@ -1,6 +1,8 @@ package code.name.monkey.retromusic.fragments.player.normal import android.animation.ObjectAnimator +import android.content.SharedPreferences +import android.content.SharedPreferences.OnSharedPreferenceChangeListener import android.graphics.PorterDuff import android.os.Bundle import android.view.LayoutInflater @@ -15,6 +17,7 @@ import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialValueHelper import code.name.monkey.appthemehelper.util.TintHelper import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.extensions.hide import code.name.monkey.retromusic.extensions.ripAlpha import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote @@ -32,11 +35,12 @@ import kotlinx.android.synthetic.main.fragment_player_playback_controls.progress import kotlinx.android.synthetic.main.fragment_player_playback_controls.repeatButton import kotlinx.android.synthetic.main.fragment_player_playback_controls.shuffleButton import kotlinx.android.synthetic.main.fragment_player_playback_controls.songCurrentProgress +import kotlinx.android.synthetic.main.fragment_player_playback_controls.songInfo import kotlinx.android.synthetic.main.fragment_player_playback_controls.songTotalTime import kotlinx.android.synthetic.main.fragment_player_playback_controls.text import kotlinx.android.synthetic.main.fragment_player_playback_controls.title -class PlayerPlaybackControlsFragment : AbsPlayerControlsFragment() { +class PlayerPlaybackControlsFragment : AbsPlayerControlsFragment(), OnSharedPreferenceChangeListener { private var lastPlaybackControlsColor: Int = 0 private var lastDisabledPlaybackControlsColor: Int = 0 @@ -51,7 +55,6 @@ class PlayerPlaybackControlsFragment : AbsPlayerControlsFragment() { inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - return inflater.inflate(R.layout.fragment_player_playback_controls, container, false) } @@ -67,6 +70,7 @@ class PlayerPlaybackControlsFragment : AbsPlayerControlsFragment() { showBonceAnimation(playPauseButton) } title.isSelected = true + PreferenceUtil.getInstance(requireContext()).registerOnSharedPreferenceChangedListener(this) } override fun setDark(color: Int) { @@ -103,10 +107,16 @@ class PlayerPlaybackControlsFragment : AbsPlayerControlsFragment() { updatePrevNextColor() } + private fun updateSong() { val song = MusicPlayerRemote.currentSong title.text = song.title text.text = song.artistName + if (PreferenceUtil.getInstance(requireContext()).isSongInfo) { + songInfo?.text = getSongInfo(song) + } else { + songInfo?.hide() + } } override fun onResume() { @@ -253,4 +263,16 @@ class PlayerPlaybackControlsFragment : AbsPlayerControlsFragment() { songTotalTime.text = MusicUtil.getReadableDurationString(total.toLong()) songCurrentProgress.text = MusicUtil.getReadableDurationString(progress.toLong()) } + + override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { + println(key) + if (key == PreferenceUtil.EXTRA_SONG_INFO) { + updateSong() + } + } + + override fun onDestroyView() { + super.onDestroyView() + PreferenceUtil.getInstance(requireContext()).unregisterOnSharedPreferenceChangedListener(this) + } } 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 16d9f4ed..8ca714c8 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 @@ -39,7 +39,14 @@ import code.name.monkey.retromusic.service.MusicService import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.ViewUtil -import kotlinx.android.synthetic.main.fragment_peak_control_player.* +import kotlinx.android.synthetic.main.fragment_peak_control_player.nextButton +import kotlinx.android.synthetic.main.fragment_peak_control_player.playPauseButton +import kotlinx.android.synthetic.main.fragment_peak_control_player.previousButton +import kotlinx.android.synthetic.main.fragment_peak_control_player.progressSlider +import kotlinx.android.synthetic.main.fragment_peak_control_player.repeatButton +import kotlinx.android.synthetic.main.fragment_peak_control_player.shuffleButton +import kotlinx.android.synthetic.main.fragment_peak_control_player.songCurrentProgress +import kotlinx.android.synthetic.main.fragment_peak_control_player.songTotalTime /** * Created by hemanths on 2019-10-04. @@ -67,37 +74,37 @@ class PeakPlayerControlFragment : AbsPlayerControlsFragment() { } override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? ): View? { return inflater.inflate(R.layout.fragment_peak_control_player, container, false) } override fun onViewCreated( - view: View, - savedInstanceState: Bundle? + view: View, + savedInstanceState: Bundle? ) { super.onViewCreated(view, savedInstanceState) setUpMusicControllers() } override fun show() { - } override fun hide() { - } override fun setDark(color: Int) { val colorBg = ATHUtil.resolveColor(requireContext(), android.R.attr.colorBackground) if (ColorUtil.isColorLight(colorBg)) { lastPlaybackControlsColor = MaterialValueHelper.getSecondaryTextColor(requireContext(), true) - lastDisabledPlaybackControlsColor = MaterialValueHelper.getSecondaryDisabledTextColor(requireContext(), true) + lastDisabledPlaybackControlsColor = + MaterialValueHelper.getSecondaryDisabledTextColor(requireContext(), true) } else { lastPlaybackControlsColor = MaterialValueHelper.getPrimaryTextColor(requireContext(), false) - lastDisabledPlaybackControlsColor = MaterialValueHelper.getPrimaryDisabledTextColor(requireContext(), false) + lastDisabledPlaybackControlsColor = + MaterialValueHelper.getPrimaryDisabledTextColor(requireContext(), false) } val colorFinal = if (PreferenceUtil.getInstance(requireContext()).adaptiveColor) { @@ -185,15 +192,16 @@ class PeakPlayerControlFragment : AbsPlayerControlsFragment() { previousButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) } - override fun updateShuffleState() { when (MusicPlayerRemote.shuffleMode) { - MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter( + lastPlaybackControlsColor, + PorterDuff.Mode.SRC_IN + ) else -> shuffleButton.setColorFilter(lastDisabledPlaybackControlsColor, PorterDuff.Mode.SRC_IN) } } - override fun updateRepeatState() { when (MusicPlayerRemote.repeatMode) { MusicService.REPEAT_MODE_NONE -> { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/peak/PeakPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/peak/PeakPlayerFragment.kt index 09f6fa99..497603d1 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/peak/PeakPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/peak/PeakPlayerFragment.kt @@ -22,13 +22,19 @@ import androidx.appcompat.widget.Toolbar 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.extensions.hide import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment import code.name.monkey.retromusic.glide.RetroMusicColoredTarget import code.name.monkey.retromusic.glide.SongGlideRequest import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.util.NavigationUtil +import code.name.monkey.retromusic.util.PreferenceUtil import com.bumptech.glide.Glide -import kotlinx.android.synthetic.main.fragment_peak_player.* +import kotlinx.android.synthetic.main.fragment_peak_player.playerImage +import kotlinx.android.synthetic.main.fragment_peak_player.playerToolbar +import kotlinx.android.synthetic.main.fragment_peak_player.songInfo +import kotlinx.android.synthetic.main.fragment_peak_player.text +import kotlinx.android.synthetic.main.fragment_peak_player.title /** * Created by hemanths on 2019-10-03. @@ -54,7 +60,8 @@ class PeakPlayerFragment : AbsPlayerFragment() { } private fun setUpSubFragments() { - playbackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as PeakPlayerControlFragment + playbackControlsFragment = + childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as PeakPlayerControlFragment } private fun setUpPlayerToolbar() { @@ -62,7 +69,11 @@ class PeakPlayerFragment : AbsPlayerFragment() { inflateMenu(R.menu.menu_player) setNavigationOnClickListener { requireActivity().onBackPressed() } setOnMenuItemClickListener(this@PeakPlayerFragment) - ToolbarContentTintHelper.colorizeToolbar(this, ATHUtil.resolveColor(context, R.attr.colorControlNormal), requireActivity()) + ToolbarContentTintHelper.colorizeToolbar( + this, + ATHUtil.resolveColor(context, R.attr.colorControlNormal), + requireActivity() + ) } } @@ -71,11 +82,9 @@ class PeakPlayerFragment : AbsPlayerFragment() { } override fun onShow() { - } override fun onHide() { - } override fun onBackPressed(): Boolean { @@ -96,24 +105,27 @@ class PeakPlayerFragment : AbsPlayerFragment() { } override fun onFavoriteToggled() { - } private fun updateSong() { val song = MusicPlayerRemote.currentSong title.text = song.title text.text = song.artistName + if (PreferenceUtil.getInstance(requireContext()).isSongInfo) { + songInfo?.text = getSongInfo(song) + } else { + songInfo?.hide() + } SongGlideRequest.Builder.from(Glide.with(requireActivity()), MusicPlayerRemote.currentSong) - .checkIgnoreMediaStore(requireContext()) - .generatePalette(requireContext()) - .build() - .into(object : RetroMusicColoredTarget(playerImage) { - override fun onColorReady(color: Int) { - playbackControlsFragment.setDark(color) - } - }) - + .checkIgnoreMediaStore(requireContext()) + .generatePalette(requireContext()) + .build() + .into(object : RetroMusicColoredTarget(playerImage) { + override fun onColorReady(color: Int) { + playbackControlsFragment.setDark(color) + } + }) } override fun onServiceConnected() { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/plain/PlainPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/plain/PlainPlaybackControlsFragment.kt index f7c7911d..1d27251e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/plain/PlainPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/plain/PlainPlaybackControlsFragment.kt @@ -16,6 +16,7 @@ import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialValueHelper import code.name.monkey.appthemehelper.util.TintHelper import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.extensions.hide import code.name.monkey.retromusic.extensions.ripAlpha import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote @@ -26,6 +27,7 @@ import code.name.monkey.retromusic.service.MusicService import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.ViewUtil +import kotlinx.android.synthetic.main.fragment_adaptive_player_playback_controls.songInfo import kotlinx.android.synthetic.main.fragment_plain_controls_fragment.nextButton import kotlinx.android.synthetic.main.fragment_plain_controls_fragment.playPauseButton import kotlinx.android.synthetic.main.fragment_plain_controls_fragment.previousButton @@ -61,6 +63,20 @@ class PlainPlaybackControlsFragment : AbsPlayerControlsFragment() { updatePlayPauseDrawableState() updateRepeatState() updateShuffleState() + updateSong() + } + + override fun onPlayingMetaChanged() { + super.onPlayingMetaChanged() + updateSong() + } + + private fun updateSong() { + if (PreferenceUtil.getInstance(requireContext()).isSongInfo) { + songInfo?.text = getSongInfo(MusicPlayerRemote.currentSong) + } else { + songInfo?.hide() + } } override fun onCreate(savedInstanceState: Bundle?) { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/plain/PlainPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/plain/PlainPlayerFragment.kt index 98f09f0e..30241f14 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/plain/PlainPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/plain/PlainPlayerFragment.kt @@ -12,7 +12,9 @@ import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.model.Song -import kotlinx.android.synthetic.main.fragment_plain_player.* +import kotlinx.android.synthetic.main.fragment_plain_player.playerToolbar +import kotlinx.android.synthetic.main.fragment_plain_player.text +import kotlinx.android.synthetic.main.fragment_plain_player.title class PlainPlayerFragment : AbsPlayerFragment() { override fun playerToolbar(): Toolbar { @@ -24,7 +26,6 @@ class PlainPlayerFragment : AbsPlayerFragment() { override val paletteColor: Int get() = lastColor - override fun onPlayingMetaChanged() { super.onPlayingMetaChanged() updateSong() @@ -41,8 +42,10 @@ class PlainPlayerFragment : AbsPlayerFragment() { updateSong() } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { return inflater.inflate(R.layout.fragment_plain_player, container, false) } @@ -51,7 +54,11 @@ class PlainPlayerFragment : AbsPlayerFragment() { inflateMenu(R.menu.menu_player) setNavigationOnClickListener { requireActivity().onBackPressed() } setOnMenuItemClickListener(this@PlainPlayerFragment) - ToolbarContentTintHelper.colorizeToolbar(this, ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), requireActivity()) + ToolbarContentTintHelper.colorizeToolbar( + this, + ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), + requireActivity() + ) } } @@ -64,8 +71,10 @@ class PlainPlayerFragment : AbsPlayerFragment() { } private fun setUpSubFragments() { - plainPlaybackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as PlainPlaybackControlsFragment - val playerAlbumCoverFragment = childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment + plainPlaybackControlsFragment = + childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as PlainPlaybackControlsFragment + val playerAlbumCoverFragment = + childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment playerAlbumCoverFragment.setCallbacks(this) } @@ -90,7 +99,11 @@ class PlainPlayerFragment : AbsPlayerFragment() { plainPlaybackControlsFragment.setDark(color) lastColor = color callbacks!!.onPaletteColorChanged() - ToolbarContentTintHelper.colorizeToolbar(playerToolbar, ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), requireActivity()) + ToolbarContentTintHelper.colorizeToolbar( + playerToolbar, + ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), + requireActivity() + ) } override fun onFavoriteToggled() { diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/simple/SimplePlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/simple/SimplePlaybackControlsFragment.kt index e100c686..5f9a03d3 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/simple/SimplePlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/simple/SimplePlaybackControlsFragment.kt @@ -12,6 +12,7 @@ import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialValueHelper import code.name.monkey.appthemehelper.util.TintHelper import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.extensions.hide import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.helper.MusicProgressViewUpdateHelper @@ -19,7 +20,15 @@ import code.name.monkey.retromusic.helper.PlayPauseButtonOnClickHandler import code.name.monkey.retromusic.service.MusicService import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.PreferenceUtil -import kotlinx.android.synthetic.main.fragment_simple_controls_fragment.* +import kotlinx.android.synthetic.main.fragment_simple_controls_fragment.nextButton +import kotlinx.android.synthetic.main.fragment_simple_controls_fragment.playPauseButton +import kotlinx.android.synthetic.main.fragment_simple_controls_fragment.previousButton +import kotlinx.android.synthetic.main.fragment_simple_controls_fragment.repeatButton +import kotlinx.android.synthetic.main.fragment_simple_controls_fragment.shuffleButton +import kotlinx.android.synthetic.main.fragment_simple_controls_fragment.songCurrentProgress +import kotlinx.android.synthetic.main.fragment_simple_controls_fragment.songInfo +import kotlinx.android.synthetic.main.fragment_simple_controls_fragment.text +import kotlinx.android.synthetic.main.fragment_simple_controls_fragment.title /** * @author Hemanth S (h4h13). @@ -31,7 +40,6 @@ class SimplePlaybackControlsFragment : AbsPlayerControlsFragment() { private var lastDisabledPlaybackControlsColor: Int = 0 private lateinit var progressViewUpdateHelper: MusicProgressViewUpdateHelper - override fun onPlayStateChanged() { updatePlayPauseDrawableState() } @@ -56,7 +64,6 @@ class SimplePlaybackControlsFragment : AbsPlayerControlsFragment() { progressViewUpdateHelper = MusicProgressViewUpdateHelper(this) } - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { return inflater.inflate(R.layout.fragment_simple_controls_fragment, container, false) } @@ -110,7 +117,10 @@ class SimplePlaybackControlsFragment : AbsPlayerControlsFragment() { override fun updateShuffleState() { when (MusicPlayerRemote.shuffleMode) { - MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + MusicService.SHUFFLE_MODE_SHUFFLE -> shuffleButton.setColorFilter( + lastPlaybackControlsColor, + PorterDuff.Mode.SRC_IN + ) else -> shuffleButton.setColorFilter(lastDisabledPlaybackControlsColor, PorterDuff.Mode.SRC_IN) } } @@ -140,21 +150,25 @@ class SimplePlaybackControlsFragment : AbsPlayerControlsFragment() { val song = MusicPlayerRemote.currentSong title.text = song.title text.text = song.artistName + if (PreferenceUtil.getInstance(requireContext()).isSongInfo) { + songInfo?.text = getSongInfo(song) + } else { + songInfo?.hide() + } } override fun onPlayingMetaChanged() { super.onPlayingMetaChanged() updateSong() - } public override fun show() { playPauseButton!!.animate() - .scaleX(1f) - .scaleY(1f) - .rotation(360f) - .setInterpolator(DecelerateInterpolator()) - .start() + .scaleX(1f) + .scaleY(1f) + .rotation(360f) + .setInterpolator(DecelerateInterpolator()) + .start() } public override fun hide() { @@ -168,12 +182,14 @@ class SimplePlaybackControlsFragment : AbsPlayerControlsFragment() { } override fun setUpProgressSlider() { - } - override fun onUpdateProgressViews(progress: Int, total: Int) { - songCurrentProgress!!.text = String.format("%s / %s", MusicUtil.getReadableDurationString(progress.toLong()), MusicUtil.getReadableDurationString(total.toLong())) + songCurrentProgress!!.text = String.format( + "%s / %s", + MusicUtil.getReadableDurationString(progress.toLong()), + MusicUtil.getReadableDurationString(total.toLong()) + ) } override fun setDark(color: Int) { @@ -194,7 +210,11 @@ class SimplePlaybackControlsFragment : AbsPlayerControlsFragment() { volumeFragment?.setTintable(colorFinal) - TintHelper.setTintAuto(playPauseButton, MaterialValueHelper.getPrimaryTextColor(context!!, ColorUtil.isColorLight(colorFinal)), false) + TintHelper.setTintAuto( + playPauseButton, + MaterialValueHelper.getPrimaryTextColor(context!!, ColorUtil.isColorLight(colorFinal)), + false + ) TintHelper.setTintAuto(playPauseButton, colorFinal, true) text.setTextColor(colorFinal) diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/simple/SimplePlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/simple/SimplePlayerFragment.kt index 5cb9e65c..4b08839f 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/simple/SimplePlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/simple/SimplePlayerFragment.kt @@ -12,13 +12,14 @@ import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.model.Song -import kotlinx.android.synthetic.main.fragment_simple_player.* +import kotlinx.android.synthetic.main.fragment_simple_player.playerToolbar /** * @author Hemanth S (h4h13). */ class SimplePlayerFragment : AbsPlayerFragment() { + override fun playerToolbar(): Toolbar { return playerToolbar } @@ -29,8 +30,10 @@ class SimplePlayerFragment : AbsPlayerFragment() { private lateinit var simplePlaybackControlsFragment: SimplePlaybackControlsFragment - override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle?): View? { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { return inflater.inflate(R.layout.fragment_simple_player, container, false) } @@ -42,9 +45,11 @@ class SimplePlayerFragment : AbsPlayerFragment() { } private fun setUpSubFragments() { - val playerAlbumCoverFragment = childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment + val playerAlbumCoverFragment = + childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment playerAlbumCoverFragment.setCallbacks(this) - simplePlaybackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as SimplePlaybackControlsFragment + simplePlaybackControlsFragment = + childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as SimplePlaybackControlsFragment } override fun onShow() { @@ -67,7 +72,11 @@ class SimplePlayerFragment : AbsPlayerFragment() { lastColor = color callbacks?.onPaletteColorChanged() simplePlaybackControlsFragment.setDark(color) - ToolbarContentTintHelper.colorizeToolbar(playerToolbar, ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), requireActivity()) + ToolbarContentTintHelper.colorizeToolbar( + playerToolbar, + ATHUtil.resolveColor(requireContext(), R.attr.colorControlNormal), + requireActivity() + ) } override fun onFavoriteToggled() { @@ -85,6 +94,10 @@ class SimplePlayerFragment : AbsPlayerFragment() { playerToolbar.inflateMenu(R.menu.menu_player) playerToolbar.setNavigationOnClickListener { requireActivity().onBackPressed() } playerToolbar.setOnMenuItemClickListener(this) - ToolbarContentTintHelper.colorizeToolbar(playerToolbar, ATHUtil.resolveColor(context, R.attr.colorControlNormal), requireActivity()) + ToolbarContentTintHelper.colorizeToolbar( + playerToolbar, + ATHUtil.resolveColor(context, R.attr.colorControlNormal), + requireActivity() + ) } } diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/tiny/TinyPlaybackControlsFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/tiny/TinyPlaybackControlsFragment.kt index 147faf4a..686f556e 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/tiny/TinyPlaybackControlsFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/tiny/TinyPlaybackControlsFragment.kt @@ -11,45 +11,44 @@ import code.name.monkey.retromusic.R import code.name.monkey.retromusic.fragments.base.AbsPlayerControlsFragment import code.name.monkey.retromusic.helper.MusicPlayerRemote import code.name.monkey.retromusic.service.MusicService -import kotlinx.android.synthetic.main.fragment_tiny_controls_fragment.* +import kotlinx.android.synthetic.main.fragment_tiny_controls_fragment.playerRepeatButton +import kotlinx.android.synthetic.main.fragment_tiny_controls_fragment.playerShuffleButton class TinyPlaybackControlsFragment : AbsPlayerControlsFragment() { override fun show() { - } override fun hide() { - } override fun setUpProgressSlider() { - } override fun setDark(color: Int) { if (ColorUtil.isColorLight(color)) { lastPlaybackControlsColor = MaterialValueHelper.getSecondaryTextColor(requireContext(), true) - lastDisabledPlaybackControlsColor = MaterialValueHelper.getSecondaryDisabledTextColor(requireContext(), true) + lastDisabledPlaybackControlsColor = + MaterialValueHelper.getSecondaryDisabledTextColor(requireContext(), true) } else { lastPlaybackControlsColor = MaterialValueHelper.getPrimaryTextColor(requireContext(), false) - lastDisabledPlaybackControlsColor = MaterialValueHelper.getPrimaryDisabledTextColor(requireContext(), false) + lastDisabledPlaybackControlsColor = + MaterialValueHelper.getPrimaryDisabledTextColor(requireContext(), false) } - updateRepeatState(); - updateShuffleState(); + updateRepeatState() + updateShuffleState() } override fun onUpdateProgressViews(progress: Int, total: Int) { - } private var lastPlaybackControlsColor: Int = 0 private var lastDisabledPlaybackControlsColor: Int = 0 override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { - return inflater.inflate(R.layout.fragment_tiny_controls_fragment, container, false); + return inflater.inflate(R.layout.fragment_tiny_controls_fragment, container, false) } override fun onViewCreated(view: View, savedInstanceState: Bundle?) { @@ -73,7 +72,10 @@ class TinyPlaybackControlsFragment : AbsPlayerControlsFragment() { override fun updateShuffleState() { when (MusicPlayerRemote.shuffleMode) { - MusicService.SHUFFLE_MODE_SHUFFLE -> playerShuffleButton.setColorFilter(lastPlaybackControlsColor, PorterDuff.Mode.SRC_IN) + MusicService.SHUFFLE_MODE_SHUFFLE -> playerShuffleButton.setColorFilter( + lastPlaybackControlsColor, + PorterDuff.Mode.SRC_IN + ) else -> playerShuffleButton.setColorFilter(lastDisabledPlaybackControlsColor, PorterDuff.Mode.SRC_IN) } } @@ -107,4 +109,5 @@ class TinyPlaybackControlsFragment : AbsPlayerControlsFragment() { override fun onShuffleModeChanged() { updateShuffleState() } + } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/fragments/player/tiny/TinyPlayerFragment.kt b/app/src/main/java/code/name/monkey/retromusic/fragments/player/tiny/TinyPlayerFragment.kt index 105531fe..9b50716a 100644 --- a/app/src/main/java/code/name/monkey/retromusic/fragments/player/tiny/TinyPlayerFragment.kt +++ b/app/src/main/java/code/name/monkey/retromusic/fragments/player/tiny/TinyPlayerFragment.kt @@ -13,6 +13,7 @@ import code.name.monkey.appthemehelper.util.ColorUtil import code.name.monkey.appthemehelper.util.MaterialValueHelper import code.name.monkey.appthemehelper.util.ToolbarContentTintHelper import code.name.monkey.retromusic.R +import code.name.monkey.retromusic.extensions.hide import code.name.monkey.retromusic.fragments.MiniPlayerFragment import code.name.monkey.retromusic.fragments.base.AbsPlayerFragment import code.name.monkey.retromusic.fragments.player.PlayerAlbumCoverFragment @@ -23,7 +24,12 @@ import code.name.monkey.retromusic.model.Song import code.name.monkey.retromusic.util.MusicUtil import code.name.monkey.retromusic.util.PreferenceUtil import code.name.monkey.retromusic.util.ViewUtil -import kotlinx.android.synthetic.main.fragment_tiny_player.* +import kotlinx.android.synthetic.main.fragment_tiny_player.playerSongTotalTime +import kotlinx.android.synthetic.main.fragment_tiny_player.playerToolbar +import kotlinx.android.synthetic.main.fragment_tiny_player.progressBar +import kotlinx.android.synthetic.main.fragment_tiny_player.songInfo +import kotlinx.android.synthetic.main.fragment_tiny_player.text +import kotlinx.android.synthetic.main.fragment_tiny_player.title class TinyPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Callback { override fun onUpdateProgressViews(progress: Int, total: Int) { @@ -38,17 +44,17 @@ class TinyPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Ca animatorSet.interpolator = LinearInterpolator() animatorSet.start() - playerSongTotalTime.text = String.format("%s/%s", MusicUtil.getReadableDurationString(total.toLong()), - MusicUtil.getReadableDurationString(progress.toLong())) + playerSongTotalTime.text = String.format( + "%s/%s", MusicUtil.getReadableDurationString(total.toLong()), + MusicUtil.getReadableDurationString(progress.toLong()) + ) } - override fun playerToolbar(): Toolbar { return playerToolbar } override fun onShow() { - } override fun onHide() { @@ -95,7 +101,7 @@ class TinyPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Ca title.setTextColor(textColorPrimary) text.setTextColor(textColorPrimaryDisabled) - + songInfo.setTextColor(textColorPrimaryDisabled) playerSongTotalTime.setTextColor(textColorPrimary) ToolbarContentTintHelper.colorizeToolbar(playerToolbar, textColorPrimary, requireActivity()) @@ -127,6 +133,12 @@ class TinyPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Ca val song = MusicPlayerRemote.currentSong title.text = song.title text.text = String.format("%s \nby - %s", song.albumName, song.artistName) + + if (PreferenceUtil.getInstance(requireContext()).isSongInfo) { + songInfo?.text = getSongInfo(song) + } else { + songInfo?.hide() + } } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { @@ -144,10 +156,11 @@ class TinyPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Ca } private fun setUpSubFragments() { - tinyPlaybackControlsFragment = childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as TinyPlaybackControlsFragment - val playerAlbumCoverFragment = childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment + tinyPlaybackControlsFragment = + childFragmentManager.findFragmentById(R.id.playbackControlsFragment) as TinyPlaybackControlsFragment + val playerAlbumCoverFragment = + childFragmentManager.findFragmentById(R.id.playerAlbumCoverFragment) as PlayerAlbumCoverFragment playerAlbumCoverFragment.setCallbacks(this) - } private fun setUpPlayerToolbar() { @@ -174,5 +187,4 @@ class TinyPlayerFragment : AbsPlayerFragment(), MusicProgressViewUpdateHelper.Ca super.onPlayingMetaChanged() updateSong() } - } \ 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 02fc53c5..ad38af9a 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 @@ -18,6 +18,7 @@ import android.annotation.SuppressLint; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; +import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.content.res.TypedArray; import android.net.ConnectivityManager; import android.net.NetworkInfo; @@ -57,7 +58,7 @@ public final class PreferenceUtil { public static final String LIBRARY_CATEGORIES = "library_categories"; - public static final String HIDE_HOME_BANNER_SEARCH = "hide_home_banner_search"; + public static final String EXTRA_SONG_INFO = "extra_song_info"; public static final String DESATURATED_COLOR = "desaturated_color"; @@ -698,8 +699,8 @@ public final class PreferenceUtil { return mPreferences.getBoolean(SLEEP_TIMER_FINISH_SONG, false); } - public boolean getBannerSearchEnable() { - return mPreferences.getBoolean(HIDE_HOME_BANNER_SEARCH, false); + public boolean isSongInfo() { + return mPreferences.getBoolean(EXTRA_SONG_INFO, false); } public void setSleepTimerFinishMusic(final boolean value) { @@ -992,7 +993,7 @@ public final class PreferenceUtil { } public void unregisterOnSharedPreferenceChangedListener( - SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener) { + @NonNull OnSharedPreferenceChangeListener sharedPreferenceChangeListener) { mPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener); } } diff --git a/app/src/main/java/code/name/monkey/retromusic/util/RetroUtil.java b/app/src/main/java/code/name/monkey/retromusic/util/RetroUtil.java index 36f65da4..9fdcb4fb 100755 --- a/app/src/main/java/code/name/monkey/retromusic/util/RetroUtil.java +++ b/app/src/main/java/code/name/monkey/retromusic/util/RetroUtil.java @@ -16,7 +16,6 @@ package code.name.monkey.retromusic.util; import android.annotation.TargetApi; import android.app.Activity; -import android.content.ContentUris; import android.content.Context; import android.content.Intent; import android.content.res.Configuration; @@ -36,21 +35,19 @@ import android.view.View; import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; - import androidx.annotation.ColorInt; import androidx.annotation.DrawableRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.vectordrawable.graphics.drawable.VectorDrawableCompat; - import code.name.monkey.appthemehelper.util.TintHelper; import code.name.monkey.retromusic.App; public class RetroUtil { private static final int[] TEMP_ARRAY = new int[1]; - private static final String SHOW_NAV_BAR_RES_NAME = "config_showNavigationBar"; + private static final String SHOW_NAV_BAR_RES_NAME = "config_showNavigationBar"; public static int calculateNoOfColumns(@NonNull Context context) { DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); @@ -58,25 +55,18 @@ public class RetroUtil { return (int) (dpWidth / 180); } - public static boolean isTablet() { - return App.Companion.getContext().getResources().getConfiguration().smallestScreenWidthDp >= 600; + @NonNull + public static Bitmap createBitmap(@NonNull Drawable drawable, float sizeMultiplier) { + Bitmap bitmap = Bitmap.createBitmap((int) (drawable.getIntrinsicWidth() * sizeMultiplier), + (int) (drawable.getIntrinsicHeight() * sizeMultiplier), Bitmap.Config.ARGB_8888); + Canvas c = new Canvas(bitmap); + drawable.setBounds(0, 0, c.getWidth(), c.getHeight()); + drawable.draw(c); + return bitmap; } - public static boolean isLandscape() { - return App.Companion.getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; - } - - @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) - public static boolean isRTL(@NonNull Context context) { - Configuration config = context.getResources().getConfiguration(); - return config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; - } - - public static void openUrl(@NonNull Activity context, @NonNull String str) { - Intent intent = new Intent("android.intent.action.VIEW"); - intent.setData(Uri.parse(str)); - intent.setFlags(268435456); - context.startActivity(intent); + public static float frequencyCount(int frequency) { + return (float) (frequency / 1000.0); } public static Point getScreenSize(@NonNull Context c) { @@ -91,6 +81,38 @@ public class RetroUtil { return size; } + public static int getStatusBarHeight() { + int result = 0; + int resourceId = App.Companion.getContext().getResources() + .getIdentifier("status_bar_height", "dimen", "android"); + if (resourceId > 0) { + result = App.Companion.getContext().getResources().getDimensionPixelSize(resourceId); + } + return result; + } + + @Nullable + public static Drawable getTintedVectorDrawable(@NonNull Context context, @DrawableRes int id, + @ColorInt int color) { + return TintHelper.createTintedDrawable( + getVectorDrawable(context.getResources(), id, context.getTheme()), color); + } + + @Nullable + public static Drawable getTintedVectorDrawable(@NonNull Resources res, @DrawableRes int resId, + @Nullable Resources.Theme theme, @ColorInt int color) { + return TintHelper.createTintedDrawable(getVectorDrawable(res, resId, theme), color); + } + + @Nullable + public static Drawable getVectorDrawable(@NonNull Resources res, @DrawableRes int resId, + @Nullable Resources.Theme theme) { + if (Build.VERSION.SDK_INT >= 21) { + return res.getDrawable(resId, theme); + } + return VectorDrawableCompat.create(res, resId, theme); + } + public static void hideSoftKeyboard(@Nullable Activity activity) { if (activity != null) { View currentFocus = activity.getCurrentFocus(); @@ -104,38 +126,6 @@ public class RetroUtil { } } - @Nullable - public static Drawable getVectorDrawable(@NonNull Resources res, @DrawableRes int resId, - @Nullable Resources.Theme theme) { - if (Build.VERSION.SDK_INT >= 21) { - return res.getDrawable(resId, theme); - } - return VectorDrawableCompat.create(res, resId, theme); - } - - @Nullable - public static Drawable getTintedVectorDrawable(@NonNull Context context, @DrawableRes int id, - @ColorInt int color) { - return TintHelper.createTintedDrawable( - getVectorDrawable(context.getResources(), id, context.getTheme()), color); - } - - @NonNull - public static Bitmap createBitmap(@NonNull Drawable drawable, float sizeMultiplier) { - Bitmap bitmap = Bitmap.createBitmap((int) (drawable.getIntrinsicWidth() * sizeMultiplier), - (int) (drawable.getIntrinsicHeight() * sizeMultiplier), Bitmap.Config.ARGB_8888); - Canvas c = new Canvas(bitmap); - drawable.setBounds(0, 0, c.getWidth(), c.getHeight()); - drawable.draw(c); - return bitmap; - } - - @Nullable - public static Drawable getTintedVectorDrawable(@NonNull Resources res, @DrawableRes int resId, - @Nullable Resources.Theme theme, @ColorInt int color) { - return TintHelper.createTintedDrawable(getVectorDrawable(res, resId, theme), color); - } - public static boolean isAllowedToDownloadMetadata(final @NonNull Context context) { switch (PreferenceUtil.getInstance(context).autoDownloadImagesPolicy()) { case "always": @@ -152,13 +142,26 @@ public class RetroUtil { } } - public static int getStatusBarHeight() { - int result = 0; - int resourceId = App.Companion.getContext().getResources().getIdentifier("status_bar_height", "dimen", "android"); - if (resourceId > 0) { - result = App.Companion.getContext().getResources().getDimensionPixelSize(resourceId); - } - return result; + public static boolean isLandscape() { + return App.Companion.getContext().getResources().getConfiguration().orientation + == Configuration.ORIENTATION_LANDSCAPE; + } + + @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) + public static boolean isRTL(@NonNull Context context) { + Configuration config = context.getResources().getConfiguration(); + return config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL; + } + + public static boolean isTablet() { + return App.Companion.getContext().getResources().getConfiguration().smallestScreenWidthDp >= 600; + } + + public static void openUrl(@NonNull Activity context, @NonNull String str) { + Intent intent = new Intent("android.intent.action.VIEW"); + intent.setData(Uri.parse(str)); + intent.setFlags(268435456); + context.startActivity(intent); } public static void setAllowDrawUnderNavigationBar(Window window) { diff --git a/app/src/main/res/layout-xlarge-land/fragment_player_playback_controls.xml b/app/src/main/res/layout-xlarge-land/fragment_player_playback_controls.xml index 1d104566..7558016c 100755 --- a/app/src/main/res/layout-xlarge-land/fragment_player_playback_controls.xml +++ b/app/src/main/res/layout-xlarge-land/fragment_player_playback_controls.xml @@ -43,13 +43,30 @@ android:paddingEnd="24dp" android:textAppearance="@style/TextViewHeadline5" android:textColor="?android:attr/textColorSecondary" - app:layout_constraintBottom_toTopOf="@+id/playPauseButton" + app:layout_constraintBottom_toTopOf="@+id/songInfo" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.5" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/title" tools:text="@tools:sample/lorem/random" /> + + diff --git a/app/src/main/res/layout/fragment_adaptive_player.xml b/app/src/main/res/layout/fragment_adaptive_player.xml index 0c290604..24cc6be4 100644 --- a/app/src/main/res/layout/fragment_adaptive_player.xml +++ b/app/src/main/res/layout/fragment_adaptive_player.xml @@ -108,5 +108,4 @@ tools:layout="@layout/fragment_adaptive_player_playback_controls" /> - \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_adaptive_player_playback_controls.xml b/app/src/main/res/layout/fragment_adaptive_player_playback_controls.xml index b40225b9..57be9f22 100644 --- a/app/src/main/res/layout/fragment_adaptive_player_playback_controls.xml +++ b/app/src/main/res/layout/fragment_adaptive_player_playback_controls.xml @@ -152,4 +152,19 @@ android:paddingStart="8dp" android:paddingEnd="8dp" /> + diff --git a/app/src/main/res/layout/fragment_blur_player_playback_controls.xml b/app/src/main/res/layout/fragment_blur_player_playback_controls.xml index 6455e657..384a7dbf 100644 --- a/app/src/main/res/layout/fragment_blur_player_playback_controls.xml +++ b/app/src/main/res/layout/fragment_blur_player_playback_controls.xml @@ -13,211 +13,212 @@ --> + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/playback_controls" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:gravity="center_vertical" + android:orientation="vertical" + tools:ignore="MissingPrefix"> - + - + - + - - + + - + - - + + - + - + - + - + - + - + - + - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_card_blur_player_playback_controls.xml b/app/src/main/res/layout/fragment_card_blur_player_playback_controls.xml index f0e7af1f..381c80ef 100644 --- a/app/src/main/res/layout/fragment_card_blur_player_playback_controls.xml +++ b/app/src/main/res/layout/fragment_card_blur_player_playback_controls.xml @@ -71,5 +71,19 @@ android:thumbTint="@color/md_white_1000" tools:progress="20" /> + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_card_player_playback_controls.xml b/app/src/main/res/layout/fragment_card_player_playback_controls.xml index aba4ceb1..b562f204 100644 --- a/app/src/main/res/layout/fragment_card_player_playback_controls.xml +++ b/app/src/main/res/layout/fragment_card_player_playback_controls.xml @@ -1,122 +1,133 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:id="@+id/playback_controls" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:clickable="true" + android:focusable="true" + android:orientation="vertical" + tools:ignore="MissingPrefix"> - + - + - + - + - + - + - + - + - + - + - + - - - + + + + + diff --git a/app/src/main/res/layout/fragment_color_player_playback_controls.xml b/app/src/main/res/layout/fragment_color_player_playback_controls.xml index 5ff78bee..a6a23c93 100644 --- a/app/src/main/res/layout/fragment_color_player_playback_controls.xml +++ b/app/src/main/res/layout/fragment_color_player_playback_controls.xml @@ -91,7 +91,6 @@ tools:text="@tools:sample/lorem/random" /> - - - + + + app:layout_constraintTop_toTopOf="@+id/previousButton" + app:srcCompat="@drawable/ic_repeat_white_24dp" + tools:ignore="MissingPrefix" + tools:tint="@color/md_black_1000" /> - + - + - + - - - - - - - + - + - + - + - + - + - + - + - + + - - + - + - - + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_flat_player_playback_controls.xml b/app/src/main/res/layout/fragment_flat_player_playback_controls.xml index a43b31ab..d1477890 100644 --- a/app/src/main/res/layout/fragment_flat_player_playback_controls.xml +++ b/app/src/main/res/layout/fragment_flat_player_playback_controls.xml @@ -57,6 +57,27 @@ tools:progress="20" /> + + app:layout_constraintTop_toBottomOf="@+id/songInfo" + tools:text="@tools:sample/full_names" /> + tools:text="@tools:sample/full_names" /> diff --git a/app/src/main/res/layout/fragment_full_player_controls.xml b/app/src/main/res/layout/fragment_full_player_controls.xml index 2958e091..f109f58d 100644 --- a/app/src/main/res/layout/fragment_full_player_controls.xml +++ b/app/src/main/res/layout/fragment_full_player_controls.xml @@ -8,7 +8,6 @@ android:orientation="vertical" tools:background="@color/md_grey_800"> - + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_library.xml b/app/src/main/res/layout/fragment_library.xml index e9a78714..176ff771 100644 --- a/app/src/main/res/layout/fragment_library.xml +++ b/app/src/main/res/layout/fragment_library.xml @@ -59,7 +59,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - + diff --git a/app/src/main/res/layout/fragment_peak_player.xml b/app/src/main/res/layout/fragment_peak_player.xml index afda28a5..4de46632 100644 --- a/app/src/main/res/layout/fragment_peak_player.xml +++ b/app/src/main/res/layout/fragment_peak_player.xml @@ -70,7 +70,7 @@ android:layout_height="wrap_content" app:layout_constraintBottom_toTopOf="@+id/text" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toEndOf="@+id/imageContainer" + app:layout_constraintStart_toEndOf="@id/imageContainer" app:layout_constraintTop_toBottomOf="@+id/toolbarContainer"> + + + app:layout_constraintTop_toBottomOf="@+id/songInfo"> + + diff --git a/app/src/main/res/layout/fragment_player_playback_controls.xml b/app/src/main/res/layout/fragment_player_playback_controls.xml index 6088a761..ff5f263c 100755 --- a/app/src/main/res/layout/fragment_player_playback_controls.xml +++ b/app/src/main/res/layout/fragment_player_playback_controls.xml @@ -101,10 +101,26 @@ android:paddingEnd="16dp" android:textAppearance="@style/TextViewBody1" android:textColor="?android:attr/textColorSecondary" - app:layout_constraintBottom_toTopOf="@+id/playPauseButton" + app:layout_constraintBottom_toTopOf="@+id/songInfo" app:layout_constraintTop_toBottomOf="@+id/titleContainer" tools:text="@tools:sample/lorem/random" /> + + diff --git a/app/src/main/res/layout/fragment_simple_controls_fragment.xml b/app/src/main/res/layout/fragment_simple_controls_fragment.xml index 7e4fc971..1e2f6e61 100644 --- a/app/src/main/res/layout/fragment_simple_controls_fragment.xml +++ b/app/src/main/res/layout/fragment_simple_controls_fragment.xml @@ -58,15 +58,28 @@ android:layout_height="wrap_content" android:gravity="center" android:paddingStart="16dp" - - android:paddingEnd="16dp" android:textAppearance="@style/TextViewSubtitle2" - app:layout_constraintBottom_toTopOf="@+id/playerMediaControllerContainer" + app:layout_constraintBottom_toTopOf="@+id/songInfo" app:layout_constraintTop_toBottomOf="@+id/text" tools:layout_editor_absoluteX="16dp" tools:text="22.00/ 33.00" /> + diff --git a/app/src/main/res/layout/fragment_tiny_player.xml b/app/src/main/res/layout/fragment_tiny_player.xml index 26866597..bd723c3d 100644 --- a/app/src/main/res/layout/fragment_tiny_player.xml +++ b/app/src/main/res/layout/fragment_tiny_player.xml @@ -51,16 +51,37 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="end" - - - android:padding="16dp" + android:ellipsize="end" + android:maxLines="1" + android:paddingStart="16dp" + android:paddingEnd="16dp" android:textAppearance="@style/TextViewHeadline3" android:textStyle="bold" - app:layout_constraintEnd_toEndOf="parent" + app:layout_constrainedWidth="true" + app:layout_constraintBottom_toTopOf="@+id/playbackControlsFragmentContainer" + app:layout_constraintEnd_toStartOf="@+id/songInfo" app:layout_constraintTop_toBottomOf="@id/status_bar" + app:layout_constraintVertical_bias="0" tools:ignore="MissingPrefix" tools:text="@tools:sample/date/hhmm" /> + + \ No newline at end of file diff --git a/app/src/main/res/layout/media_button.xml b/app/src/main/res/layout/media_button.xml index a2c17c98..1f843ebe 100644 --- a/app/src/main/res/layout/media_button.xml +++ b/app/src/main/res/layout/media_button.xml @@ -1,5 +1,5 @@ - + + + + - - - - - - - \ No newline at end of file + \ 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 35b9ee0b..dc830cfb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -403,6 +403,8 @@ No lyrics found + No songs playing + You have no playlists No purchase found. @@ -420,6 +422,7 @@ %s is not listed in the media store.]]> Nothing to scan. + Nothing to see Notification @@ -483,8 +486,10 @@ Filter songs by length Filter song duration + Advanced Album style Audio + Blacklist Controls Theme Images @@ -515,6 +520,7 @@ As per Material Design guide lines in dark mode colors should be desaturated Most dominant color will be picked from the album or artist cover Add extra controls for mini player + Show extra Song information, such as file format, bitrate and frequency "Can cause playback issues on some devices." Toggle genre tab Toggle home banner style @@ -545,6 +551,7 @@ Colored notification Desaturated color Extra controls + Song info Gapless playback App theme Show genre tab @@ -810,9 +817,4 @@ You will be forwarded to the issue tracker website. Your account data is only used for authentication. - Advanced - Blacklist - No songs playing - Nothing to see - diff --git a/app/src/main/res/xml/pref_ui.xml b/app/src/main/res/xml/pref_ui.xml index 3df9f9d1..f1dac342 100644 --- a/app/src/main/res/xml/pref_ui.xml +++ b/app/src/main/res/xml/pref_ui.xml @@ -49,10 +49,10 @@ android:title="@string/pref_title_home_banner" /> + android:summary="@string/pref_summary_extra_song_info" + android:title="@string/pref_title_extra_song_info" /> diff --git a/appthemehelper/src/main/java/code/name/monkey/appthemehelper/util/ToolbarContentTintHelper.java b/appthemehelper/src/main/java/code/name/monkey/appthemehelper/util/ToolbarContentTintHelper.java index 5fb476c9..3b91f0fb 100755 --- a/appthemehelper/src/main/java/code/name/monkey/appthemehelper/util/ToolbarContentTintHelper.java +++ b/appthemehelper/src/main/java/code/name/monkey/appthemehelper/util/ToolbarContentTintHelper.java @@ -17,7 +17,6 @@ import android.widget.ImageButton; import android.widget.ImageView; import android.widget.ListView; import android.widget.RadioButton; - import androidx.annotation.CheckResult; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; @@ -36,55 +35,266 @@ import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.ToolbarWidgetWrapper; import androidx.core.graphics.drawable.DrawableCompat; - +import code.name.monkey.appthemehelper.R; +import code.name.monkey.appthemehelper.ThemeStore; import java.lang.reflect.Field; import java.util.ArrayList; -import code.name.monkey.appthemehelper.R; -import code.name.monkey.appthemehelper.ThemeStore; - public final class ToolbarContentTintHelper { - private ToolbarContentTintHelper() { - } + public static class InternalToolbarContentTintUtil { - public static void tintAllIcons(Menu menu, final int color) { - for (int i = 0; i < menu.size(); ++i) { - final MenuItem item = menu.getItem(i); - tintMenuItemIcon(color, item); - tintShareIconIfPresent(color, item); - } - } + public static final class SearchViewTintUtil { - private static void tintMenuItemIcon(int color, MenuItem item) { - final Drawable drawable = item.getIcon(); - if (drawable != null) { - final Drawable wrapped = DrawableCompat.wrap(drawable); - drawable.mutate(); - DrawableCompat.setTint(wrapped, color); - item.setIcon(drawable); - } - } + public static void setSearchViewContentColor(View searchView, final @ColorInt int color) { + if (searchView == null) { + return; + } + final Class cls = searchView.getClass(); + try { + final Field mSearchSrcTextViewField = cls.getDeclaredField("mSearchSrcTextView"); + mSearchSrcTextViewField.setAccessible(true); + final EditText mSearchSrcTextView = (EditText) mSearchSrcTextViewField.get(searchView); + mSearchSrcTextView.setTextColor(color); + mSearchSrcTextView.setHintTextColor(ColorUtil.INSTANCE.adjustAlpha(color, 0.5f)); + TintHelper.setCursorTint(mSearchSrcTextView, color); - private static void tintShareIconIfPresent(int color, MenuItem item) { - if (item.getActionView() != null) { - final View actionView = item.getActionView(); - final View expandActivitiesButton = actionView.findViewById(R.id.expand_activities_button); - if (expandActivitiesButton != null) { - final ImageView image = (ImageView) expandActivitiesButton.findViewById(R.id.image); - if (image != null) { - final Drawable drawable = image.getDrawable(); - final Drawable wrapped = DrawableCompat.wrap(drawable); - drawable.mutate(); - DrawableCompat.setTint(wrapped, color); - image.setImageDrawable(drawable); + Field field = cls.getDeclaredField("mSearchButton"); + tintImageView(searchView, field, color); + field = cls.getDeclaredField("mGoButton"); + tintImageView(searchView, field, color); + field = cls.getDeclaredField("mCloseButton"); + tintImageView(searchView, field, color); + field = cls.getDeclaredField("mVoiceButton"); + tintImageView(searchView, field, color); + } catch (Exception e) { + e.printStackTrace(); } } + + private SearchViewTintUtil() { + } + + private static void tintImageView(Object target, Field field, final @ColorInt int color) + throws Exception { + field.setAccessible(true); + final ImageView imageView = (ImageView) field.get(target); + if (imageView.getDrawable() != null) { + imageView + .setImageDrawable( + TintHelper.createTintedDrawable(imageView.getDrawable(), color)); + } + } + } + + public static void applyOverflowMenuTint(final @NonNull Context context, final Toolbar toolbar, + final @ColorInt int color) { + if (toolbar == null) { + return; + } + toolbar.post(new Runnable() { + @Override + public void run() { + try { + Field f1 = Toolbar.class.getDeclaredField("mMenuView"); + f1.setAccessible(true); + ActionMenuView actionMenuView = (ActionMenuView) f1.get(toolbar); + Field f2 = ActionMenuView.class.getDeclaredField("mPresenter"); + f2.setAccessible(true); + + // Actually ActionMenuPresenter + BaseMenuPresenter presenter = (BaseMenuPresenter) f2.get(actionMenuView); + Field f3 = presenter.getClass().getDeclaredField("mOverflowPopup"); + f3.setAccessible(true); + MenuPopupHelper overflowMenuPopupHelper = (MenuPopupHelper) f3.get(presenter); + setTintForMenuPopupHelper(context, overflowMenuPopupHelper, color); + + Field f4 = presenter.getClass().getDeclaredField("mActionButtonPopup"); + f4.setAccessible(true); + MenuPopupHelper subMenuPopupHelper = (MenuPopupHelper) f4.get(presenter); + setTintForMenuPopupHelper(context, subMenuPopupHelper, color); + } catch (Exception e) { + e.printStackTrace(); + } + } + }); + } + + public static void setOverflowButtonColor(@NonNull Activity activity, + final @ColorInt int color) { + final String overflowDescription = activity + .getString(R.string.abc_action_menu_overflow_description); + final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); + final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver(); + viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + final ArrayList outViews = new ArrayList<>(); + decorView.findViewsWithText(outViews, overflowDescription, + View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); + if (outViews.isEmpty()) { + return; + } + final AppCompatImageView overflow = (AppCompatImageView) outViews.get(0); + overflow.setImageDrawable(TintHelper.createTintedDrawable(overflow.getDrawable(), color)); + ViewUtil.INSTANCE.removeOnGlobalLayoutListener(decorView, this); + } + }); + } + + public static void setTintForMenuPopupHelper(final @NonNull Context context, + @Nullable MenuPopupHelper menuPopupHelper, final @ColorInt int color) { + try { + if (menuPopupHelper != null) { + final ListView listView = ((ShowableListMenu) menuPopupHelper.getPopup()).getListView(); + listView.getViewTreeObserver() + .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + try { + Field checkboxField = ListMenuItemView.class.getDeclaredField("mCheckBox"); + checkboxField.setAccessible(true); + Field radioButtonField = ListMenuItemView.class + .getDeclaredField("mRadioButton"); + radioButtonField.setAccessible(true); + + final boolean isDark = !ColorUtil.INSTANCE.isColorLight( + ATHUtil.INSTANCE + .resolveColor(context, android.R.attr.windowBackground)); + + for (int i = 0; i < listView.getChildCount(); i++) { + View v = listView.getChildAt(i); + if (!(v instanceof ListMenuItemView)) { + continue; + } + ListMenuItemView iv = (ListMenuItemView) v; + + CheckBox check = (CheckBox) checkboxField.get(iv); + if (check != null) { + TintHelper.setTint(check, color, isDark); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + check.setBackground(null); + } + } + + RadioButton radioButton = (RadioButton) radioButtonField.get(iv); + if (radioButton != null) { + TintHelper.setTint(radioButton, color, isDark); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + radioButton.setBackground(null); + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + listView.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } else { + //noinspection deprecation + listView.getViewTreeObserver().removeGlobalOnLayoutListener(this); + } + } + }); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + @SuppressWarnings("unchecked") + public static void tintMenu(@NonNull Toolbar toolbar, @Nullable Menu menu, + final @ColorInt int color) { + try { + final Field field = Toolbar.class.getDeclaredField("mCollapseIcon"); + field.setAccessible(true); + Drawable collapseIcon = (Drawable) field.get(toolbar); + if (collapseIcon != null) { + field.set(toolbar, TintHelper.createTintedDrawable(collapseIcon, color)); + } + } catch (Exception e) { + e.printStackTrace(); + } + + if (menu != null && menu.size() > 0) { + for (int i = 0; i < menu.size(); i++) { + final MenuItem item = menu.getItem(i); + if (item.getIcon() != null) { + item.setIcon(TintHelper.createTintedDrawable(item.getIcon(), color)); + } + // Search view theming + if (item.getActionView() != null && ( + item.getActionView() instanceof android.widget.SearchView || item + .getActionView() instanceof androidx.appcompat.widget.SearchView)) { + SearchViewTintUtil.setSearchViewContentColor(item.getActionView(), color); + } + } + } + } + + private InternalToolbarContentTintUtil() { + } + } + + private static class ATHMenuPresenterCallback implements MenuPresenter.Callback { + + private int mColor; + + private Context mContext; + + private MenuPresenter.Callback mParentCb; + + private Toolbar mToolbar; + + public ATHMenuPresenterCallback(Context context, final @ColorInt int color, + MenuPresenter.Callback parentCb, Toolbar toolbar) { + mContext = context; + mColor = color; + mParentCb = parentCb; + mToolbar = toolbar; + } + + @Override + public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { + if (mParentCb != null) { + mParentCb.onCloseMenu(menu, allMenusAreClosing); + } + } + + @Override + public boolean onOpenSubMenu(MenuBuilder subMenu) { + InternalToolbarContentTintUtil.applyOverflowMenuTint(mContext, mToolbar, mColor); + return mParentCb != null && mParentCb.onOpenSubMenu(subMenu); + } + } + + private static class ATHOnMenuItemClickListener implements Toolbar.OnMenuItemClickListener { + + private int mColor; + + private Context mContext; + + private Toolbar.OnMenuItemClickListener mParentListener; + + private Toolbar mToolbar; + + public ATHOnMenuItemClickListener(Context context, final @ColorInt int color, + Toolbar.OnMenuItemClickListener parentCb, Toolbar toolbar) { + mContext = context; + mColor = color; + mParentListener = parentCb; + mToolbar = toolbar; + } + + @Override + public boolean onMenuItemClick(MenuItem item) { + InternalToolbarContentTintUtil.applyOverflowMenuTint(mContext, mToolbar, mColor); + return mParentListener != null && mParentListener.onMenuItemClick(item); } } public static void colorBackButton(@NonNull Toolbar toolbar) { - int color = ATHUtil.INSTANCE.resolveColor(toolbar.getContext(), R.attr.colorControlNormal); + int color = ATHUtil.INSTANCE.resolveColor(toolbar.getContext(), R.attr.colorControlNormal); final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY); for (int i = 0; i < toolbar.getChildCount(); i++) { final View backButton = toolbar.getChildAt(i); @@ -102,7 +312,7 @@ public final class ToolbarContentTintHelper { * @param activity reference to activity needed to register observers */ public static void colorizeToolbar(Toolbar toolbarView, int toolbarIconsColor, - Activity activity) { + Activity activity) { final PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(toolbarIconsColor, PorterDuff.Mode.MULTIPLY); @@ -150,93 +360,64 @@ public final class ToolbarContentTintHelper { } } - /** - * It's important to set overflowDescription atribute in styles, so we can grab the reference to - * the overflow icon. Check: res/values/styles.xml - */ - private static void setOverflowButtonColor(final Activity activity, - final PorterDuffColorFilter colorFilter) { - final String overflowDescription = activity - .getString(R.string.abc_action_menu_overflow_description); - final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); - final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver(); - viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - final ArrayList outViews = new ArrayList(); - decorView.findViewsWithText(outViews, overflowDescription, - View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); - if (outViews.isEmpty()) { - return; - } - final ActionMenuView overflowViewParent = (ActionMenuView) outViews.get(0).getParent(); - overflowViewParent.getOverflowIcon().setColorFilter(colorFilter); - removeOnGlobalLayoutListener(decorView, this); - } - }); + @Nullable + public static Toolbar getSupportActionBarView(@Nullable ActionBar ab) { + if (ab == null || !(ab instanceof WindowDecorActionBar)) { + return null; + } + try { + WindowDecorActionBar decorAb = (WindowDecorActionBar) ab; + Field field = WindowDecorActionBar.class.getDeclaredField("mDecorToolbar"); + field.setAccessible(true); + ToolbarWidgetWrapper wrapper = (ToolbarWidgetWrapper) field.get(decorAb); + field = ToolbarWidgetWrapper.class.getDeclaredField("mToolbar"); + field.setAccessible(true); + return (Toolbar) field.get(wrapper); + } catch (Throwable t) { + throw new RuntimeException( + "Failed to retrieve Toolbar from AppCompat support ActionBar: " + t.getMessage(), t); + } } - private static void setOverflowButtonColor(final Activity activity, final Toolbar toolbar, - final int toolbarIconsColor) { - final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); - final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver(); - viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - - if (toolbar != null && toolbar.getOverflowIcon() != null) { - Drawable bg = DrawableCompat.wrap(toolbar.getOverflowIcon()); - DrawableCompat.setTint(bg, toolbarIconsColor); - } - removeOnGlobalLayoutListener(decorView, this); - } - }); + public static void handleOnCreateOptionsMenu( + @NonNull Context context, + @NonNull Toolbar toolbar, + @NonNull Menu menu, + int toolbarColor) { + setToolbarContentColorBasedOnToolbarColor(context, toolbar, menu, toolbarColor); } - private static void removeOnGlobalLayoutListener(View v, - ViewTreeObserver.OnGlobalLayoutListener listener) { - v.getViewTreeObserver().removeOnGlobalLayoutListener(listener); + public static void handleOnCreateOptionsMenu(Context context, Toolbar toolbar, Menu menu, + @ColorInt int toolbarContentColor, @ColorInt int titleTextColor, + @ColorInt int subtitleTextColor, @ColorInt int menuWidgetColor) { + setToolbarContentColor(context, toolbar, menu, toolbarContentColor, titleTextColor, + subtitleTextColor, menuWidgetColor); } - public static void setToolbarContentColorBasedOnToolbarColor(@NonNull Context context, - Toolbar toolbar, - int toolbarColor) { - setToolbarContentColorBasedOnToolbarColor(context, toolbar, null, toolbarColor); + public static void handleOnPrepareOptionsMenu(Activity activity, Toolbar toolbar) { + handleOnPrepareOptionsMenu(activity, toolbar, ThemeStore.Companion.accentColor(activity)); } - public static void setToolbarContentColorBasedOnToolbarColor(@NonNull Context context, - Toolbar toolbar, - @Nullable Menu menu, - int toolbarColor) { - setToolbarContentColorBasedOnToolbarColor(context, toolbar, menu, toolbarColor, - ThemeStore.Companion.accentColor(context)); - } - - public static void setToolbarContentColorBasedOnToolbarColor(@NonNull Context context, - Toolbar toolbar, - @Nullable Menu menu, - int toolbarColor, - final @ColorInt int menuWidgetColor) { - setToolbarContentColor(context, toolbar, menu, toolbarContentColor(context, toolbarColor), - toolbarTitleColor(context, toolbarColor), toolbarSubtitleColor(context, toolbarColor), - menuWidgetColor); + public static void handleOnPrepareOptionsMenu(Activity activity, Toolbar toolbar, + int widgetColor) { + InternalToolbarContentTintUtil.applyOverflowMenuTint(activity, toolbar, widgetColor); } public static void setToolbarContentColor(@NonNull Context context, Toolbar toolbar, - final @ColorInt int toolbarContentColor, final @ColorInt int primaryTextColor, - final @ColorInt int secondaryTextColor, final @ColorInt int menuWidgetColor) { + final @ColorInt int toolbarContentColor, final @ColorInt int primaryTextColor, + final @ColorInt int secondaryTextColor, final @ColorInt int menuWidgetColor) { setToolbarContentColor(context, toolbar, null, toolbarContentColor, primaryTextColor, secondaryTextColor, menuWidgetColor); } @SuppressWarnings("unchecked") public static void setToolbarContentColor(@NonNull Context context, - Toolbar toolbar, - @Nullable Menu menu, - final @ColorInt int toolbarContentColor, - final @ColorInt int titleTextColor, - final @ColorInt int subtitleTextColor, - final @ColorInt int menuWidgetColor) { + Toolbar toolbar, + @Nullable Menu menu, + final @ColorInt int toolbarContentColor, + final @ColorInt int titleTextColor, + final @ColorInt int subtitleTextColor, + final @ColorInt int menuWidgetColor) { if (toolbar == null) { return; } @@ -258,8 +439,7 @@ public final class ToolbarContentTintHelper { InternalToolbarContentTintUtil.applyOverflowMenuTint(context, toolbar, menuWidgetColor); if (context instanceof Activity) { - InternalToolbarContentTintUtil - .setOverflowButtonColor((Activity) context, toolbarContentColor); + InternalToolbarContentTintUtil.setOverflowButtonColor((Activity) context, toolbarContentColor); } try { @@ -288,7 +468,8 @@ public final class ToolbarContentTintHelper { final Field menuItemClickListener = Toolbar.class .getDeclaredField("mOnMenuItemClickListener"); menuItemClickListener.setAccessible(true); - Toolbar.OnMenuItemClickListener currentClickListener = (Toolbar.OnMenuItemClickListener) menuItemClickListener + Toolbar.OnMenuItemClickListener currentClickListener + = (Toolbar.OnMenuItemClickListener) menuItemClickListener .get(toolbar); if (!(currentClickListener instanceof ATHOnMenuItemClickListener)) { final ATHOnMenuItemClickListener newClickListener = new ATHOnMenuItemClickListener(context, @@ -300,44 +481,38 @@ public final class ToolbarContentTintHelper { } } - @Nullable - public static Toolbar getSupportActionBarView(@Nullable ActionBar ab) { - if (ab == null || !(ab instanceof WindowDecorActionBar)) { - return null; + public static void setToolbarContentColorBasedOnToolbarColor(@NonNull Context context, + Toolbar toolbar, + int toolbarColor) { + setToolbarContentColorBasedOnToolbarColor(context, toolbar, null, toolbarColor); + } + + public static void setToolbarContentColorBasedOnToolbarColor( + @NonNull Context context, + @NonNull Toolbar toolbar, + @Nullable Menu menu, + int toolbarColor) { + setToolbarContentColorBasedOnToolbarColor(context, toolbar, menu, toolbarColor, + ThemeStore.Companion.accentColor(context)); + } + + public static void setToolbarContentColorBasedOnToolbarColor( + @NonNull Context context, + @NonNull Toolbar toolbar, + @Nullable Menu menu, + int toolbarColor, + final @ColorInt int menuWidgetColor) { + setToolbarContentColor(context, toolbar, menu, toolbarContentColor(context, toolbarColor), + toolbarTitleColor(context, toolbarColor), toolbarSubtitleColor(context, toolbarColor), + menuWidgetColor); + } + + public static void tintAllIcons(Menu menu, final int color) { + for (int i = 0; i < menu.size(); ++i) { + final MenuItem item = menu.getItem(i); + tintMenuItemIcon(color, item); + tintShareIconIfPresent(color, item); } - try { - WindowDecorActionBar decorAb = (WindowDecorActionBar) ab; - Field field = WindowDecorActionBar.class.getDeclaredField("mDecorToolbar"); - field.setAccessible(true); - ToolbarWidgetWrapper wrapper = (ToolbarWidgetWrapper) field.get(decorAb); - field = ToolbarWidgetWrapper.class.getDeclaredField("mToolbar"); - field.setAccessible(true); - return (Toolbar) field.get(wrapper); - } catch (Throwable t) { - throw new RuntimeException( - "Failed to retrieve Toolbar from AppCompat support ActionBar: " + t.getMessage(), t); - } - } - - public static void handleOnPrepareOptionsMenu(Activity activity, Toolbar toolbar) { - handleOnPrepareOptionsMenu(activity, toolbar, ThemeStore.Companion.accentColor(activity)); - } - - public static void handleOnPrepareOptionsMenu(Activity activity, Toolbar toolbar, - int widgetColor) { - InternalToolbarContentTintUtil.applyOverflowMenuTint(activity, toolbar, widgetColor); - } - - public static void handleOnCreateOptionsMenu(Context context, Toolbar toolbar, Menu menu, - int toolbarColor) { - setToolbarContentColorBasedOnToolbarColor(context, toolbar, menu, toolbarColor); - } - - public static void handleOnCreateOptionsMenu(Context context, Toolbar toolbar, Menu menu, - @ColorInt int toolbarContentColor, @ColorInt int titleTextColor, - @ColorInt int subtitleTextColor, @ColorInt int menuWidgetColor) { - setToolbarContentColor(context, toolbar, menu, toolbarContentColor, titleTextColor, - subtitleTextColor, menuWidgetColor); } @CheckResult @@ -352,254 +527,90 @@ public final class ToolbarContentTintHelper { @CheckResult @ColorInt public static int toolbarSubtitleColor(@NonNull Context context, @ColorInt int toolbarColor) { - return MaterialValueHelper.INSTANCE.getSecondaryTextColor(context, ColorUtil.INSTANCE.isColorLight(toolbarColor)); + return MaterialValueHelper.INSTANCE + .getSecondaryTextColor(context, ColorUtil.INSTANCE.isColorLight(toolbarColor)); } @CheckResult @ColorInt public static int toolbarTitleColor(@NonNull Context context, @ColorInt int toolbarColor) { - return MaterialValueHelper.INSTANCE.getPrimaryTextColor(context, ColorUtil.INSTANCE.isColorLight(toolbarColor)); + return MaterialValueHelper.INSTANCE + .getPrimaryTextColor(context, ColorUtil.INSTANCE.isColorLight(toolbarColor)); } - private static class ATHMenuPresenterCallback implements MenuPresenter.Callback { - - private Context mContext; - private int mColor; - private MenuPresenter.Callback mParentCb; - private Toolbar mToolbar; - - public ATHMenuPresenterCallback(Context context, final @ColorInt int color, - MenuPresenter.Callback parentCb, Toolbar toolbar) { - mContext = context; - mColor = color; - mParentCb = parentCb; - mToolbar = toolbar; - } - - @Override - public void onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing) { - if (mParentCb != null) { - mParentCb.onCloseMenu(menu, allMenusAreClosing); - } - } - - @Override - public boolean onOpenSubMenu(MenuBuilder subMenu) { - InternalToolbarContentTintUtil.applyOverflowMenuTint(mContext, mToolbar, mColor); - return mParentCb != null && mParentCb.onOpenSubMenu(subMenu); - } + private ToolbarContentTintHelper() { } - private static class ATHOnMenuItemClickListener implements Toolbar.OnMenuItemClickListener { - - private Context mContext; - private int mColor; - private Toolbar.OnMenuItemClickListener mParentListener; - private Toolbar mToolbar; - - public ATHOnMenuItemClickListener(Context context, final @ColorInt int color, - Toolbar.OnMenuItemClickListener parentCb, Toolbar toolbar) { - mContext = context; - mColor = color; - mParentListener = parentCb; - mToolbar = toolbar; - } - - @Override - public boolean onMenuItemClick(MenuItem item) { - InternalToolbarContentTintUtil.applyOverflowMenuTint(mContext, mToolbar, mColor); - return mParentListener != null && mParentListener.onMenuItemClick(item); - } + private static void removeOnGlobalLayoutListener(View v, + ViewTreeObserver.OnGlobalLayoutListener listener) { + v.getViewTreeObserver().removeOnGlobalLayoutListener(listener); } - public static class InternalToolbarContentTintUtil { + private static void setOverflowButtonColor(final Activity activity, final Toolbar toolbar, + final int toolbarIconsColor) { + final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); + final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver(); + viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { - private InternalToolbarContentTintUtil() { - } - - @SuppressWarnings("unchecked") - public static void tintMenu(@NonNull Toolbar toolbar, @Nullable Menu menu, - final @ColorInt int color) { - try { - final Field field = Toolbar.class.getDeclaredField("mCollapseIcon"); - field.setAccessible(true); - Drawable collapseIcon = (Drawable) field.get(toolbar); - if (collapseIcon != null) { - field.set(toolbar, TintHelper.createTintedDrawable(collapseIcon, color)); + if (toolbar != null && toolbar.getOverflowIcon() != null) { + Drawable bg = DrawableCompat.wrap(toolbar.getOverflowIcon()); + DrawableCompat.setTint(bg, toolbarIconsColor); } - } catch (Exception e) { - e.printStackTrace(); + removeOnGlobalLayoutListener(decorView, this); } + }); + } - if (menu != null && menu.size() > 0) { - for (int i = 0; i < menu.size(); i++) { - final MenuItem item = menu.getItem(i); - if (item.getIcon() != null) { - item.setIcon(TintHelper.createTintedDrawable(item.getIcon(), color)); - } - // Search view theming - if (item.getActionView() != null && ( - item.getActionView() instanceof android.widget.SearchView || item - .getActionView() instanceof androidx.appcompat.widget.SearchView)) { - SearchViewTintUtil.setSearchViewContentColor(item.getActionView(), color); - } - } - } - } - - public static void applyOverflowMenuTint(final @NonNull Context context, final Toolbar toolbar, - final @ColorInt int color) { - if (toolbar == null) { - return; - } - toolbar.post(new Runnable() { - @Override - public void run() { - try { - Field f1 = Toolbar.class.getDeclaredField("mMenuView"); - f1.setAccessible(true); - ActionMenuView actionMenuView = (ActionMenuView) f1.get(toolbar); - Field f2 = ActionMenuView.class.getDeclaredField("mPresenter"); - f2.setAccessible(true); - - // Actually ActionMenuPresenter - BaseMenuPresenter presenter = (BaseMenuPresenter) f2.get(actionMenuView); - Field f3 = presenter.getClass().getDeclaredField("mOverflowPopup"); - f3.setAccessible(true); - MenuPopupHelper overflowMenuPopupHelper = (MenuPopupHelper) f3.get(presenter); - setTintForMenuPopupHelper(context, overflowMenuPopupHelper, color); - - Field f4 = presenter.getClass().getDeclaredField("mActionButtonPopup"); - f4.setAccessible(true); - MenuPopupHelper subMenuPopupHelper = (MenuPopupHelper) f4.get(presenter); - setTintForMenuPopupHelper(context, subMenuPopupHelper, color); - } catch (Exception e) { - e.printStackTrace(); - } - } - }); - } - - public static void setTintForMenuPopupHelper(final @NonNull Context context, - @Nullable MenuPopupHelper menuPopupHelper, final @ColorInt int color) { - try { - if (menuPopupHelper != null) { - final ListView listView = ((ShowableListMenu) menuPopupHelper.getPopup()).getListView(); - listView.getViewTreeObserver() - .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - try { - Field checkboxField = ListMenuItemView.class.getDeclaredField("mCheckBox"); - checkboxField.setAccessible(true); - Field radioButtonField = ListMenuItemView.class - .getDeclaredField("mRadioButton"); - radioButtonField.setAccessible(true); - - final boolean isDark = !ColorUtil.INSTANCE.isColorLight( - ATHUtil.INSTANCE.resolveColor(context, android.R.attr.windowBackground)); - - for (int i = 0; i < listView.getChildCount(); i++) { - View v = listView.getChildAt(i); - if (!(v instanceof ListMenuItemView)) { - continue; - } - ListMenuItemView iv = (ListMenuItemView) v; - - CheckBox check = (CheckBox) checkboxField.get(iv); - if (check != null) { - TintHelper.setTint(check, color, isDark); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - check.setBackground(null); - } - } - - RadioButton radioButton = (RadioButton) radioButtonField.get(iv); - if (radioButton != null) { - TintHelper.setTint(radioButton, color, isDark); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - radioButton.setBackground(null); - } - } - } - } catch (Exception e) { - e.printStackTrace(); - } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - listView.getViewTreeObserver().removeOnGlobalLayoutListener(this); - } else { - //noinspection deprecation - listView.getViewTreeObserver().removeGlobalOnLayoutListener(this); - } - } - }); - } - } catch (Exception e) { - e.printStackTrace(); - } - } - - public static void setOverflowButtonColor(@NonNull Activity activity, - final @ColorInt int color) { - final String overflowDescription = activity - .getString(R.string.abc_action_menu_overflow_description); - final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); - final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver(); - viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { - @Override - public void onGlobalLayout() { - final ArrayList outViews = new ArrayList<>(); - decorView.findViewsWithText(outViews, overflowDescription, - View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); - if (outViews.isEmpty()) { - return; - } - final AppCompatImageView overflow = (AppCompatImageView) outViews.get(0); - overflow.setImageDrawable(TintHelper.createTintedDrawable(overflow.getDrawable(), color)); - ViewUtil.INSTANCE.removeOnGlobalLayoutListener(decorView, this); - } - }); - } - - public static final class SearchViewTintUtil { - - private SearchViewTintUtil() { - } - - private static void tintImageView(Object target, Field field, final @ColorInt int color) - throws Exception { - field.setAccessible(true); - final ImageView imageView = (ImageView) field.get(target); - if (imageView.getDrawable() != null) { - imageView - .setImageDrawable( - TintHelper.createTintedDrawable(imageView.getDrawable(), color)); - } - } - - public static void setSearchViewContentColor(View searchView, final @ColorInt int color) { - if (searchView == null) { + /** + * It's important to set overflowDescription atribute in styles, so we can grab the reference to + * the overflow icon. Check: res/values/styles.xml + */ + private static void setOverflowButtonColor(final Activity activity, + final PorterDuffColorFilter colorFilter) { + final String overflowDescription = activity + .getString(R.string.abc_action_menu_overflow_description); + final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView(); + final ViewTreeObserver viewTreeObserver = decorView.getViewTreeObserver(); + viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + final ArrayList outViews = new ArrayList(); + decorView.findViewsWithText(outViews, overflowDescription, + View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION); + if (outViews.isEmpty()) { return; } - final Class cls = searchView.getClass(); - try { - final Field mSearchSrcTextViewField = cls.getDeclaredField("mSearchSrcTextView"); - mSearchSrcTextViewField.setAccessible(true); - final EditText mSearchSrcTextView = (EditText) mSearchSrcTextViewField.get(searchView); - mSearchSrcTextView.setTextColor(color); - mSearchSrcTextView.setHintTextColor(ColorUtil.INSTANCE.adjustAlpha(color, 0.5f)); - TintHelper.setCursorTint(mSearchSrcTextView, color); + final ActionMenuView overflowViewParent = (ActionMenuView) outViews.get(0).getParent(); + overflowViewParent.getOverflowIcon().setColorFilter(colorFilter); + removeOnGlobalLayoutListener(decorView, this); + } + }); + } - Field field = cls.getDeclaredField("mSearchButton"); - tintImageView(searchView, field, color); - field = cls.getDeclaredField("mGoButton"); - tintImageView(searchView, field, color); - field = cls.getDeclaredField("mCloseButton"); - tintImageView(searchView, field, color); - field = cls.getDeclaredField("mVoiceButton"); - tintImageView(searchView, field, color); - } catch (Exception e) { - e.printStackTrace(); + private static void tintMenuItemIcon(int color, MenuItem item) { + final Drawable drawable = item.getIcon(); + if (drawable != null) { + final Drawable wrapped = DrawableCompat.wrap(drawable); + drawable.mutate(); + DrawableCompat.setTint(wrapped, color); + item.setIcon(drawable); + } + } + + private static void tintShareIconIfPresent(int color, MenuItem item) { + if (item.getActionView() != null) { + final View actionView = item.getActionView(); + final View expandActivitiesButton = actionView.findViewById(R.id.expand_activities_button); + if (expandActivitiesButton != null) { + final ImageView image = (ImageView) expandActivitiesButton.findViewById(R.id.image); + if (image != null) { + final Drawable drawable = image.getDrawable(); + final Drawable wrapped = DrawableCompat.wrap(drawable); + drawable.mutate(); + DrawableCompat.setTint(wrapped, color); + image.setImageDrawable(drawable); } } }