parent
9aa051068b
commit
6dd88b796e
5 changed files with 57 additions and 33 deletions
|
@ -4,6 +4,7 @@ import androidx.compose.animation.ExperimentalAnimationApi
|
||||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.saveable.rememberSaveableStateHolder
|
import androidx.compose.runtime.saveable.rememberSaveableStateHolder
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import it.vfsfitvnm.route.RouteHandler
|
import it.vfsfitvnm.route.RouteHandler
|
||||||
import it.vfsfitvnm.route.defaultStacking
|
import it.vfsfitvnm.route.defaultStacking
|
||||||
import it.vfsfitvnm.route.defaultStill
|
import it.vfsfitvnm.route.defaultStill
|
||||||
|
@ -30,13 +31,14 @@ import it.vfsfitvnm.vimusic.ui.screens.searchRoute
|
||||||
import it.vfsfitvnm.vimusic.ui.screens.searchresult.SearchResultScreen
|
import it.vfsfitvnm.vimusic.ui.screens.searchresult.SearchResultScreen
|
||||||
import it.vfsfitvnm.vimusic.ui.screens.settings.SettingsScreen
|
import it.vfsfitvnm.vimusic.ui.screens.settings.SettingsScreen
|
||||||
import it.vfsfitvnm.vimusic.ui.screens.settingsRoute
|
import it.vfsfitvnm.vimusic.ui.screens.settingsRoute
|
||||||
import it.vfsfitvnm.vimusic.utils.homeScreenTabIndexKey
|
import it.vfsfitvnm.vimusic.utils.*
|
||||||
import it.vfsfitvnm.vimusic.utils.rememberPreference
|
|
||||||
|
|
||||||
@ExperimentalFoundationApi
|
@ExperimentalFoundationApi
|
||||||
@ExperimentalAnimationApi
|
@ExperimentalAnimationApi
|
||||||
@Composable
|
@Composable
|
||||||
fun HomeScreen(onPlaylistUrl: (String) -> Unit) {
|
fun HomeScreen(onPlaylistUrl: (String) -> Unit) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
val saveableStateHolder = rememberSaveableStateHolder()
|
val saveableStateHolder = rememberSaveableStateHolder()
|
||||||
|
|
||||||
RouteHandler(
|
RouteHandler(
|
||||||
|
@ -88,7 +90,7 @@ fun HomeScreen(onPlaylistUrl: (String) -> Unit) {
|
||||||
pop()
|
pop()
|
||||||
searchResultRoute(query)
|
searchResultRoute(query)
|
||||||
|
|
||||||
query {
|
if (!context.preferences.getBoolean(pauseSearchHistoryKey, false)) query {
|
||||||
Database.insert(SearchQuery(query = query))
|
Database.insert(SearchQuery(query = query))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -113,7 +115,7 @@ fun HomeScreen(onPlaylistUrl: (String) -> Unit) {
|
||||||
Item(2, "Playlists", R.drawable.playlist)
|
Item(2, "Playlists", R.drawable.playlist)
|
||||||
Item(3, "Artists", R.drawable.person)
|
Item(3, "Artists", R.drawable.person)
|
||||||
Item(4, "Albums", R.drawable.disc)
|
Item(4, "Albums", R.drawable.disc)
|
||||||
},
|
}
|
||||||
) { currentTabIndex ->
|
) { currentTabIndex ->
|
||||||
saveableStateHolder.SaveableStateProvider(key = currentTabIndex) {
|
saveableStateHolder.SaveableStateProvider(key = currentTabIndex) {
|
||||||
when (currentTabIndex) {
|
when (currentTabIndex) {
|
||||||
|
|
|
@ -38,6 +38,7 @@ import androidx.compose.ui.focus.FocusRequester
|
||||||
import androidx.compose.ui.focus.focusRequester
|
import androidx.compose.ui.focus.focusRequester
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
import androidx.compose.ui.graphics.ColorFilter
|
||||||
import androidx.compose.ui.graphics.SolidColor
|
import androidx.compose.ui.graphics.SolidColor
|
||||||
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.text.TextRange
|
import androidx.compose.ui.text.TextRange
|
||||||
import androidx.compose.ui.text.input.ImeAction
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
|
@ -57,6 +58,7 @@ import it.vfsfitvnm.vimusic.ui.components.themed.FloatingActionsContainerWithScr
|
||||||
import it.vfsfitvnm.vimusic.ui.components.themed.Header
|
import it.vfsfitvnm.vimusic.ui.components.themed.Header
|
||||||
import it.vfsfitvnm.vimusic.ui.components.themed.SecondaryTextButton
|
import it.vfsfitvnm.vimusic.ui.components.themed.SecondaryTextButton
|
||||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||||
|
import it.vfsfitvnm.vimusic.utils.*
|
||||||
import it.vfsfitvnm.vimusic.utils.align
|
import it.vfsfitvnm.vimusic.utils.align
|
||||||
import it.vfsfitvnm.vimusic.utils.center
|
import it.vfsfitvnm.vimusic.utils.center
|
||||||
import it.vfsfitvnm.vimusic.utils.medium
|
import it.vfsfitvnm.vimusic.utils.medium
|
||||||
|
@ -79,6 +81,8 @@ fun OnlineSearch(
|
||||||
onViewPlaylist: (String) -> Unit,
|
onViewPlaylist: (String) -> Unit,
|
||||||
decorationBox: @Composable (@Composable () -> Unit) -> Unit
|
decorationBox: @Composable (@Composable () -> Unit) -> Unit
|
||||||
) {
|
) {
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
val (colorPalette, typography) = LocalAppearance.current
|
val (colorPalette, typography) = LocalAppearance.current
|
||||||
|
|
||||||
val history by produceSaveableState(
|
val history by produceSaveableState(
|
||||||
|
@ -108,7 +112,7 @@ fun OnlineSearch(
|
||||||
val isPlaylistUrl = listOf(
|
val isPlaylistUrl = listOf(
|
||||||
"https://www.youtube.com/playlist?",
|
"https://www.youtube.com/playlist?",
|
||||||
"https://music.youtube.com/playlist?",
|
"https://music.youtube.com/playlist?",
|
||||||
"https://m.youtube.com/playlist?",
|
"https://m.youtube.com/playlist?"
|
||||||
).any(textFieldValue.text::startsWith)
|
).any(textFieldValue.text::startsWith)
|
||||||
|
|
||||||
if (isPlaylistUrl) textFieldValue.text.toUri().getQueryParameter("list") else null
|
if (isPlaylistUrl) textFieldValue.text.toUri().getQueryParameter("list") else null
|
||||||
|
@ -164,7 +168,7 @@ fun OnlineSearch(
|
||||||
val isAlbum = playlistId.startsWith("OLAK5uy_")
|
val isAlbum = playlistId.startsWith("OLAK5uy_")
|
||||||
|
|
||||||
SecondaryTextButton(
|
SecondaryTextButton(
|
||||||
text = "View ${if (isAlbum) "album" else "playlist"}",
|
text = "View ${if (isAlbum) "album" else "playlist"}",
|
||||||
onClick = { onViewPlaylist(textFieldValue.text) }
|
onClick = { onViewPlaylist(textFieldValue.text) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -176,7 +180,7 @@ fun OnlineSearch(
|
||||||
|
|
||||||
if (textFieldValue.text.isNotEmpty()) {
|
if (textFieldValue.text.isNotEmpty()) {
|
||||||
SecondaryTextButton(
|
SecondaryTextButton(
|
||||||
text = "Clear",
|
text = "Clear",
|
||||||
onClick = { onTextFieldValueChanged(TextFieldValue()) }
|
onClick = { onTextFieldValueChanged(TextFieldValue()) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -184,7 +188,7 @@ fun OnlineSearch(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
items(
|
if (!context.preferences.getBoolean(pauseSearchHistoryKey, false)) items(
|
||||||
items = history,
|
items = history,
|
||||||
key = SearchQuery::id
|
key = SearchQuery::id
|
||||||
) { searchQuery ->
|
) { searchQuery ->
|
||||||
|
|
|
@ -28,14 +28,14 @@ import it.vfsfitvnm.vimusic.ui.components.themed.Header
|
||||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||||
import it.vfsfitvnm.vimusic.utils.intent
|
import it.vfsfitvnm.vimusic.utils.intent
|
||||||
import it.vfsfitvnm.vimusic.utils.produceSaveableState
|
import it.vfsfitvnm.vimusic.utils.produceSaveableState
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
import kotlinx.coroutines.flow.flowOn
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
import kotlin.system.exitProcess
|
import kotlin.system.exitProcess
|
||||||
import kotlinx.coroutines.Dispatchers
|
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
|
||||||
import kotlinx.coroutines.flow.flowOn
|
|
||||||
|
|
||||||
@ExperimentalAnimationApi
|
@ExperimentalAnimationApi
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -50,13 +50,6 @@ fun DatabaseSettings() {
|
||||||
.collect { value = it }
|
.collect { value = it }
|
||||||
}
|
}
|
||||||
|
|
||||||
val queriesCount by produceSaveableState(initialValue = 0, stateSaver = autoSaver()) {
|
|
||||||
Database.queriesCount()
|
|
||||||
.flowOn(Dispatchers.IO)
|
|
||||||
.distinctUntilChanged()
|
|
||||||
.collect { value = it }
|
|
||||||
}
|
|
||||||
|
|
||||||
val backupLauncher =
|
val backupLauncher =
|
||||||
rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument("application/vnd.sqlite3")) { uri ->
|
rememberLauncherForActivityResult(ActivityResultContracts.CreateDocument("application/vnd.sqlite3")) { uri ->
|
||||||
if (uri == null) return@rememberLauncherForActivityResult
|
if (uri == null) return@rememberLauncherForActivityResult
|
||||||
|
@ -93,7 +86,6 @@ fun DatabaseSettings() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.background(colorPalette.background0)
|
.background(colorPalette.background0)
|
||||||
|
@ -109,17 +101,6 @@ fun DatabaseSettings() {
|
||||||
|
|
||||||
SettingsEntryGroupText(title = "CLEANUP")
|
SettingsEntryGroupText(title = "CLEANUP")
|
||||||
|
|
||||||
SettingsEntry(
|
|
||||||
title = "Clear search history",
|
|
||||||
text = if (queriesCount > 0) {
|
|
||||||
"Delete $queriesCount search queries"
|
|
||||||
} else {
|
|
||||||
"History is empty"
|
|
||||||
},
|
|
||||||
isEnabled = queriesCount > 0,
|
|
||||||
onClick = { query(Database::clearQueries) }
|
|
||||||
)
|
|
||||||
|
|
||||||
SettingsEntry(
|
SettingsEntry(
|
||||||
title = "Reset quick picks",
|
title = "Reset quick picks",
|
||||||
text = if (eventsCount > 0) {
|
text = if (eventsCount > 0) {
|
||||||
|
|
|
@ -29,12 +29,16 @@ import androidx.compose.foundation.layout.WindowInsetsSides
|
||||||
import androidx.compose.foundation.layout.asPaddingValues
|
import androidx.compose.foundation.layout.asPaddingValues
|
||||||
import androidx.compose.foundation.layout.only
|
import androidx.compose.foundation.layout.only
|
||||||
import androidx.compose.runtime.SnapshotMutationPolicy
|
import androidx.compose.runtime.SnapshotMutationPolicy
|
||||||
|
import androidx.compose.runtime.saveable.autoSaver
|
||||||
|
import it.vfsfitvnm.vimusic.Database
|
||||||
|
import it.vfsfitvnm.vimusic.query
|
||||||
import it.vfsfitvnm.vimusic.service.PlayerMediaBrowserService
|
import it.vfsfitvnm.vimusic.service.PlayerMediaBrowserService
|
||||||
import it.vfsfitvnm.vimusic.ui.components.themed.Header
|
import it.vfsfitvnm.vimusic.ui.components.themed.Header
|
||||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||||
import it.vfsfitvnm.vimusic.utils.isIgnoringBatteryOptimizations
|
import it.vfsfitvnm.vimusic.utils.*
|
||||||
import it.vfsfitvnm.vimusic.utils.isInvincibilityEnabledKey
|
import kotlinx.coroutines.Dispatchers
|
||||||
import it.vfsfitvnm.vimusic.utils.rememberPreference
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
import kotlinx.coroutines.flow.flowOn
|
||||||
|
|
||||||
@ExperimentalAnimationApi
|
@ExperimentalAnimationApi
|
||||||
@Composable
|
@Composable
|
||||||
|
@ -73,6 +77,18 @@ fun OtherSettings() {
|
||||||
isIgnoringBatteryOptimizations = context.isIgnoringBatteryOptimizations
|
isIgnoringBatteryOptimizations = context.isIgnoringBatteryOptimizations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pauseSearchHistory by rememberPreference(
|
||||||
|
pauseSearchHistoryKey,
|
||||||
|
false
|
||||||
|
)
|
||||||
|
|
||||||
|
val queriesCount by produceSaveableState(initialValue = 0, stateSaver = autoSaver()) {
|
||||||
|
Database.queriesCount()
|
||||||
|
.flowOn(Dispatchers.IO)
|
||||||
|
.distinctUntilChanged()
|
||||||
|
.collect { value = it }
|
||||||
|
}
|
||||||
|
|
||||||
Column(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.background(colorPalette.background0)
|
.background(colorPalette.background0)
|
||||||
|
@ -147,5 +163,25 @@ fun OtherSettings() {
|
||||||
isChecked = isInvincibilityEnabled,
|
isChecked = isInvincibilityEnabled,
|
||||||
onCheckedChange = { isInvincibilityEnabled = it }
|
onCheckedChange = { isInvincibilityEnabled = it }
|
||||||
)
|
)
|
||||||
|
|
||||||
|
SettingsEntryGroupText(title = "SEARCH HISTORY")
|
||||||
|
|
||||||
|
SwitchSettingEntry(
|
||||||
|
title = "Pause search history",
|
||||||
|
text = "Neither save new searched queries nor show already existing items in the history",
|
||||||
|
isChecked = pauseSearchHistory,
|
||||||
|
onCheckedChange = { pauseSearchHistory = it }
|
||||||
|
)
|
||||||
|
|
||||||
|
SettingsEntry(
|
||||||
|
title = "Clear search history",
|
||||||
|
text = if (queriesCount > 0) {
|
||||||
|
"Delete $queriesCount search queries"
|
||||||
|
} else {
|
||||||
|
"History is empty"
|
||||||
|
},
|
||||||
|
isEnabled = queriesCount > 0,
|
||||||
|
onClick = { query(Database::clearQueries) }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ const val isShowingThumbnailInLockscreenKey = "isShowingThumbnailInLockscreen"
|
||||||
const val homeScreenTabIndexKey = "homeScreenTabIndex"
|
const val homeScreenTabIndexKey = "homeScreenTabIndex"
|
||||||
const val searchResultScreenTabIndexKey = "searchResultScreenTabIndex"
|
const val searchResultScreenTabIndexKey = "searchResultScreenTabIndex"
|
||||||
const val artistScreenTabIndexKey = "artistScreenTabIndex"
|
const val artistScreenTabIndexKey = "artistScreenTabIndex"
|
||||||
|
const val pauseSearchHistoryKey = "pauseSearchHistory"
|
||||||
|
|
||||||
inline fun <reified T : Enum<T>> SharedPreferences.getEnum(
|
inline fun <reified T : Enum<T>> SharedPreferences.getEnum(
|
||||||
key: String,
|
key: String,
|
||||||
|
|
Loading…
Reference in a new issue