From 9220f9f113df4495d9052f7e188bdb27556d90d0 Mon Sep 17 00:00:00 2001 From: Mygod Date: Sat, 21 Jul 2018 19:04:53 +0800 Subject: [PATCH] Refine code style --- .../net/wifi/WifiP2pDialogFragment.kt | 54 +++++++++---------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pDialogFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pDialogFragment.kt index e5da0522..a693d90c 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pDialogFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pDialogFragment.kt @@ -46,32 +46,31 @@ class WifiP2pDialogFragment : DialogFragment(), TextWatcher, DialogInterface.OnC return config } - override fun onCreateDialog(savedInstanceState: Bundle?): AlertDialog { - return AlertDialog.Builder(requireContext()).apply { - mView = requireActivity().layoutInflater.inflate(R.layout.dialog_wifi_ap, null) - setView(mView) - setTitle(R.string.repeater_configure) - mSsid = mView.findViewById(R.id.ssid) - mPassword = mView.findViewById(R.id.password) - // Note: Reading persistent group information in p2p_supplicant.conf wasn't available until this commit: - // https://android.googlesource.com/platform/external/wpa_supplicant_8/+/216983bceec7c450951e2fbcd076b5c75d432e57%5E%21/ - // which isn't merged until Android 6.0. - if (Build.VERSION.SDK_INT >= 23) { - setPositiveButton(context.getString(R.string.wifi_save), this@WifiP2pDialogFragment) - } - setNegativeButton(context.getString(R.string.wifi_cancel), this@WifiP2pDialogFragment) - setNeutralButton(context.getString(R.string.repeater_reset_credentials), this@WifiP2pDialogFragment) - val arguments = arguments!! - configurer = arguments.getParcelable(KEY_CONFIGURER) - val mWifiConfig = arguments.getParcelable(KEY_CONFIGURATION) - if (mWifiConfig != null) { - mSsid.text = mWifiConfig.SSID - mPassword.setText(mWifiConfig.preSharedKey) - } - mSsid.addTextChangedListener(this@WifiP2pDialogFragment) - mPassword.addTextChangedListener(this@WifiP2pDialogFragment) - }.create() - } + override fun onCreateDialog(savedInstanceState: Bundle?): AlertDialog = + AlertDialog.Builder(requireContext()).apply { + mView = requireActivity().layoutInflater.inflate(R.layout.dialog_wifi_ap, null) + setView(mView) + setTitle(R.string.repeater_configure) + mSsid = mView.findViewById(R.id.ssid) + mPassword = mView.findViewById(R.id.password) + // Note: Reading persistent group information in p2p_supplicant.conf wasn't available until this commit: + // https://android.googlesource.com/platform/external/wpa_supplicant_8/+/216983bceec7c450951e2fbcd076b5c75d432e57%5E%21/ + // which isn't merged until Android 6.0. + if (Build.VERSION.SDK_INT >= 23) { + setPositiveButton(context.getString(R.string.wifi_save), this@WifiP2pDialogFragment) + } + setNegativeButton(context.getString(R.string.wifi_cancel), this@WifiP2pDialogFragment) + setNeutralButton(context.getString(R.string.repeater_reset_credentials), this@WifiP2pDialogFragment) + val arguments = arguments!! + configurer = arguments.getParcelable(KEY_CONFIGURER) + val mWifiConfig = arguments.getParcelable(KEY_CONFIGURATION) + if (mWifiConfig != null) { + mSsid.text = mWifiConfig.SSID + mPassword.setText(mWifiConfig.preSharedKey) + } + mSsid.addTextChangedListener(this@WifiP2pDialogFragment) + mPassword.addTextChangedListener(this@WifiP2pDialogFragment) + }.create() override fun onStart() { super.onStart() @@ -101,9 +100,8 @@ class WifiP2pDialogFragment : DialogFragment(), TextWatcher, DialogInterface.OnC false -> (activity as MainActivity).snackbar().setText(R.string.noisy_su_failure).show() null -> (activity as MainActivity).snackbar().setText(R.string.root_unavailable).show() } - DialogInterface.BUTTON_NEUTRAL -> { + DialogInterface.BUTTON_NEUTRAL -> (targetFragment as TetheringFragment).adapter.repeaterManager.binder!!.resetCredentials() - } } } }