diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
new file mode 100644
index 00000000..0c0c3383
--- /dev/null
+++ b/.idea/deploymentTargetDropDown.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/java/com/bnyro/wallpaper/ui/components/BlockButton.kt b/app/src/main/java/com/bnyro/wallpaper/ui/components/BlockButton.kt
index 0a3457b0..4e88384c 100644
--- a/app/src/main/java/com/bnyro/wallpaper/ui/components/BlockButton.kt
+++ b/app/src/main/java/com/bnyro/wallpaper/ui/components/BlockButton.kt
@@ -1,5 +1,6 @@
package com.bnyro.wallpaper.ui.components
+import android.util.Log
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
@@ -23,12 +24,13 @@ fun BlockButton(
selected: Boolean,
onClick: () -> Unit
) {
+ Log.e(text, selected.toString())
Column(
modifier = modifier
.height(50.dp)
.clip(RoundedCornerShape(12.dp))
.background(
- if (selected) {
+ if (!selected) {
MaterialTheme.colorScheme.surfaceVariant.copy(
0.5f
)
@@ -46,7 +48,7 @@ fun BlockButton(
style = MaterialTheme.typography.labelLarge.copy(
textAlign = TextAlign.Center
),
- color = if (selected) MaterialTheme.colorScheme.onSurface else MaterialTheme.colorScheme.inverseSurface
+ color = if (!selected) MaterialTheme.colorScheme.onSurface else MaterialTheme.colorScheme.inverseSurface
)
}
}
diff --git a/app/src/main/java/com/bnyro/wallpaper/ui/components/WallpaperChangerPref.kt b/app/src/main/java/com/bnyro/wallpaper/ui/components/WallpaperChangerPref.kt
index 3e5fc5dc..fdc9ce81 100644
--- a/app/src/main/java/com/bnyro/wallpaper/ui/components/WallpaperChangerPref.kt
+++ b/app/src/main/java/com/bnyro/wallpaper/ui/components/WallpaperChangerPref.kt
@@ -11,6 +11,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
+import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
@@ -25,11 +26,10 @@ import com.bnyro.wallpaper.R
import com.bnyro.wallpaper.enums.WallpaperConfig
import com.bnyro.wallpaper.enums.WallpaperSource
import com.bnyro.wallpaper.enums.WallpaperTarget
-import com.bnyro.wallpaper.ui.components.prefs.BlockPreference
+import com.bnyro.wallpaper.ui.components.prefs.MultiSelectionBlockPreference
import com.bnyro.wallpaper.ui.components.prefs.ListPreference
import com.bnyro.wallpaper.ui.components.prefs.SettingsCategory
import com.bnyro.wallpaper.ui.nav.DrawerScreens
-import com.bnyro.wallpaper.util.LocalWallpaperHelper
import com.bnyro.wallpaper.util.PickFolderContract
@Composable
@@ -84,19 +84,20 @@ fun WallpaperChangerPref(config: WallpaperConfig, onChange: (WallpaperConfig) ->
Crossfade(targetState = wallpaperSource, label = "wallpaper_source") { state ->
when (state) {
WallpaperSource.ONLINE -> {
- var currentIndex by remember {
- mutableIntStateOf(
- DrawerScreens.apiScreens.indexOfFirst { it.route == config.apiRoute }
- )
+ var currentSelections = remember {
+ config.apiRoute?.split(",").orEmpty().map { route ->
+ DrawerScreens.apiScreens.indexOfFirst { it.route == route }
+ }
}
- BlockPreference(
+ MultiSelectionBlockPreference(
preferenceKey = null,
entries = DrawerScreens.apiScreens.map { stringResource(it.titleResource) },
values = DrawerScreens.apiScreens.map { it.route },
- defaultSelection = currentIndex
- ) { index ->
- config.apiRoute = DrawerScreens.apiScreens[index].route
- currentIndex = index
+ defaultSelections = currentSelections
+ ) { selections ->
+ config.apiRoute =
+ selections.joinToString(",") { DrawerScreens.apiScreens[it].route }
+ currentSelections = selections
onChange(config)
}
}
diff --git a/app/src/main/java/com/bnyro/wallpaper/ui/components/prefs/BlockPreference.kt b/app/src/main/java/com/bnyro/wallpaper/ui/components/prefs/BlockPreference.kt
index f08e2e26..ed5b7ec8 100644
--- a/app/src/main/java/com/bnyro/wallpaper/ui/components/prefs/BlockPreference.kt
+++ b/app/src/main/java/com/bnyro/wallpaper/ui/components/prefs/BlockPreference.kt
@@ -2,48 +2,42 @@ package com.bnyro.wallpaper.ui.components.prefs
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyRow
-import androidx.compose.foundation.lazy.items
+import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.runtime.Composable
-import androidx.compose.runtime.LaunchedEffect
-import androidx.compose.runtime.getValue
-import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
-import androidx.compose.runtime.setValue
+import androidx.compose.runtime.toMutableStateList
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.bnyro.wallpaper.ui.components.BlockButton
import com.bnyro.wallpaper.util.Preferences
@Composable
-fun BlockPreference(
+fun MultiSelectionBlockPreference(
preferenceKey: String?,
entries: List,
values: List,
- defaultSelection: Int = 0,
- onSelectionChange: (Int) -> Unit = {}
+ defaultSelections: List = listOf(0),
+ onSelectionChange: (List) -> Unit = {}
) {
- var selected by remember {
- mutableIntStateOf(defaultSelection)
- }
-
- LaunchedEffect(Unit) {
- if (preferenceKey == null) return@LaunchedEffect
- val pref = Preferences.getString(preferenceKey, "")
- if (pref.orEmpty().isNotEmpty()) selected = values.indexOf(pref)
+ val selected = remember {
+ val pref = preferenceKey?.let { Preferences.getString(it, "").split(",") }
+ val sel = if (!pref.isNullOrEmpty()) pref.map { values.indexOf(it) } else defaultSelections
+ sel.toMutableStateList()
}
LazyRow(
modifier = Modifier.padding(horizontal = 5.dp)
) {
- items(entries) {
- val index = entries.indexOf(it)
+ itemsIndexed(entries) { index, it ->
BlockButton(
modifier = Modifier.padding(2.dp, 0.dp),
text = it,
- selected = index != selected
+ selected = selected.contains(index)
) {
- Preferences.edit { putString(preferenceKey, values[index]) }
- selected = index
+ if (selected.contains(index)) selected.remove(index) else selected.add(index)
+ if (preferenceKey != null) Preferences.edit {
+ putString(preferenceKey, values.joinToString(","))
+ }
onSelectionChange.invoke(selected)
}
}
diff --git a/app/src/main/java/com/bnyro/wallpaper/util/BackgroundWorker.kt b/app/src/main/java/com/bnyro/wallpaper/util/BackgroundWorker.kt
index 58f987ed..f8f149da 100644
--- a/app/src/main/java/com/bnyro/wallpaper/util/BackgroundWorker.kt
+++ b/app/src/main/java/com/bnyro/wallpaper/util/BackgroundWorker.kt
@@ -39,9 +39,11 @@ class BackgroundWorker(
}
private suspend fun getOnlineWallpaper(config: WallpaperConfig): Bitmap? {
+ val source = config.apiRoute?.split(",")?.randomOrNull() ?: return null
+
return withContext(Dispatchers.IO) {
val url = runCatching {
- Preferences.getApiByRoute(config.apiRoute.orEmpty()).getRandomWallpaperUrl()
+ Preferences.getApiByRoute(source).getRandomWallpaperUrl()
}.getOrElse { return@withContext null }
ImageHelper.getSuspend(applicationContext, url, true)
}