Add repeat_off playback option

This commit is contained in:
Andrii Chubko 2021-08-23 03:31:31 +03:00
parent 6b014db4cf
commit 9a3824588e
35 changed files with 67 additions and 2 deletions

View file

@ -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())
}
}

View file

@ -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

View file

@ -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
}
}

View file

@ -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 -> {

View file

@ -5,6 +5,7 @@
<string name="rename_song">Yenidən adlandır</string>
<string name="rename_song_error">Yenidən adlandırarkən xəta baş verdi</string>
<string name="rename_song_empty">Xahiş olunur bütün yerləri doldurun</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Hazırki musiqini təkrarla</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Přejmenovat skladbu</string>
<string name="rename_song_error">Během přejmenování došlo k chybě</string>
<string name="rename_song_empty">Prosím vyplňte všechna pole</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Opakovat aktuální skladbu</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Omdøb sang</string>
<string name="rename_song_error">En fejl opstod under omdøbningen</string>
<string name="rename_song_empty">Udfyld venligst alle felter</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Gentag den valgte sang</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Song umbenennen</string>
<string name="rename_song_error">Während des Umbenennens ist ein Fehler aufgetreten</string>
<string name="rename_song_empty">Fülle bitte alle Felder aus</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Aktuellen Song wiederholen</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Μετονομασία τραγουδιού</string>
<string name="rename_song_error">Παρουσιάστηκε σφάλμα κατά τη μετονομασία</string>
<string name="rename_song_empty">Συμπληρώστε όλα τα πεδία</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Επανάληψη τρέχοντος τραγουδιού</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Renombrar canción</string>
<string name="rename_song_error">Ha ocurrido un error durante el renombrado</string>
<string name="rename_song_empty">Por favor, rellene todos los campos</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Repetir la canción actual</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Abestia berrizendatu</string>
<string name="rename_song_error">Akats bat gertatu da berrizendatzerakoan</string>
<string name="rename_song_empty">Mesedez, eremu guztiak bete itzazu</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Uneko abestia errepikatu</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -6,6 +6,7 @@
<string name="rename_song">تغییر نام آهنگ</string>
<string name="rename_song_error">هنگام تغییر نام خطایی روی داد</string>
<string name="rename_song_empty">لطفا همه موارد را پر کنید</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">تکرار آهنگ فعلی</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Nimeä kappale uudelleen</string>
<string name="rename_song_error">Nimeämisen aikana tapahtui virhe</string>
<string name="rename_song_empty">Täytä kaikki kentät</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Toista nykyinen kappale</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Renommer la chanson</string>
<string name="rename_song_error">Une erreur s\'est produite lors du changement de nom</string>
<string name="rename_song_empty">Veuillez remplir tous les champs</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Répéter la chanson en cours</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Renomear canción</string>
<string name="rename_song_error">Algo fallou ao renomear</string>
<string name="rename_song_empty">Por favor complete todos os campos</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Repetir a canción actual</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Preimenuj pjesmu</string>
<string name="rename_song_error">Došlo je do pogreške prilikom preimenovanja</string>
<string name="rename_song_empty">Ispunite sva polja</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Ponovi trenutnu pjesmu</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Szám átnevezése</string>
<string name="rename_song_error">Hiba történt az átnevezés során</string>
<string name="rename_song_empty">Töltse ki az összes mezőt</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Jelenlegi szám ismétlése</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Ubah nama lagu</string>
<string name="rename_song_error">Terjadi kesalahan saat mengubah nama</string>
<string name="rename_song_empty">Silakan isi semua ruas</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Ulangi lagi ini</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Ubah nama lagu</string>
<string name="rename_song_error">Terjadi kesalahan saat mengubah nama</string>
<string name="rename_song_empty">Silakan isi semua ruas</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Ulangi lagi ini</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Rinomina brano</string>
<string name="rename_song_error">Impossibile rinominare</string>
<string name="rename_song_empty">Completare tutti i campi</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Ripeti il brano attuale</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">曲の名前を変更</string>
<string name="rename_song_error">名前を変更中にエラーが発生しました</string>
<string name="rename_song_empty">すべてのフィールドを入力してください</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">現在の曲を繰り返し</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">음악파일명 변경</string>
<string name="rename_song_error">이름변경 중 오류발생</string>
<string name="rename_song_empty">모든 항목 정보를 입력하세요.</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">현재 노래 반복</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Pervardinti dainą</string>
<string name="rename_song_error">Įvyko klaida pervardinant</string>
<string name="rename_song_empty">Prašome užpildyti visus laukelius</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Pakartoti dabartinę dainą</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Namakan semula lagu</string>
<string name="rename_song_error">Ralat berlaku semasa proses penamaan</string>
<string name="rename_song_empty">Sila isi semua bidang</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Ulangi lagu semasa</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Nummer hernoemen</string>
<string name="rename_song_error">Naam kon niet worden gewijzigd</string>
<string name="rename_song_empty">Vul alle velden in</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Nummer herhalen</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Zmień nazwę</string>
<string name="rename_song_error">Wystąpił błąd podczas zmiany nazwy</string>
<string name="rename_song_empty">Wypełnij wszystkie pola</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Powtarzaj bieżący utwór</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Renomear música</string>
<string name="rename_song_error">Ocorreu um erro ao renomear</string>
<string name="rename_song_empty">Por favor preencha todos os campos</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Repetir faixa atual</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Переименовать композицию</string>
<string name="rename_song_error">Во время переименования произошла ошибка</string>
<string name="rename_song_empty">Пожалуйста, заполните все поля</string>
<string name="repeat_off">Повтор выключен</string>
<string name="repeat_song">Повторять текущую композицию</string>
<string name="repeat_playlist">Повторять всё</string>
<string name="stop_playback_after_current_song">Остановить воспроизведение после текущей композиции</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Premenovať pesničku</string>
<string name="rename_song_error">Počas premenúvania došlo k chybe</string>
<string name="rename_song_empty">Prosím vyplňte všetky polia</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Opakovať súčasnú pesničku</string>
<string name="repeat_playlist">Opakovať playlist</string>
<string name="stop_playback_after_current_song">Zastaviť prehrávanie po tejto skladbe</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Byt namn på låt</string>
<string name="rename_song_error">Ett fel uppstod under namnbytet</string>
<string name="rename_song_empty">Du måste fylla i alla fält</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Repetera nuvarande låt</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Şarkıyı yeniden adlandır</string>
<string name="rename_song_error">Yeniden adlandırma sırasında bir hata oluştu</string>
<string name="rename_song_empty">lütfen tüm boşlukları doldurun</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Geçerli şarkıyı tekrarla</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Перейменувати пісню</string>
<string name="rename_song_error">Трапилася помилка під час перейменування</string>
<string name="rename_song_empty">Будь ласка, заповніть всі поля</string>
<string name="repeat_off">Повтор вимкнено</string>
<string name="repeat_song">Повторювати поточну пісню</string>
<string name="repeat_playlist">Повторювати список</string>
<string name="stop_playback_after_current_song">Зупинити відтворення після поточної пісні</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">重命名歌曲</string>
<string name="rename_song_error">在重命名过程中发生错误</string>
<string name="rename_song_empty">请填写全部字段</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">重复当前歌曲</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">重新命名歌曲</string>
<string name="rename_song_error">重新命名時發生錯誤</string>
<string name="rename_song_empty">請填入全部欄位</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">重播當前歌曲</string>
<string name="repeat_playlist">Repeat playlist</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>

View file

@ -5,6 +5,7 @@
<string name="rename_song">Rename song</string>
<string name="rename_song_error">An error occurred during the renaming</string>
<string name="rename_song_empty">Please fill in all fields</string>
<string name="repeat_off">Repeat off</string>
<string name="repeat_song">Repeat current song</string>
<string name="repeat_playlist">Repeat all</string>
<string name="stop_playback_after_current_song">Stop playback after current song</string>