From 391287453d4c1602ffeec66bf04b068e92c2ad50 Mon Sep 17 00:00:00 2001 From: 1984Enjoyer <334879034+1984Enjoyer@users.noreply.github.com> Date: Sun, 22 Nov 2026 15:33:44 +0500 Subject: [PATCH 1/3] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D1=82=D1=8C=20?= =?UTF-8?q?=D0=BE=D0=B1=D0=B2=D0=BE=D0=B4=D0=BA=D1=83=20=D0=B8=20=D0=BE?= =?UTF-8?q?=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D1=84=D0=BE?= =?UTF-8?q?=D0=BD=20=D0=B1=D0=BB=D0=BE=D0=BA=D0=B0=20=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D1=82=D0=B8=D1=81=D1=82=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../freeturn/app/ui/screens/home/ConnectionStatsCard.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/freeturn/app/ui/screens/home/ConnectionStatsCard.kt b/app/src/main/java/com/freeturn/app/ui/screens/home/ConnectionStatsCard.kt index ffa9639..22fd90d 100644 --- a/app/src/main/java/com/freeturn/app/ui/screens/home/ConnectionStatsCard.kt +++ b/app/src/main/java/com/freeturn/app/ui/screens/home/ConnectionStatsCard.kt @@ -2,7 +2,6 @@ package com.freeturn.app.ui.screens.home import android.text.format.Formatter import android.widget.Toast -import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -21,6 +20,7 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.alpha import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource @@ -55,11 +55,7 @@ internal fun ConnectionStatsCard( if (shown) { Surface( shape = MaterialTheme.shapes.large, - color = MaterialTheme.colorScheme.surfaceContainerLow, - border = BorderStroke( - 1.dp, - MaterialTheme.colorScheme.outlineVariant - ), + color = Color.Transparent, modifier = Modifier .fillMaxWidth() .padding(horizontal = Spacing.xxl) From d176926145498fb691f8b68b3e90b313e6ca78d4 Mon Sep 17 00:00:00 2001 From: 1984Enjoyer <334879034+1984Enjoyer@users.noreply.github.com> Date: Sun, 22 Nov 2026 15:33:44 +0500 Subject: [PATCH 2/3] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B8=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0?= =?UTF-8?q?=D0=B6=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D0=B1=D1=89=D0=B8=D1=85?= =?UTF-8?q?=20=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20=D1=82=D1=83=D0=BD?= =?UTF-8?q?=D0=BD=D0=B5=D0=BB=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/freeturn/app/data/AppPreferences.kt | 49 +---------- .../app/data/SplitTunnelPreferences.kt | 60 +++++++++++++ .../screens/splittunnel/SplitTunnelSheet.kt | 6 +- .../app/data/SplitTunnelPreferencesTest.kt | 88 +++++++++++++++++++ 4 files changed, 156 insertions(+), 47 deletions(-) create mode 100644 app/src/main/java/com/freeturn/app/data/SplitTunnelPreferences.kt create mode 100644 app/src/test/java/com/freeturn/app/data/SplitTunnelPreferencesTest.kt diff --git a/app/src/main/java/com/freeturn/app/data/AppPreferences.kt b/app/src/main/java/com/freeturn/app/data/AppPreferences.kt index deed307..34a0f35 100644 --- a/app/src/main/java/com/freeturn/app/data/AppPreferences.kt +++ b/app/src/main/java/com/freeturn/app/data/AppPreferences.kt @@ -24,7 +24,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.async import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.first @@ -158,9 +157,7 @@ class AppPreferences(context: Context) { /** Конфиг активного сервера; правила туннелирования общие, если включена галочка. */ val clientConfigFlow: Flow = - activeServerFlow.combine(splitSharedFlow) { server, shared -> - (server?.client ?: ClientConfig()).withShared(shared) - }.distinctUntilChanged() + prefFlow { p -> p.activeSplitClient() }.distinctUntilChanged() private fun ClientConfig.withShared(shared: SplitRules?): ClientConfig = if (splitTunnelShared && shared != null) { @@ -429,50 +426,12 @@ class AppPreferences(context: Context) { /** Правка правил: в общий набор, если у активного сервера включена галочка, иначе в его свои. */ suspend fun setSplitTunnelRule(mode: String? = null, apps: String? = null) { - val cfg = clientConfigFlow.first() - if (cfg.splitTunnelShared) { - context.dataStore.edit { p -> - p[SPLIT_SHARED_MODE] = mode ?: cfg.splitTunnelMode - p[SPLIT_SHARED_APPS] = apps ?: cfg.splitTunnelApps - } - } else { - updateActiveServer { s -> - s.copy( - client = s.client.copy( - splitTunnelMode = mode ?: s.client.splitTunnelMode, - splitTunnelApps = apps ?: s.client.splitTunnelApps - ) - ) - } - } + context.dataStore.edit { it.updateSplitTunnelRule(mode, apps) } } - /** - * Включение: общий набор создаётся из правил этого сервера, если его ещё нет. - * Выключение: общий набор копируется в собственные правила сервера, остальные не меняются. - */ + /** Общий набор и флаг профиля меняются одним атомарным снимком. */ suspend fun setSplitShared(enabled: Boolean) { - val own = serversSnapshot.first().active?.client ?: return - val shared = splitSharedFlow.first() - if (enabled) { - if (shared == null) { - context.dataStore.edit { - it[SPLIT_SHARED_MODE] = own.splitTunnelMode - it[SPLIT_SHARED_APPS] = own.splitTunnelApps - } - } - updateActiveServer { s -> s.copy(client = s.client.copy(splitTunnelShared = true)) } - } else { - updateActiveServer { s -> - s.copy( - client = s.client.copy( - splitTunnelShared = false, - splitTunnelMode = shared?.mode ?: s.client.splitTunnelMode, - splitTunnelApps = shared?.apps ?: s.client.splitTunnelApps - ) - ) - } - } + context.dataStore.edit { it.updateSplitShared(enabled) } } suspend fun setTgSubscribeShown() { diff --git a/app/src/main/java/com/freeturn/app/data/SplitTunnelPreferences.kt b/app/src/main/java/com/freeturn/app/data/SplitTunnelPreferences.kt new file mode 100644 index 0000000..c754ca2 --- /dev/null +++ b/app/src/main/java/com/freeturn/app/data/SplitTunnelPreferences.kt @@ -0,0 +1,60 @@ +package com.freeturn.app.data + +import androidx.datastore.preferences.core.MutablePreferences +import androidx.datastore.preferences.core.Preferences +import com.freeturn.app.data.AppPreferences.Companion.ACTIVE_SERVER_ID +import com.freeturn.app.data.AppPreferences.Companion.SERVERS_JSON +import com.freeturn.app.data.AppPreferences.Companion.SPLIT_SHARED_APPS +import com.freeturn.app.data.AppPreferences.Companion.SPLIT_SHARED_MODE +import com.freeturn.app.data.config.ClientConfig +import com.freeturn.app.data.server.Server +import com.freeturn.app.data.server.ServerJson + +/** Read effective rules from the same snapshot as the active profile. */ +internal fun Preferences.activeSplitClient(): ClientConfig { + val own = ServerJson.decodeList(this[SERVERS_JSON]) + .firstOrNull { it.id == this[ACTIVE_SERVER_ID] }?.client ?: return ClientConfig() + val mode = this[SPLIT_SHARED_MODE] + return if (own.splitTunnelShared && mode != null) own.copy( + splitTunnelMode = mode, splitTunnelApps = this[SPLIT_SHARED_APPS].orEmpty() + ) else own +} + +private fun MutablePreferences.editActiveSplit(transform: (Server) -> Server) { + val activeId = this[ACTIVE_SERVER_ID] ?: return + val list = ServerJson.decodeListOrNull(this[SERVERS_JSON]) ?: return + if (list.none { it.id == activeId }) return + this[SERVERS_JSON] = ServerJson.encodeList(list.map { if (it.id == activeId) transform(it) else it }) +} + +/** Called only inside DataStore.edit: never merge with a pre-transaction snapshot. */ +internal fun MutablePreferences.updateSplitTunnelRule(mode: String?, apps: String?) { + editActiveSplit { server -> + if (server.client.splitTunnelShared) { + this[SPLIT_SHARED_MODE] = mode ?: this[SPLIT_SHARED_MODE] ?: server.client.splitTunnelMode + this[SPLIT_SHARED_APPS] = apps ?: this[SPLIT_SHARED_APPS] ?: server.client.splitTunnelApps + server + } else server.copy(client = server.client.copy( + splitTunnelMode = mode ?: server.client.splitTunnelMode, + splitTunnelApps = apps ?: server.client.splitTunnelApps + )) + } +} + +internal fun MutablePreferences.updateSplitShared(enabled: Boolean) { + editActiveSplit { server -> + val own = server.client + if (own.splitTunnelShared == enabled) return@editActiveSplit server + if (enabled) { + if (this[SPLIT_SHARED_MODE] == null) { + this[SPLIT_SHARED_MODE] = own.splitTunnelMode + this[SPLIT_SHARED_APPS] = own.splitTunnelApps + } + server.copy(client = own.copy(splitTunnelShared = true)) + } else server.copy(client = own.copy( + splitTunnelShared = false, + splitTunnelMode = this[SPLIT_SHARED_MODE] ?: own.splitTunnelMode, + splitTunnelApps = this[SPLIT_SHARED_APPS] ?: own.splitTunnelApps + )) + } +} diff --git a/app/src/main/java/com/freeturn/app/ui/screens/splittunnel/SplitTunnelSheet.kt b/app/src/main/java/com/freeturn/app/ui/screens/splittunnel/SplitTunnelSheet.kt index d67ef9a..7c6060f 100644 --- a/app/src/main/java/com/freeturn/app/ui/screens/splittunnel/SplitTunnelSheet.kt +++ b/app/src/main/java/com/freeturn/app/ui/screens/splittunnel/SplitTunnelSheet.kt @@ -103,9 +103,10 @@ fun SplitTunnelSheetContent( val splitOn = mode != SplitTunnelMode.ALL val controlsEnabled = splitOn && !locked // Последний выбранный "рабочий" режим, чтобы свитч вкл возвращал его, а не дефолт. - var modeChoice by remember(shared) { + var lastEnabledMode by remember(shared) { mutableStateOf(if (mode != SplitTunnelMode.ALL) mode else SplitTunnelMode.EXCLUDE) } + val modeChoice = if (splitOn) mode else lastEnabledMode var query by remember { mutableStateOf("") } // Пустой exclude-список показывает рос-сервисы отмеченными (тот же дефолт, что и в WG). val selected = remember(apps, modeChoice) { splitTunnelSelection(modeChoice, apps) } @@ -142,6 +143,7 @@ fun SplitTunnelSheetContent( thumbContent = { SwitchThumbIcon(splitOn) }, onCheckedChange = { on -> HapticUtil.perform(context, HapticUtil.Pattern.SELECTION) + lastEnabledMode = modeChoice onModeChange(if (on) modeChoice else SplitTunnelMode.ALL) } ) @@ -206,7 +208,7 @@ fun SplitTunnelSheetContent( .fillMaxWidth() .padding(horizontal = HorizontalPadding), onSelect = { value -> - modeChoice = value + lastEnabledMode = value onModeChange(value) } ) diff --git a/app/src/test/java/com/freeturn/app/data/SplitTunnelPreferencesTest.kt b/app/src/test/java/com/freeturn/app/data/SplitTunnelPreferencesTest.kt new file mode 100644 index 0000000..ba24516 --- /dev/null +++ b/app/src/test/java/com/freeturn/app/data/SplitTunnelPreferencesTest.kt @@ -0,0 +1,88 @@ +package com.freeturn.app.data + +import androidx.datastore.preferences.core.mutablePreferencesOf +import com.freeturn.app.data.AppPreferences.Companion.ACTIVE_SERVER_ID +import com.freeturn.app.data.AppPreferences.Companion.SERVERS_JSON +import com.freeturn.app.data.AppPreferences.Companion.SPLIT_SHARED_APPS +import com.freeturn.app.data.AppPreferences.Companion.SPLIT_SHARED_MODE +import com.freeturn.app.data.config.ClientConfig +import com.freeturn.app.data.config.SplitTunnelMode +import com.freeturn.app.data.server.Server +import com.freeturn.app.data.server.ServerJson +import org.junit.Assert.* +import org.junit.Test + +class SplitTunnelPreferencesTest { + private val a = Server(id = "a", name = "a", client = ClientConfig( + splitTunnelMode = SplitTunnelMode.INCLUDE, splitTunnelApps = "app.a")) + private val b = Server(id = "b", name = "b", client = ClientConfig( + splitTunnelMode = SplitTunnelMode.EXCLUDE, splitTunnelApps = "app.b")) + private fun prefs() = mutablePreferencesOf( + SERVERS_JSON to ServerJson.encodeList(listOf(a, b)), ACTIVE_SERVER_ID to a.id) + + @Test fun `joining uses existing shared mode and apps together`() { + val p = prefs() + p.updateSplitShared(true) + p[ACTIVE_SERVER_ID] = b.id + p.updateSplitShared(true) + assertEquals(SplitTunnelMode.INCLUDE, p.activeSplitClient().splitTunnelMode) + assertEquals("app.a", p.activeSplitClient().splitTunnelApps) + assertTrue(ServerJson.decodeList(p[SERVERS_JSON]).all { it.client.splitTunnelShared }) + } + + @Test fun `partial shared edits preserve preceding edits`() { + val p = prefs() + p.updateSplitShared(true) + p.updateSplitTunnelRule(SplitTunnelMode.EXCLUDE, null) + p.updateSplitTunnelRule(null, "app.new") + assertEquals(SplitTunnelMode.EXCLUDE, p[SPLIT_SHARED_MODE]) + assertEquals("app.new", p[SPLIT_SHARED_APPS]) + p.updateSplitShared(false) + assertEquals(SplitTunnelMode.EXCLUDE, p.activeSplitClient().splitTunnelMode) + assertEquals("app.new", p.activeSplitClient().splitTunnelApps) + assertFalse(p.activeSplitClient().splitTunnelShared) + } + + @Test fun `leaving freezes private rules and does not change other profiles`() { + val p = prefs() + p.updateSplitShared(true) + p[ACTIVE_SERVER_ID] = b.id + p.updateSplitShared(true) + p.updateSplitShared(false) + p[ACTIVE_SERVER_ID] = a.id + p.updateSplitTunnelRule(null, "app.changed") + p[ACTIVE_SERVER_ID] = b.id + assertEquals("app.a", p.activeSplitClient().splitTunnelApps) + p.updateSplitShared(false) // duplicate callback must not overwrite private rules + assertEquals("app.a", p.activeSplitClient().splitTunnelApps) + p.updateSplitTunnelRule(null, "app.private") + p[ACTIVE_SERVER_ID] = a.id + assertEquals("app.changed", p.activeSplitClient().splitTunnelApps) + } + + @Test fun `private edits do not touch shared rules`() { + val p = prefs() + p.updateSplitShared(true) + p[ACTIVE_SERVER_ID] = b.id + p.updateSplitTunnelRule(null, "app.private") + assertEquals("app.a", p[SPLIT_SHARED_APPS]) + assertEquals("app.private", p.activeSplitClient().splitTunnelApps) + assertFalse(p.activeSplitClient().splitTunnelShared) + } + + @Test fun `missing active profile and corrupted list do not mutate shared rules`() { + val p = prefs() + p.updateSplitShared(true) + p[ACTIVE_SERVER_ID] = "missing" + val before = p.toPreferences() + p.updateSplitShared(false) + p.updateSplitTunnelRule(null, "wrong") + assertEquals(before, p) + p[SERVERS_JSON] = "broken" + p[ACTIVE_SERVER_ID] = a.id + val broken = p.toPreferences() + p.updateSplitShared(true) + p.updateSplitTunnelRule(SplitTunnelMode.ALL, null) + assertEquals(broken, p) + } +} From 7abfd1b00d88574804cbb3f5664dc658e05e246c Mon Sep 17 00:00:00 2001 From: 1984Enjoyer <334879034+1984Enjoyer@users.noreply.github.com> Date: Sun, 22 Nov 2026 15:33:44 +0500 Subject: [PATCH 3/3] =?UTF-8?q?=D0=92=D1=8B=D0=B1=D0=B8=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20=D1=81=D0=B5=D0=B7=D0=BE=D0=BD=D0=BD=D1=8B=D0=B9=20?= =?UTF-8?q?=D0=B4=D0=B5=D0=BA=D0=BE=D1=80=20=D0=BF=D0=BE=20=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B4=D0=B0=D1=80=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../freeturn/app/data/config/DecorSeason.kt | 14 +++++ .../app/ui/screens/home/ConnectionHero.kt | 10 +++- .../app/ui/screens/home/DecorCalendar.kt | 31 ++++++++++ .../app/ui/screens/home/HomeScreen.kt | 2 + .../home/{AutumnHero.kt => SeasonalHero.kt} | 57 ++++++++----------- .../res/drawable/snowflake_outlined_24px.xml | 32 +++++++++++ app/src/main/res/values-en/strings.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- .../app/data/config/DecorSeasonTest.kt | 14 +++++ 9 files changed, 125 insertions(+), 39 deletions(-) create mode 100644 app/src/main/java/com/freeturn/app/data/config/DecorSeason.kt create mode 100644 app/src/main/java/com/freeturn/app/ui/screens/home/DecorCalendar.kt rename app/src/main/java/com/freeturn/app/ui/screens/home/{AutumnHero.kt => SeasonalHero.kt} (87%) create mode 100644 app/src/main/res/drawable/snowflake_outlined_24px.xml create mode 100644 app/src/test/java/com/freeturn/app/data/config/DecorSeasonTest.kt diff --git a/app/src/main/java/com/freeturn/app/data/config/DecorSeason.kt b/app/src/main/java/com/freeturn/app/data/config/DecorSeason.kt new file mode 100644 index 0000000..7442556 --- /dev/null +++ b/app/src/main/java/com/freeturn/app/data/config/DecorSeason.kt @@ -0,0 +1,14 @@ +package com.freeturn.app.data.config + +/** Calendar seasons for the northern hemisphere; independent of locale language. */ +enum class DecorSeason { SPRING, SUMMER, AUTUMN, WINTER } + +internal fun decorSeason(month: Int): DecorSeason { + require(month in 1..12) + return when (month) { + 3, 4, 5 -> DecorSeason.SPRING + 6, 7, 8 -> DecorSeason.SUMMER + 9, 10, 11 -> DecorSeason.AUTUMN + else -> DecorSeason.WINTER + } +} diff --git a/app/src/main/java/com/freeturn/app/ui/screens/home/ConnectionHero.kt b/app/src/main/java/com/freeturn/app/ui/screens/home/ConnectionHero.kt index 25c8bc1..827d5d8 100644 --- a/app/src/main/java/com/freeturn/app/ui/screens/home/ConnectionHero.kt +++ b/app/src/main/java/com/freeturn/app/ui/screens/home/ConnectionHero.kt @@ -60,6 +60,7 @@ import androidx.compose.ui.unit.dp import androidx.graphics.shapes.Morph import androidx.graphics.shapes.RoundedPolygon import androidx.graphics.shapes.toPath +import com.freeturn.app.data.config.DecorSeason import com.freeturn.app.R import com.freeturn.app.ui.theme.LocalReducedMotion import com.freeturn.app.ui.theme.extendedColorScheme @@ -75,12 +76,13 @@ internal fun ConnectionHero( uptimeText: String?, showStreams: Boolean, decorEnabled: Boolean, + season: DecorSeason, onToggle: () -> Unit, modifier: Modifier = Modifier ) { val kind = status.phase.heroKind() val reducedMotion = LocalReducedMotion.current - val decor = AUTUMN_VIBE && decorEnabled + val decor = decorEnabled // Ноль - ещё не жали: с него разлёт не запускается. var burstKey by remember { mutableIntStateOf(0) } @@ -93,6 +95,7 @@ internal fun ConnectionHero( tunnelActive = status.tunnelUp, reducedMotion = reducedMotion, decor = decor, + season = season, burstKey = burstKey, onClick = { if (decor && !reducedMotion) burstKey++ @@ -128,6 +131,7 @@ private fun HeroToggleButton( tunnelActive: Boolean, reducedMotion: Boolean, decor: Boolean, + season: DecorSeason, burstKey: Int, onClick: () -> Unit ) { @@ -192,7 +196,7 @@ private fun HeroToggleButton( Box(contentAlignment = Alignment.Center) { if (decor) { - AutumnHeroGlow( + SeasonalHeroGlow( color = containerColor, strong = kind == HeroKind.Running, buttonSize = HeroButtonSize @@ -226,7 +230,7 @@ private fun HeroToggleButton( } if (decor) { - AutumnLeafBurst(burstKey = burstKey, buttonSize = HeroButtonSize) + SeasonalParticleBurst(burstKey = burstKey, buttonSize = HeroButtonSize, season = season) } } } diff --git a/app/src/main/java/com/freeturn/app/ui/screens/home/DecorCalendar.kt b/app/src/main/java/com/freeturn/app/ui/screens/home/DecorCalendar.kt new file mode 100644 index 0000000..084c788 --- /dev/null +++ b/app/src/main/java/com/freeturn/app/ui/screens/home/DecorCalendar.kt @@ -0,0 +1,31 @@ +package com.freeturn.app.ui.screens.home + +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.produceState +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.compose.LocalLifecycleOwner +import androidx.lifecycle.repeatOnLifecycle +import com.freeturn.app.data.config.DecorSeason +import com.freeturn.app.data.config.decorSeason +import kotlinx.coroutines.delay +import java.time.Duration +import java.time.ZonedDateTime + +/** Refresh on resume and local midnight; stop the timer while the screen is stopped. */ +@Composable +internal fun rememberDecorSeason(): DecorSeason { + val owner = LocalLifecycleOwner.current + fun current() = decorSeason(ZonedDateTime.now().monthValue) + val season by produceState(current(), owner) { + owner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { + while (true) { + value = current() + val now = ZonedDateTime.now() + val midnight = now.toLocalDate().plusDays(1).atStartOfDay(now.zone) + delay(Duration.between(now, midnight).toMillis().coerceAtLeast(1_000)) + } + } + } + return season +} diff --git a/app/src/main/java/com/freeturn/app/ui/screens/home/HomeScreen.kt b/app/src/main/java/com/freeturn/app/ui/screens/home/HomeScreen.kt index 2104f3e..09539e8 100644 --- a/app/src/main/java/com/freeturn/app/ui/screens/home/HomeScreen.kt +++ b/app/src/main/java/com/freeturn/app/ui/screens/home/HomeScreen.kt @@ -66,6 +66,7 @@ fun HomeScreen( val updateState by settingsViewModel.updateState.collectAsStateWithLifecycle() val suppressUpdatePrompt by settingsViewModel.suppressUpdatePrompt.collectAsStateWithLifecycle() val privacyMode by settingsViewModel.privacyMode.collectAsStateWithLifecycle() + val season = rememberDecorSeason() val seasonalDecor by settingsViewModel.seasonalDecor.collectAsStateWithLifecycle() val serversSnapshot by serverConfigViewModel.serversSnapshot.collectAsStateWithLifecycle() @@ -164,6 +165,7 @@ fun HomeScreen( // direct - всегда один поток, счётчик ничего не сообщает. showStreams = clientConfig.provider != Provider.DIRECT, decorEnabled = seasonalDecor, + season = season, onToggle = { // Любая непокоящаяся фаза (включая капчу и старт) - остановка. if (status.busy) { diff --git a/app/src/main/java/com/freeturn/app/ui/screens/home/AutumnHero.kt b/app/src/main/java/com/freeturn/app/ui/screens/home/SeasonalHero.kt similarity index 87% rename from app/src/main/java/com/freeturn/app/ui/screens/home/AutumnHero.kt rename to app/src/main/java/com/freeturn/app/ui/screens/home/SeasonalHero.kt index 3301d18..e27b4e0 100644 --- a/app/src/main/java/com/freeturn/app/ui/screens/home/AutumnHero.kt +++ b/app/src/main/java/com/freeturn/app/ui/screens/home/SeasonalHero.kt @@ -36,6 +36,7 @@ import androidx.compose.ui.platform.LocalDensity import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp +import com.freeturn.app.data.config.DecorSeason import com.freeturn.app.R import com.freeturn.app.ui.util.HapticUtil import kotlinx.coroutines.launch @@ -46,15 +47,7 @@ import kotlin.math.roundToInt import kotlin.math.sin import kotlin.random.Random -/** - * Сезонное оформление героя: вращение фигуры кнопки пальцем, тёплый ореол и разлёт - * листвы по нажатию. Флаг про сезон, а не про вкус пользователя: вкус живёт тумблером - * в настройках, а этим снимается вся тема целиком, когда осень прошла. Форму и палитру - * кнопки не трогаем: на Material You цвета приходят с обоев, и своя пара выбивалась бы - * из темы пользователя. - */ -internal const val AUTUMN_VIBE = true - +/** Seasonal particles reuse one short animation; no frames run while idle. */ private const val LEAF_COUNT = 7 private const val BURST_MS = 950 @@ -66,27 +59,20 @@ private const val SPIN_TICK_MIN_MS = 30L private const val SPREAD_FROM_DEG = -170f private const val SPREAD_TO_DEG = -10f -private val autumnLeavesLight = listOf( - Color(0xFFB4530A), - Color(0xFFD97706), - Color(0xFF8B3A0F), - Color(0xFFC98A12), - Color(0xFF9A6212), -) - -private val autumnLeavesDark = listOf( - Color(0xFFFFB787), - Color(0xFFFFC46B), - Color(0xFFE98A4F), - Color(0xFFD9A441), - Color(0xFFFFD9A0), -) - -// Тема не отдаёт darkTheme наружу, а Material You подменяет всю схему - светлота фона -// единственный признак, верный и для статичных схем, и для динамических. @Composable -private fun autumnLeafColors(): List = - if (MaterialTheme.colorScheme.surface.luminance() < 0.5f) autumnLeavesDark else autumnLeavesLight +private fun seasonalColors(season: DecorSeason): List { + val dark = MaterialTheme.colorScheme.surface.luminance() < 0.5f + return when (season) { + DecorSeason.WINTER -> listOf(Color.White) + DecorSeason.SPRING, DecorSeason.SUMMER -> if (dark) listOf(Color(0xFF86EFAC), Color(0xFF4ADE80), Color(0xFFA3E635)) + else listOf(Color(0xFF15803D), Color(0xFF16A34A), Color(0xFF4D7C0F)) + DecorSeason.AUTUMN -> if (dark) listOf( + Color(0xFFFFB787), Color(0xFFFFC46B), Color(0xFFE98A4F), Color(0xFFD9A441), Color(0xFFFFD9A0) + ) else listOf( + Color(0xFFB4530A), Color(0xFFD97706), Color(0xFF8B3A0F), Color(0xFFC98A12), Color(0xFF9A6212) + ) + } +} @Immutable private class Leaf( @@ -124,7 +110,7 @@ private fun leafBatch(seed: Int, colorCount: Int): List { * снаружи - анимация контейнера уже посчитана вызывающим. */ @Composable -internal fun AutumnHeroGlow( +internal fun SeasonalHeroGlow( color: Color, strong: Boolean, buttonSize: Dp, @@ -151,17 +137,20 @@ internal fun AutumnHeroGlow( * родитель не должен клипать содержимое. */ @Composable -internal fun AutumnLeafBurst( +internal fun SeasonalParticleBurst( burstKey: Int, buttonSize: Dp, + season: DecorSeason, modifier: Modifier = Modifier ) { - val colors = autumnLeafColors() - val painter = painterResource(R.drawable.eco_24px) + val colors = seasonalColors(season) + val painter = painterResource(if (season == DecorSeason.WINTER) R.drawable.snowflake_outlined_24px else R.drawable.eco_24px) val progress = remember { Animatable(1f) } var batch by remember { mutableStateOf(emptyList()) } - LaunchedEffect(burstKey) { + LaunchedEffect(burstKey, season) { + progress.snapTo(1f) + batch = emptyList() if (burstKey == 0) return@LaunchedEffect batch = leafBatch(burstKey, colors.size) progress.snapTo(0f) diff --git a/app/src/main/res/drawable/snowflake_outlined_24px.xml b/app/src/main/res/drawable/snowflake_outlined_24px.xml new file mode 100644 index 0000000..6b45622 --- /dev/null +++ b/app/src/main/res/drawable/snowflake_outlined_24px.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index d7d5601..5ca0709 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -302,7 +302,7 @@ Privacy mode Hides IPs and ports Seasonal decor - Leaves and glow around the connect button + Seasonal effects: green and yellow leaves, snowflakes in winter Language System default diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index f597f5d..d4c064b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -327,7 +327,7 @@ Приватный режим Скрывает IP и порты Сезонный декор - Листва и свечение вокруг кнопки подключения + Эффекты по времени года: зелёные и жёлтые листья, зимой — снежинки Язык Как в системе Русский diff --git a/app/src/test/java/com/freeturn/app/data/config/DecorSeasonTest.kt b/app/src/test/java/com/freeturn/app/data/config/DecorSeasonTest.kt new file mode 100644 index 0000000..8d11820 --- /dev/null +++ b/app/src/test/java/com/freeturn/app/data/config/DecorSeasonTest.kt @@ -0,0 +1,14 @@ +package com.freeturn.app.data.config + +import org.junit.Assert.assertEquals +import org.junit.Test + +class DecorSeasonTest { + @Test fun `all calendar months select the correct season`() { + val expected = listOf(DecorSeason.WINTER, DecorSeason.WINTER, + DecorSeason.SPRING, DecorSeason.SPRING, DecorSeason.SPRING, + DecorSeason.SUMMER, DecorSeason.SUMMER, DecorSeason.SUMMER, + DecorSeason.AUTUMN, DecorSeason.AUTUMN, DecorSeason.AUTUMN, DecorSeason.WINTER) + expected.forEachIndexed { index, season -> assertEquals(season, decorSeason(index + 1)) } + } +}