Fix editing Repeater config

This commit is contained in:
Mygod
2019-07-17 17:14:27 +08:00
parent 7a4264e2df
commit 3bd81b942f
4 changed files with 27 additions and 20 deletions

View File

@@ -31,6 +31,8 @@ import be.mygod.vpnhotspot.util.ServiceForegroundConnector
import be.mygod.vpnhotspot.util.formatAddresses
import be.mygod.vpnhotspot.widget.SmartSnackbar
import kotlinx.android.parcel.Parcelize
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import timber.log.Timber
import java.net.NetworkInterface
import java.net.SocketException
@@ -197,7 +199,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
SmartSnackbar.make(R.string.repeater_configure_failure).show()
return null
}
fun updateConfiguration(config: WifiConfiguration) {
suspend fun updateConfiguration(config: WifiConfiguration) {
if (Build.VERSION.SDK_INT >= 29) {
RepeaterService.networkName = config.SSID
RepeaterService.passphrase = config.preSharedKey
@@ -209,7 +211,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
}
} else @Suppress("DEPRECATION") holder.config?.let { master ->
if (binder?.group?.networkName != config.SSID || master.psk != config.preSharedKey) try {
master.update(config.SSID, config.preSharedKey)
withContext(Dispatchers.Default) { master.update(config.SSID, config.preSharedKey) }
binder!!.group = null
} catch (e: Exception) {
Timber.w(e)

View File

@@ -14,6 +14,7 @@ import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.ListAdapter
@@ -31,6 +32,8 @@ import be.mygod.vpnhotspot.util.broadcastReceiver
import be.mygod.vpnhotspot.util.isNotGone
import be.mygod.vpnhotspot.widget.SmartSnackbar
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import timber.log.Timber
import java.lang.IllegalArgumentException
import java.lang.reflect.InvocationTargetException
@@ -126,10 +129,11 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
true
}
R.id.configuration_repeater -> {
WifiApDialogFragment().withArg(WifiApDialogFragment.Arg(
adapter.repeaterManager.configuration ?: return false,
p2pMode = true
)).show(this, CONFIGURE_REPEATER)
lifecycleScope.launchWhenCreated {
WifiApDialogFragment().withArg(WifiApDialogFragment.Arg(withContext(Dispatchers.Default) {
adapter.repeaterManager.configuration
} ?: return@launchWhenCreated, p2pMode = true)).show(this@TetheringFragment, CONFIGURE_REPEATER)
}
true
}
R.id.configuration_temp_hotspot -> {
@@ -185,7 +189,7 @@ class TetheringFragment : Fragment(), ServiceConnection, Toolbar.OnMenuItemClick
val configuration by lazy { AlertDialogFragment.getRet<WifiApDialogFragment.Arg>(data!!).configuration }
when (requestCode) {
REPEATER_WPS -> adapter.repeaterManager.onWpsResult(resultCode, data)
CONFIGURE_REPEATER -> if (resultCode == DialogInterface.BUTTON_POSITIVE) {
CONFIGURE_REPEATER -> if (resultCode == DialogInterface.BUTTON_POSITIVE) lifecycleScope.launchWhenCreated {
adapter.repeaterManager.updateConfiguration(configuration)
}
CONFIGURE_AP -> if (resultCode == DialogInterface.BUTTON_POSITIVE) try {