mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-05-14 17:32:12 +00:00
Setup multiplatform settings with KMP and theme
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
@@ -17,6 +17,9 @@ kotlin {
|
||||
jvmToolchain(21)
|
||||
|
||||
compilerOptions {
|
||||
freeCompilerArgs.addAll(
|
||||
"-Xexpect-actual-classes"
|
||||
)
|
||||
optIn.addAll(
|
||||
"androidx.compose.material3.ExperimentalMaterial3Api",
|
||||
"androidx.compose.material3.ExperimentalMaterial3ExpressiveApi",
|
||||
@@ -65,6 +68,8 @@ kotlin {
|
||||
|
||||
implementation(libs.koin.compose.viewmodel)
|
||||
implementation(libs.koin.annotations)
|
||||
|
||||
implementation(libs.russhwolf.settings)
|
||||
}
|
||||
commonTest.dependencies {
|
||||
implementation(libs.kotlin.test)
|
||||
@@ -72,6 +77,7 @@ kotlin {
|
||||
androidMain.dependencies {
|
||||
implementation(libs.jetbrains.compose.preview)
|
||||
implementation(libs.androidx.activity)
|
||||
implementation(libs.androidx.preference)
|
||||
}
|
||||
jvmMain.dependencies {
|
||||
implementation(compose.desktop.currentOs)
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package net.newpipe.app.di.settings
|
||||
|
||||
import android.content.Context
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.russhwolf.settings.Settings
|
||||
import com.russhwolf.settings.SharedPreferencesSettings
|
||||
import org.koin.core.annotation.Singleton
|
||||
|
||||
/**
|
||||
* Settings for Android based on SharedPreferences
|
||||
*/
|
||||
@Singleton
|
||||
fun provideSettings(context: Context): Settings = SharedPreferencesSettings(
|
||||
PreferenceManager.getDefaultSharedPreferences(context)
|
||||
)
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package net.newpipe.app.di.settings
|
||||
|
||||
import org.koin.core.annotation.ComponentScan
|
||||
import org.koin.core.annotation.Configuration
|
||||
import org.koin.core.annotation.Module
|
||||
|
||||
/**
|
||||
* Settings module to access key-value pairs across different platforms.
|
||||
* See individual platform packages for the declarations included in this module.
|
||||
*/
|
||||
@Module
|
||||
@ComponentScan
|
||||
@Configuration
|
||||
class SettingsModule
|
||||
@@ -12,6 +12,9 @@ import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import com.russhwolf.settings.Settings
|
||||
import org.koin.compose.koinInject
|
||||
|
||||
private val lightScheme = lightColorScheme(
|
||||
primary = primaryLight,
|
||||
@@ -89,12 +92,25 @@ private val darkScheme = darkColorScheme(
|
||||
surfaceContainerHighest = surfaceContainerHighestDark,
|
||||
)
|
||||
|
||||
private val blackScheme = darkScheme.copy(surface = Color.Black)
|
||||
|
||||
@Composable
|
||||
fun AppTheme(useDarkTheme: Boolean = isSystemInDarkTheme(), content: @Composable () -> Unit) {
|
||||
fun AppTheme(
|
||||
useDarkTheme: Boolean = isSystemInDarkTheme(),
|
||||
settings: Settings = koinInject(),
|
||||
content: @Composable () -> Unit
|
||||
) {
|
||||
val nightScheme = when(settings.getString("night_theme", "dark_theme")) {
|
||||
"black_theme" -> blackScheme
|
||||
else -> darkScheme
|
||||
}
|
||||
|
||||
MaterialExpressiveTheme(
|
||||
colorScheme = when {
|
||||
!useDarkTheme -> lightScheme
|
||||
else -> darkScheme
|
||||
colorScheme = when(settings.getString("theme", "auto_device_theme")) {
|
||||
"light_theme" -> lightScheme
|
||||
"dark_theme" -> darkScheme
|
||||
"black_theme" -> blackScheme
|
||||
else -> if (!useDarkTheme) lightScheme else nightScheme
|
||||
},
|
||||
content = content
|
||||
)
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package net.newpipe.app.di.settings
|
||||
|
||||
import com.russhwolf.settings.NSUserDefaultsSettings
|
||||
import com.russhwolf.settings.Settings
|
||||
import org.koin.core.annotation.Singleton
|
||||
import platform.Foundation.NSUserDefaults
|
||||
|
||||
/**
|
||||
* Settings for iOS based on UserDefaultsSettings
|
||||
*/
|
||||
@Singleton
|
||||
fun provideSettings(): Settings = NSUserDefaultsSettings(NSUserDefaults())
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
|
||||
package net.newpipe.app.di.settings
|
||||
|
||||
import com.russhwolf.settings.PreferencesSettings
|
||||
import com.russhwolf.settings.Settings
|
||||
import org.koin.core.annotation.Singleton
|
||||
import java.util.prefs.Preferences
|
||||
|
||||
/**
|
||||
* Settings for JVM devices based on Java Preferences
|
||||
*/
|
||||
@Singleton
|
||||
fun provideSettings(): Settings = PreferencesSettings(Preferences.userRoot())
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
[versions]
|
||||
acra = "5.13.1"
|
||||
agp = "9.2.0"
|
||||
activity = "1.13.0"
|
||||
agp = "9.2.0"
|
||||
appcompat = "1.7.1"
|
||||
assertj = "3.27.7"
|
||||
autoservice-google = "1.1.1"
|
||||
@@ -53,6 +53,7 @@ runner = "1.7.0"
|
||||
rxandroid = "3.0.2"
|
||||
rxbinding = "4.0.0"
|
||||
rxjava = "3.1.12"
|
||||
settings = "1.3.0"
|
||||
sonarqube = "7.2.3.7755"
|
||||
statesaver = "1.4.1" # TODO: Drop because it is deprecated and incompatible with KSP2
|
||||
stetho = "1.6.0"
|
||||
@@ -150,6 +151,7 @@ pinterest-ktlint = { module = "com.pinterest.ktlint:ktlint-cli", version.ref = "
|
||||
puppycrawl-checkstyle = { module = "com.puppycrawl.tools:checkstyle", version.ref = "checkstyle" }
|
||||
reactivex-rxandroid = { module = "io.reactivex.rxjava3:rxandroid", version.ref = "rxandroid" }
|
||||
reactivex-rxjava = { module = "io.reactivex.rxjava3:rxjava", version.ref = "rxjava" }
|
||||
russhwolf-settings = { module = "com.russhwolf:multiplatform-settings", version.ref = "settings" }
|
||||
squareup-leakcanary-core = { module = "com.squareup.leakcanary:leakcanary-android-core", version.ref = "leakcanary" }
|
||||
squareup-leakcanary-plumber = { module = "com.squareup.leakcanary:plumber-android", version.ref = "leakcanary" }
|
||||
squareup-leakcanary-watcher = { module = "com.squareup.leakcanary:leakcanary-object-watcher-android", version.ref = "leakcanary" }
|
||||
|
||||
Reference in New Issue
Block a user