fix: Fix theme settings real-time updates and auto-update check failure

This commit is contained in:
tunbmoon
2026-02-06 14:40:01 +08:00
parent 43077ee0aa
commit e94edcfaaf
10 changed files with 58 additions and 91 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ Astronia 是一款轻量级的现代化 Android M3U8 视频播放器,采用 Ma
- 🔄 自动更新功能
- 🎨 现代化直观界面
- 🔒 注重隐私(不收集数据)
- 🌐 多语言支持
- 🌐 多语言支持30+
## ⬇️ 下载
+1 -1
View File
@@ -24,7 +24,7 @@ Astronia 是一款輕量級的現代化 Android M3U8 視訊播放器,採用 Ma
- 🔄 自動更新功能
- 🎨 現代化直觀介面
- 🔒 注重隱私(不收集資料)
- 🌐 多語言支援
- 🌐 多語言支援30+
## ⬇️ 下載
+1 -1
View File
@@ -24,7 +24,7 @@ Astronia is a lightweight and modern M3U8 video player for Android, built with M
- 🔄 Auto-update functionality
- 🎨 Modern and intuitive interface
- 🔒 Privacy-focused (no data collection)
- 🌐 Multi-language support
- 🌐 Multi-language support (30+)
## ⬇️ Download
+9 -7
View File
@@ -22,8 +22,8 @@ android {
applicationId = "com.antoniegil.astronia"
minSdk = 24
targetSdk = 36
versionCode = 10000
versionName = "1.0.0"
versionCode = 101
versionName = "1.0.1"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables { useSupportLibrary = true }
@@ -115,11 +115,13 @@ android {
onVariants { variant ->
variant.outputs.forEach { output ->
val abiName = output.filters.find { it.filterType == com.android.build.api.variant.FilterConfiguration.FilterType.ABI }?.identifier ?: "universal"
output.versionCode.set((output.versionCode.orNull ?: 0) + when(abiName) {
"arm64-v8a" -> 3
"armeabi-v7a" -> 2
"x86_64" -> 1
"x86" -> 0
val baseVersionCode = output.versionCode.orNull ?: 0
output.versionCode.set(baseVersionCode * 100 + when(abiName) {
"arm64-v8a" -> 4
"armeabi-v7a" -> 3
"x86_64" -> 2
"x86" -> 1
"universal" -> 0
else -> 0
})
}
@@ -60,12 +60,6 @@ class MainActivity : AppCompatActivity() {
SettingsManager.initializeThemeSettings(context)
}
val themeSettings by SettingsManager.themeSettingsFlow.collectAsState()
val paletteStyleIndex = SettingsManager.getPaletteStyle(context)
val backgroundPlay = SettingsManager.getBackgroundPlay(context)
val proxyEnabled = SettingsManager.getProxyEnabled(context)
val proxyHost = SettingsManager.getProxyHost(context)
val proxyPort = SettingsManager.getProxyPort(context)
val pendingNav = remember { SettingsManager.getPendingNavigation(context) }
LaunchedEffect(Unit) {
@@ -74,31 +68,12 @@ class MainActivity : AppCompatActivity() {
}
}
SettingsProvider(
themeMode = themeSettings.themeMode,
dynamicColor = themeSettings.dynamicColor,
seedColor = themeSettings.seedColor,
paletteStyleIndex = paletteStyleIndex,
isHighContrastModeEnabled = themeSettings.highContrast,
backgroundPlay = backgroundPlay,
proxyEnabled = proxyEnabled,
proxyHost = proxyHost,
proxyPort = proxyPort
) {
SettingsProvider {
MainScreen(
initialNavigation = pendingNav,
onThemeChanged = { newTheme ->
SettingsManager.setThemeMode(context, newTheme)
},
onDynamicColorChanged = { enabled ->
SettingsManager.setDynamicColor(context, enabled)
},
onSeedColorChanged = { color ->
SettingsManager.setSeedColor(context, color)
recreate()
},
onHighContrastChanged = { enabled ->
SettingsManager.setHighContrast(context, enabled)
}
)
}
@@ -121,10 +96,7 @@ class MainActivity : AppCompatActivity() {
@Composable
fun MainScreen(
initialNavigation: String = "",
onThemeChanged: (Int) -> Unit = {},
onDynamicColorChanged: (Boolean) -> Unit = {},
onSeedColorChanged: (Int) -> Unit = {},
onHighContrastChanged: (Boolean) -> Unit = {},
viewModel: MainViewModel = viewModel()
) {
val playbackState by viewModel.playbackState.collectAsState()
@@ -236,19 +208,13 @@ fun MainScreen(
animatedComposable(Route.APPEARANCE) {
AppearancePage(
onNavigateBack = onNavigateBack,
onThemeChanged = onThemeChanged,
onDynamicColorChanged = onDynamicColorChanged,
onSeedColorChanged = onSeedColorChanged,
onNavigateToDarkTheme = { navController.navigate(Route.DARK_THEME) { launchSingleTop = true } },
onNavigateToLanguage = { navController.navigate(Route.LANGUAGE) { launchSingleTop = true } }
)
}
animatedComposable(Route.DARK_THEME) {
DarkThemePage(
onNavigateBack = onNavigateBack,
onThemeChanged = onThemeChanged,
onHighContrastChanged = onHighContrastChanged
)
DarkThemePage(onNavigateBack = onNavigateBack)
}
animatedComposable(Route.LANGUAGE) {
LanguagePage(onNavigateBack = onNavigateBack)
@@ -65,8 +65,6 @@ private const val STYLE_MONOCHROME = 4
@Composable
fun AppearancePage(
onNavigateBack: () -> Unit,
onThemeChanged: (Int) -> Unit = {},
onDynamicColorChanged: (Boolean) -> Unit = {},
onSeedColorChanged: (Int) -> Unit = {},
onNavigateToDarkTheme: () -> Unit = {},
onNavigateToLanguage: () -> Unit = {}
@@ -115,7 +113,7 @@ fun AppearancePage(
initialPage = if (paletteStyleIndex == STYLE_MONOCHROME) {
pageCount - 1
} else {
ColorList.indexOf(Color(seedColor)).run {
ColorList.indexOfFirst { it.toArgb() == seedColor }.run {
if (this == -1) 0 else this
}
}
@@ -158,7 +156,7 @@ fun AppearancePage(
icon = Icons.Outlined.Colorize,
isChecked = dynamicColorSwitch,
onCheckedChange = { enabled ->
onDynamicColorChanged(enabled)
SettingsManager.setDynamicColor(context, enabled)
}
)
}
@@ -170,7 +168,7 @@ fun AppearancePage(
isChecked = isDarkTheme,
onChecked = { checked: Boolean ->
val newTheme = if (checked) 2 else 1
onThemeChanged(newTheme)
SettingsManager.setThemeMode(context, newTheme)
},
onClick = onNavigateToDarkTheme
)
@@ -21,14 +21,13 @@ import com.antoniegil.astronia.util.SettingsManager
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun DarkThemePage(
onNavigateBack: () -> Unit,
onThemeChanged: (Int) -> Unit = {},
onHighContrastChanged: (Boolean) -> Unit = {}
onNavigateBack: () -> Unit
) {
val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior()
val context = LocalContext.current
val currentTheme = remember { mutableIntStateOf(SettingsManager.getThemeMode(context)) }
var highContrastEnabled by remember { mutableStateOf(SettingsManager.getHighContrast(context)) }
val themeMode = com.antoniegil.astronia.ui.theme.LocalThemeMode.current
val highContrast = com.antoniegil.astronia.ui.theme.LocalHighContrast.current
Scaffold(
modifier = Modifier
@@ -50,10 +49,9 @@ fun DarkThemePage(
item {
PreferenceSingleChoiceItem(
text = stringResource(R.string.follow_system),
selected = currentTheme.intValue == 0,
selected = themeMode == 0,
onClick = {
currentTheme.intValue = 0
onThemeChanged(0)
SettingsManager.setThemeMode(context, 0)
}
)
}
@@ -62,10 +60,9 @@ fun DarkThemePage(
item {
PreferenceSingleChoiceItem(
text = stringResource(R.string.open),
selected = currentTheme.intValue == 2,
selected = themeMode == 2,
onClick = {
currentTheme.intValue = 2
onThemeChanged(2)
SettingsManager.setThemeMode(context, 2)
}
)
}
@@ -73,10 +70,9 @@ fun DarkThemePage(
item {
PreferenceSingleChoiceItem(
text = stringResource(R.string.close),
selected = currentTheme.intValue == 1,
selected = themeMode == 1,
onClick = {
currentTheme.intValue = 1
onThemeChanged(1)
SettingsManager.setThemeMode(context, 1)
}
)
}
@@ -89,10 +85,9 @@ fun DarkThemePage(
PreferenceSwitchVariant(
title = stringResource(R.string.high_contrast),
icon = Icons.Outlined.Contrast,
isChecked = highContrastEnabled,
isChecked = highContrast,
onClick = {
highContrastEnabled = !highContrastEnabled
onHighContrastChanged(highContrastEnabled)
SettingsManager.setHighContrast(context, !highContrast)
}
)
}
@@ -6,13 +6,15 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.runtime.getValue
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
import com.antoniegil.astronia.ui.theme.monet.LocalTonalPalettes
import com.antoniegil.astronia.ui.theme.monet.dynamicColorScheme
import com.antoniegil.astronia.util.SettingsManager
import com.kyant.monet.PaletteStyle
import com.kyant.monet.TonalPalettes.Companion.toTonalPalettes
@@ -21,11 +23,12 @@ val LocalProxyEnabled = compositionLocalOf { false }
val LocalProxyHost = compositionLocalOf { "" }
val LocalProxyPort = compositionLocalOf { 8080 }
val LocalThemeMode = staticCompositionLocalOf { 0 }
val LocalThemeMode = compositionLocalOf { 0 }
val LocalSeedColor = compositionLocalOf { 0xd40054 }
val LocalPaletteStyleIndex = compositionLocalOf { 0 }
val LocalDynamicColorSwitch = compositionLocalOf { false }
val LocalFixedColorRoles = staticCompositionLocalOf {
val LocalHighContrast = compositionLocalOf { false }
val LocalFixedColorRoles = compositionLocalOf {
FixedColorRoles.fromColorSchemes(
lightColors = androidx.compose.material3.lightColorScheme(),
darkColors = androidx.compose.material3.darkColorScheme(),
@@ -42,45 +45,43 @@ val paletteStyles = listOf(
@Composable
fun SettingsProvider(
themeMode: Int = 0,
dynamicColor: Boolean = true,
seedColor: Int = 0xd40054,
paletteStyleIndex: Int = 0,
isHighContrastModeEnabled: Boolean = false,
backgroundPlay: Boolean = false,
proxyEnabled: Boolean = false,
proxyHost: String = "",
proxyPort: Int = 8080,
content: @Composable () -> Unit
) {
val context = LocalContext.current
val themeSettings by SettingsManager.themeSettingsFlow.collectAsState()
val backgroundPlay = SettingsManager.getBackgroundPlay(context)
val proxyEnabled = SettingsManager.getProxyEnabled(context)
val proxyHost = SettingsManager.getProxyHost(context)
val proxyPort = SettingsManager.getProxyPort(context)
val systemInDarkTheme = isSystemInDarkTheme()
val isDarkTheme = when (themeMode) {
val isDarkTheme = when (themeSettings.themeMode) {
1 -> false
2 -> true
else -> systemInDarkTheme
}
val tonalPalettes = if (dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val tonalPalettes = if (themeSettings.dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if (isDarkTheme) {
androidx.compose.material3.dynamicDarkColorScheme(context)
} else {
androidx.compose.material3.dynamicLightColorScheme(context)
}.toTonalPalettes()
} else {
Color(seedColor).toTonalPalettes(
paletteStyles.getOrElse(paletteStyleIndex) { PaletteStyle.TonalSpot }
Color(themeSettings.seedColor).toTonalPalettes(
paletteStyles.getOrElse(themeSettings.paletteStyleIndex) { PaletteStyle.TonalSpot }
)
}
val fixedColorRoles = FixedColorRoles.fromTonalPalettes(tonalPalettes)
CompositionLocalProvider(
LocalThemeMode provides themeMode,
LocalSeedColor provides seedColor,
LocalPaletteStyleIndex provides paletteStyleIndex,
LocalDynamicColorSwitch provides dynamicColor,
LocalThemeMode provides themeSettings.themeMode,
LocalSeedColor provides themeSettings.seedColor,
LocalPaletteStyleIndex provides themeSettings.paletteStyleIndex,
LocalDynamicColorSwitch provides themeSettings.dynamicColor,
LocalHighContrast provides themeSettings.highContrast,
LocalTonalPalettes provides tonalPalettes,
LocalFixedColorRoles provides fixedColorRoles,
LocalBackgroundPlay provides backgroundPlay,
@@ -90,7 +91,7 @@ fun SettingsProvider(
) {
AstroniaTheme(
isDarkTheme = isDarkTheme,
isHighContrastModeEnabled = isHighContrastModeEnabled,
isHighContrastModeEnabled = themeSettings.highContrast,
content = content
)
}
@@ -73,7 +73,12 @@ class OrientationHelper(
private fun initGravity(activity: Activity) {
if (isLand == LAND_TYPE_NULL) {
val defaultRotation = activity.windowManager.defaultDisplay.rotation
val defaultRotation = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
activity.display?.rotation ?: Surface.ROTATION_0
} else {
@Suppress("DEPRECATION")
activity.windowManager.defaultDisplay.rotation
}
when (defaultRotation) {
Surface.ROTATION_0 -> {
isLand = LAND_TYPE_NULL
@@ -27,7 +27,7 @@ import java.util.regex.Pattern
object UpdateUtil {
private const val OWNER = "antoniegil"
private const val REPO = "com.antoniegil.astronia"
private const val REPO = "Astronia"
private const val TAG = "UpdateUtil"
private val client = OkHttpClient()