From 714158d3e9a2b1ba7f203c63c598cca7f81bdfdc Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 8 Oct 2020 22:35:42 +0200 Subject: [PATCH] allow skipping forward/backward by pressing the current/max track progress --- .../musicplayer/activities/MainActivity.kt | 6 ++-- .../musicplayer/activities/TrackActivity.kt | 30 ++++++++++--------- .../musicplayer/adapters/OldSongAdapter.kt | 4 +-- .../musicplayer/fragments/SongsFragment.kt | 10 +++---- .../musicplayer/helpers/Config.kt | 2 +- .../musicplayer/models/Events.kt | 2 +- .../musicplayer/services/MusicService.kt | 4 +-- 7 files changed, 30 insertions(+), 28 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt index a75618a1..702ea229 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/MainActivity.kt @@ -222,7 +222,7 @@ class MainActivity : SimpleActivity(), MainActivityInterface { } ) - val tabLabels = arrayOf("PLAYER", "PLAYLISTS", "ARTISTS") + val tabLabels = arrayOf("ARTISTS", "PLAYLISTS") main_tabs_holder.apply { setTabTextColors(config.backgroundColor.getContrastColor(), getAdjustedPrimaryColor()) setSelectedTabIndicatorColor(getAdjustedPrimaryColor()) @@ -464,14 +464,14 @@ class MainActivity : SimpleActivity(), MainActivityInterface { } @Subscribe(threadMode = ThreadMode.MAIN) - fun songChangedEvent(event: Events.TrackChanged) { + fun trackChangedEvent(event: Events.TrackChanged) { if (wasInitialPlaylistSet) { getCurrentFragment()?.songChangedEvent(event.track) } } @Subscribe(threadMode = ThreadMode.MAIN) - fun songStateChanged(event: Events.SongStateChanged) { + fun trackStateChanged(event: Events.TrackStateChanged) { getCurrentFragment()?.songStateChanged(event.isPlaying) } diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/TrackActivity.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/TrackActivity.kt index 3b9dcc6c..d3376f8f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/TrackActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/TrackActivity.kt @@ -86,9 +86,11 @@ class TrackActivity : SimpleActivity() { activity_track_previous.setOnClickListener { sendIntent(PREVIOUS) } activity_track_play_pause.setOnClickListener { sendIntent(PLAYPAUSE) } activity_track_next.setOnClickListener { sendIntent(NEXT) } - activity_track_repeat.setOnClickListener { toggleSongRepetition() } + activity_track_progress_current.setOnClickListener { sendIntent(SKIP_BACKWARD) } + activity_track_progress_max.setOnClickListener { sendIntent(SKIP_FORWARD) } + activity_track_repeat.setOnClickListener { toggleTrackRepetition() } setupShuffleButton() - setupSongRepetitionButton() + setupTrackRepetitionButton() setupSeekbar() } @@ -127,19 +129,19 @@ class TrackActivity : SimpleActivity() { } } - private fun toggleSongRepetition() { - val repeatSong = !config.repeatSong - config.repeatSong = repeatSong - toast(if (repeatSong) R.string.song_repetition_enabled else R.string.song_repetition_disabled) - setupSongRepetitionButton() + private fun toggleTrackRepetition() { + val repeatTrack = !config.repeatTrack + config.repeatTrack = repeatTrack + toast(if (repeatTrack) R.string.song_repetition_enabled else R.string.song_repetition_disabled) + setupTrackRepetitionButton() } - private fun setupSongRepetitionButton() { - val repeatSong = config.repeatSong + private fun setupTrackRepetitionButton() { + val repeatTrack = config.repeatTrack activity_track_repeat.apply { - applyColorFilter(if (repeatSong) getAdjustedPrimaryColor() else config.textColor) - alpha = if (repeatSong) 1f else LOWER_ALPHA - contentDescription = getString(if (repeatSong) R.string.disable_song_repetition else R.string.enable_song_repetition) + applyColorFilter(if (repeatTrack) getAdjustedPrimaryColor() else config.textColor) + alpha = if (repeatTrack) 1f else LOWER_ALPHA + contentDescription = getString(if (repeatTrack) R.string.disable_song_repetition else R.string.enable_song_repetition) } } @@ -174,13 +176,13 @@ class TrackActivity : SimpleActivity() { } @Subscribe(threadMode = ThreadMode.MAIN) - fun songStateChanged(event: Events.SongStateChanged) { + fun trackStateChanged(event: Events.TrackStateChanged) { val drawableId = if (event.isPlaying) R.drawable.ic_pause_vector else R.drawable.ic_play_vector activity_track_play_pause.setImageDrawable(resources.getDrawable(drawableId)) } @Subscribe(threadMode = ThreadMode.MAIN) - fun songChangedEvent(event: Events.TrackChanged) { + fun trackChangedEvent(event: Events.TrackChanged) { val track = event.track if (track == null) { finish() diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/OldSongAdapter.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/OldSongAdapter.kt index 758e573f..4deff9c1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/OldSongAdapter.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/adapters/OldSongAdapter.kt @@ -430,8 +430,8 @@ class OldSongAdapter(activity: SimpleActivity, var songs: ArrayList, val shuffle_btn.applyColorFilter(if (config.isShuffleEnabled) adjustedPrimaryColor else textColor) shuffle_btn.alpha = if (config.isShuffleEnabled) 1f else LOWER_ALPHA - repeat_btn.applyColorFilter(if (config.repeatSong) adjustedPrimaryColor else textColor) - repeat_btn.alpha = if (config.repeatSong) 1f else LOWER_ALPHA + repeat_btn.applyColorFilter(if (config.repeatTrack) adjustedPrimaryColor else textColor) + repeat_btn.alpha = if (config.repeatTrack) 1f else LOWER_ALPHA song_info_title.setTextColor(textColor) song_info_artist.setTextColor(textColor) diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/fragments/SongsFragment.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/fragments/SongsFragment.kt index eb91ff8c..0eae100a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/fragments/SongsFragment.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/fragments/SongsFragment.kt @@ -165,8 +165,8 @@ class SongsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF } override fun toggleSongRepetition() { - val repeatSong = !config.repeatSong - config.repeatSong = repeatSong + val repeatSong = !config.repeatTrack + config.repeatTrack = repeatSong repeat_btn.applyColorFilter(if (repeatSong) activity.getAdjustedPrimaryColor() else config.textColor) repeat_btn.alpha = if (repeatSong) 1f else LOWER_ALPHA repeat_btn.contentDescription = activity.getString(if (repeatSong) R.string.disable_song_repetition else R.string.enable_song_repetition) @@ -189,8 +189,8 @@ class SongsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF shuffle_btn.applyColorFilter(if (config.isShuffleEnabled) activity.getAdjustedPrimaryColor() else config.textColor) shuffle_btn.alpha = if (config.isShuffleEnabled) 1f else LOWER_ALPHA - repeat_btn.applyColorFilter(if (config.repeatSong) activity.getAdjustedPrimaryColor() else config.textColor) - repeat_btn.alpha = if (config.repeatSong) 1f else LOWER_ALPHA + repeat_btn.applyColorFilter(if (config.repeatTrack) activity.getAdjustedPrimaryColor() else config.textColor) + repeat_btn.alpha = if (config.repeatTrack) 1f else LOWER_ALPHA getSongsAdapter()?.updateTextColor(textColor) songs_fastscroller.updatePrimaryColor() @@ -198,7 +198,7 @@ class SongsFragment(context: Context, attributeSet: AttributeSet) : MyViewPagerF private fun setupIconDescriptions() { shuffle_btn.contentDescription = activity.getString(if (config.isShuffleEnabled) R.string.disable_shuffle else R.string.enable_shuffle) - repeat_btn.contentDescription = activity.getString(if (config.repeatSong) R.string.disable_song_repetition else R.string.enable_song_repetition) + repeat_btn.contentDescription = activity.getString(if (config.repeatTrack) R.string.disable_song_repetition else R.string.enable_song_repetition) } private fun songPicked(pos: Int) { diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Config.kt index 72bbaf34..ebc30a13 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Config.kt @@ -20,7 +20,7 @@ class Config(context: Context) : BaseConfig(context) { get() = prefs.getInt(CURRENT_PLAYLIST, ALL_TRACKS_PLAYLIST_ID) set(currentPlaylist) = prefs.edit().putInt(CURRENT_PLAYLIST, currentPlaylist).apply() - var repeatSong: Boolean + var repeatTrack: Boolean get() = prefs.getBoolean(REPEAT_TRACK, false) set(repeat) = prefs.edit().putBoolean(REPEAT_TRACK, repeat).apply() diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/Events.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/Events.kt index 9d03b8fe..8ef8ae4d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/Events.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/models/Events.kt @@ -4,7 +4,7 @@ import java.util.* class Events { class TrackChanged(val track: Track?) - class SongStateChanged(val isPlaying: Boolean) + class TrackStateChanged(val isPlaying: Boolean) class PlaylistUpdated(val tracks: ArrayList) class ProgressUpdated(val progress: Int) class SleepTimerChanged(val seconds: Int) diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt index 8b67e054..1aaff761 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt @@ -709,7 +709,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr return } - if (config.repeatSong) { + if (config.repeatTrack) { restartTrack() } else if (mPlayer!!.currentPosition > 0) { mPlayer!!.reset() @@ -753,7 +753,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr private fun broadcastTrackStateChange(isPlaying: Boolean) { broadcastUpdateWidgetTrackState(isPlaying) - EventBus.getDefault().post(Events.SongStateChanged(isPlaying)) + EventBus.getDefault().post(Events.TrackStateChanged(isPlaying)) } // do not just return the album cover, but also a boolean to indicate if it a real cover, or just the placeholder