From 0cd0ed7a9291a80d5485e2be116af35bd4975230 Mon Sep 17 00:00:00 2001 From: Akihiro Nagai <77012577+314systems@users.noreply.github.com> Date: Sat, 17 Jan 2026 23:09:18 +0900 Subject: [PATCH 1/6] =?UTF-8?q?update=20theme=20style=20implementation=20a?= =?UTF-8?q?nd=20use=20AppCompatDelegate=20for=20night=E2=80=A6=20(#584)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * update theme style implementation and use AppCompatDelegate for night mode * change default theme style to DARK * update theme style default to dark in SettingsTest * fix theme style default value in SettingsTest * refactor MainActivity to streamline theme style initialization * add ThemeInstrumentedTest to verify theme settings and functionality --- .../vrem/wifianalyzer/MainInstrumentedTest.kt | 5 ++ .../wifianalyzer/ThemeInstrumentedTest.kt | 66 +++++++++++++++++++ .../com/vrem/wifianalyzer/MainActivity.kt | 7 +- .../vrem/wifianalyzer/settings/ThemeStyle.kt | 10 +-- app/src/main/res/values/styles.xml | 20 ------ .../wifianalyzer/settings/ThemeStyleTest.kt | 17 +++-- 6 files changed, 96 insertions(+), 29 deletions(-) create mode 100644 app/src/androidTest/kotlin/com/vrem/wifianalyzer/ThemeInstrumentedTest.kt diff --git a/app/src/androidTest/kotlin/com/vrem/wifianalyzer/MainInstrumentedTest.kt b/app/src/androidTest/kotlin/com/vrem/wifianalyzer/MainInstrumentedTest.kt index 7fc055e3f..2802cdd7a 100644 --- a/app/src/androidTest/kotlin/com/vrem/wifianalyzer/MainInstrumentedTest.kt +++ b/app/src/androidTest/kotlin/com/vrem/wifianalyzer/MainInstrumentedTest.kt @@ -115,4 +115,9 @@ class MainInstrumentedTest { fun settings() { SettingsInstrumentedTest().run() } + + @Test + fun theme() { + ThemeInstrumentedTest().run() + } } diff --git a/app/src/androidTest/kotlin/com/vrem/wifianalyzer/ThemeInstrumentedTest.kt b/app/src/androidTest/kotlin/com/vrem/wifianalyzer/ThemeInstrumentedTest.kt new file mode 100644 index 000000000..6f93d3fe1 --- /dev/null +++ b/app/src/androidTest/kotlin/com/vrem/wifianalyzer/ThemeInstrumentedTest.kt @@ -0,0 +1,66 @@ +/* + * WiFiAnalyzer + * Copyright (C) 2026 VREM Software Development + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see + */ +package com.vrem.wifianalyzer + +import androidx.appcompat.app.AppCompatDelegate +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.Espresso.pressBack +import androidx.test.espresso.action.ViewActions.click +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers.isDisplayed +import androidx.test.espresso.matcher.ViewMatchers.withText +import org.junit.Assert.assertEquals + +internal class ThemeInstrumentedTest : Runnable { + override fun run() { + verifyThemeSettings() + + listOf( + "Dark" to AppCompatDelegate.MODE_NIGHT_YES, + "Light" to AppCompatDelegate.MODE_NIGHT_NO, + "System" to AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM, + "Black" to AppCompatDelegate.MODE_NIGHT_YES, + ).forEach { (themeName, expectedNightMode) -> + changeThemeAndVerify(themeName, expectedNightMode) + } + } + + private fun verifyThemeSettings() { + selectMenuItem(R.id.nav_drawer_settings, "Settings") + scrollToAndVerify("Theme") + pressBack() + } + + private fun changeThemeAndVerify( + themeName: String, + expectedNightMode: Int, + ) { + selectMenuItem(R.id.nav_drawer_settings, "Settings") + scrollToAndVerify("Theme") + onView(withText("Theme")).perform(click()) + pauseShort() + onView(withText(themeName)).check(matches(isDisplayed())) + onView(withText(themeName)).perform(click()) + pauseShort() + assertEquals( + "Theme $themeName should set night mode to $expectedNightMode", + expectedNightMode, + AppCompatDelegate.getDefaultNightMode(), + ) + } +} diff --git a/app/src/main/kotlin/com/vrem/wifianalyzer/MainActivity.kt b/app/src/main/kotlin/com/vrem/wifianalyzer/MainActivity.kt index b61b2f7c1..52df659f0 100644 --- a/app/src/main/kotlin/com/vrem/wifianalyzer/MainActivity.kt +++ b/app/src/main/kotlin/com/vrem/wifianalyzer/MainActivity.kt @@ -26,6 +26,7 @@ import android.view.Menu import android.view.MenuItem import android.view.View import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.app.AppCompatDelegate import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.core.view.GravityCompat import androidx.drawerlayout.widget.DrawerLayout @@ -61,7 +62,11 @@ class MainActivity : val settings = mainContext.settings settings.initializeDefaultValues() - setTheme(settings.themeStyle().themeNoActionBar) + + settings.themeStyle().apply { + AppCompatDelegate.setDefaultNightMode(nightMode) + setTheme(themeNoActionBar) + } mainReload = MainReload(settings) diff --git a/app/src/main/kotlin/com/vrem/wifianalyzer/settings/ThemeStyle.kt b/app/src/main/kotlin/com/vrem/wifianalyzer/settings/ThemeStyle.kt index 6f6385767..f457f5993 100644 --- a/app/src/main/kotlin/com/vrem/wifianalyzer/settings/ThemeStyle.kt +++ b/app/src/main/kotlin/com/vrem/wifianalyzer/settings/ThemeStyle.kt @@ -20,15 +20,17 @@ package com.vrem.wifianalyzer.settings import android.graphics.Color import androidx.annotation.ColorInt import androidx.annotation.StyleRes +import androidx.appcompat.app.AppCompatDelegate import com.vrem.wifianalyzer.R enum class ThemeStyle( @param:StyleRes val theme: Int, @param:StyleRes val themeNoActionBar: Int, @param:ColorInt val colorGraphText: Int, + val nightMode: Int, ) { - DARK(R.style.ThemeDark, R.style.ThemeDarkNoActionBar, Color.WHITE), - LIGHT(R.style.ThemeLight, R.style.ThemeLightNoActionBar, Color.BLACK), - SYSTEM(R.style.ThemeSystem, R.style.ThemeSystemNoActionBar, Color.GRAY), - BLACK(R.style.ThemeBlack, R.style.ThemeBlackNoActionBar, Color.WHITE), + DARK(R.style.ThemeSystem, R.style.ThemeSystemNoActionBar, Color.WHITE, AppCompatDelegate.MODE_NIGHT_YES), + LIGHT(R.style.ThemeSystem, R.style.ThemeSystemNoActionBar, Color.BLACK, AppCompatDelegate.MODE_NIGHT_NO), + SYSTEM(R.style.ThemeSystem, R.style.ThemeSystemNoActionBar, Color.GRAY, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM), + BLACK(R.style.ThemeBlack, R.style.ThemeBlackNoActionBar, Color.WHITE, AppCompatDelegate.MODE_NIGHT_YES), } diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 60e7451e2..50a3c57b4 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -18,26 +18,6 @@ - - - - - - - -