From 9a3824588e8507093dc008d00ebbbeb28c4067d6 Mon Sep 17 00:00:00 2001 From: Andrii Chubko Date: Mon, 23 Aug 2021 03:31:31 +0300 Subject: [PATCH 1/4] Add repeat_off playback option --- .../musicplayer/activities/TrackActivity.kt | 6 +++++ .../musicplayer/helpers/Config.kt | 2 +- .../musicplayer/helpers/PlaybackSetting.kt | 7 +++++- .../musicplayer/services/MusicService.kt | 23 +++++++++++++++++++ app/src/main/res/values-az/strings.xml | 1 + app/src/main/res/values-cs/strings.xml | 1 + app/src/main/res/values-da/strings.xml | 1 + app/src/main/res/values-de/strings.xml | 1 + app/src/main/res/values-el/strings.xml | 1 + app/src/main/res/values-es/strings.xml | 1 + app/src/main/res/values-eu/strings.xml | 1 + app/src/main/res/values-fa/strings.xml | 1 + app/src/main/res/values-fi/strings.xml | 1 + app/src/main/res/values-fr/strings.xml | 1 + app/src/main/res/values-gl/strings.xml | 1 + app/src/main/res/values-hr/strings.xml | 1 + app/src/main/res/values-hu/strings.xml | 1 + app/src/main/res/values-id/strings.xml | 1 + app/src/main/res/values-in/strings.xml | 1 + app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-ko-rKR/strings.xml | 1 + app/src/main/res/values-lt/strings.xml | 1 + app/src/main/res/values-ms/strings.xml | 1 + app/src/main/res/values-nl/strings.xml | 1 + app/src/main/res/values-pl/strings.xml | 1 + app/src/main/res/values-pt/strings.xml | 1 + app/src/main/res/values-ru/strings.xml | 1 + app/src/main/res/values-sk/strings.xml | 1 + app/src/main/res/values-sv/strings.xml | 1 + app/src/main/res/values-tr/strings.xml | 1 + app/src/main/res/values-uk/strings.xml | 1 + app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 35 files changed, 67 insertions(+), 2 deletions(-) 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 2ea17e6b..78907d20 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/TrackActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/TrackActivity.kt @@ -13,6 +13,7 @@ import android.view.MotionEvent import android.view.View import android.widget.SeekBar import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.content.ContextCompat import androidx.core.view.GestureDetectorCompat import com.bumptech.glide.Glide import com.bumptech.glide.load.DataSource @@ -310,6 +311,11 @@ class TrackActivity : SimpleActivity(), PlaybackSpeedListener { activity_track_playback_setting.apply { contentDescription = getString(playbackSetting.contentDescriptionStringRes) setImageResource(playbackSetting.iconRes) + + val isRepeatOff = playbackSetting == PlaybackSetting.REPEAT_OFF + + alpha = if (isRepeatOff) MEDIUM_ALPHA else 1f + applyColorFilter(if (isRepeatOff) config.textColor else getAdjustedPrimaryColor()) } } 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 85d93174..0343fdb2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/Config.kt @@ -13,7 +13,7 @@ class Config(context: Context) : BaseConfig(context) { set(shuffle) = prefs.edit().putBoolean(SHUFFLE, shuffle).apply() var playbackSetting: PlaybackSetting - get() = PlaybackSetting.values()[prefs.getInt(PLAYBACK_SETTING, PlaybackSetting.REPEAT_PLAYLIST.ordinal)] + get() = PlaybackSetting.values()[prefs.getInt(PLAYBACK_SETTING, PlaybackSetting.REPEAT_OFF.ordinal)] set(playbackSetting) = prefs.edit().putInt(PLAYBACK_SETTING, playbackSetting.ordinal).apply() var autoplay: Boolean diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/PlaybackSetting.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/PlaybackSetting.kt index ff413d91..3b237fb6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/PlaybackSetting.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/PlaybackSetting.kt @@ -8,6 +8,10 @@ enum class PlaybackSetting( @DrawableRes val iconRes: Int, @StringRes val descriptionStringRes: Int ) { + REPEAT_OFF( + iconRes = R.drawable.ic_repeat_playlist_vector, + descriptionStringRes = R.string.repeat_off + ), REPEAT_PLAYLIST( iconRes = R.drawable.ic_repeat_playlist_vector, descriptionStringRes = R.string.repeat_playlist @@ -26,8 +30,9 @@ enum class PlaybackSetting( val nextPlaybackOption: PlaybackSetting get() = when (this) { + REPEAT_OFF -> REPEAT_PLAYLIST REPEAT_PLAYLIST -> REPEAT_SONG REPEAT_SONG -> STOP_AFTER_CURRENT_SONG - STOP_AFTER_CURRENT_SONG -> REPEAT_PLAYLIST + STOP_AFTER_CURRENT_SONG -> REPEAT_OFF } } 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 c7b691fd..8d3b8cd1 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt @@ -540,6 +540,13 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr } } + private fun isEndOfPlaylist(): Boolean { + return when (mTracks.size) { + 0, 1 -> true + else -> mCurrTrack?.mediaStoreId == mTracks.last().mediaStoreId + } + } + private fun playPreviousTrack() { if (mTracks.isEmpty()) { handleEmptyPlaylist() @@ -592,6 +599,14 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr } } + private fun setupNextTrackAndStop() { + mPlayer?.seekTo(0) + broadcastTrackProgress(0) + + mPlayOnPrepare = false + setupNextTrack() + } + private fun restartTrack() { if (mCurrTrack != null) { setTrack(mCurrTrack!!.mediaStoreId) @@ -668,11 +683,19 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr val playbackSetting = config.playbackSetting mPlayOnPrepare = when (playbackSetting) { + PlaybackSetting.REPEAT_OFF -> isEndOfPlaylist().not() PlaybackSetting.REPEAT_PLAYLIST, PlaybackSetting.REPEAT_SONG -> true PlaybackSetting.STOP_AFTER_CURRENT_SONG -> false } when (config.playbackSetting) { + PlaybackSetting.REPEAT_OFF -> { + if (isEndOfPlaylist()) { + setupNextTrackAndStop() + } else { + setupNextTrack() + } + } PlaybackSetting.REPEAT_PLAYLIST -> setupNextTrack() PlaybackSetting.REPEAT_SONG -> restartTrack() PlaybackSetting.STOP_AFTER_CURRENT_SONG -> { diff --git a/app/src/main/res/values-az/strings.xml b/app/src/main/res/values-az/strings.xml index ed768e1b..c5a4e05e 100644 --- a/app/src/main/res/values-az/strings.xml +++ b/app/src/main/res/values-az/strings.xml @@ -5,6 +5,7 @@ Yenidən adlandır Yenidən adlandırarkən xəta baş verdi Xahiş olunur bütün yerləri doldurun + Repeat off Hazırki musiqini təkrarla Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-cs/strings.xml b/app/src/main/res/values-cs/strings.xml index c07cc8e3..56fb74f0 100644 --- a/app/src/main/res/values-cs/strings.xml +++ b/app/src/main/res/values-cs/strings.xml @@ -5,6 +5,7 @@ Přejmenovat skladbu Během přejmenování došlo k chybě Prosím vyplňte všechna pole + Repeat off Opakovat aktuální skladbu Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-da/strings.xml b/app/src/main/res/values-da/strings.xml index 3cebd2c4..931da9e1 100644 --- a/app/src/main/res/values-da/strings.xml +++ b/app/src/main/res/values-da/strings.xml @@ -5,6 +5,7 @@ Omdøb sang En fejl opstod under omdøbningen Udfyld venligst alle felter + Repeat off Gentag den valgte sang Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index eabe1727..bad79c5e 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -5,6 +5,7 @@ Song umbenennen Während des Umbenennens ist ein Fehler aufgetreten Fülle bitte alle Felder aus + Repeat off Aktuellen Song wiederholen Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-el/strings.xml b/app/src/main/res/values-el/strings.xml index 974ec18a..e21fb80d 100644 --- a/app/src/main/res/values-el/strings.xml +++ b/app/src/main/res/values-el/strings.xml @@ -5,6 +5,7 @@ Μετονομασία τραγουδιού Παρουσιάστηκε σφάλμα κατά τη μετονομασία Συμπληρώστε όλα τα πεδία + Repeat off Επανάληψη τρέχοντος τραγουδιού Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-es/strings.xml b/app/src/main/res/values-es/strings.xml index 5f5a2a28..07e45592 100644 --- a/app/src/main/res/values-es/strings.xml +++ b/app/src/main/res/values-es/strings.xml @@ -5,6 +5,7 @@ Renombrar canción Ha ocurrido un error durante el renombrado Por favor, rellene todos los campos + Repeat off Repetir la canción actual Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-eu/strings.xml b/app/src/main/res/values-eu/strings.xml index a666bcd2..d0385a92 100644 --- a/app/src/main/res/values-eu/strings.xml +++ b/app/src/main/res/values-eu/strings.xml @@ -5,6 +5,7 @@ Abestia berrizendatu Akats bat gertatu da berrizendatzerakoan Mesedez, eremu guztiak bete itzazu + Repeat off Uneko abestia errepikatu Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-fa/strings.xml b/app/src/main/res/values-fa/strings.xml index f73d903c..a82ba9db 100644 --- a/app/src/main/res/values-fa/strings.xml +++ b/app/src/main/res/values-fa/strings.xml @@ -6,6 +6,7 @@ تغییر نام آهنگ هنگام تغییر نام خطایی روی داد لطفا همه موارد را پر کنید + Repeat off تکرار آهنگ فعلی Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-fi/strings.xml b/app/src/main/res/values-fi/strings.xml index 2cb276dc..44e404fa 100644 --- a/app/src/main/res/values-fi/strings.xml +++ b/app/src/main/res/values-fi/strings.xml @@ -5,6 +5,7 @@ Nimeä kappale uudelleen Nimeämisen aikana tapahtui virhe Täytä kaikki kentät + Repeat off Toista nykyinen kappale Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index ab22742f..67577660 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -5,6 +5,7 @@ Renommer la chanson Une erreur s\'est produite lors du changement de nom Veuillez remplir tous les champs + Repeat off Répéter la chanson en cours Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-gl/strings.xml b/app/src/main/res/values-gl/strings.xml index 6663dc70..cd1cde65 100644 --- a/app/src/main/res/values-gl/strings.xml +++ b/app/src/main/res/values-gl/strings.xml @@ -5,6 +5,7 @@ Renomear canción Algo fallou ao renomear Por favor complete todos os campos + Repeat off Repetir a canción actual Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-hr/strings.xml b/app/src/main/res/values-hr/strings.xml index 5afd03e6..e5d1c700 100644 --- a/app/src/main/res/values-hr/strings.xml +++ b/app/src/main/res/values-hr/strings.xml @@ -5,6 +5,7 @@ Preimenuj pjesmu Došlo je do pogreške prilikom preimenovanja Ispunite sva polja + Repeat off Ponovi trenutnu pjesmu Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-hu/strings.xml b/app/src/main/res/values-hu/strings.xml index 50848e45..718fa121 100644 --- a/app/src/main/res/values-hu/strings.xml +++ b/app/src/main/res/values-hu/strings.xml @@ -5,6 +5,7 @@ Szám átnevezése Hiba történt az átnevezés során Töltse ki az összes mezőt + Repeat off Jelenlegi szám ismétlése Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-id/strings.xml b/app/src/main/res/values-id/strings.xml index 67c5a0fd..2197fde7 100644 --- a/app/src/main/res/values-id/strings.xml +++ b/app/src/main/res/values-id/strings.xml @@ -5,6 +5,7 @@ Ubah nama lagu Terjadi kesalahan saat mengubah nama Silakan isi semua ruas + Repeat off Ulangi lagi ini Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-in/strings.xml b/app/src/main/res/values-in/strings.xml index 67c5a0fd..2197fde7 100644 --- a/app/src/main/res/values-in/strings.xml +++ b/app/src/main/res/values-in/strings.xml @@ -5,6 +5,7 @@ Ubah nama lagu Terjadi kesalahan saat mengubah nama Silakan isi semua ruas + Repeat off Ulangi lagi ini Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 21202859..f07e53cb 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -5,6 +5,7 @@ Rinomina brano Impossibile rinominare Completare tutti i campi + Repeat off Ripeti il brano attuale Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 1f0bd607..eeb91b63 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -5,6 +5,7 @@ 曲の名前を変更 名前を変更中にエラーが発生しました すべてのフィールドを入力してください + Repeat off 現在の曲を繰り返し Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-ko-rKR/strings.xml b/app/src/main/res/values-ko-rKR/strings.xml index db71ce0d..fba39f5e 100644 --- a/app/src/main/res/values-ko-rKR/strings.xml +++ b/app/src/main/res/values-ko-rKR/strings.xml @@ -5,6 +5,7 @@ 음악파일명 변경 이름변경 중 오류발생 모든 항목 정보를 입력하세요. + Repeat off 현재 노래 반복 Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-lt/strings.xml b/app/src/main/res/values-lt/strings.xml index ecd42a5a..6f8203f5 100644 --- a/app/src/main/res/values-lt/strings.xml +++ b/app/src/main/res/values-lt/strings.xml @@ -5,6 +5,7 @@ Pervardinti dainą Įvyko klaida pervardinant Prašome užpildyti visus laukelius + Repeat off Pakartoti dabartinę dainą Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-ms/strings.xml b/app/src/main/res/values-ms/strings.xml index fbc06acf..1ae2326b 100644 --- a/app/src/main/res/values-ms/strings.xml +++ b/app/src/main/res/values-ms/strings.xml @@ -5,6 +5,7 @@ Namakan semula lagu Ralat berlaku semasa proses penamaan Sila isi semua bidang + Repeat off Ulangi lagu semasa Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-nl/strings.xml b/app/src/main/res/values-nl/strings.xml index e1d07db5..8e3c7274 100644 --- a/app/src/main/res/values-nl/strings.xml +++ b/app/src/main/res/values-nl/strings.xml @@ -5,6 +5,7 @@ Nummer hernoemen Naam kon niet worden gewijzigd Vul alle velden in + Repeat off Nummer herhalen Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 7a05c584..19f14ef8 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -5,6 +5,7 @@ Zmień nazwę Wystąpił błąd podczas zmiany nazwy Wypełnij wszystkie pola + Repeat off Powtarzaj bieżący utwór Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index 354349d0..d41c9caa 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -5,6 +5,7 @@ Renomear música Ocorreu um erro ao renomear Por favor preencha todos os campos + Repeat off Repetir faixa atual Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index e73ce6b9..2b9adde6 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -5,6 +5,7 @@ Переименовать композицию Во время переименования произошла ошибка Пожалуйста, заполните все поля + Повтор выключен Повторять текущую композицию Повторять всё Остановить воспроизведение после текущей композиции diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index 5881f63b..a1a0977a 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -5,6 +5,7 @@ Premenovať pesničku Počas premenúvania došlo k chybe Prosím vyplňte všetky polia + Repeat off Opakovať súčasnú pesničku Opakovať playlist Zastaviť prehrávanie po tejto skladbe diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index f5658275..2beafa55 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -5,6 +5,7 @@ Byt namn på låt Ett fel uppstod under namnbytet Du måste fylla i alla fält + Repeat off Repetera nuvarande låt Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-tr/strings.xml b/app/src/main/res/values-tr/strings.xml index 6b13dd87..32585a73 100644 --- a/app/src/main/res/values-tr/strings.xml +++ b/app/src/main/res/values-tr/strings.xml @@ -5,6 +5,7 @@ Şarkıyı yeniden adlandır Yeniden adlandırma sırasında bir hata oluştu lütfen tüm boşlukları doldurun + Repeat off Geçerli şarkıyı tekrarla Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-uk/strings.xml b/app/src/main/res/values-uk/strings.xml index 92e687ec..1eb43344 100644 --- a/app/src/main/res/values-uk/strings.xml +++ b/app/src/main/res/values-uk/strings.xml @@ -5,6 +5,7 @@ Перейменувати пісню Трапилася помилка під час перейменування Будь ласка, заповніть всі поля + Повтор вимкнено Повторювати поточну пісню Повторювати список Зупинити відтворення після поточної пісні diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index 614bc85a..c0925439 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -5,6 +5,7 @@ 重命名歌曲 在重命名过程中发生错误 请填写全部字段 + Repeat off 重复当前歌曲 Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 0bd8ff71..9457142b 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -5,6 +5,7 @@ 重新命名歌曲 重新命名時發生錯誤 請填入全部欄位 + Repeat off 重播當前歌曲 Repeat playlist Stop playback after current song diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e51d4ba2..806d5535 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -5,6 +5,7 @@ Rename song An error occurred during the renaming Please fill in all fields + Repeat off Repeat current song Repeat all Stop playback after current song From e92ba9ab9ddba64586b90e271a7be285a3954040 Mon Sep 17 00:00:00 2001 From: Andrii Chubko Date: Mon, 23 Aug 2021 03:34:44 +0300 Subject: [PATCH 2/4] Change 'song' to 'track' in code --- .../musicplayer/helpers/PlaybackSetting.kt | 10 +++++----- .../musicplayer/services/MusicService.kt | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/PlaybackSetting.kt b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/PlaybackSetting.kt index 3b237fb6..dc3c0cee 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/PlaybackSetting.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/helpers/PlaybackSetting.kt @@ -16,11 +16,11 @@ enum class PlaybackSetting( iconRes = R.drawable.ic_repeat_playlist_vector, descriptionStringRes = R.string.repeat_playlist ), - REPEAT_SONG( + REPEAT_TRACK( iconRes = R.drawable.ic_repeat_one_song_vector, descriptionStringRes = R.string.repeat_song ), - STOP_AFTER_CURRENT_SONG( + STOP_AFTER_CURRENT_TRACK( iconRes = R.drawable.ic_play_one_song_vector, descriptionStringRes = R.string.stop_playback_after_current_song ); @@ -31,8 +31,8 @@ enum class PlaybackSetting( val nextPlaybackOption: PlaybackSetting get() = when (this) { REPEAT_OFF -> REPEAT_PLAYLIST - REPEAT_PLAYLIST -> REPEAT_SONG - REPEAT_SONG -> STOP_AFTER_CURRENT_SONG - STOP_AFTER_CURRENT_SONG -> REPEAT_OFF + REPEAT_PLAYLIST -> REPEAT_TRACK + REPEAT_TRACK -> STOP_AFTER_CURRENT_TRACK + STOP_AFTER_CURRENT_TRACK -> REPEAT_OFF } } 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 8d3b8cd1..253cfad2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt @@ -684,8 +684,8 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr mPlayOnPrepare = when (playbackSetting) { PlaybackSetting.REPEAT_OFF -> isEndOfPlaylist().not() - PlaybackSetting.REPEAT_PLAYLIST, PlaybackSetting.REPEAT_SONG -> true - PlaybackSetting.STOP_AFTER_CURRENT_SONG -> false + PlaybackSetting.REPEAT_PLAYLIST, PlaybackSetting.REPEAT_TRACK -> true + PlaybackSetting.STOP_AFTER_CURRENT_TRACK -> false } when (config.playbackSetting) { @@ -697,8 +697,8 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr } } PlaybackSetting.REPEAT_PLAYLIST -> setupNextTrack() - PlaybackSetting.REPEAT_SONG -> restartTrack() - PlaybackSetting.STOP_AFTER_CURRENT_SONG -> { + PlaybackSetting.REPEAT_TRACK -> restartTrack() + PlaybackSetting.STOP_AFTER_CURRENT_TRACK -> { broadcastTrackProgress(0) restartTrack() } From d2a088a175f9254a9c3ae1a4263b3e3a86a245c5 Mon Sep 17 00:00:00 2001 From: Andrii Chubko Date: Tue, 24 Aug 2021 13:46:34 +0300 Subject: [PATCH 3/4] Simplify code --- .../musicplayer/activities/TrackActivity.kt | 17 +++++++++-- .../musicplayer/services/MusicService.kt | 29 +++++++++---------- 2 files changed, 27 insertions(+), 19 deletions(-) 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 78907d20..6f45b3ad 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/TrackActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/activities/TrackActivity.kt @@ -13,7 +13,6 @@ import android.view.MotionEvent import android.view.View import android.widget.SeekBar import androidx.constraintlayout.widget.ConstraintLayout -import androidx.core.content.ContextCompat import androidx.core.view.GestureDetectorCompat import com.bumptech.glide.Glide import com.bumptech.glide.load.DataSource @@ -209,7 +208,13 @@ class TrackActivity : SimpleActivity(), PlaybackSpeedListener { return true } - override fun onResourceReady(resource: Drawable, model: Any?, target: Target?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { + override fun onResourceReady( + resource: Drawable, + model: Any?, + target: Target?, + dataSource: DataSource?, + isFirstResource: Boolean + ): Boolean { next_track_image.setImageDrawable(resource) return false } @@ -243,7 +248,13 @@ class TrackActivity : SimpleActivity(), PlaybackSpeedListener { return true } - override fun onResourceReady(resource: Drawable, model: Any?, target: Target?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { + override fun onResourceReady( + resource: Drawable, + model: Any?, + target: Target?, + dataSource: DataSource?, + isFirstResource: Boolean + ): Boolean { val coverHeight = resource.intrinsicHeight if (coverHeight > 0 && activity_track_image.height != coverHeight) { activity_track_image.layoutParams.height = coverHeight 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 253cfad2..9a5f7ad8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/musicplayer/services/MusicService.kt @@ -463,9 +463,11 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr .setOngoing(ongoing) .setChannelId(NOTIFICATION_CHANNEL) .setCategory(Notification.CATEGORY_SERVICE) - .setStyle(androidx.media.app.NotificationCompat.MediaStyle() - .setShowActionsInCompactView(0, 1, 2) - .setMediaSession(mMediaSession?.sessionToken)) + .setStyle( + androidx.media.app.NotificationCompat.MediaStyle() + .setShowActionsInCompactView(0, 1, 2) + .setMediaSession(mMediaSession?.sessionToken) + ) .setDeleteIntent(notificationDismissedPendingIntent) .addAction(R.drawable.ic_previous_vector, getString(R.string.previous), getIntent(PREVIOUS)) .addAction(playPauseIcon, getString(R.string.playpause), getIntent(PLAYPAUSE)) @@ -482,9 +484,11 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr val playbackState = if (getIsPlaying()) PlaybackStateCompat.STATE_PLAYING else PlaybackStateCompat.STATE_PAUSED try { - mMediaSession!!.setPlaybackState(PlaybackStateCompat.Builder() - .setState(playbackState, PLAYBACK_POSITION_UNKNOWN, 1.0f) - .build()) + mMediaSession!!.setPlaybackState( + PlaybackStateCompat.Builder() + .setState(playbackState, PLAYBACK_POSITION_UNKNOWN, 1.0f) + .build() + ) } catch (ignored: IllegalStateException) { } } @@ -599,14 +603,6 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr } } - private fun setupNextTrackAndStop() { - mPlayer?.seekTo(0) - broadcastTrackProgress(0) - - mPlayOnPrepare = false - setupNextTrack() - } - private fun restartTrack() { if (mCurrTrack != null) { setTrack(mCurrTrack!!.mediaStoreId) @@ -683,7 +679,7 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr val playbackSetting = config.playbackSetting mPlayOnPrepare = when (playbackSetting) { - PlaybackSetting.REPEAT_OFF -> isEndOfPlaylist().not() + PlaybackSetting.REPEAT_OFF -> !isEndOfPlaylist() PlaybackSetting.REPEAT_PLAYLIST, PlaybackSetting.REPEAT_TRACK -> true PlaybackSetting.STOP_AFTER_CURRENT_TRACK -> false } @@ -691,7 +687,8 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr when (config.playbackSetting) { PlaybackSetting.REPEAT_OFF -> { if (isEndOfPlaylist()) { - setupNextTrackAndStop() + broadcastTrackProgress(0) + setupNextTrack() } else { setupNextTrack() } From 2578f8973efd78aac4b463127d1cfcdec424c20c Mon Sep 17 00:00:00 2001 From: Tibor Kaputa Date: Tue, 24 Aug 2021 14:17:12 +0200 Subject: [PATCH 4/4] Update strings.xml --- app/src/main/res/values-sk/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index a1a0977a..6704db7d 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -5,7 +5,7 @@ Premenovať pesničku Počas premenúvania došlo k chybe Prosím vyplňte všetky polia - Repeat off + Opakovanie vypnuté Opakovať súčasnú pesničku Opakovať playlist Zastaviť prehrávanie po tejto skladbe