Skip to content

Commit 18cc747

Browse files
committed
theme changes rebuild host activity
1 parent 2f1afa0 commit 18cc747

7 files changed

Lines changed: 45 additions & 10 deletions

File tree

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1+
#Wed Jul 22 11:32:35 BST 2026
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
3-
distributionSha256Sum=bafc141b619ad6350fd975fc903156dd5c151998cc8b058e8c1044ab5f7b031f
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip
5-
networkTimeout=10000
6-
retries=0
7-
retryBackOffMs=500
8-
validateDistributionUrl=true
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.6.1-bin.zip
95
zipStoreBase=GRADLE_USER_HOME
106
zipStorePath=wrapper/dists

settings.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ pluginManagement {
1212
mavenCentral()
1313
}
1414
}
15+
plugins {
16+
id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"
17+
}
1518
dependencyResolutionManagement {
1619
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
1720
repositories {

shared/src/androidMain/kotlin/net/newpipe/app/platform/AndroidAppearanceActions.kt

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,45 @@ package net.newpipe.app.platform
88
import android.content.ActivityNotFoundException
99
import android.content.Context
1010
import android.content.Intent
11-
import android.provider.Settings
11+
import android.provider.Settings as AndroidSettings
12+
import androidx.appcompat.app.AppCompatDelegate
1213
import co.touchlab.kermit.Logger
14+
import com.russhwolf.settings.Settings
15+
import net.newpipe.app.preferences.AppearancePreferences
1316
import org.koin.core.annotation.Singleton
1417

1518
@Singleton(binds = [AppearanceActions::class])
16-
class AndroidAppearanceActions(private val context: Context) : AppearanceActions {
19+
class AndroidAppearanceActions(
20+
private val context: Context,
21+
private val settings: Settings,
22+
) : AppearanceActions {
1723

1824
override fun openCaptionSettings() {
1925
try {
2026
context.startActivity(
21-
Intent(Settings.ACTION_CAPTIONING_SETTINGS)
27+
Intent(AndroidSettings.ACTION_CAPTIONING_SETTINGS)
2228
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
2329
)
2430
} catch (exception: ActivityNotFoundException) {
2531
Logger.e(messageString = "No activity found for captioning settings", throwable = exception)
2632
}
2733
}
34+
35+
override fun applyThemeChange(theme: String) {
36+
AppCompatDelegate.setDefaultNightMode(
37+
when (theme) {
38+
AppearancePreferences.THEME_LIGHT -> AppCompatDelegate.MODE_NIGHT_NO
39+
40+
AppearancePreferences.THEME_DARK,
41+
AppearancePreferences.THEME_BLACK -> AppCompatDelegate.MODE_NIGHT_YES
42+
43+
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
44+
}
45+
)
46+
settings.putBoolean(KEY_THEME_CHANGE, true)
47+
}
48+
49+
private companion object {
50+
const val KEY_THEME_CHANGE = "key_theme_change"
51+
}
2852
}

shared/src/commonMain/kotlin/net/newpipe/app/platform/AppearanceActions.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ package net.newpipe.app.platform
1010
*/
1111
interface AppearanceActions {
1212
fun openCaptionSettings()
13+
14+
fun applyThemeChange(theme: String)
1315
}

shared/src/commonMain/kotlin/net/newpipe/app/viewmodel/settings/AppearanceSettingsViewModel.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ import androidx.lifecycle.ViewModel
99
import com.russhwolf.settings.Settings
1010
import kotlinx.coroutines.flow.MutableStateFlow
1111
import kotlinx.coroutines.flow.StateFlow
12+
import net.newpipe.app.platform.AppearanceActions
1213
import net.newpipe.app.preferences.AppearancePreferences
1314
import org.koin.core.annotation.KoinViewModel
1415

1516

1617
@KoinViewModel
17-
class AppearanceSettingsViewModel(private val settings: Settings) : ViewModel() {
18+
class AppearanceSettingsViewModel(
19+
private val settings: Settings,
20+
private val appearanceActions: AppearanceActions,
21+
) : ViewModel() {
1822

1923
val theme: StateFlow<String>
2024
field = MutableStateFlow(
@@ -64,11 +68,13 @@ class AppearanceSettingsViewModel(private val settings: Settings) : ViewModel()
6468
fun setTheme(value: String) {
6569
settings.putString(AppearancePreferences.KEY_THEME, value)
6670
theme.value = value
71+
appearanceActions.applyThemeChange(value)
6772
}
6873

6974
fun setNightTheme(value: String) {
7075
settings.putString(AppearancePreferences.KEY_NIGHT_THEME, value)
7176
nightTheme.value = value
77+
appearanceActions.applyThemeChange(theme.value)
7278
}
7379

7480
fun setHoldToAppend(value: Boolean) {

shared/src/iosMain/kotlin/net/newpipe/app/platform/IOSAppearanceActions.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ import org.koin.core.annotation.Singleton
1010
@Singleton(binds = [AppearanceActions::class])
1111
class IOSAppearanceActions : AppearanceActions {
1212
override fun openCaptionSettings() = Unit
13+
14+
override fun applyThemeChange(theme: String) = Unit
1315
}

shared/src/jvmMain/kotlin/net/newpipe/app/platform/JVMAppearanceActions.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ import org.koin.core.annotation.Singleton
1010
@Singleton(binds = [AppearanceActions::class])
1111
class JVMAppearanceActions : AppearanceActions {
1212
override fun openCaptionSettings() = Unit
13+
14+
override fun applyThemeChange(theme: String) = Unit
1315
}

0 commit comments

Comments
 (0)