Skip to content

Commit

Permalink
Hopefully fix a crash with invalid auth types on some devices
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharee committed Apr 16, 2024
1 parent be2965b commit c294376
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion app/src/main/java/tk/zwander/wifilist/data/ExportChoice.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ data class ExportChoice(

@Composable
fun rememberExportChoices(configs: List<WifiConfiguration>): List<ExportChoice> {
val context = LocalContext.current

return remember(configs.toList()) {
val exportItems = configs.mapToExportItems()
val exportItems = configs.mapToExportItems(context)

listOf(
ExportChoice(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

package tk.zwander.wifilist.util

import android.content.Context
import android.net.wifi.WifiConfiguration
import com.google.gson.GsonBuilder
import de.siegmar.fastcsv.writer.CsvWriter
import tk.zwander.wifilist.data.WiFiExportItem
import java.io.StringWriter

object WiFiExportGenerator {
fun Collection<WifiConfiguration>.mapToExportItems(): List<WiFiExportItem> {
fun Collection<WifiConfiguration>.mapToExportItems(context: Context): List<WiFiExportItem> {
return map {
WiFiExportItem(
ssid = it.printableSsid,
security = WifiConfiguration.KeyMgmt.strings[it.authType],
security = it.getSecurityType(context = context),
password = it.simpleKey ?: "",
)
}
Expand All @@ -29,10 +30,10 @@ object WiFiExportGenerator {
val writer = StringWriter()
val csv = CsvWriter.builder().build(writer)

csv.writeRow("SSID", "PASSWORD", "SECURITY")
csv.writeRecord("SSID", "PASSWORD", "SECURITY")

forEach { item ->
csv.writeRow(item.ssid, item.password, item.security)
csv.writeRecord(item.ssid, item.password, item.security)
}

csv.close()
Expand Down

0 comments on commit c294376

Please sign in to comment.