Skip to content

Commit 1cd3c47

Browse files
refactor code for improved readability
1 parent 12b5f20 commit 1cd3c47

File tree

26 files changed

+180
-150
lines changed

26 files changed

+180
-150
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-
#Mon Mar 31 20:38:21 EDT 2025
3-
version_build=4
2+
#Wed Apr 02 19:13:56 EDT 2025
3+
version_build=5
44
version_major=3
55
version_minor=2
66
version_patch=0

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,5 @@ const val SIZE_MAX = 4096
2626
class Configuration(val largeScreen: Boolean) {
2727
var size = SIZE_MAX
2828

29-
val sizeAvailable: Boolean
30-
get() = size == SIZE_MAX
29+
val sizeAvailable: Boolean get() = size == SIZE_MAX
3130
}

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,13 @@ enum class MainContext {
4444
lateinit var configuration: Configuration
4545
lateinit var filtersAdapter: FiltersAdapter
4646

47-
val context: Context
48-
get() = mainActivity.applicationContext
47+
val context: Context get() = mainActivity.applicationContext
4948

50-
val resources: Resources
51-
get() = context.resources
49+
val resources: Resources get() = context.resources
5250

53-
val layoutInflater: LayoutInflater
54-
get() = mainActivity.layoutInflater
51+
val layoutInflater: LayoutInflater get() = mainActivity.layoutInflater
5552

56-
private val wiFiManager: WifiManager
57-
get() = context.getSystemService(Context.WIFI_SERVICE) as WifiManager
53+
private val wiFiManager: WifiManager get() = context.getSystemService(Context.WIFI_SERVICE) as WifiManager
5854

5955
fun initialize(activity: MainActivity, largeScreen: Boolean) {
6056
mainActivity = activity

app/src/main/kotlin/com/vrem/wifianalyzer/navigation/items/NavigationItem.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import com.vrem.wifianalyzer.navigation.NavigationMenu
2323

2424
interface NavigationItem {
2525
fun activate(mainActivity: MainActivity, menuItem: MenuItem, navigationMenu: NavigationMenu)
26-
val registered: Boolean
27-
get() = false
28-
val visibility: Int
29-
get() = android.view.View.GONE
26+
val registered: Boolean get() = false
27+
val visibility: Int get() = android.view.View.GONE
3028
}

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/accesspoint/ConnectionViewType.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,5 @@ enum class ConnectionViewType(@LayoutRes val layout: Int) {
2525
COMPACT(R.layout.access_point_view_compact),
2626
HIDE(R.layout.access_point_view_hide);
2727

28-
val hide: Boolean
29-
get() = HIDE == this
28+
val hide: Boolean get() = HIDE == this
3029
}

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/band/WiFiChannelCountry.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,14 @@ import java.util.Locale
2525
class WiFiChannelCountry(val locale: Locale) {
2626
private val unknown = "-Unknown"
2727

28-
val countryCode: String
29-
get() = locale.country.toCapitalize(locale)
28+
val countryCode: String get() = locale.country.toCapitalize(locale)
3029

3130
fun countryName(currentLocale: Locale): String {
3231
val countryName: String = locale.getDisplayCountry(currentLocale)
3332
return if (locale.country == countryName) countryName + unknown else countryName
3433
}
3534

36-
fun channels(wiFiBand: WiFiBand): List<Int> {
37-
val wiFiChannels = wiFiBand.wiFiChannels
38-
return wiFiChannels.availableChannels
39-
.subtract(wiFiChannels.excludeChannels.flatMap { it[countryCode] ?: emptyList() })
40-
.toList()
41-
}
35+
fun channels(wiFiBand: WiFiBand): List<Int> = wiFiBand.wiFiChannels.ratingChannels(wiFiBand, countryCode)
4236

4337
companion object {
4438
fun find(countryCode: String): WiFiChannelCountry = WiFiChannelCountry(findByCountryCode(countryCode))

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/band/WiFiChannels.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,22 @@ package com.vrem.wifianalyzer.wifi.band
2020
import com.vrem.util.EMPTY
2121
import com.vrem.wifianalyzer.wifi.model.WiFiWidth
2222

23+
typealias RatingChannels = (wiFiBand: WiFiBand, countryCode: String) -> List<Int>
24+
2325
class WiFiChannels(
2426
val channelRange: WiFiChannelPair,
2527
val offset: Int,
2628
val activeChannels: Map<WiFiWidth, List<Int>>,
2729
val graphChannels: Map<Int, String>,
2830
val availableChannels: List<Int>,
29-
val excludeChannels: List<Map<String, List<Int>>> = listOf()
31+
val ratingChannels: RatingChannels
3032
) {
3133

3234
fun availableChannels(wiFiBand: WiFiBand, countryCode: String): List<WiFiChannel> =
3335
WiFiChannelCountry.find(countryCode).channels(wiFiBand).map { wiFiChannelByChannel(it) }
3436

35-
fun availableChannels(wiFiWidth: WiFiWidth, countryCode: String): List<Int> =
36-
activeChannels[wiFiWidth]
37-
.orEmpty()
38-
.subtract(excludeChannels.flatMap { it[countryCode] ?: emptyList() })
39-
.toList()
37+
fun availableChannels(wiFiWidth: WiFiWidth, wiFiBand: WiFiBand, countryCode: String): List<Int> =
38+
activeChannels[wiFiWidth].orEmpty().filter { it in ratingChannels(wiFiBand, countryCode) }
4039

4140
fun inRange(frequency: Int): Boolean = frequency in channelRange.first.frequency..channelRange.second.frequency
4241

@@ -66,4 +65,5 @@ class WiFiChannels(
6665
val channel = ((frequency - channelRange.first.frequency) / FREQUENCY_SPREAD + firstChannel).toInt()
6766
return WiFiChannel(channel, frequency)
6867
}
68+
6969
}

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/band/WiFiInfo.kt

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ private val countriesETSI = listOf(
5757
"IL"
5858
)
5959

60+
private val countriesNA = listOf("AS", "CA", "CO", "DO", "FM", "GT", "GU", "MP", "MX", "PA", "PR", "UM", "US", "UZ", "VI")
61+
62+
private val countriesGHZ6 = listOf("JP", "RU", "NZ", "AU", "GL", "AE", "GB", "MX", "SG", "HK", "MO", "PH")
63+
64+
private val channelsWorldGHZ2 = listOf(1, 3, 5, 9, 13)
65+
private val channelsNAGHZ2 = listOf(1, 3, 6, 9, 11)
66+
6067
private val excludeGHZ5: List<Map<String, List<Int>>> =
6168
countriesETSI.map { mapOf(it to listOf(177)) } +
6269
listOf(
@@ -82,18 +89,33 @@ private val excludeGHZ5: List<Map<String, List<Int>>> =
8289
).map { mapOf(it.first to it.second) }
8390

8491
private val excludeGHZ6: List<Map<String, List<Int>>> =
85-
(countriesETSI + listOf("JP", "RU", "NZ", "AU", "GL", "AE", "GB", "MX", "SG", "HK", "MO", "PH"))
86-
.map { mapOf(it to (97..223).toList()) }
92+
(countriesETSI + countriesGHZ6).map { mapOf(it to (97..223).toList()) }
93+
94+
private val ratingChannelsGHZ2: RatingChannels = { wiFiBand, countryCode ->
95+
val channels = if (countriesNA.contains(countryCode)) channelsNAGHZ2 else channelsWorldGHZ2
96+
wiFiBand.wiFiChannels.availableChannels.filter { it in channels }
97+
}
98+
99+
private val ratingChannelsGHZ5: RatingChannels = { wiFiBand, countryCode ->
100+
val excludedChannels = excludeGHZ5.flatMap { it[countryCode] ?: emptyList() }
101+
wiFiBand.wiFiChannels.availableChannels.filterNot { it in excludedChannels }
102+
}
103+
104+
private val ratingChannelsGHZ6: RatingChannels = { wiFiBand, countryCode ->
105+
val excludedChannels = excludeGHZ6.flatMap { it[countryCode] ?: emptyList() }
106+
wiFiBand.wiFiChannels.availableChannels.filterNot { it in excludedChannels }
107+
}
87108

88109
internal val wiFiChannelsGHZ2 = WiFiChannels(
89110
WiFiChannelPair(WiFiChannel(-1, 2402), WiFiChannel(15, 2482)),
90111
1,
91112
mapOf(
92-
WiFiWidth.MHZ_20 to listOf(1, 2, 3, 6, 7, 8, 11, 12, 13),
93-
WiFiWidth.MHZ_40 to listOf(3, 7, 11)
113+
WiFiWidth.MHZ_20 to listOf(1, 5, 6, 9, 13).toList(),
114+
WiFiWidth.MHZ_40 to listOf(3, 11).toList(),
94115
),
95116
(1..13).associateWith { "$it" },
96-
listOf(1, 2, 3, 6, 7, 8, 11, 12, 13)
117+
listOf(1, 3, 5, 6, 9, 11, 13),
118+
ratingChannelsGHZ2
97119
)
98120

99121
internal val wiFiChannelsGHZ5 = WiFiChannels(
@@ -113,9 +135,13 @@ internal val wiFiChannelsGHZ5 = WiFiChannels(
113135
else -> "$it"
114136
}
115137
},
116-
((42..138 step WiFiWidth.MHZ_80.step) + (155..171 step WiFiWidth.MHZ_80.step) +
117-
(50..114 step WiFiWidth.MHZ_160.step) + 163).toSortedSet().toList(),
118-
excludeGHZ5
138+
((32..144 step WiFiWidth.MHZ_20.step) + (149..177 step WiFiWidth.MHZ_20.step) +
139+
(38..142 step WiFiWidth.MHZ_40.step) + (151..175 step WiFiWidth.MHZ_40.step) +
140+
(42..138 step WiFiWidth.MHZ_80.step) + (155..171 step WiFiWidth.MHZ_80.step) +
141+
(50..114 step WiFiWidth.MHZ_160.step) + 163)
142+
.toSortedSet()
143+
.toList(),
144+
ratingChannelsGHZ5
119145
)
120146

121147
internal val wiFiChannelsGHZ6 = WiFiChannels(
@@ -137,6 +163,12 @@ internal val wiFiChannelsGHZ6 = WiFiChannels(
137163
else -> "$it"
138164
}
139165
},
140-
((15..207 step WiFiWidth.MHZ_160.step) + (31..191 step WiFiWidth.MHZ_320.step)).toSortedSet().toList(),
141-
excludeGHZ6
166+
((1..233 step WiFiWidth.MHZ_20.step) +
167+
(3..227 step WiFiWidth.MHZ_40.step) +
168+
(7..215 step WiFiWidth.MHZ_80.step) +
169+
(15..207 step WiFiWidth.MHZ_160.step) +
170+
(31..191 step WiFiWidth.MHZ_320.step))
171+
.toSortedSet()
172+
.toList(),
173+
ratingChannelsGHZ6
142174
)

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/channelavailable/ChannelAvailableFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class ChannelAvailableFragment : Fragment() {
5858
channelsAvailableCountryCode.text = countryCode
5959
channelsAvailableCountryName.text = WiFiChannelCountry.find(countryCode).countryName(languageLocale)
6060
textViews.forEach { (textView, wiFiBand, wiFiWidth) ->
61-
textView.text = wiFiBand.wiFiChannels.availableChannels(wiFiWidth, countryCode).joinToString(", ")
61+
textView.text = wiFiBand.wiFiChannels.availableChannels(wiFiWidth, wiFiBand, countryCode).joinToString(", ")
6262
}
6363
}
6464
}

app/src/main/kotlin/com/vrem/wifianalyzer/wifi/graphutils/GraphViewBuilder.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,9 @@ class GraphViewBuilder(
137137
return this
138138
}
139139

140-
val numVerticalLabels: Int
141-
get() = (maximumPortY - MIN_Y) / 10 + 1
140+
val numVerticalLabels: Int get() = (maximumPortY - MIN_Y) / 10 + 1
142141

143-
val maximumPortY: Int
144-
get() = if (maximumY > MAX_Y || maximumY < MIN_Y_HALF) MAX_Y_DEFAULT else maximumY
142+
val maximumPortY: Int get() = if (maximumY > MAX_Y || maximumY < MIN_Y_HALF) MAX_Y_DEFAULT else maximumY
145143

146144
val layoutParams: ViewGroup.LayoutParams =
147145
ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)

0 commit comments

Comments
 (0)