-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3259837
commit 71b9f20
Showing
10 changed files
with
173 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
data/src/main/java/com/yapp/android2/data/remote/request/LoginForAppReviewRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.yapp.android2.data.remote.request | ||
|
||
data class LoginForAppReviewRequest( | ||
val email: String, | ||
val password: String | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
presentation/login/src/main/java/com/best/friends/login/LoginForAppReviewActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,68 @@ | ||
package com.best.friends.login | ||
|
||
import android.os.Bundle | ||
import androidx.activity.viewModels | ||
import com.best.friends.core.BaseActivity | ||
import com.best.friends.login.databinding.ActivityLoginForAppReviewBinding | ||
import com.best.friends.navigator.HomeNavigator | ||
import com.google.android.gms.tasks.OnCompleteListener | ||
import com.google.firebase.messaging.FirebaseMessaging | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
@AndroidEntryPoint | ||
class LoginForAppReviewActivity : | ||
BaseActivity<ActivityLoginForAppReviewBinding>(R.layout.activity_login_for_app_review) { | ||
|
||
private val viewModel by viewModels<LoginForAppReviewViewModel>() | ||
|
||
@Inject | ||
lateinit var homeNavigator: HomeNavigator | ||
|
||
@Inject | ||
lateinit var firebaseMessaging: FirebaseMessaging | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
initView() | ||
observe() | ||
initFirebase() | ||
} | ||
|
||
private fun initView() { | ||
binding.viewModel = viewModel | ||
} | ||
|
||
private fun observe() { | ||
viewModel.isRegisterUser.observe(this) { | ||
if (it) { | ||
viewModel.addFCMToken() | ||
} | ||
} | ||
|
||
viewModel.isSuccess.observe(this) { | ||
if (it) { | ||
// 메인 화면으로 이동 | ||
val intent = homeNavigator.intent(this) | ||
startActivity(intent) | ||
finish() | ||
} | ||
} | ||
} | ||
|
||
private fun initFirebase() { | ||
firebaseMessaging.token.addOnCompleteListener(OnCompleteListener { task -> | ||
if (!task.isSuccessful) { | ||
Timber.e(task.exception) | ||
return@OnCompleteListener | ||
} | ||
|
||
// Get new FCM registration token | ||
val token = task.result | ||
viewModel.setFCMToken(token) | ||
Timber.i("FCM Token: $token") | ||
}) | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
presentation/login/src/main/java/com/best/friends/login/LoginForAppReviewViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.best.friends.login | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.distinctUntilChanged | ||
import androidx.lifecycle.viewModelScope | ||
import com.best.friends.core.BaseViewModel | ||
import com.best.friends.core.extensions.Empty | ||
import com.yapp.android2.domain.repository.login.LoginRepository | ||
import com.yapp.android2.domain.usecase.PostFCMTokenUseCase | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.launch | ||
import timber.log.Timber | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class LoginForAppReviewViewModel @Inject constructor( | ||
private val loginRepository: LoginRepository, | ||
private val postFCMTokenUseCase: PostFCMTokenUseCase | ||
) : BaseViewModel() { | ||
|
||
val email = MutableStateFlow(String.Empty) | ||
val password = MutableStateFlow(String.Empty) | ||
|
||
private val _fcmToken = MutableLiveData<String>() | ||
val fcmToken: LiveData<String> | ||
get() = _fcmToken | ||
|
||
private val _isSuccess = MutableLiveData(false) | ||
val isSuccess: LiveData<Boolean> | ||
get() = _isSuccess.distinctUntilChanged() | ||
|
||
private val _isRegisterUser = MutableLiveData(false) | ||
val isRegisterUser: LiveData<Boolean> | ||
get() = _isRegisterUser | ||
|
||
fun login() { | ||
viewModelScope.launch { | ||
startLoading() | ||
kotlin.runCatching { | ||
loginRepository.loginForAppReview(email.value, password.value) | ||
}.onSuccess { | ||
_isRegisterUser.postValue(true) | ||
}.onFailure { | ||
|
||
} | ||
|
||
stopLoading() | ||
} | ||
} | ||
|
||
fun setFCMToken(token: String) { | ||
_fcmToken.value = token | ||
} | ||
|
||
fun addFCMToken() { | ||
viewModelScope.launch { | ||
kotlin.runCatching { | ||
postFCMTokenUseCase(requireNotNull(fcmToken.value)) | ||
}.onSuccess { | ||
_isSuccess.postValue(true) | ||
}.onFailure { | ||
Timber.tag("--- LoginViewModel - FCM Token error").e("$it") | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters