Skip to content

Commit

Permalink
feat: option to set wallpaper changer network type (closes #183)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Apr 2, 2024
1 parent 7c35b57 commit cdf3509
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
17 changes: 17 additions & 0 deletions app/src/main/java/com/bnyro/wallpaper/ui/pages/SettingsPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.work.NetworkType
import com.bnyro.wallpaper.R
import com.bnyro.wallpaper.enums.ThemeMode
import com.bnyro.wallpaper.enums.WallpaperConfig
Expand Down Expand Up @@ -138,6 +139,13 @@ fun SettingsPage(
1440L
)

val networkTypes = listOf(
R.string.all_networks to NetworkType.CONNECTED,
R.string.unmetered to NetworkType.UNMETERED,
R.string.metered to NetworkType.METERED,
R.string.not_roaming to NetworkType.NOT_ROAMING,
)

AboutContainer {
SettingsCategory(
title = stringResource(R.string.wallpaper_changer)
Expand All @@ -152,6 +160,15 @@ fun SettingsPage(
) {
WorkerHelper.enqueue(context, true)
}
ListPreference(
prefKey = Preferences.wallpaperChangerNetworkTypeKey,
title = stringResource(R.string.network_type),
entries = networkTypes.map { stringResource(id = it.first) },
values = networkTypes.map { it.second.name },
defaultValue = NetworkType.CONNECTED.name
) {
WorkerHelper.enqueue(context, true)
}
ListPreference(
prefKey = Preferences.wallpaperChangerIntervalKey,
title = stringResource(R.string.change_interval),
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/bnyro/wallpaper/util/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ object Preferences {

const val wallpaperChangerKey = "wallpaperChanger"
const val wallpaperChangerIntervalKey = "wallpaperChangerInterval"
const val wallpaperChangerNetworkTypeKey = "wallpaperChangerNetworkType"
private const val wallpaperChangerConfigKey = "wallpaperChangerConfig"
const val combineWallpaperChangers = "combineWallpaperChangers"

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/com/bnyro/wallpaper/util/WorkerHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ object WorkerHelper {
val wallpaperConfigs = Preferences.getWallpaperConfigs()
// only require internet when the source is not local
val networkType = if (wallpaperConfigs.any { it.source != WallpaperSource.LOCAL }) {
NetworkType.CONNECTED
val pref = Preferences.getString(Preferences.wallpaperChangerNetworkTypeKey, NetworkType.CONNECTED.name)
NetworkType.valueOf(pref)
} else {
NetworkType.NOT_REQUIRED
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@
<string name="none">None</string>
<string name="invert_wallpaper_by_theme">Invert wallpaper by theme</string>
<string name="invert_wallpaper_by_theme_summary">Invert the wallpaper to be dark on dark themes and light on light themes.</string>
<!-- Network constraints -->
<string name="network_type">Network type</string>
<string name="all_networks">All networks</string>
<string name="unmetered">Unmetered</string>
<string name="metered">Metered</string>
<string name="not_roaming">Not roaming</string>
<!-- Wallpaper changer source -->
<string name="online">Online</string>
<string name="local">Local</string>
Expand Down

0 comments on commit cdf3509

Please sign in to comment.