Move edit configuration logic out of WifiP2pDialogFragment

This commit is contained in:
Mygod
2018-09-17 23:35:18 +08:00
parent dbe43624ed
commit 204145ef4f
3 changed files with 31 additions and 19 deletions

View File

@@ -1,6 +1,7 @@
package be.mygod.vpnhotspot.manage
import android.content.ComponentName
import android.content.DialogInterface
import android.content.Intent
import android.content.ServiceConnection
import android.net.wifi.WifiConfiguration
@@ -111,7 +112,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
WifiP2pDialogFragment().apply {
arguments = bundleOf(Pair(WifiP2pDialogFragment.KEY_CONFIGURATION, wifi),
Pair(WifiP2pDialogFragment.KEY_CONFIGURER, conf))
setTargetFragment(parent, 0)
setTargetFragment(parent, TetheringFragment.REPEATER_EDIT_CONFIGURATION)
}.show(parent.fragmentManager, WifiP2pDialogFragment.TAG)
return
}
@@ -147,4 +148,19 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
binder.groupChanged -= this
data.onStatusChanged()
}
fun onEditResult(which: Int, data: Intent) {
when (which) {
DialogInterface.BUTTON_POSITIVE -> try {
data.getParcelableExtra<P2pSupplicantConfiguration>(WifiP2pDialogFragment.KEY_CONFIGURER)
.update(data.getParcelableExtra(WifiP2pDialogFragment.KEY_CONFIGURATION))
app.handler.postDelayed(binder!!::requestGroupUpdate, 1000)
} catch (e: RuntimeException) {
e.printStackTrace()
Crashlytics.logException(e)
SmartSnackbar.make(e.localizedMessage).show()
}
DialogInterface.BUTTON_NEUTRAL -> binder!!.resetCredentials()
}
}
}