Skip to content
This repository was archived by the owner on Dec 16, 2023. It is now read-only.

Commit 165f87d

Browse files
committed
Update sign up activity
1 parent c809e9a commit 165f87d

8 files changed

Lines changed: 38 additions & 70 deletions

File tree

app/src/main/java/com/marknkamau/justjava/data/network/authentication/AuthenticationService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ interface AuthenticationService {
2222
interface AuthActionListener {
2323
fun actionSuccessful(response: String)
2424

25-
fun actionFailed(response: String?)
25+
fun actionFailed(response: String)
2626
}
2727
}

app/src/main/java/com/marknkamau/justjava/data/network/authentication/AuthenticationServiceImpl.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,27 @@ object AuthenticationServiceImpl : AuthenticationService {
2222
override fun createUser(email: String, password: String, listener: AuthenticationService.AuthActionListener) {
2323
firebaseAuth.createUserWithEmailAndPassword(email, password)
2424
.addOnSuccessListener { listener.actionSuccessful("User created successfully") }
25-
.addOnFailureListener { exception -> listener.actionFailed(exception.message) }
25+
.addOnFailureListener { exception -> listener.actionFailed(exception.message ?: "Unable to create account") }
2626
}
2727

2828
override fun signIn(email: String, password: String, listener: AuthenticationService.AuthActionListener) {
2929
firebaseAuth.signInWithEmailAndPassword(email, password)
3030
.addOnSuccessListener { listener.actionSuccessful(it.user.uid) }
31-
.addOnFailureListener { exception -> listener.actionFailed(exception.message) }
31+
.addOnFailureListener { exception -> listener.actionFailed(exception.message ?: "Unable to sign in") }
3232
}
3333

3434
override fun sendPasswordResetEmail(email: String, listener: AuthenticationService.AuthActionListener) {
3535
firebaseAuth.sendPasswordResetEmail(email)
3636
.addOnSuccessListener { listener.actionSuccessful("Password reset email sent") }
37-
.addOnFailureListener { exception -> listener.actionFailed(exception.message) }
37+
.addOnFailureListener { exception -> listener.actionFailed(exception.message ?: "Unable to send email") }
3838
}
3939

4040
override fun setUserDisplayName(name: String, listener: AuthenticationService.AuthActionListener) {
4141
val profileUpdate = UserProfileChangeRequest.Builder().setDisplayName(name).build()
4242

4343
firebaseAuth.currentUser?.updateProfile(profileUpdate)
4444
?.addOnSuccessListener { listener.actionSuccessful("User display name set") }
45-
?.addOnFailureListener { exception -> listener.actionFailed(exception.message) }
45+
?.addOnFailureListener { exception -> listener.actionFailed(exception.message ?: "Unable to update profile") }
4646
}
4747

4848
override fun getUserId() = if (isSignedIn) firebaseAuth.currentUser!!.uid else null

app/src/main/java/com/marknkamau/justjava/ui/login/LogInPresenter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal class LogInPresenter(private val activityView: LogInView,
2424
getUserDefaults(response)
2525
}
2626

27-
override fun actionFailed(response: String?) {
27+
override fun actionFailed(response: String) {
2828
activityView.displayMessage(response)
2929
}
3030
})
@@ -51,7 +51,7 @@ internal class LogInPresenter(private val activityView: LogInView,
5151
activityView.displayMessage(response)
5252
}
5353

54-
override fun actionFailed(response: String?) {
54+
override fun actionFailed(response: String) {
5555
activityView.displayMessage(response)
5656
}
5757
})

app/src/main/java/com/marknkamau/justjava/ui/profile/ProfilePresenter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ internal class ProfilePresenter(private val view: ProfileView,
6565
})
6666
}
6767

68-
override fun actionFailed(response: String?) {
68+
override fun actionFailed(response: String) {
6969
view.displayMessage(response)
7070
}
7171
})

app/src/main/java/com/marknkamau/justjava/ui/signup/SignUpActivity.kt

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class SignUpActivity : AppCompatActivity(), SignUpView, View.OnClickListener {
1919
private lateinit var address: String
2020
private lateinit var password: String
2121
private var passVisible = false
22-
private var passRptVisible = false
2322
private lateinit var presenter: SignUpPresenter
2423

2524
override fun onCreate(savedInstanceState: Bundle?) {
@@ -33,7 +32,6 @@ class SignUpActivity : AppCompatActivity(), SignUpView, View.OnClickListener {
3332
presenter = SignUpPresenter(this, preferencesRepository, auth, database)
3433

3534
imgViewPass.setOnClickListener(this)
36-
imgViewPassRpt.setOnClickListener(this)
3735
btnSignup.setOnClickListener(this)
3836
tvLogin.setOnClickListener(this)
3937
}
@@ -50,16 +48,6 @@ class SignUpActivity : AppCompatActivity(), SignUpView, View.OnClickListener {
5048
imgViewPass.setImageResource(R.drawable.ic_visibility)
5149
passVisible = true
5250
}
53-
imgViewPassRpt ->
54-
if (passRptVisible) {
55-
etPasswordRepeat.transformationMethod = PasswordTransformationMethod()
56-
imgViewPassRpt.setImageResource(R.drawable.ic_visibility_off)
57-
passRptVisible = false
58-
} else {
59-
etPasswordRepeat.transformationMethod = null
60-
imgViewPassRpt.setImageResource(R.drawable.ic_visibility)
61-
passRptVisible = true
62-
}
6351
btnSignup -> createUser()
6452
tvLogin -> {
6553
finish()
@@ -79,7 +67,9 @@ class SignUpActivity : AppCompatActivity(), SignUpView, View.OnClickListener {
7967
btnSignup.isEnabled = false
8068
}
8169

82-
override fun displayMessage(message: String?) = Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
70+
override fun displayMessage(message: String) {
71+
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
72+
}
8373

8474
override fun finishActivity() = finish()
8575

@@ -92,7 +82,6 @@ class SignUpActivity : AppCompatActivity(), SignUpView, View.OnClickListener {
9282
private fun fieldsOk(): Boolean {
9383
email = etEmailAddress.trimmedText
9484
password = etPassword.trimmedText
95-
val passwordRpt = etPasswordRepeat.trimmedText
9685

9786
name = etName.trimmedText
9887
phone = etPhone.trimmedText
@@ -105,23 +94,21 @@ class SignUpActivity : AppCompatActivity(), SignUpView, View.OnClickListener {
10594
etEmailAddress.error = "Can not use @justjava.com"
10695
return false
10796
}
108-
if (email.isEmpty() || password.isEmpty() || passwordRpt.isEmpty()
97+
if (email.isEmpty() || password.isEmpty()
10998
|| name.isEmpty() || phone.isEmpty() || address.isEmpty()) {
11099
Toast.makeText(this, "All fields are required", Toast.LENGTH_SHORT).show()
111100
return false
112101
}
113102
if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
103+
Toast.makeText(this, "Invalid email", Toast.LENGTH_SHORT).show()
114104
etEmailAddress.error = "Incorrect format"
115105
return false
116106
}
117107
if (password.length < 6) {
108+
Toast.makeText(this, "Password must be at least 6 characters", Toast.LENGTH_LONG).show()
118109
etPassword.error = "At least 6 characters"
119110
return false
120111
}
121-
if (password != passwordRpt) {
122-
etPasswordRepeat.error = "Passwords do no match"
123-
return false
124-
}
125112
return true
126113
}
127114
}

app/src/main/java/com/marknkamau/justjava/ui/signup/SignUpPresenter.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ internal class SignUpPresenter(private val activityView: SignUpView,
1818
signInUser(email, password, name, phone, address)
1919
}
2020

21-
override fun actionFailed(response: String?) {
21+
override fun actionFailed(response: String) {
2222
activityView.enableUserInteraction()
2323
activityView.displayMessage(response)
2424
}
@@ -31,7 +31,7 @@ internal class SignUpPresenter(private val activityView: SignUpView,
3131
setUserDisplayName(response, email, name, phone, address)
3232
}
3333

34-
override fun actionFailed(response: String?) {
34+
override fun actionFailed(response: String) {
3535
activityView.enableUserInteraction()
3636
activityView.displayMessage(response)
3737
}
@@ -59,7 +59,7 @@ internal class SignUpPresenter(private val activityView: SignUpView,
5959

6060
}
6161

62-
override fun actionFailed(response: String?) {
62+
override fun actionFailed(response: String) {
6363
activityView.enableUserInteraction()
6464
activityView.displayMessage(response)
6565
}

app/src/main/java/com/marknkamau/justjava/ui/signup/SignUpView.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ package com.marknkamau.justjava.ui.signup
33
interface SignUpView {
44
fun enableUserInteraction()
55
fun disableUserInteraction()
6-
fun displayMessage(message: String?)
6+
fun displayMessage(message: String)
77
fun finishActivity()
88
}

app/src/main/res/layout/activity_sign_up.xml

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
app:layout_constraintHorizontal_bias="0.0"
2929
app:layout_constraintLeft_toLeftOf="parent"
3030
app:layout_constraintRight_toRightOf="parent"
31-
app:layout_constraintTop_toBottomOf="@+id/textView14"
31+
app:layout_constraintTop_toBottomOf="@+id/textView4"
3232
tools:ignore="Autofill" />
3333

3434
<EditText
@@ -63,52 +63,19 @@
6363
tools:ignore="ContentDescription"
6464
tools:layout_editor_absoluteX="320dp" />
6565

66-
<EditText
67-
android:id="@+id/etPasswordRepeat"
68-
style="@style/DarkInputField"
69-
android:layout_width="0dp"
70-
android:layout_height="wrap_content"
71-
android:layout_marginStart="16dp"
72-
android:layout_marginTop="6dp"
73-
android:layout_marginEnd="16dp"
74-
android:hint="@string/repeat_password"
75-
android:inputType="textPassword"
76-
app:layout_constraintEnd_toEndOf="parent"
77-
app:layout_constraintHorizontal_bias="0.0"
78-
app:layout_constraintLeft_toLeftOf="@+id/etPassword"
79-
app:layout_constraintRight_toLeftOf="@+id/imgViewPassRpt"
80-
app:layout_constraintStart_toStartOf="parent"
81-
app:layout_constraintTop_toBottomOf="@+id/etPassword"
82-
tools:ignore="Autofill" />
83-
84-
<ImageView
85-
android:id="@+id/imgViewPassRpt"
86-
android:layout_width="wrap_content"
87-
android:layout_height="wrap_content"
88-
android:layout_marginTop="8dp"
89-
android:layout_marginBottom="8dp"
90-
android:alpha=".87"
91-
app:layout_constraintBottom_toBottomOf="@+id/etPasswordRepeat"
92-
app:layout_constraintEnd_toEndOf="@+id/imgViewPass"
93-
app:layout_constraintTop_toTopOf="@+id/etPasswordRepeat"
94-
app:srcCompat="@drawable/ic_visibility_off"
95-
tools:ignore="ContentDescription" />
96-
9766
<EditText
9867
android:id="@+id/etName"
9968
style="@style/DarkInputField"
10069
android:layout_width="0dp"
10170
android:layout_height="wrap_content"
10271
android:layout_marginStart="16dp"
103-
android:layout_marginTop="16dp"
72+
android:layout_marginTop="32dp"
10473
android:layout_marginEnd="16dp"
10574
android:hint="@string/full_name"
106-
android:inputType="textPersonName"
75+
android:inputType="textCapWords|textPersonName"
10776
app:layout_constraintEnd_toEndOf="parent"
108-
app:layout_constraintLeft_toLeftOf="@+id/etPasswordRepeat"
109-
app:layout_constraintRight_toRightOf="@+id/imgViewPassRpt"
11077
app:layout_constraintStart_toStartOf="parent"
111-
app:layout_constraintTop_toBottomOf="@+id/etPasswordRepeat"
78+
app:layout_constraintTop_toBottomOf="@+id/etPassword"
11279
tools:ignore="Autofill" />
11380

11481
<EditText
@@ -129,7 +96,7 @@
12996
app:layout_constraintTop_toBottomOf="@+id/etName"
13097
tools:ignore="Autofill" />
13198

132-
<MultiAutoCompleteTextView
99+
<EditText
133100
android:id="@+id/etDeliveryAddress"
134101
style="@style/DarkInputField"
135102
android:layout_width="0dp"
@@ -138,11 +105,13 @@
138105
android:layout_marginTop="8dp"
139106
android:layout_marginEnd="16dp"
140107
android:hint="@string/default_address"
108+
android:inputType="textCapWords|textAutoComplete|textMultiLine"
141109
app:layout_constraintEnd_toEndOf="parent"
142110
app:layout_constraintLeft_toLeftOf="@+id/etPhone"
143111
app:layout_constraintRight_toRightOf="@+id/etPhone"
144112
app:layout_constraintStart_toStartOf="parent"
145-
app:layout_constraintTop_toBottomOf="@+id/etPhone" />
113+
app:layout_constraintTop_toBottomOf="@+id/etPhone"
114+
tools:ignore="Autofill" />
146115

147116
<Button
148117
android:id="@+id/btnSignup"
@@ -207,5 +176,17 @@
207176
app:layout_constraintStart_toStartOf="parent"
208177
app:layout_constraintTop_toTopOf="parent" />
209178

179+
<TextView
180+
android:id="@+id/textView4"
181+
android:layout_width="wrap_content"
182+
android:layout_height="wrap_content"
183+
android:layout_marginStart="16dp"
184+
android:layout_marginTop="16dp"
185+
android:text="@string/create_an_account"
186+
android:textColor="@android:color/white"
187+
android:textSize="17sp"
188+
app:layout_constraintStart_toStartOf="parent"
189+
app:layout_constraintTop_toBottomOf="@+id/textView14" />
190+
210191
</android.support.constraint.ConstraintLayout>
211192
</ScrollView>

0 commit comments

Comments
 (0)