Merge pull request #341 from qwertyfinger/feature/repeat-off-option

Add option to disable repeat entirely
This commit is contained in:
Tibor Kaputa 2021-08-24 14:17:33 +02:00 committed by GitHub
commit de8bf63a8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 91 additions and 18 deletions

View file

@ -208,7 +208,13 @@ class TrackActivity : SimpleActivity(), PlaybackSpeedListener {
return true
}
override fun onResourceReady(resource: Drawable, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
override fun onResourceReady(
resource: Drawable,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
next_track_image.setImageDrawable(resource)
return false
}
@ -242,7 +248,13 @@ class TrackActivity : SimpleActivity(), PlaybackSpeedListener {
return true
}
override fun onResourceReady(resource: Drawable, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
override fun onResourceReady(
resource: Drawable,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
val coverHeight = resource.intrinsicHeight
if (coverHeight > 0 && activity_track_image.height != coverHeight) {
activity_track_image.layoutParams.height = coverHeight
@ -310,6 +322,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,15 +8,19 @@ 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
),
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
);
@ -26,8 +30,9 @@ enum class PlaybackSetting(
val nextPlaybackOption: PlaybackSetting
get() = when (this) {
REPEAT_PLAYLIST -> REPEAT_SONG
REPEAT_SONG -> STOP_AFTER_CURRENT_SONG
STOP_AFTER_CURRENT_SONG -> REPEAT_PLAYLIST
REPEAT_OFF -> REPEAT_PLAYLIST
REPEAT_PLAYLIST -> REPEAT_TRACK
REPEAT_TRACK -> STOP_AFTER_CURRENT_TRACK
STOP_AFTER_CURRENT_TRACK -> REPEAT_OFF
}
}

View file

@ -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) {
}
}
@ -540,6 +544,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()
@ -668,14 +679,23 @@ class MusicService : Service(), MediaPlayer.OnPreparedListener, MediaPlayer.OnEr
val playbackSetting = config.playbackSetting
mPlayOnPrepare = when (playbackSetting) {
PlaybackSetting.REPEAT_PLAYLIST, PlaybackSetting.REPEAT_SONG -> true
PlaybackSetting.STOP_AFTER_CURRENT_SONG -> false
PlaybackSetting.REPEAT_OFF -> !isEndOfPlaylist()
PlaybackSetting.REPEAT_PLAYLIST, PlaybackSetting.REPEAT_TRACK -> true
PlaybackSetting.STOP_AFTER_CURRENT_TRACK -> false
}
when (config.playbackSetting) {
PlaybackSetting.REPEAT_OFF -> {
if (isEndOfPlaylist()) {
broadcastTrackProgress(0)
setupNextTrack()
} else {
setupNextTrack()
}
}
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()
}

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">Opakovanie vypnuté</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>