Skip to content

Commit f3c0380

Browse files
refactor theme and add more tests
1 parent a32138f commit f3c0380

File tree

6 files changed

+76
-42
lines changed

6 files changed

+76
-42
lines changed

app/build.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Build Properties
2-
#Sat Jan 17 10:15:29 EST 2026
3-
version_build=1
2+
#Sat Jan 17 13:51:56 EST 2026
3+
version_build=2
44
version_major=3
55
version_minor=2
66
version_patch=2

app/src/androidTest/kotlin/com/vrem/wifianalyzer/ThemeInstrumentedTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* WiFiAnalyzer
3-
* Copyright (C) 2026 VREM Software Development <VREMSoftwareDevelopment@gmail.com>
3+
* Copyright (C) 2015 - 2026 VREM Software Development <VREMSoftwareDevelopment@gmail.com>
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by

app/src/main/kotlin/com/vrem/wifianalyzer/MainActivity.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import android.view.Menu
2626
import android.view.MenuItem
2727
import android.view.View
2828
import androidx.appcompat.app.AppCompatActivity
29-
import androidx.appcompat.app.AppCompatDelegate
3029
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
3130
import androidx.core.view.GravityCompat
3231
import androidx.drawerlayout.widget.DrawerLayout
@@ -62,11 +61,7 @@ class MainActivity :
6261

6362
val settings = mainContext.settings
6463
settings.initializeDefaultValues()
65-
66-
settings.themeStyle().apply {
67-
AppCompatDelegate.setDefaultNightMode(nightMode)
68-
setTheme(themeNoActionBar)
69-
}
64+
settings.themeStyle().setTheme(this)
7065

7166
mainReload = MainReload(settings)
7267

app/src/main/kotlin/com/vrem/wifianalyzer/settings/ThemeStyle.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,23 @@ package com.vrem.wifianalyzer.settings
2020
import android.graphics.Color
2121
import androidx.annotation.ColorInt
2222
import androidx.annotation.StyleRes
23+
import androidx.appcompat.app.AppCompatActivity
2324
import androidx.appcompat.app.AppCompatDelegate
2425
import com.vrem.wifianalyzer.R
2526

2627
enum class ThemeStyle(
27-
@param:StyleRes val theme: Int,
28-
@param:StyleRes val themeNoActionBar: Int,
2928
@param:ColorInt val colorGraphText: Int,
30-
val nightMode: Int,
29+
@param:StyleRes private val theme: Int,
30+
private val nightMode: Int,
3131
) {
32-
DARK(R.style.ThemeSystem, R.style.ThemeSystemNoActionBar, Color.WHITE, AppCompatDelegate.MODE_NIGHT_YES),
33-
LIGHT(R.style.ThemeSystem, R.style.ThemeSystemNoActionBar, Color.BLACK, AppCompatDelegate.MODE_NIGHT_NO),
34-
SYSTEM(R.style.ThemeSystem, R.style.ThemeSystemNoActionBar, Color.GRAY, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM),
35-
BLACK(R.style.ThemeBlack, R.style.ThemeBlackNoActionBar, Color.WHITE, AppCompatDelegate.MODE_NIGHT_YES),
32+
DARK(Color.WHITE, R.style.ThemeSystemNoActionBar, AppCompatDelegate.MODE_NIGHT_YES),
33+
LIGHT(Color.BLACK, R.style.ThemeSystemNoActionBar, AppCompatDelegate.MODE_NIGHT_NO),
34+
SYSTEM(Color.GRAY, R.style.ThemeSystemNoActionBar, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM),
35+
BLACK(Color.WHITE, R.style.ThemeBlackNoActionBar, AppCompatDelegate.MODE_NIGHT_YES);
36+
37+
fun setTheme(activity: AppCompatActivity) {
38+
activity.setTheme(theme)
39+
AppCompatDelegate.setDefaultNightMode(nightMode)
40+
}
41+
3642
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* WiFiAnalyzer
3+
* Copyright (C) 2015 - 2026 VREM Software Development <VREMSoftwareDevelopment@gmail.com>
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>
17+
*/
18+
package com.vrem.wifianalyzer.settings
19+
20+
import androidx.appcompat.app.AppCompatActivity
21+
import androidx.appcompat.app.AppCompatDelegate
22+
import com.vrem.wifianalyzer.R
23+
import org.junit.Test
24+
import org.junit.runner.RunWith
25+
import org.junit.runners.Parameterized
26+
import org.mockito.Mockito
27+
import org.mockito.kotlin.mock
28+
import org.mockito.kotlin.verify
29+
30+
@RunWith(Parameterized::class)
31+
class ThemeStyleParameterizedTest(
32+
private val themeStyle: ThemeStyle,
33+
private val expectedTheme: Int,
34+
private val expectedNightMode: Int
35+
) {
36+
companion object {
37+
@JvmStatic
38+
@Parameterized.Parameters(name = "{0}")
39+
fun data(): Collection<Array<Any>> = listOf(
40+
arrayOf(ThemeStyle.DARK, R.style.ThemeSystemNoActionBar, AppCompatDelegate.MODE_NIGHT_YES),
41+
arrayOf(ThemeStyle.LIGHT, R.style.ThemeSystemNoActionBar, AppCompatDelegate.MODE_NIGHT_NO),
42+
arrayOf(ThemeStyle.SYSTEM, R.style.ThemeSystemNoActionBar, AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM),
43+
arrayOf(ThemeStyle.BLACK, R.style.ThemeBlackNoActionBar, AppCompatDelegate.MODE_NIGHT_YES)
44+
)
45+
}
46+
47+
@Test
48+
fun setThemeParameterized() {
49+
// Arrange
50+
val activity: AppCompatActivity = mock()
51+
Mockito.mockStatic(AppCompatDelegate::class.java).use { mockedStatic ->
52+
// Act
53+
themeStyle.setTheme(activity)
54+
// Assert
55+
verify(activity).setTheme(expectedTheme)
56+
mockedStatic.verify { AppCompatDelegate.setDefaultNightMode(expectedNightMode) }
57+
}
58+
}
59+
}

app/src/test/kotlin/com/vrem/wifianalyzer/settings/ThemeStyleTest.kt

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
package com.vrem.wifianalyzer.settings
1919

2020
import android.graphics.Color
21-
import androidx.appcompat.app.AppCompatDelegate
22-
import com.vrem.wifianalyzer.R
2321
import org.assertj.core.api.Assertions.assertThat
2422
import org.junit.Test
2523

@@ -31,22 +29,6 @@ class ThemeStyleTest {
3129
.containsExactly(ThemeStyle.DARK, ThemeStyle.LIGHT, ThemeStyle.SYSTEM, ThemeStyle.BLACK)
3230
}
3331

34-
@Test
35-
fun theme() {
36-
assertThat(ThemeStyle.LIGHT.theme).isEqualTo(R.style.ThemeSystem)
37-
assertThat(ThemeStyle.DARK.theme).isEqualTo(R.style.ThemeSystem)
38-
assertThat(ThemeStyle.SYSTEM.theme).isEqualTo(R.style.ThemeSystem)
39-
assertThat(ThemeStyle.BLACK.theme).isEqualTo(R.style.ThemeBlack)
40-
}
41-
42-
@Test
43-
fun themeNoActionBar() {
44-
assertThat(ThemeStyle.DARK.themeNoActionBar).isEqualTo(R.style.ThemeSystemNoActionBar)
45-
assertThat(ThemeStyle.LIGHT.themeNoActionBar).isEqualTo(R.style.ThemeSystemNoActionBar)
46-
assertThat(ThemeStyle.SYSTEM.themeNoActionBar).isEqualTo(R.style.ThemeSystemNoActionBar)
47-
assertThat(ThemeStyle.BLACK.themeNoActionBar).isEqualTo(R.style.ThemeBlackNoActionBar)
48-
}
49-
5032
@Test
5133
fun colorGraphText() {
5234
assertThat(ThemeStyle.DARK.colorGraphText).isEqualTo(Color.WHITE)
@@ -55,14 +37,6 @@ class ThemeStyleTest {
5537
assertThat(ThemeStyle.BLACK.colorGraphText).isEqualTo(Color.WHITE)
5638
}
5739

58-
@Test
59-
fun nightMode() {
60-
assertThat(ThemeStyle.DARK.nightMode).isEqualTo(AppCompatDelegate.MODE_NIGHT_YES)
61-
assertThat(ThemeStyle.LIGHT.nightMode).isEqualTo(AppCompatDelegate.MODE_NIGHT_NO)
62-
assertThat(ThemeStyle.SYSTEM.nightMode).isEqualTo(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
63-
assertThat(ThemeStyle.BLACK.nightMode).isEqualTo(AppCompatDelegate.MODE_NIGHT_YES)
64-
}
65-
6640
@Test
6741
fun themeStyleOrdinal() {
6842
assertThat(ThemeStyle.DARK.ordinal).isEqualTo(0)

0 commit comments

Comments
 (0)