Support changing repeater operating channel on Android 5
This commit is contained in:
@@ -4,7 +4,6 @@ import android.annotation.TargetApi
|
|||||||
import android.content.ClipData
|
import android.content.ClipData
|
||||||
import android.content.DialogInterface
|
import android.content.DialogInterface
|
||||||
import android.net.wifi.WifiConfiguration
|
import android.net.wifi.WifiConfiguration
|
||||||
import android.net.wifi.WifiConfiguration.AuthAlgorithm
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.text.Editable
|
import android.text.Editable
|
||||||
@@ -20,6 +19,7 @@ import androidx.core.view.isGone
|
|||||||
import be.mygod.vpnhotspot.AlertDialogFragment
|
import be.mygod.vpnhotspot.AlertDialogFragment
|
||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.R
|
import be.mygod.vpnhotspot.R
|
||||||
|
import be.mygod.vpnhotspot.RepeaterService
|
||||||
import be.mygod.vpnhotspot.util.QRCodeDialog
|
import be.mygod.vpnhotspot.util.QRCodeDialog
|
||||||
import be.mygod.vpnhotspot.util.toByteArray
|
import be.mygod.vpnhotspot.util.toByteArray
|
||||||
import be.mygod.vpnhotspot.util.toParcelable
|
import be.mygod.vpnhotspot.util.toParcelable
|
||||||
@@ -78,7 +78,7 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
|
|||||||
SSID = dialogView.ssid.text.toString()
|
SSID = dialogView.ssid.text.toString()
|
||||||
allowedKeyManagement.set(
|
allowedKeyManagement.set(
|
||||||
if (arg.p2pMode) WifiConfiguration.KeyMgmt.WPA_PSK else dialogView.security.selectedItemPosition)
|
if (arg.p2pMode) WifiConfiguration.KeyMgmt.WPA_PSK else dialogView.security.selectedItemPosition)
|
||||||
allowedAuthAlgorithms.set(AuthAlgorithm.OPEN)
|
allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN)
|
||||||
if (dialogView.password.length() != 0) preSharedKey = dialogView.password.text.toString()
|
if (dialogView.password.length() != 0) preSharedKey = dialogView.password.text.toString()
|
||||||
if (Build.VERSION.SDK_INT >= 23) {
|
if (Build.VERSION.SDK_INT >= 23) {
|
||||||
val bandOption = dialogView.band.selectedItem as BandOption
|
val bandOption = dialogView.band.selectedItem as BandOption
|
||||||
@@ -110,7 +110,7 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!arg.readOnly) dialogView.password.addTextChangedListener(this@WifiApDialogFragment)
|
if (!arg.readOnly) dialogView.password.addTextChangedListener(this@WifiApDialogFragment)
|
||||||
if (Build.VERSION.SDK_INT >= 23) {
|
if (Build.VERSION.SDK_INT >= 23 || arg.p2pMode) dialogView.band.apply {
|
||||||
bandOptions = mutableListOf<BandOption>().apply {
|
bandOptions = mutableListOf<BandOption>().apply {
|
||||||
if (arg.p2pMode) add(BandOption.BandAny) else {
|
if (arg.p2pMode) add(BandOption.BandAny) else {
|
||||||
if (Build.VERSION.SDK_INT >= 28) add(BandOption.BandAny)
|
if (Build.VERSION.SDK_INT >= 28) add(BandOption.BandAny)
|
||||||
@@ -119,11 +119,13 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
|
|||||||
}
|
}
|
||||||
addAll(channels)
|
addAll(channels)
|
||||||
}
|
}
|
||||||
dialogView.band.adapter = ArrayAdapter(activity, android.R.layout.simple_spinner_item, 0,
|
adapter = ArrayAdapter(activity, android.R.layout.simple_spinner_item, 0, bandOptions).apply {
|
||||||
bandOptions).apply {
|
|
||||||
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||||
}
|
}
|
||||||
} else dialogView.band_wrapper.isGone = true
|
if (Build.VERSION.SDK_INT < 23) {
|
||||||
|
setSelection(bandOptions.indexOfFirst { it.apChannel == RepeaterService.operatingChannel })
|
||||||
|
}
|
||||||
|
}
|
||||||
populateFromConfiguration(arg.configuration)
|
populateFromConfiguration(arg.configuration)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,4 +189,11 @@ class WifiApDialogFragment : AlertDialogFragment<WifiApDialogFragment.Arg, WifiA
|
|||||||
else -> false
|
else -> false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onClick(dialog: DialogInterface?, which: Int) {
|
||||||
|
super.onClick(dialog, which)
|
||||||
|
if (Build.VERSION.SDK_INT < 23 && which == DialogInterface.BUTTON_POSITIVE) {
|
||||||
|
RepeaterService.operatingChannel = (dialogView.band.selectedItem as BandOption).apChannel
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user