Skip to content

Commit

Permalink
feat: song duration filter (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
sevonj authored Dec 7, 2024
1 parent 60541cd commit f8bdd78
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .phrasey/schema.toml
Original file line number Diff line number Diff line change
Expand Up @@ -756,3 +756,6 @@ name = "CaseSensitiveSorting"

[[keys]]
name = "KeepScreenAwakeOnLyrics"

[[keys]]
name = "MinSongDurationFilter"
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class Settings(private val symphony: Symphony) {
}
val lastHomeTab = EnumEntry("home_last_page", enumEntries<HomePage>(), HomePage.Songs)
val songsFilterPattern = NullableStringEntry("songs_filter_pattern")
val minSongDuration = IntEntry("min_song_duration", 0)
val checkForUpdates = BooleanEntry("check_for_updates", false)
val fadePlayback = BooleanEntry("fade_playback", false)
val requireAudioFocus = BooleanEntry("require_audio_focus", true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.withContext
import java.util.concurrent.ConcurrentHashMap
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds

class MediaExposer(private val symphony: Symphony) {
internal val uris = ConcurrentHashMap<String, Uri>()
Expand Down Expand Up @@ -128,6 +130,9 @@ class MediaExposer(private val symphony: Symphony) {
cacheHit -> cached
else -> Song.parse(symphony, path, file)
}
if (song.duration.milliseconds < symphony.settings.minSongDuration.value.seconds) {
return
}
if (!cacheHit) {
symphony.database.songCache.insert(song)
cached?.coverFile?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import io.github.zyrouge.symphony.ui.components.settings.SettingsMultiTextOption
import io.github.zyrouge.symphony.ui.components.settings.SettingsOptionTile
import io.github.zyrouge.symphony.ui.components.settings.SettingsSideHeading
import io.github.zyrouge.symphony.ui.components.settings.SettingsSimpleTile
import io.github.zyrouge.symphony.ui.components.settings.SettingsSliderTile
import io.github.zyrouge.symphony.ui.components.settings.SettingsSwitchTile
import io.github.zyrouge.symphony.ui.components.settings.SettingsTextInputTile
import io.github.zyrouge.symphony.ui.helpers.TransitionDurations
Expand All @@ -63,6 +64,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.serialization.Serializable
import kotlin.math.roundToInt

@Serializable
data class GrooveSettingsViewRoute(val initialElement: String? = null)
Expand All @@ -74,6 +76,7 @@ fun GrooveSettingsView(context: ViewContext, route: GrooveSettingsViewRoute) {
val snackbarHostState = remember { SnackbarHostState() }
val scrollState = rememberScrollState()
val songsFilterPattern by context.symphony.settings.songsFilterPattern.flow.collectAsState()
val minSongDuration by context.symphony.settings.minSongDuration.flow.collectAsState()
val blacklistFolders by context.symphony.settings.blacklistFolders.flow.collectAsState()
val whitelistFolders by context.symphony.settings.whitelistFolders.flow.collectAsState()
val artistTagSeparators by context.symphony.settings.artistTagSeparators.flow.collectAsState()
Expand Down Expand Up @@ -122,6 +125,7 @@ fun GrooveSettingsView(context: ViewContext, route: GrooveSettingsViewRoute) {
) {
Column(modifier = Modifier.verticalScroll(scrollState)) {
val defaultSongsFilterPattern = ".*"
val minSongDurationRange = 0f..60f

ConsiderContributingTile(context)
SettingsSideHeading(context.symphony.t.Groove)
Expand Down Expand Up @@ -165,6 +169,32 @@ fun GrooveSettingsView(context: ViewContext, route: GrooveSettingsViewRoute) {
}
)
HorizontalDivider()
SettingsSliderTile(
context,
icon = {
Icon(Icons.Filled.FilterAlt, null)
},
title = {
Text(context.symphony.t.MinSongDurationFilter)
},
label = { value ->
Text(context.symphony.t.XSecs(value.toString()))
},
range = minSongDurationRange,
initialValue = minSongDuration.toFloat(),
onValue = { value ->
value.roundToInt().toFloat()
},
onChange = { value ->
context.symphony.settings.minSongDuration.setValue(value.toInt())
},
onReset = {
context.symphony.settings.minSongDuration.setValue(
context.symphony.settings.minSongDuration.defaultValue,
)
},
)
HorizontalDivider()
SettingsMultiGrooveFolderTile(
context,
icon = {
Expand Down
1 change: 1 addition & 0 deletions i18n/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,4 @@ GaplessPlayback = "Gapless playback"
GridColumns = "Grid columns"
CaseSensitiveSorting = "Case sensitive sorting"
KeepScreenAwakeOnLyrics = "Keep screen awake on lyrics content"
MinSongDurationFilter = "Minimum song duration filter"

0 comments on commit f8bdd78

Please sign in to comment.