From 39cd40627fa2b799903eca1e558f804c647c006c Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 24 Apr 2018 22:48:34 -0700 Subject: [PATCH] Redesign WifiP2pDialog using design lib --- .../vpnhotspot/net/wifi/WifiP2pDialog.kt | 33 ++----- mobile/src/main/res/layout/dialog_wifi_ap.xml | 95 ++++++------------- mobile/src/main/res/values-zh-rCN/strings.xml | 2 - mobile/src/main/res/values/strings.xml | 2 - mobile/src/main/res/values/styles.xml | 15 --- 5 files changed, 37 insertions(+), 110 deletions(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pDialog.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pDialog.kt index 1312270f..670129a8 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pDialog.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiP2pDialog.kt @@ -5,6 +5,7 @@ import android.content.DialogInterface import android.net.wifi.WifiConfiguration import android.net.wifi.WifiConfiguration.AuthAlgorithm import android.os.Bundle +import android.support.design.widget.TextInputLayout import android.support.v7.app.AlertDialog import android.text.Editable import android.text.InputType @@ -20,8 +21,7 @@ import java.nio.charset.Charset * https://android.googlesource.com/platform/packages/apps/Settings/+/39b4674/src/com/android/settings/wifi/WifiApDialog.java */ class WifiP2pDialog(mContext: Context, private val mListener: DialogInterface.OnClickListener, - private val mWifiConfig: WifiConfiguration?) : - AlertDialog(mContext), View.OnClickListener, TextWatcher { + private val mWifiConfig: WifiConfiguration?) : AlertDialog(mContext), TextWatcher { companion object { private const val BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE } @@ -29,12 +29,6 @@ class WifiP2pDialog(mContext: Context, private val mListener: DialogInterface.On private lateinit var mView: View private lateinit var mSsid: TextView private lateinit var mPassword: EditText - /** - * TODO: SSID in WifiConfiguration for soft ap - * is being stored as a raw string without quotes. - * This is not the case on the client side. We need to - * make things consistent and clean it up - */ val config: WifiConfiguration? get() { val config = WifiConfiguration() @@ -64,30 +58,17 @@ class WifiP2pDialog(mContext: Context, private val mListener: DialogInterface.On } mSsid.addTextChangedListener(this) mPassword.addTextChangedListener(this) - (mView.findViewById(R.id.show_password) as CheckBox).setOnClickListener(this) super.onCreate(savedInstanceState) validate() } - override fun onRestoreInstanceState(savedInstanceState: Bundle) { - super.onRestoreInstanceState(savedInstanceState) - mPassword.inputType = InputType.TYPE_CLASS_TEXT or - if ((mView.findViewById(R.id.show_password) as CheckBox).isChecked) - InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD - else InputType.TYPE_TEXT_VARIATION_PASSWORD - } - private fun validate() { val mSsidString = mSsid.text.toString() - getButton(BUTTON_SUBMIT).isEnabled = mSsid.length() != 0 && - mPassword.length() >= 8 && Charset.forName("UTF-8").encode(mSsidString).limit() <= 32 - } - - override fun onClick(view: View) { - mPassword.inputType = InputType.TYPE_CLASS_TEXT or if ((view as CheckBox).isChecked) - InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD - else - InputType.TYPE_TEXT_VARIATION_PASSWORD + val ssidValid = mSsid.length() != 0 && Charset.forName("UTF-8").encode(mSsidString).limit() <= 32 + val passwordValid = mPassword.length() >= 8 + mView.findViewById(R.id.password_wrapper).error = + if (passwordValid) null else context.getString(R.string.credentials_password_too_short) + getButton(BUTTON_SUBMIT).isEnabled = ssidValid && passwordValid } override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { } diff --git a/mobile/src/main/res/layout/dialog_wifi_ap.xml b/mobile/src/main/res/layout/dialog_wifi_ap.xml index 144ace3e..db280c00 100644 --- a/mobile/src/main/res/layout/dialog_wifi_ap.xml +++ b/mobile/src/main/res/layout/dialog_wifi_ap.xml @@ -12,6 +12,7 @@ limitations under the License. --> @@ -20,74 +21,38 @@ android:layout_height="wrap_content" android:descendantFocusability="beforeDescendants" android:focusableInTouchMode="true" - android:orientation="vertical"> - - - + + - - - - - - + + + - - - - - - - - + style="@style/wifi_item_edit_content" + android:singleLine="true" + android:hint="@string/wifi_password" + android:inputType="textPassword" + android:maxLength="63" + android:imeOptions="flagForceAscii" /> + diff --git a/mobile/src/main/res/values-zh-rCN/strings.xml b/mobile/src/main/res/values-zh-rCN/strings.xml index bceabd82..7b403f02 100644 --- a/mobile/src/main/res/values-zh-rCN/strings.xml +++ b/mobile/src/main/res/values-zh-rCN/strings.xml @@ -77,9 +77,7 @@ 发生异常,详情请查看调试信息。 "网络名称" - "输入 SSID" "密码" - "显示密码" "密码至少应包含 8 个字符。" "保存" "取消" diff --git a/mobile/src/main/res/values/strings.xml b/mobile/src/main/res/values/strings.xml index 16b80dbd..e8dc48ad 100644 --- a/mobile/src/main/res/values/strings.xml +++ b/mobile/src/main/res/values/strings.xml @@ -82,9 +82,7 @@ Something went wrong, please check the debug information. Network name - Enter the SSID Password - Show password The password must have at least 8 characters. Save Cancel diff --git a/mobile/src/main/res/values/styles.xml b/mobile/src/main/res/values/styles.xml index 95c9fe8c..e2d504af 100644 --- a/mobile/src/main/res/values/styles.xml +++ b/mobile/src/main/res/values/styles.xml @@ -23,25 +23,10 @@ vertical start - - -