This commit is contained in:
Mygod
2019-02-04 14:23:12 +08:00
parent fa43c41ed4
commit 50911bd31f
3 changed files with 13 additions and 9 deletions

View File

@@ -7,6 +7,7 @@ import android.os.Bundle
import android.os.Parcelable import android.os.Parcelable
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatDialogFragment import androidx.appcompat.app.AppCompatDialogFragment
import androidx.fragment.app.Fragment
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
/** /**
@@ -38,6 +39,11 @@ abstract class AlertDialogFragment<Arg : Parcelable, Ret : Parcelable> :
super.onDismiss(dialog) super.onDismiss(dialog)
targetFragment?.onActivityResult(targetRequestCode, Activity.RESULT_CANCELED, null) targetFragment?.onActivityResult(targetRequestCode, Activity.RESULT_CANCELED, null)
} }
fun show(target: Fragment, requestCode: Int = 0, tag: String = javaClass.simpleName) {
setTargetFragment(target, requestCode)
show(target.fragmentManager ?: return, tag)
}
} }
@Parcelize @Parcelize

View File

@@ -132,7 +132,7 @@ class ClientsFragment : Fragment(), MainScope by MainScope.Supervisor() {
R.id.nickname -> { R.id.nickname -> {
val client = binding.client ?: return false val client = binding.client ?: return false
NicknameDialogFragment().withArg(NicknameArg(client.mac, client.nickname)) NicknameDialogFragment().withArg(NicknameArg(client.mac, client.nickname))
.show(fragmentManager ?: return false, "NicknameDialogFragment") .show(this@ClientsFragment)
true true
} }
R.id.block, R.id.unblock -> { R.id.block, R.id.unblock -> {
@@ -151,9 +151,10 @@ class ClientsFragment : Fragment(), MainScope by MainScope.Supervisor() {
R.id.stats -> { R.id.stats -> {
binding.client?.let { client -> binding.client?.let { client ->
launch(start = CoroutineStart.UNDISPATCHED) { launch(start = CoroutineStart.UNDISPATCHED) {
StatsDialogFragment().withArg(StatsArg(client.title.value ?: return@launch, StatsDialogFragment().withArg(StatsArg(
AppDatabase.instance.trafficRecordDao.queryStats(client.mac))) client.title.value ?: return@launch,
.show(fragmentManager ?: return@launch, "StatsDialogFragment") AppDatabase.instance.trafficRecordDao.queryStats(client.mac)
)).show(this@ClientsFragment)
} }
} }
true true

View File

@@ -90,10 +90,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
} }
fun wps() { fun wps() {
if (binder?.active == true) WpsDialogFragment().run { if (binder?.active == true) WpsDialogFragment().show(parent, TetheringFragment.REPEATER_WPS)
setTargetFragment(parent, TetheringFragment.REPEATER_WPS)
show(parent.fragmentManager ?: return, "WpsDialogFragment")
}
} }
fun editConfigurations() { fun editConfigurations() {
@@ -104,7 +101,7 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
WifiP2pDialogFragment().withArg(WifiP2pDialogFragment.Arg(WifiConfiguration().apply { WifiP2pDialogFragment().withArg(WifiP2pDialogFragment.Arg(WifiConfiguration().apply {
SSID = group.networkName SSID = group.networkName
preSharedKey = config.psk preSharedKey = config.psk
})).show(parent.fragmentManager ?: return, "WifiP2pDialogFragment") })).show(parent, TetheringFragment.REPEATER_EDIT_CONFIGURATION)
return return
} catch (e: RuntimeException) { } catch (e: RuntimeException) {
Timber.w(e) Timber.w(e)