Skip to content

Commit

Permalink
Merge branch 'z-huang:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitrysaf authored Aug 27, 2024
2 parents 2af448a + b0e88e1 commit 94a2252
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum class AudioQuality {
val PersistentQueueKey = booleanPreferencesKey("persistentQueue")
val SkipSilenceKey = booleanPreferencesKey("skipSilence")
val AudioNormalizationKey = booleanPreferencesKey("audioNormalization")
val AutoSkipNextOnErrorKey = booleanPreferencesKey("autoSkipNextOnError")
val StopMusicOnTaskClearKey = booleanPreferencesKey("stopMusicOnTaskClear")

val MaxImageCacheSizeKey = intPreferencesKey("maxImageCacheSize")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import com.zionhuang.music.R
import com.zionhuang.music.constants.AudioNormalizationKey
import com.zionhuang.music.constants.AudioQuality
import com.zionhuang.music.constants.AudioQualityKey
import com.zionhuang.music.constants.AutoSkipNextOnErrorKey
import com.zionhuang.music.constants.DiscordTokenKey
import com.zionhuang.music.constants.EnableDiscordRPCKey
import com.zionhuang.music.constants.HideExplicitKey
Expand Down Expand Up @@ -583,6 +584,14 @@ class MusicService : MediaLibraryService(),
}
}

override fun onPlayerError(error: PlaybackException) {
if (dataStore.get(AutoSkipNextOnErrorKey, false) && player.hasNextMediaItem()) {
player.seekToNext()
player.prepare()
player.playWhenReady = true
}
}

private fun createCacheDataSource(): CacheDataSource.Factory =
CacheDataSource.Factory()
.setCache(downloadCache)
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/zionhuang/music/ui/player/Queue.kt
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ fun Queue(
}

LaunchedEffect(mutableQueueWindows) {
reorderableState.listState.scrollToItem(currentWindowIndex)
if (currentWindowIndex != -1) {
reorderableState.listState.scrollToItem(currentWindowIndex)
}
}

LazyColumn(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -44,8 +45,13 @@ import com.zionhuang.music.constants.SuggestionItemHeight
import com.zionhuang.music.extensions.togglePlayPause
import com.zionhuang.music.models.toMediaMetadata
import com.zionhuang.music.playback.queues.YouTubeQueue
import com.zionhuang.music.ui.component.LocalMenuState
import com.zionhuang.music.ui.component.SearchBarIconOffsetX
import com.zionhuang.music.ui.component.YouTubeListItem
import com.zionhuang.music.ui.menu.YouTubeAlbumMenu
import com.zionhuang.music.ui.menu.YouTubeArtistMenu
import com.zionhuang.music.ui.menu.YouTubePlaylistMenu
import com.zionhuang.music.ui.menu.YouTubeSongMenu
import com.zionhuang.music.viewmodels.OnlineSearchSuggestionViewModel
import kotlinx.coroutines.flow.drop

Expand All @@ -58,9 +64,13 @@ fun OnlineSearchScreen(
onDismiss: () -> Unit,
viewModel: OnlineSearchSuggestionViewModel = hiltViewModel(),
) {
val menuState = LocalMenuState.current
val database = LocalDatabase.current
val keyboardController = LocalSoftwareKeyboardController.current
val playerConnection = LocalPlayerConnection.current ?: return

val scope = rememberCoroutineScope()

val isPlaying by playerConnection.isPlaying.collectAsState()
val mediaMetadata by playerConnection.mediaMetadata.collectAsState()

Expand Down Expand Up @@ -155,6 +165,47 @@ fun OnlineSearchScreen(
else -> false
},
isPlaying = isPlaying,
trailingContent = {
IconButton(
onClick = {
menuState.show {
when (item) {
is SongItem ->
YouTubeSongMenu(
song = item,
navController = navController,
onDismiss = menuState::dismiss,
)

is AlbumItem ->
YouTubeAlbumMenu(
albumItem = item,
navController = navController,
onDismiss = menuState::dismiss,
)

is ArtistItem ->
YouTubeArtistMenu(
artist = item,
onDismiss = menuState::dismiss,
)

is PlaylistItem ->
YouTubePlaylistMenu(
playlist = item,
coroutineScope = scope,
onDismiss = menuState::dismiss,
)
}
}
}
) {
Icon(
painter = painterResource(R.drawable.more_vert),
contentDescription = null
)
}
},
modifier = Modifier
.clickable {
when (item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.zionhuang.music.R
import com.zionhuang.music.constants.AudioNormalizationKey
import com.zionhuang.music.constants.AudioQuality
import com.zionhuang.music.constants.AudioQualityKey
import com.zionhuang.music.constants.AutoSkipNextOnErrorKey
import com.zionhuang.music.constants.PersistentQueueKey
import com.zionhuang.music.constants.SkipSilenceKey
import com.zionhuang.music.constants.StopMusicOnTaskClearKey
Expand All @@ -38,11 +39,12 @@ fun PlayerSettings(
navController: NavController,
scrollBehavior: TopAppBarScrollBehavior,
) {
val (audioQuality, onAudioQualityChange) = rememberEnumPreference(key = AudioQualityKey, defaultValue = AudioQuality.AUTO)
val (persistentQueue, onPersistentQueueChange) = rememberPreference(key = PersistentQueueKey, defaultValue = true)
val (skipSilence, onSkipSilenceChange) = rememberPreference(key = SkipSilenceKey, defaultValue = false)
val (audioNormalization, onAudioNormalizationChange) = rememberPreference(key = AudioNormalizationKey, defaultValue = true)
val (stopMusicOnTaskClear, onStopMusicOnTaskClearChange) = rememberPreference(key = StopMusicOnTaskClearKey, defaultValue = false)
val (audioQuality, onAudioQualityChange) = rememberEnumPreference(AudioQualityKey, defaultValue = AudioQuality.AUTO)
val (persistentQueue, onPersistentQueueChange) = rememberPreference(PersistentQueueKey, defaultValue = true)
val (skipSilence, onSkipSilenceChange) = rememberPreference(SkipSilenceKey, defaultValue = false)
val (audioNormalization, onAudioNormalizationChange) = rememberPreference(AudioNormalizationKey, defaultValue = true)
val (autoSkipNextOnError, onAutoSkipNextOnErrorChange) = rememberPreference(AutoSkipNextOnErrorKey, defaultValue = false)
val (stopMusicOnTaskClear, onStopMusicOnTaskClearChange) = rememberPreference(StopMusicOnTaskClearKey, defaultValue = false)

Column(
Modifier
Expand All @@ -66,13 +68,14 @@ fun PlayerSettings(
)
SwitchPreference(
title = { Text(stringResource(R.string.persistent_queue)) },
description = stringResource(R.string.persistent_queue_desc),
icon = { Icon(painterResource(R.drawable.queue_music), null) },
checked = persistentQueue,
onCheckedChange = onPersistentQueueChange
)
SwitchPreference(
title = { Text(stringResource(R.string.skip_silence)) },
icon = { Icon(painterResource(R.drawable.skip_next), null) },
icon = { Icon(painterResource(R.drawable.fast_forward), null) },
checked = skipSilence,
onCheckedChange = onSkipSilenceChange
)
Expand All @@ -82,6 +85,13 @@ fun PlayerSettings(
checked = audioNormalization,
onCheckedChange = onAudioNormalizationChange
)
SwitchPreference(
title = { Text(stringResource(R.string.auto_skip_next_on_error)) },
description = stringResource(R.string.auto_skip_next_on_error_desc),
icon = { Icon(painterResource(R.drawable.skip_next), null) },
checked = autoSkipNextOnError,
onCheckedChange = onAutoSkipNextOnErrorChange
)
SwitchPreference(
title = { Text(stringResource(R.string.stop_music_on_task_clear)) },
icon = { Icon(painterResource(R.drawable.clear_all), null) },
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/drawable/casino.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
android:viewportHeight="960">
<path
android:fillColor="@android:color/white"
android:pathData="M300,720Q325,720 342.5,702.5Q360,685 360,660Q360,635 342.5,617.5Q325,600 300,600Q275,600 257.5,617.5Q240,635 240,660Q240,685 257.5,702.5Q275,720 300,720ZM300,360Q325,360 342.5,342.5Q360,325 360,300Q360,275 342.5,257.5Q325,240 300,240Q275,240 257.5,257.5Q240,275 240,300Q240,325 257.5,342.5Q275,360 300,360ZM480,540Q505,540 522.5,522.5Q540,505 540,480Q540,455 522.5,437.5Q505,420 480,420Q455,420 437.5,437.5Q420,455 420,480Q420,505 437.5,522.5Q455,540 480,540ZM660,720Q685,720 702.5,702.5Q720,685 720,660Q720,635 702.5,617.5Q685,600 660,600Q635,600 617.5,617.5Q600,635 600,660Q600,685 617.5,702.5Q635,720 660,720ZM660,360Q685,360 702.5,342.5Q720,325 720,300Q720,275 702.5,257.5Q685,240 660,240Q635,240 617.5,257.5Q600,275 600,300Q600,325 617.5,342.5Q635,360 660,360ZM200,840Q167,840 143.5,816.5Q120,793 120,760L120,200Q120,167 143.5,143.5Q167,120 200,120L760,120Q793,120 816.5,143.5Q840,167 840,200L840,760Q840,793 816.5,816.5Q793,840 760,840L200,840ZM200,760L760,760Q760,760 760,760Q760,760 760,760L760,200Q760,200 760,200Q760,200 760,200L200,200Q200,200 200,200Q200,200 200,200L200,760Q200,760 200,760Q200,760 200,760ZM200,200L200,200Q200,200 200,200Q200,200 200,200L200,760Q200,760 200,760Q200,760 200,760L200,760Q200,760 200,760Q200,760 200,760L200,200Q200,200 200,200Q200,200 200,200Z" />
android:pathData="M300,720Q325,720 342.5,702.5Q360,685 360,660Q360,635 342.5,617.5Q325,600 300,600Q275,600 257.5,617.5Q240,635 240,660Q240,685 257.5,702.5Q275,720 300,720ZM300,360Q325,360 342.5,342.5Q360,325 360,300Q360,275 342.5,257.5Q325,240 300,240Q275,240 257.5,257.5Q240,275 240,300Q240,325 257.5,342.5Q275,360 300,360ZM480,540Q505,540 522.5,522.5Q540,505 540,480Q540,455 522.5,437.5Q505,420 480,420Q455,420 437.5,437.5Q420,455 420,480Q420,505 437.5,522.5Q455,540 480,540ZM660,720Q685,720 702.5,702.5Q720,685 720,660Q720,635 702.5,617.5Q685,600 660,600Q635,600 617.5,617.5Q600,635 600,660Q600,685 617.5,702.5Q635,720 660,720ZM660,360Q685,360 702.5,342.5Q720,325 720,300Q720,275 702.5,257.5Q685,240 660,240Q635,240 617.5,257.5Q600,275 600,300Q600,325 617.5,342.5Q635,360 660,360ZM200,840Q167,840 143.5,816.5Q120,793 120,760L120,200Q120,167 143.5,143.5Q167,120 200,120L760,120Q793,120 816.5,143.5Q840,167 840,200L840,760Q840,793 816.5,816.5Q793,840 760,840L200,840Z" />
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/fast_forward.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="@android:color/white"
android:pathData="M100,720L100,240L460,480L100,720ZM500,720L500,240L860,480L500,720ZM180,480L180,480L180,480ZM580,480L580,480L580,480ZM180,570L316,480L180,390L180,570ZM580,570L716,480L580,390L580,570Z" />
</vector>
3 changes: 3 additions & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,11 @@
<string name="audio_quality_high">高</string>
<string name="audio_quality_low">低</string>
<string name="persistent_queue">保留播放佇列</string>
<string name="persistent_queue_desc">開啟應用程式時還原上次的播放佇列</string>
<string name="skip_silence">跳過無聲片段</string>
<string name="audio_normalization">標準化音量</string>
<string name="auto_skip_next_on_error">發生錯誤時自動跳到下一首</string>
<string name="auto_skip_next_on_error_desc">讓你享受音樂不中斷</string>
<string name="stop_music_on_task_clear">將音樂在清除任務時停止</string>
<string name="equalizer">等化器</string>

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,11 @@
<string name="audio_quality_high">High</string>
<string name="audio_quality_low">Low</string>
<string name="persistent_queue">Persistent queue</string>
<string name="persistent_queue_desc">Restore your last queue when the app starts</string>
<string name="skip_silence">Skip silence</string>
<string name="audio_normalization">Audio normalization</string>
<string name="auto_skip_next_on_error">Auto skip to next song when error occurs</string>
<string name="auto_skip_next_on_error_desc">Ensure your continuous playback experience</string>
<string name="stop_music_on_task_clear">Stop music on task clear</string>
<string name="equalizer">Equalizer</string>

Expand Down

0 comments on commit 94a2252

Please sign in to comment.