Fix editing Repeater config
This commit is contained in:
@@ -67,7 +67,7 @@ def aux = [
|
||||
'com.crashlytics.sdk.android:crashlytics:2.10.1',
|
||||
'com.google.firebase:firebase-core:17.0.1',
|
||||
]
|
||||
def lifecycleVersion = '2.1.0-rc01'
|
||||
def lifecycleVersion = '2.2.0-alpha02'
|
||||
def roomVersion = '2.1.0'
|
||||
dependencies {
|
||||
kapt "androidx.room:room-compiler:$roomVersion"
|
||||
@@ -78,6 +78,7 @@ dependencies {
|
||||
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
|
||||
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"
|
||||
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycleVersion"
|
||||
implementation "androidx.lifecycle:lifecycle-runtime-ktx:$lifecycleVersion"
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
|
||||
implementation 'androidx.preference:preference:1.1.0-rc01'
|
||||
implementation "androidx.room:room-ktx:$roomVersion"
|
||||
|
||||
@@ -19,6 +19,7 @@ import androidx.databinding.DataBindingUtil
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.ViewModelProviders
|
||||
import androidx.lifecycle.get
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.observe
|
||||
import androidx.recyclerview.widget.DefaultItemAnimator
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
@@ -41,7 +42,10 @@ import be.mygod.vpnhotspot.util.computeIfAbsentCompat
|
||||
import be.mygod.vpnhotspot.util.toPluralInt
|
||||
import be.mygod.vpnhotspot.widget.SmartSnackbar
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
import kotlinx.coroutines.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.text.NumberFormat
|
||||
|
||||
class ClientsFragment : Fragment() {
|
||||
@@ -149,13 +153,15 @@ class ClientsFragment : Fragment() {
|
||||
}
|
||||
R.id.stats -> {
|
||||
binding.client?.let { client ->
|
||||
scope.launch {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
withContext(Dispatchers.Unconfined) {
|
||||
StatsDialogFragment().withArg(StatsArg(
|
||||
client.title.value ?: return@launch,
|
||||
client.title.value ?: return@withContext,
|
||||
AppDatabase.instance.trafficRecordDao.queryStats(client.mac)
|
||||
)).show(this@ClientsFragment)
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
else -> false
|
||||
@@ -204,7 +210,6 @@ class ClientsFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
private val scope = MainScope() + Dispatchers.Unconfined
|
||||
private lateinit var binding: FragmentClientsBinding
|
||||
private val adapter = ClientAdapter()
|
||||
private var rates = HashMap<Pair<String, Long>, TrafficRate>()
|
||||
@@ -236,9 +241,4 @@ class ClientsFragment : Fragment() {
|
||||
TrafficRecorder.foregroundListeners -= this
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
scope.cancel()
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user