-
-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wallpaper changer: option to set different walls for lockscreen than …
…homescreen (closes #110)
- Loading branch information
Showing
41 changed files
with
231 additions
and
165 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
7 changes: 0 additions & 7 deletions
7
app/src/main/java/com/bnyro/wallpaper/constants/WallpaperMode.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.bnyro.wallpaper.enums | ||
|
||
enum class ThemeMode(val value: Int) { | ||
AUTO(0), | ||
LIGHT(1), | ||
DARK(2) | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/bnyro/wallpaper/enums/WallpaperConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.bnyro.wallpaper.enums | ||
|
||
import com.bnyro.wallpaper.ui.nav.DrawerScreens | ||
|
||
data class WallpaperConfig( | ||
var target: WallpaperTarget = WallpaperTarget.BOTH, | ||
var source: WallpaperSource = WallpaperSource.ONLINE, | ||
var apiRoute: String? = DrawerScreens.apiScreens.firstOrNull()?.route, | ||
var localFolderUri: String? = null, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/src/main/java/com/bnyro/wallpaper/enums/WallpaperTarget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.bnyro.wallpaper.enums | ||
|
||
enum class WallpaperTarget(val value: Int) { | ||
BOTH(0), | ||
HOME(1), | ||
LOCK (2) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
app/src/main/java/com/bnyro/wallpaper/ui/components/WallpaperChangerPref.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package com.bnyro.wallpaper.ui.components | ||
|
||
import androidx.activity.compose.rememberLauncherForActivityResult | ||
import androidx.compose.animation.Crossfade | ||
import androidx.compose.material3.Button | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableIntStateOf | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
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.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 | ||
import com.bnyro.wallpaper.util.WorkerHelper | ||
|
||
@Composable | ||
fun WallpaperChangerPref(config: WallpaperConfig, onChange: (WallpaperConfig) -> Unit) { | ||
val context = LocalContext.current | ||
|
||
val localWallpaperDirChooser = rememberLauncherForActivityResult(PickFolderContract()) { | ||
val uri = it ?: return@rememberLauncherForActivityResult | ||
config.localFolderUri = uri.toString() | ||
onChange(config) | ||
} | ||
|
||
SettingsCategory( | ||
title = stringResource( | ||
when (config.target) { | ||
WallpaperTarget.BOTH -> R.string.both | ||
WallpaperTarget.HOME -> R.string.home | ||
WallpaperTarget.LOCK -> R.string.lockscreen | ||
} | ||
) | ||
) | ||
val wallpaperSources = listOf(R.string.online, R.string.favorites, R.string.local) | ||
var wallpaperSource by remember { mutableStateOf(config.source) } | ||
ListPreference( | ||
prefKey = null, | ||
title = stringResource(R.string.wallpaper_changer_source), | ||
entries = wallpaperSources.map { stringResource(it) }, | ||
values = List(wallpaperSources.size) { index -> index.toString() }, | ||
defaultValue = wallpaperSource.value.toString() | ||
) { newValue -> | ||
config.source = WallpaperSource.fromInt(newValue.toInt()) | ||
wallpaperSource = config.source | ||
onChange(config) | ||
WorkerHelper.enqueue(context, true) | ||
} | ||
|
||
Crossfade(targetState = wallpaperSource) { state -> | ||
when (state) { | ||
WallpaperSource.ONLINE -> { | ||
var currentIndex by remember { | ||
mutableIntStateOf(DrawerScreens.apiScreens.indexOfFirst { it.route == config.apiRoute }) | ||
} | ||
BlockPreference( | ||
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 | ||
onChange(config) | ||
WorkerHelper.enqueue(context, true) | ||
} | ||
} | ||
|
||
WallpaperSource.LOCAL -> Button( | ||
onClick = { | ||
val currentFolder = LocalWallpaperHelper.getDirectory(config) | ||
localWallpaperDirChooser.launch(currentFolder) | ||
} | ||
) { | ||
Text(stringResource(R.string.choose_dir)) | ||
} | ||
|
||
else -> Unit | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.