Skip to content

Commit

Permalink
Merge pull request #1100
Browse files Browse the repository at this point in the history
v2.5.1
  • Loading branch information
antoinepirlot authored Dec 7, 2024
2 parents a52163a + 798f460 commit c354b71
Show file tree
Hide file tree
Showing 20 changed files with 179 additions and 71 deletions.
10 changes: 10 additions & 0 deletions RELEASES_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ Tu peux retrouver ce fichier en [français 🇫🇷](RELEASES_FR.md)

## 2.5 (Android 5.1.1 Lollipop and later)

### 2.5.1

Improvements, optimizations and troubleshooting:

* Add "Developed in Europe 🇪🇺" at the end of About settings section
* Fix snack bar not showing '%' on folder's path removed
* Fix Music control bar time when leaving and going back to the screen after a moment when playing
* Fix if forward rewind new value is <= 0 then old value is kept
* Show info dialog if setting need reload library

### 2.5.0

New features:
Expand Down
12 changes: 12 additions & 0 deletions RELEASES_FR.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ You can find this file in [english 🇬🇧](RELEASES_EN.md)

## 2.5 (Android 5.1.1 Lollipop et ultérieur)

### 2.5.1

Améliorations, optimisations et dépannage:

* Ajout du text "Développé en Europe 🇪🇺" à la fin de la section à propos dans les paramètres
* La snack bar ne montre plus le caractère '%' lors de la suppression d'un chemin de dossier
* La barre de contrôle de la musique est toujours à jour même en quittant et en revenant dans la
page lors de la lecture
* Si la nouvelle valeur pour avancer ou revenir en arrière est <= 0, alors la valeur n'est pas
changée
* Une popup d'information est montrée si le paramètre nécessite un rechargement de la bibliothèque

### 2.5.0

Nouvelles fonctionnalités:
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
applicationId = nameSpace
minSdk = 22
targetSdk = 34
versionCode = 65
versionName = "2.5.0"
versionCode = 66
versionName = "2.5.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ internal val switchSettingsNeedRestarts: List<SwitchSettings> = listOf(
SwitchSettings.PAUSE_IF_NOISY,
)

internal val switchSettingsNeedReloadLibrary: List<SwitchSettings> = listOf(
SwitchSettings.COMPILATION_MUSIC,
SwitchSettings.ARTIST_REPLACEMENT
)

internal val allFoldersSelections: List<FoldersSelection> = listOf(
FoldersSelection.INCLUDE,
FoldersSelection.EXCLUDE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,44 +288,64 @@ class DataViewModel : ViewModel() {
}
}

private fun getMediaMusicList(mediaImpl: MediaImpl): Collection<Music> = when (mediaImpl) {
is Folder -> mediaImpl.getAllMusic()
else -> mediaImpl.getMusicSet()
}

fun insertMusicsToPlaylist(
scope: CoroutineScope,
snackBarHostState: SnackbarHostState,
musics: Collection<Music>,
playlist: Playlist
playlist: Playlist,
) {
CoroutineScope(Dispatchers.IO).launch {
val context: Context = MainActivity.instance.applicationContext
try {
_db.insertMusicsToPlaylist(musics = musics, playlist = playlist)
showSnackBar(
scope = scope,
snackBarHostState = snackBarHostState,
message = context.getString(R.string.insert_musics_to_playlist_success) + ' ' + if (playlist.title == LIKES_PLAYLIST_TITLE) context.getString(
RDb.string.likes_playlist_title
)
else playlist.title,
actionLabel = context.getString(R.string.cancel),
action = {
removeMusicsFromPlaylist(
scope = scope,
snackBarHostState = snackBarHostState,
musics = musics,
playlist = playlist
)
}
val context: Context = MainActivity.instance.applicationContext
try {
_db.insertMusicsToPlaylist(musics = musics, playlist = playlist)
showSnackBar(
scope = scope,
snackBarHostState = snackBarHostState,
message = context.getString(R.string.insert_musics_to_playlist_success) + ' ' + if (playlist.title == LIKES_PLAYLIST_TITLE) context.getString(
RDb.string.likes_playlist_title
)
} catch (e: Throwable) {
_logger.warning(e.message)
showErrorSnackBar(scope = scope, snackBarHostState = snackBarHostState, action = {
insertMusicsToPlaylist(
else playlist.title,
actionLabel = context.getString(R.string.cancel),
action = {
removeMusicsFromPlaylist(
scope = scope,
snackBarHostState = snackBarHostState,
musics = musics,
playlist = playlist
)
})
}
}
)
} catch (e: Throwable) {
_logger.warning(e.message)
showErrorSnackBar(scope = scope, snackBarHostState = snackBarHostState, action = {
insertMusicsToPlaylist(
scope = scope,
snackBarHostState = snackBarHostState,
musics = musics,
playlist = playlist
)
})
}
}

fun insertMusicsToPlaylist(
scope: CoroutineScope,
snackBarHostState: SnackbarHostState,
mediaImpl: MediaImpl,
playlist: Playlist
) {
CoroutineScope(Dispatchers.IO).launch {
val musics: Collection<Music> = getMediaMusicList(mediaImpl = mediaImpl)
insertMusicsToPlaylist(
scope = scope,
snackBarHostState = snackBarHostState,
musics = musics,
playlist = playlist
)
}
}

Expand Down Expand Up @@ -374,10 +394,15 @@ class DataViewModel : ViewModel() {
fun insertMusicsToPlaylists(
scope: CoroutineScope,
snackBarHostState: SnackbarHostState,
musics: Collection<Music>,
mediaImpl: MediaImpl,
playlists: Collection<Playlist>
) {
CoroutineScope(Dispatchers.IO).launch {
val musics: Set<Music> = if (mediaImpl is Folder) {
mediaImpl.getAllMusic()
} else {
mediaImpl.getMusicSet()
}
try {
_db.insertMusicsToPlaylists(musics = musics, playlists = playlists)
val context: Context = MainActivity.instance.applicationContext
Expand All @@ -390,7 +415,7 @@ class DataViewModel : ViewModel() {
removeMusicsFromPlaylists(
scope = scope,
snackBarHostState = snackBarHostState,
musics = musics,
mediaImpl = mediaImpl,
playlists = playlists
)
}
Expand All @@ -401,7 +426,7 @@ class DataViewModel : ViewModel() {
insertMusicsToPlaylists(
scope = scope,
snackBarHostState = snackBarHostState,
musics = musics,
mediaImpl = mediaImpl,
playlists = playlists
)
})
Expand Down Expand Up @@ -494,6 +519,23 @@ class DataViewModel : ViewModel() {
}
}

fun removeMusicsFromPlaylist(
scope: CoroutineScope,
snackBarHostState: SnackbarHostState,
mediaImpl: MediaImpl,
playlist: Playlist
) {
CoroutineScope(Dispatchers.IO).launch {
val musics: Collection<Music> = getMediaMusicList(mediaImpl = mediaImpl)
removeMusicsFromPlaylist(
scope = scope,
snackBarHostState = snackBarHostState,
musics = musics,
playlist = playlist
)
}
}

fun removeMusicFromPlaylists(
scope: CoroutineScope,
snackBarHostState: SnackbarHostState,
Expand Down Expand Up @@ -537,10 +579,11 @@ class DataViewModel : ViewModel() {
fun removeMusicsFromPlaylists(
scope: CoroutineScope,
snackBarHostState: SnackbarHostState,
musics: Collection<Music>,
mediaImpl: MediaImpl,
playlists: Collection<Playlist>
) {
CoroutineScope(Dispatchers.IO).launch {
val musics: Collection<Music> = getMediaMusicList(mediaImpl = mediaImpl)
try {
_db.removeMusicsFromPlaylists(musics = musics, playlists = playlists)
val context: Context = MainActivity.instance.applicationContext
Expand All @@ -553,7 +596,7 @@ class DataViewModel : ViewModel() {
insertMusicsToPlaylists(
scope = scope,
snackBarHostState = snackBarHostState,
musics = musics,
mediaImpl = mediaImpl,
playlists = playlists
)
}
Expand All @@ -564,7 +607,7 @@ class DataViewModel : ViewModel() {
removeMusicsFromPlaylists(
scope = scope,
snackBarHostState = snackBarHostState,
musics = musics,
mediaImpl = mediaImpl,
playlists = playlists
)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ internal class SatunesViewModel : ViewModel() {
snackBarHostState = snackBarHostState,
message = MainActivity.instance.applicationContext.getString(
R.string.path_removed,
path
path.removeSuffix("%")
),
actionLabel = MainActivity.instance.applicationContext.getString(R.string.cancel),
action = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import io.github.antoinepirlot.satunes.database.services.settings.SettingsManage
import io.github.antoinepirlot.satunes.utils.logger.SatunesLogger
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch

Expand All @@ -40,6 +41,7 @@ import kotlinx.coroutines.launch
*/
internal object ProgressBarLifecycleCallbacks : DefaultLifecycleObserver {
private val _logger: SatunesLogger = SatunesLogger.getLogger()
private var _updatingJob: Job? = null;
var isUpdatingPosition: Boolean = false
private var stopRefresh: Boolean = false
private var resumed: Boolean = false // used to avoid refresh when widget is used (optimization)
Expand Down Expand Up @@ -85,20 +87,19 @@ internal object ProgressBarLifecycleCallbacks : DefaultLifecycleObserver {
}
isUpdatingPosition = true
_logger.info("Update current position")
CoroutineScope(Dispatchers.Main).launch {
_updatingJob?.cancel()
_updatingJob = CoroutineScope(Dispatchers.Main).launch {
updateCurrentPosition()
while (playbackViewModel.isPlaying && !stopRefresh) {
updateCurrentPosition(log = false)
//TODO do it outside function
val timeMillis: Long = (SettingsManager.barSpeed.speed * 1000f).toLong()
delay(timeMillis) // Wait one second to avoid refreshing all the time
}

isUpdatingPosition = false
}
}

private fun updateCurrentPosition(log: Boolean = true) {
fun updateCurrentPosition(log: Boolean = true) {
if (playbackViewModel.isEnded) {
// It means the music has reached the end of playlistDB and the music is finished
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.Slider
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalLifecycleOwner
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.viewmodel.compose.viewModel
import io.github.antoinepirlot.jetpack_libs.components.texts.NormalText
import io.github.antoinepirlot.satunes.data.viewmodels.PlaybackViewModel
Expand All @@ -55,11 +57,21 @@ internal fun MusicPositionBar(
modifier: Modifier = Modifier,
playbackViewModel: PlaybackViewModel = viewModel(),
) {
val lifecycleOwner: LifecycleOwner = LocalLifecycleOwner.current
var newPositionPercentage: Float by remember { mutableFloatStateOf(0f) }
var isUpdating: Boolean by remember { mutableStateOf(false) }
val musicPlaying: Music? = playbackViewModel.musicPlaying
var newPositionPercentage: Float by rememberSaveable { mutableFloatStateOf(0f) }
var isUpdating: Boolean by rememberSaveable { mutableStateOf(false) }
val isPlaying: Boolean = playbackViewModel.isPlaying
val currentPositionPercentage: Float = playbackViewModel.currentPositionProgression

LaunchedEffect(key1 = Unit) {
lifecycleOwner.lifecycle.addObserver(ProgressBarLifecycleCallbacks)
ProgressBarLifecycleCallbacks.updateCurrentPosition()
}

if (isPlaying && !ProgressBarLifecycleCallbacks.isUpdatingPosition)
ProgressBarLifecycleCallbacks.startUpdatingCurrentPosition()

Column(modifier = modifier) {
Slider(
value = if (isUpdating) newPositionPercentage else if (!currentPositionPercentage.isNaN()) currentPositionPercentage else 0f,
Expand All @@ -85,12 +97,6 @@ internal fun MusicPositionBar(
NormalText(text = getMillisToTimeText(maxDuration))
}
}

val isPlaying: Boolean = playbackViewModel.isPlaying
LocalLifecycleOwner.current.lifecycle.addObserver(ProgressBarLifecycleCallbacks)
if (isPlaying && !ProgressBarLifecycleCallbacks.isUpdatingPosition) {
ProgressBarLifecycleCallbacks.startUpdatingCurrentPosition()
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ private fun ForwardRewindSection(
value = mutableSeconds,
label = label,
maxValue = null,
onValueChanged = onValueChanged
onValueChanged = {
if (it > 0) onValueChanged(it)
}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import io.github.antoinepirlot.satunes.data.local.LocalMainScope
import io.github.antoinepirlot.satunes.data.local.LocalSnackBarHostState
import io.github.antoinepirlot.satunes.data.viewmodels.DataViewModel
import io.github.antoinepirlot.satunes.data.viewmodels.MediaSelectionViewModel
import io.github.antoinepirlot.satunes.database.models.Folder
import io.github.antoinepirlot.satunes.database.models.MediaImpl
import io.github.antoinepirlot.satunes.database.models.Music
import io.github.antoinepirlot.satunes.database.models.Playlist
Expand Down Expand Up @@ -106,24 +105,18 @@ private fun insertMediaToPlaylist(
mediaSelectionViewModel: MediaSelectionViewModel,
mediaImpl: MediaImpl
) {
if (mediaImpl is Music) {
dataViewModel.insertMusicToPlaylists(
when (mediaImpl) {
is Music -> dataViewModel.insertMusicToPlaylists(
scope = scope,
snackBarHostState = snackBarHostState,
music = mediaImpl,
playlists = mediaSelectionViewModel.getCheckedPlaylistWithMusics()
)
} else {
val musicList: Set<Music> = if (mediaImpl is Folder) {
mediaImpl.getAllMusic()
} else {
mediaImpl.getMusicSet()
}

dataViewModel.insertMusicsToPlaylists(
else -> dataViewModel.insertMusicsToPlaylists(
scope = scope,
snackBarHostState = snackBarHostState,
musics = musicList,
mediaImpl = mediaImpl,
playlists = mediaSelectionViewModel.getCheckedPlaylistWithMusics()
)
}
Expand Down
Loading

0 comments on commit c354b71

Please sign in to comment.