Skip to content

Commit

Permalink
Remove string_arrays.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
w2sv committed Aug 4, 2023
1 parent e3ef838 commit d13a019
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringArrayResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -34,28 +33,23 @@ internal fun WifiPropertyInfoDialog(
modifier: Modifier = Modifier
) {
val context = LocalContext.current
val stringArray = stringArrayResource(id = property.viewData.arrayRes)

InfoDialog(
modifier = modifier,
title = stringResource(id = property.viewData.labelRes),
text = stringArray[0],
learnMoreButton = when (stringArray[1].isNotEmpty()) {
true -> {
{
DialogButton(
onClick = {
context.openUrlWithActivityNotFoundHandling(stringArray[1])
onDismissRequest()
},
modifier = Modifier.padding(top = 20.dp, bottom = 12.dp)
) {
JostText(text = stringResource(R.string.learn_more))
}
text = stringResource(id = property.viewData.descriptionRes),
learnMoreButton = property.viewData.learnMoreUrl?.let {
{
DialogButton(
onClick = {
context.openUrlWithActivityNotFoundHandling(it)
onDismissRequest()
},
modifier = Modifier.padding(top = 20.dp, bottom = 12.dp)
) {
JostText(text = stringResource(R.string.learn_more))
}
}

false -> null
},
onDismissRequest = onDismissRequest
)
Expand Down
59 changes: 32 additions & 27 deletions data/src/main/kotlin/com/w2sv/data/model/WifiProperty.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.w2sv.data.model

import android.net.ConnectivityManager
import android.net.wifi.WifiManager
import androidx.annotation.ArrayRes
import androidx.annotation.StringRes
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
Expand All @@ -27,7 +26,8 @@ enum class WifiProperty(
SSID(
ViewData(
R.string.ssid,
R.array.ssid
R.string.ssid_description,
"https://en.wikipedia.org/wiki/Service_set_(802.11_network)#SSID"
),
{ wifiManager, _ ->
wifiManager.connectionInfo.ssid?.replace("\"", "") ?: DEFAULT_FALLBACK_VALUE
Expand All @@ -37,17 +37,19 @@ enum class WifiProperty(
BSSID(
ViewData(
R.string.bssid,
R.array.bssid
R.string.bssid_description,
"https://en.wikipedia.org/wiki/Service_set_(802.11_network)#BSSID"
),
{ wifiManager, _ ->
wifiManager.connectionInfo.bssid ?: DEFAULT_FALLBACK_VALUE
},
true
false
),
IP(
ViewData(
R.string.ipv4,
R.array.ipv4
R.string.ipv4_description,
"https://en.wikipedia.org/wiki/IP_address"
),
{ _, connectivityManager ->
connectivityManager
Expand All @@ -56,12 +58,12 @@ enum class WifiProperty(
?.hostAddress
?: IPV4_FALLBACK_ADDRESS
},
true
),
Netmask(
ViewData(
R.string.netmask,
R.array.netmask
R.string.netmask_description,
"https://en.wikipedia.org/wiki/Subnetwork"
),
{ _, connectivityManager ->
connectivityManager
Expand All @@ -70,12 +72,12 @@ enum class WifiProperty(
?.let { toNetmask(it) }
?: IPV4_FALLBACK_ADDRESS
},
true
),
IPv6Local(
ViewData(
R.string.ipv6_local,
R.array.ipv6_local
R.string.ipv6_local_description,
"https://en.wikipedia.org/wiki/IP_address"
),
{ _, connectivityManager ->
connectivityManager
Expand All @@ -84,12 +86,12 @@ enum class WifiProperty(
?.hostAddress
?: IPV6_FALLBACK_ADDRESS
},
true
),
IPv6Public1(
ViewData(
R.string.ipv6_public_1,
R.array.ipv6_public_1
R.string.ipv6_public_description,
"https://en.wikipedia.org/wiki/IP_address"
),
{ _, connectivityManager ->
try {
Expand All @@ -102,12 +104,12 @@ enum class WifiProperty(
IPV6_FALLBACK_ADDRESS
}
},
true
),
IPv6Public2(
ViewData(
R.string.ipv6_public_2,
R.array.ipv6_public_2
R.string.ipv6_public_description,
"https://en.wikipedia.org/wiki/IP_address"
),
{ _, connectivityManager ->
try {
Expand All @@ -120,67 +122,70 @@ enum class WifiProperty(
IPV6_FALLBACK_ADDRESS
}
},
true
),
Frequency(
ViewData(
R.string.frequency,
R.array.frequency
R.string.frequency,
"https://en.wikipedia.org/wiki/List_of_WLAN_channels"
),
{ wifiManager, _ -> "${wifiManager.connectionInfo.frequency} MHz" },
true
),
Channel(
ViewData(
R.string.channel,
R.array.channel
R.string.channel_description,
"https://en.wikipedia.org/wiki/List_of_WLAN_channels"
),
{ wifiManager, _ -> frequencyToChannel(wifiManager.connectionInfo.frequency).toString() },
true
),
LinkSpeed(
ViewData(
R.string.link_speed,
R.array.link_speed
R.string.link_speed_description,
null
),
{ wifiManager, _ -> "${wifiManager.connectionInfo.linkSpeed} Mbps" },
true
),
Gateway(
ViewData(
R.string.gateway,
R.array.gateway
R.string.gateway_description,
"https://en.wikipedia.org/wiki/Gateway_(telecommunications)#Network_gateway"
),
{ wifiManager, _ ->
textualAddressRepresentation(wifiManager.dhcpInfo.gateway)
?: IPV4_FALLBACK_ADDRESS
},
true
),
DNS(
ViewData(
R.string.dns,
R.array.dns
R.string.dns_description,
"https://en.wikipedia.org/wiki/Domain_Name_System"
),
{ wifiManager, _ ->
textualAddressRepresentation(wifiManager.dhcpInfo.dns1)
?: IPV4_FALLBACK_ADDRESS
},
true
),
DHCP(
ViewData(
R.string.dhcp,
R.array.dhcp
R.string.dhcp_description,
"https://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol"
),
{ wifiManager, _ ->
textualAddressRepresentation(wifiManager.dhcpInfo.serverAddress)
?: IPV4_FALLBACK_ADDRESS
},
true
);

data class ViewData(@StringRes val labelRes: Int, @ArrayRes val arrayRes: Int)
data class ViewData(
@StringRes val labelRes: Int,
@StringRes val descriptionRes: Int,
val learnMoreUrl: String?
)

override val preferencesKey: Preferences.Key<Boolean> = booleanPreferencesKey(name)
}
Expand Down
54 changes: 0 additions & 54 deletions data/src/main/res/values/string_arrays.xml

This file was deleted.

13 changes: 13 additions & 0 deletions data/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,17 @@
<string name="dns">DNS</string>
<string name="dhcp">DHCP</string>
<string name="netmask">Netmask</string>

<string name="ssid_description">Service Set Identifier. Your network\'s name.</string>
<string name="bssid_description">Basic Service Set Identifier. A 48-bit label abiding by MAC-48 conventions which identifies your devices basic service set.</string>
<string name="ipv4_description">Internet Protocol Address, serving the two main purposes of identifying the network interface of your device and providing its location within the network, thereby making it addressable. The IPv4 representation corresponds to a 32-bit number. The displayed address is your internal one, meaning that it\'s only visible from within your network.</string>
<string name="ipv6_local_description">Internet Protocol Address, serving the two main purposes of identifying the network interface of your device and providing its location within the network, thereby making it addressable. The IPv6 representation corresponds to a 128-bit number. This is the local IPv6 address, meaning that it\'s only visible from within your network.</string>
<string name="ipv6_public_description">Internet Protocol Address, serving the two main purposes of identifying the network interface of your device and providing its location within the network, thereby making it addressable. The IPv6 representation corresponds to a 128-bit number. This is one of the two public IPv6 addresses, Android devices are typically assigned with. Of those two addresses, one comes from the Stateless Address Autoconfiguration (SLAAC) mechanism - meaning that it will always be the same - whereas the other one is a privacy variant, that changes every few hours.</string>
<string name="frequency_description">The radio frequency band employed for WiFi signal transmission, following the IEEE 802.11 technical standards. Bands for use in WiFi communication provided by IEEE 802.11 lie at 900 MHz, 2.4 GHz, 3.6 GHz, 4.9 GHz, 5 GHz, 5.9 GHz, 6 GHz and 60 GHz. Bands are divided into several distinct channels.</string>
<string name="channel_description">The sub frequencies which the main frequency bands are divided into, and via which WiFi communication takes place. As per the IEEE 802.11 standard, channels are numbered at 5 MHz spacing within a band (except in the 60 GHz band, where they are 2.16 GHz apart), where the number corresponds to the center frequency of the channel. Although channels are numbered at 5 MHz spacing, transmitters generally occupy at least 20 MHz, and standards allow for channels to be bonded together to form wider channels for faster throughput.</string>
<string name="link_speed_description">The theoretical data transmission max speed between your device and the router.</string>
<string name="gateway_description">A Gateway is a device uniting the functionality of a modem, i.e., communicating with your ISP (Internet Service Provider), and a router, i.e., translating the data received by the modem and distributing it as WiFi signal to the client devices being present in the network.</string>
<string name="dns_description">Domain Name System. Associates domain names with various types of information, acting as a database. Most notably, it translates domain names to their underlying IP addresses, needed for locating and communicating with them.</string>
<string name="dhcp_description">Dynamic Host Configuration Protocol. A service which automatically assigns IP addresses and other network parameters to devices connected to a network.</string>
<string name="netmask_description">Also referred to as subnet mask. A bitmask determining the subnetwork within which the DHCP may operate.</string>
</resources>

0 comments on commit d13a019

Please sign in to comment.