Fix AlertDialogFragment

This commit is contained in:
Mygod
2019-01-01 12:44:02 +08:00
parent 7c72b9a235
commit 24c1d810d5
3 changed files with 13 additions and 6 deletions

View File

@@ -7,10 +7,17 @@ import android.os.Bundle
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
/**
* Based on: https://android.googlesource.com/platform/packages/apps/ExactCalculator/+/8c43f06/src/com/android/calculator2/AlertDialogFragment.java
*/
abstract class AlertDialogFragment : DialogFragment(), DialogInterface.OnClickListener { abstract class AlertDialogFragment : DialogFragment(), DialogInterface.OnClickListener {
protected abstract fun AlertDialog.Builder.prepare(listener: DialogInterface.OnClickListener) protected abstract fun AlertDialog.Builder.prepare(listener: DialogInterface.OnClickListener)
open val data: Intent? get() = null open val data: Intent? get() = null
init {
setStyle(STYLE_NO_TITLE, 0)
}
override fun onCreateDialog(savedInstanceState: Bundle?): AlertDialog = override fun onCreateDialog(savedInstanceState: Bundle?): AlertDialog =
AlertDialog.Builder(requireContext()).also { it.prepare(this) }.create() AlertDialog.Builder(requireContext()).also { it.prepare(this) }.create()

View File

@@ -164,18 +164,18 @@ class RepeaterManager(private val parent: TetheringFragment) : Manager(), Servic
data.onStatusChanged() data.onStatusChanged()
} }
fun onWpsResult(which: Int, data: Intent) { fun onWpsResult(which: Int, data: Intent?) {
when (which) { when (which) {
DialogInterface.BUTTON_POSITIVE -> binder?.startWps(data.getStringExtra(WpsDialogFragment.KEY_PIN)) DialogInterface.BUTTON_POSITIVE -> binder?.startWps(data!!.getStringExtra(WpsDialogFragment.KEY_PIN))
DialogInterface.BUTTON_NEUTRAL -> binder?.startWps(null) DialogInterface.BUTTON_NEUTRAL -> binder?.startWps(null)
} }
} }
fun onEditResult(which: Int, data: Intent) { fun onEditResult(which: Int, data: Intent?) {
when (which) { when (which) {
DialogInterface.BUTTON_POSITIVE -> try { DialogInterface.BUTTON_POSITIVE -> try {
val master = holder.config ?: return val master = holder.config ?: return
val config = data.getParcelableExtra<WifiConfiguration>(WifiP2pDialogFragment.KEY_CONFIGURATION) val config = data!!.getParcelableExtra<WifiConfiguration>(WifiP2pDialogFragment.KEY_CONFIGURATION)
master.update(config.SSID, config.preSharedKey) master.update(config.SSID, config.preSharedKey)
binder!!.group = null binder!!.group = null
} catch (e: Exception) { } catch (e: Exception) {

View File

@@ -111,8 +111,8 @@ class TetheringFragment : Fragment(), ServiceConnection {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
when (requestCode) { when (requestCode) {
REPEATER_WPS -> adapter.repeaterManager.onWpsResult(resultCode, data!!) REPEATER_WPS -> adapter.repeaterManager.onWpsResult(resultCode, data)
REPEATER_EDIT_CONFIGURATION -> adapter.repeaterManager.onEditResult(resultCode, data!!) REPEATER_EDIT_CONFIGURATION -> adapter.repeaterManager.onEditResult(resultCode, data)
else -> super.onActivityResult(requestCode, resultCode, data) else -> super.onActivityResult(requestCode, resultCode, data)
} }
} }