diff options
| author | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-08-28 07:53:25 -0300 |
|---|---|---|
| committer | Janito Vaqueiro Ferreira Filho <janito@mullvad.net> | 2019-08-28 07:53:25 -0300 |
| commit | 40f2a6d3397694d3bb0d4025daee00f61f9c92d4 (patch) | |
| tree | 33cf76174de4a4e9ed0ff4dbd2438c7bf2c56219 | |
| parent | 6bb12f63a5be8fdb3dc4847d3157263aa7442a63 (diff) | |
| parent | 5284298105438104636c3f1177499c8e105e0801 (diff) | |
| download | mullvadvpn-40f2a6d3397694d3bb0d4025daee00f61f9c92d4.tar.xz mullvadvpn-40f2a6d3397694d3bb0d4025daee00f61f9c92d4.zip | |
Merge branch 'create-account-button'
4 files changed, 71 insertions, 10 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/AccountInput.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/AccountInput.kt index eb666dc649..3559f1ba3a 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/AccountInput.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/AccountInput.kt @@ -4,6 +4,7 @@ import android.content.Context import android.view.View import android.view.View.OnFocusChangeListener import android.text.Editable +import android.text.style.MetricAffectingSpan import android.text.TextWatcher import android.widget.EditText import android.widget.ImageButton @@ -21,7 +22,16 @@ class AccountInput(val parentView: View, val context: Context) { private val focusedBorder = resources.getDrawable(R.drawable.account_input_border_focused, null) private val errorBorder = resources.getDrawable(R.drawable.account_input_border_error, null) + private var inputHasFocus = false + set(value) { + field = value + updateBorder() + } private var usingErrorColor = false + set(value) { + field = value + updateBorder() + } var state = LoginState.Initial set(value) { @@ -46,7 +56,7 @@ class AccountInput(val parentView: View, val context: Context) { input.apply { addTextChangedListener(InputWatcher()) onFocusChangeListener = OnFocusChangeListener { view, hasFocus -> - updateBorder(hasFocus && view.isEnabled()) + inputHasFocus = hasFocus && view.isEnabled() } } @@ -97,7 +107,6 @@ class AccountInput(val parentView: View, val context: Context) { } usingErrorColor = true - updateBorder(false) } private fun setButtonEnabled(enabled: Boolean) { @@ -110,7 +119,7 @@ class AccountInput(val parentView: View, val context: Context) { } } - private fun updateBorder(inputHasFocus: Boolean) { + private fun updateBorder() { if (usingErrorColor) { container.foreground = errorBorder } else { @@ -122,19 +131,29 @@ class AccountInput(val parentView: View, val context: Context) { } } + private fun leaveErrorState() { + if (usingErrorColor) { + input.setTextColor(enabledTextColor) + usingErrorColor = false + } + } + + private fun removeFormattingSpans(text: Editable) { + for (span in text.getSpans(0, text.length, MetricAffectingSpan::class.java)) { + text.removeSpan(span) + } + } + inner class InputWatcher : TextWatcher { override fun beforeTextChanged(text: CharSequence, start: Int, count: Int, after: Int) {} override fun onTextChanged(text: CharSequence, start: Int, before: Int, count: Int) {} override fun afterTextChanged(text: Editable) { + inputHasFocus = true + removeFormattingSpans(text) setButtonEnabled(text.length >= MIN_ACCOUNT_TOKEN_LENGTH) - - if (usingErrorColor) { - input.setTextColor(enabledTextColor) - usingErrorColor = false - updateBorder(true) - } + leaveErrorState() } } } diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/LoginFragment.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/LoginFragment.kt index e8b42d038c..a3871a1433 100644 --- a/android/src/main/kotlin/net/mullvad/mullvadvpn/LoginFragment.kt +++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/LoginFragment.kt @@ -9,6 +9,8 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Job import android.content.Context +import android.content.Intent +import android.net.Uri import android.os.Bundle import android.os.Handler import android.support.v4.app.Fragment @@ -51,9 +53,18 @@ class LoginFragment : Fragment() { accountInput = AccountInput(view, parentActivity) accountInput.onLogin = { accountToken -> login(accountToken) } + view.findViewById<View>(R.id.create_account).setOnClickListener { createAccount() } + return view } + private fun createAccount() { + val uri = Uri.parse(parentActivity.getString(R.string.create_account_url)) + val intent = Intent(Intent.ACTION_VIEW, uri) + + startActivity(intent) + } + private fun login(accountToken: String) { title.setText(R.string.logging_in_title) subtitle.setText(R.string.logging_in_description) diff --git a/android/src/main/res/layout/login.xml b/android/src/main/res/layout/login.xml index 58a70bf885..ea9b8da524 100644 --- a/android/src/main/res/layout/login.xml +++ b/android/src/main/res/layout/login.xml @@ -91,7 +91,7 @@ android:layout_weight="0" android:layout_marginBottom="10dp" android:gravity="start" - android:textColor="@color/white60" + android:textColor="@color/white80" android:textSize="13sp" android:text="@string/login_description" /> @@ -132,4 +132,32 @@ android:layout_weight="3" /> </LinearLayout> + <LinearLayout + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_weight="0" + android:orientation="vertical" + android:paddingHorizontal="24dp" + android:paddingBottom="24dp" + android:paddingTop="16dp" + android:background="@color/darkBlue" + > + <TextView + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_marginBottom="8dp" + android:gravity="start" + android:textColor="@color/white80" + android:textSize="13sp" + android:text="@string/dont_have_an_account" + /> + <Button android:id="@+id/create_account" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:padding="9dp" + android:drawableRight="@drawable/icon_extlink" + android:text="@string/create_account" + style="@style/BlueButton" + /> + </LinearLayout> </LinearLayout> diff --git a/android/src/main/res/values/strings.xml b/android/src/main/res/values/strings.xml index 02f4315083..50e4d43c79 100644 --- a/android/src/main/res/values/strings.xml +++ b/android/src/main/res/values/strings.xml @@ -11,6 +11,8 @@ <string name="logged_in_title">Login successful</string> <string name="login_fail_title">Login failed</string> <string name="login_fail_description">Invalid account number, try again</string> + <string name="dont_have_an_account">Don\'t have an account number?</string> + <string name="create_account">Create account</string> <string name="settings">Settings</string> <string name="settings_account">Account</string> @@ -114,5 +116,6 @@ </string> <string name="account_url">https://mullvad.net/en/account</string> + <string name="create_account_url">https://mullvad.net/en/account/create</string> <string name="download_url">https://mullvad.net/en/download</string> </resources> |
