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

Commit 253af37

Browse files
committed
Fix incorrect presenter
1 parent 9a40bd6 commit 253af37

3 files changed

Lines changed: 18 additions & 17 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import com.marknkamau.justjava.data.local.PreferencesRepository
44
import com.marknjunge.core.model.UserDetails
55
import com.marknjunge.core.auth.AuthService
66
import com.marknjunge.core.data.firebase.ClientDatabaseService
7+
import com.marknjunge.core.data.firebase.WriteListener
8+
import timber.log.Timber
79

810
internal class LogInPresenter(private val activityView: LogInView,
911
private val preferences: PreferencesRepository,
@@ -21,6 +23,7 @@ internal class LogInPresenter(private val activityView: LogInView,
2123
auth.signIn(email, password, object : AuthService.AuthActionListener {
2224
override fun actionSuccessful(response: String) {
2325
getUserDefaults(response)
26+
setFcmToken()
2427
}
2528

2629
override fun actionFailed(response: String) {
@@ -44,6 +47,19 @@ internal class LogInPresenter(private val activityView: LogInView,
4447
})
4548
}
4649

50+
private fun setFcmToken() {
51+
database.updateUserFcmToken(auth.getCurrentUser().userId, object : WriteListener {
52+
override fun onError(reason: String) {
53+
Timber.e(reason)
54+
}
55+
56+
override fun onSuccess() {
57+
Timber.i("FCM token saved")
58+
}
59+
})
60+
}
61+
62+
4763
fun resetUserPassword(email: String) {
4864
auth.sendPasswordResetEmail(email, object : AuthService.AuthActionListener {
4965
override fun actionSuccessful(response: String) {

justjavastaff/src/main/java/com/marknkamau/justjavastaff/ui/login/LogInActivity.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class LogInActivity : AppCompatActivity(), LoginView, View.OnClickListener {
2424
setContentView(R.layout.activity_log_in)
2525

2626
val auth = (application as JustJavaStaffApp).auth
27+
val db = (application as JustJavaStaffApp).databaseService
2728

2829
if (auth.isSignedIn()) {
2930
startActivity(Intent(this@LogInActivity, MainActivity::class.java))
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.marknkamau.justjavastaff.ui.login
22

33
import com.marknjunge.core.auth.AuthService
4-
import com.marknjunge.core.data.firebase.ClientDatabaseService
5-
import com.marknjunge.core.data.firebase.WriteListener
6-
import timber.log.Timber
74
import java.util.regex.Pattern
85

96
/**
@@ -12,7 +9,7 @@ import java.util.regex.Pattern
129
* https://github.com/MarkNjunge
1310
*/
1411

15-
class LoginPresenter(private val auth: AuthService, private val databaseService: ClientDatabaseService,private val view: LoginView) {
12+
class LoginPresenter(private val auth: AuthService, private val view: LoginView) {
1613

1714
fun signIn(email: String, password: String) {
1815
val pattern = Pattern.compile("^([a-zA-Z0-9_.-])+@justjava.com+")
@@ -26,7 +23,6 @@ class LoginPresenter(private val auth: AuthService, private val databaseService:
2623
auth.signIn(email, password, object : AuthService.AuthActionListener {
2724
override fun actionSuccessful(response: String) {
2825
view.onSignedIn()
29-
setFcmToken()
3026
}
3127

3228
override fun actionFailed(response: String) {
@@ -35,16 +31,4 @@ class LoginPresenter(private val auth: AuthService, private val databaseService:
3531
})
3632
}
3733

38-
private fun setFcmToken(){
39-
databaseService.updateUserFcmToken(auth.getCurrentUser().userId, object : WriteListener {
40-
override fun onError(reason: String) {
41-
Timber.e(reason)
42-
}
43-
44-
override fun onSuccess() {
45-
Timber.i("FCM token saved")
46-
}
47-
})
48-
}
49-
5034
}

0 commit comments

Comments
 (0)