diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/RegistrationContract.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/RegistrationContract.java deleted file mode 100644 index 144e5b7aa..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/RegistrationContract.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.mifos.mobilewallet.mifospay.registration; - -import org.mifos.mobilewallet.mifospay.base.BasePresenter; -import org.mifos.mobilewallet.mifospay.base.BaseView; - -/** - * Created by ankur on 21/June/2018 - */ - -public interface RegistrationContract { - - interface MobileVerificationView extends BaseView { - - void onRequestOtpSuccess(); - - void onOtpVerificationSuccess(); - - void showToast(String s); - - void hideProgressDialog(); - - void onRequestOtpFailed(String s); - - void onOtpVerificationFailed(String s); - } - - interface MobileVerificationPresenter extends BasePresenter { - - void requestOTPfromServer(String fullNumber, String s); - - void verifyOTP(String otp); - } - - - interface SignupView extends BaseView { - - void showToast(String s); - - void hideProgressDialog(); - - void loginSuccess(); - - void onRegisterFailed(String message); - - void onRegisterSuccess(String s); - - void updatePasswordStrength(int stringRes, int colorRes, int value); - } - - interface SignupPresenter extends BasePresenter { - - void checkPasswordStrength(String password); - - void registerUser(String firstName, String lastName, String mobileNumber, String email, - String businessName, String addressline1, String addressline2, String pincode, - String city, String countryName, String username, String password, - String stateId, String countryId, int mifosSavingProductId); - } -} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/RegistrationContract.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/RegistrationContract.kt new file mode 100644 index 000000000..8c2d73c26 --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/RegistrationContract.kt @@ -0,0 +1,42 @@ +package org.mifos.mobilewallet.mifospay.registration + +import org.mifos.mobilewallet.mifospay.base.BasePresenter +import org.mifos.mobilewallet.mifospay.base.BaseView + +/** + * Created by ankur on 21/June/2018 + */ +interface RegistrationContract { + interface MobileVerificationView : BaseView { + fun onRequestOtpSuccess() + fun onOtpVerificationSuccess() + fun showToast(s: String?) + fun hideProgressDialog() + fun onRequestOtpFailed(s: String?) + fun onOtpVerificationFailed(s: String?) + } + + interface MobileVerificationPresenter : BasePresenter { + fun requestOTPfromServer(fullNumber: String?, s: String?) + fun verifyOTP(otp: String?) + } + + interface SignupView : BaseView { + fun showToast(s: String?) + fun hideProgressDialog() + fun loginSuccess() + fun onRegisterFailed(message: String?) + fun onRegisterSuccess(s: String?) + fun updatePasswordStrength(stringRes: Int, colorRes: Int, value: Int) + } + + interface SignupPresenter : BasePresenter { + fun checkPasswordStrength(password: String?) + fun registerUser( + firstName: String?, lastName: String?, mobileNumber: String?, email: String?, + businessName: String?, addressline1: String?, addressline2: String?, pincode: String?, + city: String?, countryName: String?, username: String?, password: String?, + stateId: String?, countryId: String?, mifosSavingProductId: Int + ) + } +} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/presenter/MobileVerificationPresenter.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/presenter/MobileVerificationPresenter.java deleted file mode 100644 index 0102c98f1..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/presenter/MobileVerificationPresenter.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.mifos.mobilewallet.mifospay.registration.presenter; - -import org.mifos.mobilewallet.core.base.UseCase; -import org.mifos.mobilewallet.core.base.UseCaseHandler; -import org.mifos.mobilewallet.core.domain.usecase.client.SearchClient; -import org.mifos.mobilewallet.mifospay.base.BaseView; -import org.mifos.mobilewallet.mifospay.registration.RegistrationContract; - -import javax.inject.Inject; - -/** - * Created by ankur on 21/June/2018 - */ - -public class MobileVerificationPresenter implements - RegistrationContract.MobileVerificationPresenter { - - private final UseCaseHandler mUseCaseHandler; - RegistrationContract.MobileVerificationView mMobileVerificationView; - @Inject - SearchClient searchClientUseCase; - - @Inject - public MobileVerificationPresenter(UseCaseHandler useCaseHandler) { - mUseCaseHandler = useCaseHandler; - } - - @Override - public void attachView(BaseView baseView) { - mMobileVerificationView = (RegistrationContract.MobileVerificationView) baseView; - mMobileVerificationView.setPresenter(this); - } - - @Override - public void requestOTPfromServer(String fullNumber, String mobileNo) { - - mUseCaseHandler.execute(searchClientUseCase, new SearchClient.RequestValues(mobileNo), - new UseCase.UseCaseCallback() { - @Override - public void onSuccess(SearchClient.ResponseValue response) { - mMobileVerificationView.onRequestOtpFailed("Mobile number already exists."); - } - - @Override - public void onError(String message) { - // TODO:: request OTP - mMobileVerificationView.onRequestOtpSuccess(); - } - }); - } - - @Override - public void verifyOTP(String otp) { - // TODO:: verify OTP - mMobileVerificationView.onOtpVerificationSuccess(); - - // TODO:: - -// if (false) { // on error -// mMobileVerificationView.onOtpVerificationFailed("OTP Verification Failed."); -// } - } -} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/presenter/MobileVerificationPresenter.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/presenter/MobileVerificationPresenter.kt new file mode 100644 index 000000000..87b313b04 --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/presenter/MobileVerificationPresenter.kt @@ -0,0 +1,50 @@ +package org.mifos.mobilewallet.mifospay.registration.presenter + +import org.mifos.mobilewallet.core.base.UseCase.UseCaseCallback +import org.mifos.mobilewallet.core.base.UseCaseHandler +import org.mifos.mobilewallet.core.domain.usecase.client.SearchClient +import org.mifos.mobilewallet.mifospay.base.BaseView +import org.mifos.mobilewallet.mifospay.registration.RegistrationContract +import org.mifos.mobilewallet.mifospay.registration.RegistrationContract.MobileVerificationView +import javax.inject.Inject + +/** + * Created by ankur on 21/June/2018 + */ +class MobileVerificationPresenter @Inject constructor(private val mUseCaseHandler: UseCaseHandler) : + RegistrationContract.MobileVerificationPresenter { + var mMobileVerificationView: MobileVerificationView? = null + + @JvmField + @Inject + var searchClientUseCase: SearchClient? = null + override fun attachView(baseView: BaseView<*>?) { + mMobileVerificationView = baseView as MobileVerificationView? + mMobileVerificationView!!.setPresenter(this) + } + + override fun requestOTPfromServer(fullNumber: String?, mobileNo: String?) { + mUseCaseHandler.execute(searchClientUseCase, SearchClient.RequestValues(mobileNo), + object : UseCaseCallback { + override fun onSuccess(response: SearchClient.ResponseValue?) { + mMobileVerificationView!!.onRequestOtpFailed("Mobile number already exists.") + } + + override fun onError(message: String) { + // TODO:: request OTP + mMobileVerificationView!!.onRequestOtpSuccess() + } + }) + } + + override fun verifyOTP(otp: String?) { + // TODO:: verify OTP + mMobileVerificationView!!.onOtpVerificationSuccess() + + // TODO:: + +// if (false) { // on error +// mMobileVerificationView.onOtpVerificationFailed("OTP Verification Failed."); +// } + } +} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/presenter/SignupPresenter.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/presenter/SignupPresenter.java deleted file mode 100644 index 008b54711..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/presenter/SignupPresenter.java +++ /dev/null @@ -1,288 +0,0 @@ -package org.mifos.mobilewallet.mifospay.registration.presenter; - -import org.mifos.mobilewallet.core.base.UseCase; -import org.mifos.mobilewallet.core.base.UseCaseHandler; -import org.mifos.mobilewallet.core.data.fineract.api.FineractApiManager; -import org.mifos.mobilewallet.core.data.fineract.entity.UserWithRole; -import org.mifos.mobilewallet.core.domain.model.client.Client; -import org.mifos.mobilewallet.core.domain.model.client.NewClient; -import org.mifos.mobilewallet.core.domain.model.user.NewUser; -import org.mifos.mobilewallet.core.domain.model.user.UpdateUserEntityClients; -import org.mifos.mobilewallet.core.domain.model.user.User; -import org.mifos.mobilewallet.core.domain.usecase.client.CreateClient; -import org.mifos.mobilewallet.core.domain.usecase.client.FetchClientData; -import org.mifos.mobilewallet.core.domain.usecase.client.SearchClient; -import org.mifos.mobilewallet.core.domain.usecase.user.AuthenticateUser; -import org.mifos.mobilewallet.core.domain.usecase.user.CreateUser; -import org.mifos.mobilewallet.core.domain.usecase.user.DeleteUser; -import org.mifos.mobilewallet.core.domain.usecase.user.FetchUserDetails; -import org.mifos.mobilewallet.core.domain.usecase.user.UpdateUser; -import org.mifos.mobilewallet.mifospay.base.BaseView; -import org.mifos.mobilewallet.mifospay.data.local.PreferencesHelper; -import org.mifos.mobilewallet.mifospay.registration.RegistrationContract; -import org.mifos.mobilewallet.mifospay.utils.Constants; -import org.mifos.mobilewallet.mifospay.utils.DebugUtil; -import org.mifos.mobilewallet.mifospay.utils.PasswordStrength; - -import java.util.ArrayList; - -import javax.inject.Inject; - -/** - * Created by ankur on 21/June/2018 - */ - -public class SignupPresenter implements RegistrationContract.SignupPresenter { - - private final UseCaseHandler mUseCaseHandler; - private final PreferencesHelper mPreferencesHelper; - RegistrationContract.SignupView mSignupView; - @Inject - SearchClient searchClientUseCase; - @Inject - CreateClient createClientUseCase; - @Inject - CreateUser createUserUseCase; - @Inject - UpdateUser updateUserUseCase; - @Inject - AuthenticateUser authenticateUserUseCase; - @Inject - FetchClientData fetchClientDataUseCase; - @Inject - DeleteUser deleteUserUseCase; - @Inject - FetchUserDetails fetchUserDetailsUseCase; - - private String firstName, lastName, mobileNumber, email, businessName, addressLine1, - addressLine2, pincode, city, countryName, username, password, stateId, countryId; - - private int mifosSavingsProductId; - - @Inject - public SignupPresenter(UseCaseHandler useCaseHandler, PreferencesHelper preferencesHelper) { - mUseCaseHandler = useCaseHandler; - mPreferencesHelper = preferencesHelper; - } - - @Override - public void attachView(BaseView baseView) { - mSignupView = (RegistrationContract.SignupView) baseView; - mSignupView.setPresenter(this); - } - - @Override - public void checkPasswordStrength(String password) { - PasswordStrength p = new PasswordStrength(password); - mSignupView.updatePasswordStrength(p.getStrengthStringId(), - p.getColorResId(), p.getValue()); - } - - @Override - public void registerUser(final String firstName, final String lastName, - final String mobileNumber, final String email, final String businessName, - final String addressline1, final String addressline2, final String pincode, - final String city, String countryName, final String username, final String password, - final String stateId, final String countryId, int mifosSavingProductId) { - - // 0. Unique Mobile Number (checked in MOBILE VERIFICATION ACTIVITY) - // 1. Check for unique external id and username - // 2. Create user - // 3. Create Client - // 4. Update User and connect client with user - - this.firstName = firstName; - this.lastName = lastName; - this.email = email; - this.businessName = businessName; - this.addressLine1 = addressline1; - this.addressLine2 = addressline2; - this.pincode = pincode; - this.city = city; - this.countryName = countryName; - this.username = username; - this.password = password; - this.stateId = stateId; - this.countryId = countryId; - this.mobileNumber = mobileNumber; - this.mifosSavingsProductId = mifosSavingProductId; - - mUseCaseHandler.execute(searchClientUseCase, - new SearchClient.RequestValues(username + "@mifos"), - new UseCase.UseCaseCallback() { - @Override - public void onSuccess(SearchClient.ResponseValue response) { - mSignupView.onRegisterFailed("Username already exists."); - } - - @Override - public void onError(String message) { - createUser(); - } - }); - } - - private void createUser() { - - NewUser newUser = new NewUser(username, firstName, lastName, email, password); - - mUseCaseHandler.execute(createUserUseCase, new CreateUser.RequestValues(newUser), - new UseCase.UseCaseCallback() { - @Override - public void onSuccess(CreateUser.ResponseValue response) { - createClient(response.getUserId()); - } - - @Override - public void onError(String message) { - DebugUtil.log(message); - mSignupView.onRegisterFailed(message); - } - }); - } - - private void createClient(final int userId) { - - DebugUtil.log("mob::::: ", mobileNumber); - NewClient newClient = new NewClient(businessName, username, addressLine1, - addressLine2, city, pincode, stateId, countryId, mobileNumber, - mifosSavingsProductId); - - mUseCaseHandler.execute(createClientUseCase, - new CreateClient.RequestValues(newClient), - new UseCase.UseCaseCallback() { - @Override - public void onSuccess(CreateClient.ResponseValue response) { - DebugUtil.log(response.getClientId()); - ArrayList clients = new ArrayList<>(); - clients.add(response.getClientId()); - updateClient(clients, userId); - } - - @Override - public void onError(String message) { - // delete user - DebugUtil.log(message); - mSignupView.onRegisterFailed(message); - deleteUser(userId); - } - }); - } - - private void updateClient(ArrayList clients, int userId) { - mUseCaseHandler.execute(updateUserUseCase, - new UpdateUser.RequestValues(new UpdateUserEntityClients(clients), userId), - new UseCase.UseCaseCallback() { - @Override - public void onSuccess(UpdateUser.ResponseValue response) { - loginUser(username, password); - } - - @Override - public void onError(String message) { - // connect client later - DebugUtil.log(message); - mSignupView.onRegisterSuccess("update client error"); - } - }); - } - - private void loginUser(String username, String password) { - authenticateUserUseCase.setRequestValues(new - AuthenticateUser.RequestValues(username, password)); - final AuthenticateUser.RequestValues requestValue = - authenticateUserUseCase.getRequestValues(); - - mUseCaseHandler.execute(authenticateUserUseCase, requestValue, - new UseCase.UseCaseCallback() { - @Override - public void onSuccess(AuthenticateUser.ResponseValue response) { - createAuthenticatedService(response.getUser()); - fetchClientData(); - fetchUserDetails(response.getUser()); - } - - @Override - public void onError(String message) { - mSignupView.onRegisterSuccess("Login Failed"); - } - }); - - - } - - private void fetchUserDetails(final User user) { - mUseCaseHandler.execute(fetchUserDetailsUseCase, - new FetchUserDetails.RequestValues(user.getUserId()), - new UseCase.UseCaseCallback() { - @Override - public void onSuccess(FetchUserDetails.ResponseValue response) { - saveUserDetails(user, response.getUserWithRole()); - } - - @Override - public void onError(String message) { - DebugUtil.log(message); - } - }); - } - - private void fetchClientData() { - mUseCaseHandler.execute(fetchClientDataUseCase, null, - new UseCase.UseCaseCallback() { - @Override - public void onSuccess(FetchClientData.ResponseValue response) { - saveClientDetails(response.getUserDetails()); - - if (!response.getUserDetails().getName().equals("")) { - mSignupView.loginSuccess(); - } - } - - @Override - public void onError(String message) { - mSignupView.onRegisterSuccess("Fetch Client Error"); - } - }); - } - - private void createAuthenticatedService(User user) { - - final String authToken = Constants.BASIC + - user.getAuthenticationKey(); - - mPreferencesHelper.saveToken(authToken); - FineractApiManager.createSelfService(mPreferencesHelper.getToken()); - } - - private void saveUserDetails(User user, - UserWithRole userWithRole) { - final String userName = user.getUserName(); - final long userID = user.getUserId(); - - mPreferencesHelper.saveUsername(userName); - mPreferencesHelper.setUserId(userID); - mPreferencesHelper.saveEmail(userWithRole.getEmail()); - } - - private void saveClientDetails(Client client) { - mPreferencesHelper.saveFullName(client.getName()); - mPreferencesHelper.setClientId(client.getClientId()); - mPreferencesHelper.saveMobile(client.getMobileNo()); - } - - private void deleteUser(int userId) { - mUseCaseHandler.execute(deleteUserUseCase, new DeleteUser.RequestValues(userId), - new UseCase.UseCaseCallback() { - @Override - public void onSuccess(DeleteUser.ResponseValue response) { - - } - - @Override - public void onError(String message) { - - } - }); - } -} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/presenter/SignupPresenter.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/presenter/SignupPresenter.kt new file mode 100644 index 000000000..e984a156a --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/presenter/SignupPresenter.kt @@ -0,0 +1,273 @@ +package org.mifos.mobilewallet.mifospay.registration.presenter + +import org.mifos.mobilewallet.core.base.UseCase.UseCaseCallback +import org.mifos.mobilewallet.core.base.UseCaseHandler +import org.mifos.mobilewallet.core.data.fineract.api.FineractApiManager +import org.mifos.mobilewallet.core.data.fineract.entity.UserWithRole +import org.mifos.mobilewallet.core.domain.model.client.Client +import org.mifos.mobilewallet.core.domain.model.client.NewClient +import org.mifos.mobilewallet.core.domain.model.user.NewUser +import org.mifos.mobilewallet.core.domain.model.user.UpdateUserEntityClients +import org.mifos.mobilewallet.core.domain.model.user.User +import org.mifos.mobilewallet.core.domain.usecase.client.CreateClient +import org.mifos.mobilewallet.core.domain.usecase.client.FetchClientData +import org.mifos.mobilewallet.core.domain.usecase.client.SearchClient +import org.mifos.mobilewallet.core.domain.usecase.user.AuthenticateUser +import org.mifos.mobilewallet.core.domain.usecase.user.CreateUser +import org.mifos.mobilewallet.core.domain.usecase.user.DeleteUser +import org.mifos.mobilewallet.core.domain.usecase.user.FetchUserDetails +import org.mifos.mobilewallet.core.domain.usecase.user.UpdateUser +import org.mifos.mobilewallet.mifospay.base.BaseView +import org.mifos.mobilewallet.mifospay.data.local.PreferencesHelper +import org.mifos.mobilewallet.mifospay.registration.RegistrationContract +import org.mifos.mobilewallet.mifospay.registration.RegistrationContract.SignupView +import org.mifos.mobilewallet.mifospay.utils.Constants +import org.mifos.mobilewallet.mifospay.utils.DebugUtil +import org.mifos.mobilewallet.mifospay.utils.PasswordStrength +import javax.inject.Inject + +/** + * Created by ankur on 21/June/2018 + */ +class SignupPresenter @Inject constructor( + private val mUseCaseHandler: UseCaseHandler, + private val mPreferencesHelper: PreferencesHelper +) : RegistrationContract.SignupPresenter { + var mSignupView: SignupView? = null + + @JvmField + @Inject + var searchClientUseCase: SearchClient? = null + + @JvmField + @Inject + var createClientUseCase: CreateClient? = null + + @JvmField + @Inject + var createUserUseCase: CreateUser? = null + + @JvmField + @Inject + var updateUserUseCase: UpdateUser? = null + + @JvmField + @Inject + var authenticateUserUseCase: AuthenticateUser? = null + + @JvmField + @Inject + var fetchClientDataUseCase: FetchClientData? = null + + @JvmField + @Inject + var deleteUserUseCase: DeleteUser? = null + + @JvmField + @Inject + var fetchUserDetailsUseCase: FetchUserDetails? = null + private var firstName: String? = null + private var lastName: String? = null + private var mobileNumber: String? = null + private var email: String? = null + private var businessName: String? = null + private var addressLine1: String? = null + private var addressLine2: String? = null + private var pincode: String? = null + private var city: String? = null + private var countryName: String? = null + private var username: String? = null + private var password: String? = null + private var stateId: String? = null + private var countryId: String? = null + private var mifosSavingsProductId = 0 + override fun attachView(baseView: BaseView<*>?) { + mSignupView = baseView as SignupView? + mSignupView!!.setPresenter(this) + } + + override fun checkPasswordStrength(password: String?) { + val p = PasswordStrength(password) + mSignupView!!.updatePasswordStrength( + p.strengthStringId, + p.colorResId, p.value + ) + } + + override fun registerUser( + firstName: String?, lastName: String?, + mobileNumber: String?, email: String?, businessName: String?, + addressline1: String?, addressline2: String?, pincode: String?, + city: String?, countryName: String?, username: String?, password: String?, + stateId: String?, countryId: String?, mifosSavingProductId: Int + ) { + + // 0. Unique Mobile Number (checked in MOBILE VERIFICATION ACTIVITY) + // 1. Check for unique external id and username + // 2. Create user + // 3. Create Client + // 4. Update User and connect client with user + this.firstName = firstName + this.lastName = lastName + this.email = email + this.businessName = businessName + addressLine1 = addressline1 + addressLine2 = addressline2 + this.pincode = pincode + this.city = city + this.countryName = countryName + this.username = username + this.password = password + this.stateId = stateId + this.countryId = countryId + this.mobileNumber = mobileNumber + mifosSavingsProductId = mifosSavingProductId + mUseCaseHandler.execute(searchClientUseCase, + SearchClient.RequestValues("$username@mifos"), + object : UseCaseCallback { + override fun onSuccess(response: SearchClient.ResponseValue?) { + mSignupView!!.onRegisterFailed("Username already exists.") + } + + override fun onError(message: String) { + createUser() + } + }) + } + + private fun createUser() { + val newUser = NewUser(username, firstName, lastName, email, password) + mUseCaseHandler.execute(createUserUseCase, CreateUser.RequestValues(newUser), + object : UseCaseCallback { + override fun onSuccess(response: CreateUser.ResponseValue?) { + response?.userId?.let { createClient(it) } + } + + override fun onError(message: String) { + DebugUtil.log(message) + mSignupView!!.onRegisterFailed(message) + } + }) + } + + private fun createClient(userId: Int) { + DebugUtil.log("mob::::: ", mobileNumber) + val newClient = NewClient( + businessName, username, addressLine1, + addressLine2, city, pincode, stateId, countryId, mobileNumber, + mifosSavingsProductId + ) + mUseCaseHandler.execute(createClientUseCase, + CreateClient.RequestValues(newClient), + object : UseCaseCallback { + override fun onSuccess(response: CreateClient.ResponseValue?) { + DebugUtil.log(response?.clientId) + val clients = ArrayList() + response?.clientId?.let { clients.add(it) } + updateClient(clients, userId) + } + + override fun onError(message: String) { + // delete user + DebugUtil.log(message) + mSignupView!!.onRegisterFailed(message) + deleteUser(userId) + } + }) + } + + private fun updateClient(clients: ArrayList, userId: Int) { + mUseCaseHandler.execute(updateUserUseCase, + UpdateUser.RequestValues(UpdateUserEntityClients(clients), userId), + object : UseCaseCallback { + override fun onSuccess(response: UpdateUser.ResponseValue?) { + loginUser(username, password) + } + + override fun onError(message: String) { + // connect client later + DebugUtil.log(message) + mSignupView!!.onRegisterSuccess("update client error") + } + }) + } + + private fun loginUser(username: String?, password: String?) { + authenticateUserUseCase!!.requestValues = AuthenticateUser.RequestValues(username, password) + val requestValue = authenticateUserUseCase!!.requestValues + mUseCaseHandler.execute(authenticateUserUseCase, requestValue, + object : UseCaseCallback { + override fun onSuccess(response: AuthenticateUser.ResponseValue?) { + response?.user?.let { createAuthenticatedService(it) } + fetchClientData() + response?.user?.let { fetchUserDetails(it) } + } + + override fun onError(message: String) { + mSignupView!!.onRegisterSuccess("Login Failed") + } + }) + } + + private fun fetchUserDetails(user: User) { + mUseCaseHandler.execute(fetchUserDetailsUseCase, + FetchUserDetails.RequestValues(user.userId), + object : UseCaseCallback { + override fun onSuccess(response: FetchUserDetails.ResponseValue?) { + response?.userWithRole?.let { saveUserDetails(user, it) } + } + + override fun onError(message: String) { + DebugUtil.log(message) + } + }) + } + + private fun fetchClientData() { + mUseCaseHandler.execute(fetchClientDataUseCase, null, + object : UseCaseCallback { + override fun onSuccess(response: FetchClientData.ResponseValue?) { + response?.userDetails?.let { saveClientDetails(it) } + if (response?.userDetails?.name != "") { + mSignupView!!.loginSuccess() + } + } + + override fun onError(message: String) { + mSignupView!!.onRegisterSuccess("Fetch Client Error") + } + }) + } + + private fun createAuthenticatedService(user: User) { + val authToken = Constants.BASIC + + user.authenticationKey + mPreferencesHelper.saveToken(authToken) + FineractApiManager.createSelfService(mPreferencesHelper.token) + } + + private fun saveUserDetails( + user: User, + userWithRole: UserWithRole + ) { + val userName = user.userName + val userID = user.userId + mPreferencesHelper.saveUsername(userName) + mPreferencesHelper.userId = userID + mPreferencesHelper.saveEmail(userWithRole.email) + } + + private fun saveClientDetails(client: Client) { + mPreferencesHelper.saveFullName(client.name) + mPreferencesHelper.clientId = client.clientId + mPreferencesHelper.saveMobile(client.mobileNo) + } + + private fun deleteUser(userId: Int) { + mUseCaseHandler.execute(deleteUserUseCase, DeleteUser.RequestValues(userId), + object : UseCaseCallback { + override fun onSuccess(response: DeleteUser.ResponseValue?) {} + override fun onError(message: String) {} + }) + } +} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/MobileVerificationActivity.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/MobileVerificationActivity.java deleted file mode 100644 index 814cf5fcb..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/MobileVerificationActivity.java +++ /dev/null @@ -1,178 +0,0 @@ -package org.mifos.mobilewallet.mifospay.registration.ui; - -import android.content.Intent; -import android.os.Bundle; -import android.os.Handler; -import com.google.android.material.floatingactionbutton.FloatingActionButton; -import android.view.View; -import android.widget.EditText; -import android.widget.ProgressBar; -import android.widget.TextView; - -import com.hbb20.CountryCodePicker; - -import org.mifos.mobilewallet.mifospay.R; -import org.mifos.mobilewallet.mifospay.base.BaseActivity; -import org.mifos.mobilewallet.mifospay.registration.RegistrationContract; -import org.mifos.mobilewallet.mifospay.registration.presenter.MobileVerificationPresenter; -import org.mifos.mobilewallet.mifospay.utils.Constants; -import org.mifos.mobilewallet.mifospay.utils.Toaster; -import org.mifos.mobilewallet.mifospay.utils.Utils; - -import javax.inject.Inject; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import dagger.hilt.android.AndroidEntryPoint; - -@AndroidEntryPoint -public class MobileVerificationActivity extends BaseActivity implements - RegistrationContract.MobileVerificationView { - - @Inject - MobileVerificationPresenter mPresenter; - - RegistrationContract.MobileVerificationPresenter mMobileVerificationPresenter; - - @BindView(R.id.ccp_code) - CountryCodePicker mCcpCode; - @BindView(R.id.et_mobile_number) - EditText mEtMobileNumber; - @BindView(R.id.btn_get_otp) - TextView mBtnGetOtp; - @BindView(R.id.et_otp) - EditText mEtOtp; - @BindView(R.id.fab_next) - FloatingActionButton mFabNext; - @BindView(R.id.progressBar) - ProgressBar mProgressBar; - @BindView(R.id.tv_verifying_otp) - TextView mTvVerifyingOtp; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_mobile_verification); - - ButterKnife.bind(this); - mPresenter.attachView(this); - - setToolbarTitle(""); - showColoredBackButton(Constants.WHITE_BACK_BUTTON); - - mCcpCode.registerCarrierNumberEditText(mEtMobileNumber); - } - - @Override - public void setPresenter(RegistrationContract.MobileVerificationPresenter presenter) { - mMobileVerificationPresenter = presenter; - } - - @OnClick(R.id.btn_get_otp) - public void onGetOTp() { - Utils.hideSoftKeyboard(this); - if (mCcpCode.isValidFullNumber()) { - showProgressDialog(Constants.SENDING_OTP_TO_YOUR_MOBILE_NUMBER); - - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - @Override - public void run() { - mMobileVerificationPresenter.requestOTPfromServer(mCcpCode.getFullNumber(), - mEtMobileNumber.getText().toString().trim()); - } - }, 1500); - - } else { - showToast(getString(R.string.enter_valid_mob_num)); - } - } - - @Override - public void onRequestOtpSuccess() { - hideProgressDialog(); - mEtMobileNumber.setClickable(false); - mEtMobileNumber.setFocusableInTouchMode(false); - mEtMobileNumber.setFocusable(false); - mCcpCode.setCcpClickable(false); - - mEtOtp.setVisibility(View.VISIBLE); - mBtnGetOtp.setClickable(false); - mBtnGetOtp.setBackgroundResource(R.drawable.ic_done); - mFabNext.setVisibility(View.VISIBLE); - } - - @Override - public void onRequestOtpFailed(String s) { - hideProgressDialog(); - showToast(s); - } - - @OnClick(R.id.fab_next) - public void onNextClicked() { - Utils.hideSoftKeyboard(this); - - if (mEtOtp.getText().toString().trim().isEmpty()) { - showToast("OTP not Entered"); - mEtOtp.requestFocus(); - } else { - mFabNext.setClickable(false); - mProgressBar.setVisibility(View.VISIBLE); - mTvVerifyingOtp.setVisibility(View.VISIBLE); - mEtOtp.setClickable(false); - mEtOtp.setFocusableInTouchMode(false); - mEtOtp.setFocusable(false); - - Handler handler = new Handler(); - handler.postDelayed(new Runnable() { - @Override - public void run() { - mMobileVerificationPresenter.verifyOTP(mEtOtp.getText().toString().trim()); - } - }, 1500); - } - } - - @Override - public void onOtpVerificationSuccess() { - Intent intent = new Intent(MobileVerificationActivity.this, SignupActivity.class); - - intent.putExtra(Constants.MIFOS_SAVINGS_PRODUCT_ID, - getIntent().getIntExtra(Constants.MIFOS_SAVINGS_PRODUCT_ID, 0)); - intent.putExtra(Constants.GOOGLE_PHOTO_URI, - String.valueOf(getIntent().getParcelableExtra(Constants.GOOGLE_PHOTO_URI))); - intent.putExtra(Constants.GOOGLE_DISPLAY_NAME, - getIntent().getStringExtra(Constants.GOOGLE_DISPLAY_NAME)); - intent.putExtra(Constants.GOOGLE_EMAIL, - getIntent().getStringExtra(Constants.GOOGLE_EMAIL)); - intent.putExtra(Constants.GOOGLE_FAMILY_NAME, - getIntent().getStringExtra(Constants.GOOGLE_FAMILY_NAME)); - intent.putExtra(Constants.GOOGLE_GIVEN_NAME, - getIntent().getStringExtra(Constants.GOOGLE_GIVEN_NAME)); - - intent.putExtra(Constants.COUNTRY, mCcpCode.getSelectedCountryName()); - intent.putExtra(Constants.MOBILE_NUMBER, mCcpCode.getFullNumber()); - - startActivity(intent); - finish(); - } - - @Override - public void onOtpVerificationFailed(String s) { - mFabNext.setClickable(true); - mProgressBar.setVisibility(View.GONE); - mTvVerifyingOtp.setVisibility(View.GONE); - mEtOtp.setClickable(true); - mEtOtp.setFocusableInTouchMode(true); - mEtOtp.setFocusable(true); - - showToast(s); - } - - - @Override - public void showToast(String message) { - Toaster.showToast(this, message); - } -} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/MobileVerificationActivity.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/MobileVerificationActivity.kt new file mode 100644 index 000000000..ef7b9cddf --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/MobileVerificationActivity.kt @@ -0,0 +1,177 @@ +package org.mifos.mobilewallet.mifospay.registration.ui + +import android.content.Intent +import android.os.Bundle +import android.os.Handler +import android.os.Parcelable +import android.view.View +import android.widget.EditText +import android.widget.ProgressBar +import android.widget.TextView +import butterknife.BindView +import butterknife.ButterKnife +import butterknife.OnClick +import com.google.android.material.floatingactionbutton.FloatingActionButton +import com.hbb20.CountryCodePicker +import dagger.hilt.android.AndroidEntryPoint +import org.mifos.mobilewallet.mifospay.R +import org.mifos.mobilewallet.mifospay.base.BaseActivity +import org.mifos.mobilewallet.mifospay.registration.RegistrationContract +import org.mifos.mobilewallet.mifospay.registration.RegistrationContract.MobileVerificationView +import org.mifos.mobilewallet.mifospay.registration.presenter.MobileVerificationPresenter +import org.mifos.mobilewallet.mifospay.utils.Constants +import org.mifos.mobilewallet.mifospay.utils.Toaster +import org.mifos.mobilewallet.mifospay.utils.Utils.hideSoftKeyboard +import javax.inject.Inject + +@AndroidEntryPoint +class MobileVerificationActivity : BaseActivity(), MobileVerificationView { + @JvmField + @Inject + var mPresenter: MobileVerificationPresenter? = null + var mMobileVerificationPresenter: RegistrationContract.MobileVerificationPresenter? = null + + @JvmField + @BindView(R.id.ccp_code) + var mCcpCode: CountryCodePicker? = null + + @JvmField + @BindView(R.id.et_mobile_number) + var mEtMobileNumber: EditText? = null + + @JvmField + @BindView(R.id.btn_get_otp) + var mBtnGetOtp: TextView? = null + + @JvmField + @BindView(R.id.et_otp) + var mEtOtp: EditText? = null + + @JvmField + @BindView(R.id.fab_next) + var mFabNext: FloatingActionButton? = null + + @JvmField + @BindView(R.id.progressBar) + var mProgressBar: ProgressBar? = null + + @JvmField + @BindView(R.id.tv_verifying_otp) + var mTvVerifyingOtp: TextView? = null + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_mobile_verification) + ButterKnife.bind(this) + mPresenter!!.attachView(this) + setToolbarTitle("") + showColoredBackButton(Constants.WHITE_BACK_BUTTON) + mCcpCode!!.registerCarrierNumberEditText(mEtMobileNumber) + } + + @OnClick(R.id.btn_get_otp) + fun onGetOTp() { + hideSoftKeyboard(this) + if (mCcpCode!!.isValidFullNumber) { + showProgressDialog(Constants.SENDING_OTP_TO_YOUR_MOBILE_NUMBER) + val handler = Handler() + handler.postDelayed(Runnable { + mMobileVerificationPresenter!!.requestOTPfromServer( + mCcpCode!!.fullNumber, + mEtMobileNumber!!.text.toString().trim { it <= ' ' }) + }, 1500) + } else { + showToast(getString(R.string.enter_valid_mob_num)) + } + } + + override fun onRequestOtpSuccess() { + hideProgressDialog() + mEtMobileNumber!!.isClickable = false + mEtMobileNumber!!.isFocusableInTouchMode = false + mEtMobileNumber!!.isFocusable = false + mCcpCode!!.setCcpClickable(false) + mEtOtp!!.visibility = View.VISIBLE + mBtnGetOtp!!.isClickable = false + mBtnGetOtp!!.setBackgroundResource(R.drawable.ic_done) + mFabNext!!.visibility = View.VISIBLE + } + + override fun onRequestOtpFailed(s: String?) { + hideProgressDialog() + showToast(s) + } + + @OnClick(R.id.fab_next) + fun onNextClicked() { + hideSoftKeyboard(this) + if (mEtOtp!!.text.toString().trim { it <= ' ' }.isEmpty()) { + showToast("OTP not Entered") + mEtOtp!!.requestFocus() + } else { + mFabNext!!.isClickable = false + mProgressBar!!.visibility = View.VISIBLE + mTvVerifyingOtp!!.visibility = View.VISIBLE + mEtOtp!!.isClickable = false + mEtOtp!!.isFocusableInTouchMode = false + mEtOtp!!.isFocusable = false + val handler = Handler() + handler.postDelayed(object : Runnable { + override fun run() { + mMobileVerificationPresenter!!.verifyOTP( + mEtOtp!!.text.toString().trim { it <= ' ' }) + } + }, 1500) + } + } + + override fun onOtpVerificationSuccess() { + val intent = Intent(this@MobileVerificationActivity, SignupActivity::class.java) + intent.putExtra( + Constants.MIFOS_SAVINGS_PRODUCT_ID, + getIntent().getIntExtra(Constants.MIFOS_SAVINGS_PRODUCT_ID, 0) + ) + intent.putExtra( + Constants.GOOGLE_PHOTO_URI, getIntent().getParcelableExtra( + Constants.GOOGLE_PHOTO_URI + ).toString() + ) + intent.putExtra( + Constants.GOOGLE_DISPLAY_NAME, + getIntent().getStringExtra(Constants.GOOGLE_DISPLAY_NAME) + ) + intent.putExtra( + Constants.GOOGLE_EMAIL, + getIntent().getStringExtra(Constants.GOOGLE_EMAIL) + ) + intent.putExtra( + Constants.GOOGLE_FAMILY_NAME, + getIntent().getStringExtra(Constants.GOOGLE_FAMILY_NAME) + ) + intent.putExtra( + Constants.GOOGLE_GIVEN_NAME, + getIntent().getStringExtra(Constants.GOOGLE_GIVEN_NAME) + ) + intent.putExtra(Constants.COUNTRY, mCcpCode!!.selectedCountryName) + intent.putExtra(Constants.MOBILE_NUMBER, mCcpCode!!.fullNumber) + startActivity(intent) + finish() + } + + override fun onOtpVerificationFailed(s: String?) { + mFabNext!!.isClickable = true + mProgressBar!!.visibility = View.GONE + mTvVerifyingOtp!!.visibility = View.GONE + mEtOtp!!.isClickable = true + mEtOtp!!.isFocusableInTouchMode = true + mEtOtp!!.isFocusable = true + showToast(s) + } + + override fun setPresenter(presenter: RegistrationContract.MobileVerificationPresenter?) { + mMobileVerificationPresenter = presenter + } + + override fun showToast(message: String?) { + Toaster.showToast(this, message) + } +} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/SignupActivity.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/SignupActivity.java deleted file mode 100644 index a2ae6287d..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/SignupActivity.java +++ /dev/null @@ -1,315 +0,0 @@ -package org.mifos.mobilewallet.mifospay.registration.ui; - -import android.content.Intent; -import android.net.Uri; -import android.os.Bundle; -import com.google.android.material.floatingactionbutton.FloatingActionButton; -import com.google.android.material.snackbar.Snackbar; -import com.google.android.material.textfield.TextInputEditText; -import com.google.android.material.textfield.TextInputLayout; -import androidx.transition.TransitionManager; -import android.text.Editable; -import android.text.TextWatcher; -import android.util.Log; -import android.view.View; -import android.view.ViewGroup; -import android.widget.EditText; -import android.widget.ProgressBar; -import android.widget.TextView; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; -import com.mifos.mobile.passcode.utils.PassCodeConstants; - -import dagger.hilt.android.AndroidEntryPoint; -import in.galaxyofandroid.spinerdialog.OnSpinerItemClick; -import in.galaxyofandroid.spinerdialog.SpinnerDialog; -import java.util.ArrayList; -import javax.inject.Inject; -import org.json.JSONArray; -import org.json.JSONObject; -import org.mifos.mobilewallet.mifospay.R; -import org.mifos.mobilewallet.mifospay.auth.ui.LoginActivity; -import org.mifos.mobilewallet.mifospay.base.BaseActivity; -import org.mifos.mobilewallet.mifospay.passcode.ui.PassCodeActivity; -import org.mifos.mobilewallet.mifospay.registration.RegistrationContract; -import org.mifos.mobilewallet.mifospay.registration.presenter.SignupPresenter; -import org.mifos.mobilewallet.mifospay.utils.Constants; -import org.mifos.mobilewallet.mifospay.utils.DebugUtil; -import org.mifos.mobilewallet.mifospay.utils.Toaster; -import org.mifos.mobilewallet.mifospay.utils.ValidateUtil; - -import static org.mifos.mobilewallet.mifospay.utils.FileUtils.readJson; - -@AndroidEntryPoint -public class SignupActivity extends BaseActivity implements RegistrationContract.SignupView { - - @Inject - SignupPresenter mPresenter; - - RegistrationContract.SignupPresenter mSignupPresenter; - @BindView(R.id.et_first_name) - TextInputEditText mEtFirstName; - @BindView(R.id.et_last_name) - TextInputEditText mEtLastName; - @BindView(R.id.et_email) - TextInputEditText mEtEmail; - @BindView(R.id.et_business_shop_name) - TextInputEditText mEtBusinessShopName; - @BindView(R.id.et_business_shop_layout) - TextInputLayout mEtBusinessShopLayout; - @BindView(R.id.et_address_line_1) - TextInputEditText mEtAddressLine1; - @BindView(R.id.et_address_line_2) - TextInputEditText mEtAddressLine2; - @BindView(R.id.et_pin_code) - TextInputEditText mEtPinCode; - @BindView(R.id.et_state) - TextInputEditText mEtCity; - @BindView(R.id.fab_next) - FloatingActionButton mFabNext; - - - SpinnerDialog spinnerDialog; - @BindView(R.id.et_user_name) - TextInputEditText mEtUserName; - @BindView(R.id.et_password) - TextInputEditText mEtPassword; - @BindView(R.id.et_confirm_password) - TextInputEditText mEtConfirmPassword; - @BindView(R.id.rr_container) - ViewGroup container; - @BindView(R.id.pb_password_strength) - ProgressBar passwordStrengthProgress; - @BindView(R.id.tv_password_strength) - TextView passwordStrengthText; - - private String countryName; - private String mobileNumber; - private String countryId; - private String stateId; - private int mifosSavingProductId; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_signup); - - ButterKnife.bind(this); - - mPresenter.attachView(this); - - showColoredBackButton(Constants.BLACK_BACK_BUTTON); - setToolbarTitle("Registration"); - - mifosSavingProductId = getIntent().getIntExtra(Constants.MIFOS_SAVINGS_PRODUCT_ID, 0); - if (mifosSavingProductId - == org.mifos.mobilewallet.core.utils.Constants.MIFOS_MERCHANT_SAVINGS_PRODUCT_ID) { - mEtBusinessShopLayout.setVisibility(View.VISIBLE); - } else { - mEtBusinessShopLayout.setVisibility(View.GONE); - } - mobileNumber = getIntent().getStringExtra(Constants.MOBILE_NUMBER); - countryName = getIntent().getStringExtra(Constants.COUNTRY); - - String email = getIntent().getStringExtra(Constants.GOOGLE_EMAIL); - String displayName = getIntent().getStringExtra(Constants.GOOGLE_DISPLAY_NAME); - String firstName = getIntent().getStringExtra(Constants.GOOGLE_GIVEN_NAME); - String lastName = getIntent().getStringExtra(Constants.GOOGLE_FAMILY_NAME); - Uri photoUri = getIntent().getParcelableExtra(Constants.GOOGLE_PHOTO_URI); - - if (displayName != null) { - mEtBusinessShopName.setText(displayName); - } - if (email != null) { - mEtEmail.setText(email); - mEtUserName.setText(email.substring(0, email.indexOf('@'))); - } - if (firstName != null) { - mEtFirstName.setText(firstName); - } - if (lastName != null) { - mEtLastName.setText(lastName); - } - - mEtPassword.addTextChangedListener(new TextWatcher() { - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - mPresenter.checkPasswordStrength(s.toString()); - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - } - - @Override - public void afterTextChanged(Editable s) { - } - }); - - DebugUtil.log(mobileNumber, countryName, email, displayName, firstName, lastName, photoUri); - - showProgressDialog(Constants.PLEASE_WAIT); - - initSearchableStateSpinner(); - } - - private void initSearchableStateSpinner() { - JSONObject jsonObject = null; - try { - countryId = ""; - jsonObject = readJson(this, "countries.json"); - JSONArray countriesArray = jsonObject.getJSONArray("countries"); - for (int i = 0; i < countriesArray.length(); i++) { - if (countriesArray.getJSONObject(i).getString("name").equals(countryName)) { - countryId = countriesArray.getJSONObject(i).getString("id"); - break; - } - } - - jsonObject = readJson(this, "states.json"); - JSONArray statesJson = jsonObject.getJSONArray("states"); - ArrayList statesList = new ArrayList<>(); - for (int i = 0; i < statesJson.length(); i++) { - JSONObject statesJsonObject = statesJson.getJSONObject(i); - if (statesJsonObject.getString("country_id").equals(countryId)) { - statesList.add(statesJsonObject.getString("name")); - stateId = statesJsonObject.getString("id"); - } - } - - spinnerDialog = new SpinnerDialog(SignupActivity.this, statesList, - "Select or Search State", R.style.DialogAnimations_SmileWindow, "Close"); - - spinnerDialog.bindOnSpinerListener(new OnSpinerItemClick() { - @Override - public void onClick(String item, int position) { - mEtCity.setText(item); - } - }); - - mEtCity.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - spinnerDialog.showSpinerDialog(); - } - }); - - hideProgressDialog(); - - } catch (Exception e) { - Log.d("qxz", e.toString() + " " + e.getMessage()); - } - } - - @Override - public void setPresenter(RegistrationContract.SignupPresenter presenter) { - mSignupPresenter = presenter; - } - - @OnClick(R.id.fab_next) - public void onNextClicked() { - showProgressDialog(Constants.PLEASE_WAIT); - - if (mifosSavingProductId - == org.mifos.mobilewallet.core.utils.Constants.MIFOS_MERCHANT_SAVINGS_PRODUCT_ID - && isEmpty(mEtBusinessShopName)) { - Toaster.showToast(this, "All fields are mandatory"); - hideProgressDialog(); - return; - } - if (isEmpty(mEtFirstName) || isEmpty(mEtLastName) || isEmpty(mEtEmail) - || isEmpty(mEtAddressLine1) || isEmpty(mEtAddressLine2) - || isEmpty(mEtPinCode) || isEmpty(mEtCity) || isEmpty(mEtUserName) || isEmpty( - mEtPassword) || isEmpty(mEtConfirmPassword)) { - Toaster.showToast(this, "All fields are mandatory"); - hideProgressDialog(); - return; - } - if (mEtPassword.getText().toString().length() < 6) { - showToast("Password should contain more than 6 characters"); - return; - } - - String firstName = mEtFirstName.getText().toString().trim(); - String lastName = mEtLastName.getText().toString().trim(); - String email = mEtEmail.getText().toString().trim(); - String businessName = mEtBusinessShopName.getText().toString().trim(); - String addressline1 = mEtAddressLine1.getText().toString().trim(); - String addressline2 = mEtAddressLine2.getText().toString().trim(); - String pincode = mEtPinCode.getText().toString().trim(); - String city = mEtCity.getText().toString().trim(); - String username = mEtUserName.getText().toString().trim(); - String password = mEtPassword.getText().toString(); - String confirmPassword = mEtConfirmPassword.getText().toString(); - - if (!ValidateUtil.INSTANCE.isValidEmail(email)) { - Snackbar.make(container, R.string.validate_email, Snackbar.LENGTH_SHORT).show(); - hideProgressDialog(); - return; - } - - if (!password.equals(confirmPassword)) { - Toaster.showToast(this, "Password is not same as Confirm Password"); - hideProgressDialog(); - return; - } - - mSignupPresenter.registerUser(firstName, lastName, mobileNumber, email, businessName, - addressline1, addressline2, pincode, city, countryName, username, password, stateId, - countryId, mifosSavingProductId); - } - - @Override - public void onRegisterSuccess(String s) { - // registered but unable to login or user not updated with client - // TODO :: Consider this case - // 1. User not updated: when logging in update user - // 2. User unable to login (must be caused due to server) - hideProgressDialog(); - showToast("Registered successfully."); - startActivity(new Intent(SignupActivity.this, LoginActivity.class)); - finish(); - } - - @Override - public void updatePasswordStrength(int stringRes, int colorRes, int value) { - TransitionManager.beginDelayedTransition(container); - passwordStrengthText.setVisibility(View.VISIBLE); - if (value == 0) { - passwordStrengthText.setText("Password should contain more than 6 characters"); - return; - } - passwordStrengthProgress.setVisibility(View.VISIBLE); - passwordStrengthProgress.getProgressDrawable().setColorFilter( - colorRes, android.graphics.PorterDuff.Mode.SRC_IN); - passwordStrengthProgress.setProgress(value); - passwordStrengthText.setText(stringRes); - } - - @Override - public void loginSuccess() { - hideProgressDialog(); - showToast("Registered successfully"); - - Intent intent = new Intent(SignupActivity.this, PassCodeActivity.class); - intent.putExtra(PassCodeConstants.PASSCODE_INITIAL_LOGIN, true); - startActivity(intent); - finish(); - } - - @Override - public void onRegisterFailed(String message) { - hideProgressDialog(); - showToast(message); - } - - private boolean isEmpty(EditText etText) { - return etText.getText().toString().trim().length() == 0; - } - - @Override - public void showToast(String s) { - Toaster.showToast(this, s); - } -} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/SignupActivity.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/SignupActivity.kt new file mode 100644 index 000000000..530118fc8 --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/SignupActivity.kt @@ -0,0 +1,304 @@ +package org.mifos.mobilewallet.mifospay.registration.ui + +import android.content.Intent +import android.graphics.PorterDuff +import android.net.Uri +import android.os.Bundle +import android.text.Editable +import android.text.TextWatcher +import android.util.Log +import android.view.View +import android.view.ViewGroup +import android.widget.EditText +import android.widget.ProgressBar +import android.widget.TextView +import androidx.transition.TransitionManager +import butterknife.BindView +import butterknife.ButterKnife +import butterknife.OnClick +import com.google.android.material.floatingactionbutton.FloatingActionButton +import com.google.android.material.snackbar.Snackbar +import com.google.android.material.textfield.TextInputEditText +import com.google.android.material.textfield.TextInputLayout +import com.mifos.mobile.passcode.utils.PassCodeConstants +import dagger.hilt.android.AndroidEntryPoint +import `in`.galaxyofandroid.spinerdialog.OnSpinerItemClick +import `in`.galaxyofandroid.spinerdialog.SpinnerDialog +import org.json.JSONObject +import org.mifos.mobilewallet.mifospay.R +import org.mifos.mobilewallet.mifospay.auth.ui.LoginActivity +import org.mifos.mobilewallet.mifospay.base.BaseActivity +import org.mifos.mobilewallet.mifospay.passcode.ui.PassCodeActivity +import org.mifos.mobilewallet.mifospay.registration.RegistrationContract +import org.mifos.mobilewallet.mifospay.registration.RegistrationContract.SignupView +import org.mifos.mobilewallet.mifospay.registration.presenter.SignupPresenter +import org.mifos.mobilewallet.mifospay.utils.Constants +import org.mifos.mobilewallet.mifospay.utils.DebugUtil +import org.mifos.mobilewallet.mifospay.utils.FileUtils +import org.mifos.mobilewallet.mifospay.utils.Toaster +import org.mifos.mobilewallet.mifospay.utils.ValidateUtil.isValidEmail +import javax.inject.Inject + +@AndroidEntryPoint +class SignupActivity : BaseActivity(), SignupView { + @JvmField + @Inject + var mPresenter: SignupPresenter? = null + var mSignupPresenter: RegistrationContract.SignupPresenter? = null + + @JvmField + @BindView(R.id.et_first_name) + var mEtFirstName: TextInputEditText? = null + + @JvmField + @BindView(R.id.et_last_name) + var mEtLastName: TextInputEditText? = null + + @JvmField + @BindView(R.id.et_email) + var mEtEmail: TextInputEditText? = null + + @JvmField + @BindView(R.id.et_business_shop_name) + var mEtBusinessShopName: TextInputEditText? = null + + @JvmField + @BindView(R.id.et_business_shop_layout) + var mEtBusinessShopLayout: TextInputLayout? = null + + @JvmField + @BindView(R.id.et_address_line_1) + var mEtAddressLine1: TextInputEditText? = null + + @JvmField + @BindView(R.id.et_address_line_2) + var mEtAddressLine2: TextInputEditText? = null + + @JvmField + @BindView(R.id.et_pin_code) + var mEtPinCode: TextInputEditText? = null + + @JvmField + @BindView(R.id.et_state) + var mEtCity: TextInputEditText? = null + + @JvmField + @BindView(R.id.fab_next) + var mFabNext: FloatingActionButton? = null + var spinnerDialog: SpinnerDialog? = null + + @JvmField + @BindView(R.id.et_user_name) + var mEtUserName: TextInputEditText? = null + + @JvmField + @BindView(R.id.et_password) + var mEtPassword: TextInputEditText? = null + + @JvmField + @BindView(R.id.et_confirm_password) + var mEtConfirmPassword: TextInputEditText? = null + + @JvmField + @BindView(R.id.rr_container) + var container: ViewGroup? = null + + @JvmField + @BindView(R.id.pb_password_strength) + var passwordStrengthProgress: ProgressBar? = null + + @JvmField + @BindView(R.id.tv_password_strength) + var passwordStrengthText: TextView? = null + private var countryName: String? = null + private var mobileNumber: String? = null + private var countryId: String? = null + private var stateId: String? = null + private var mifosSavingProductId = 0 + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_signup) + ButterKnife.bind(this) + mPresenter!!.attachView(this) + showColoredBackButton(Constants.BLACK_BACK_BUTTON) + setToolbarTitle("Registration") + mifosSavingProductId = intent.getIntExtra(Constants.MIFOS_SAVINGS_PRODUCT_ID, 0) + if (mifosSavingProductId + == org.mifos.mobilewallet.core.utils.Constants.MIFOS_MERCHANT_SAVINGS_PRODUCT_ID + ) { + mEtBusinessShopLayout!!.visibility = View.VISIBLE + } else { + mEtBusinessShopLayout!!.visibility = View.GONE + } + mobileNumber = intent.getStringExtra(Constants.MOBILE_NUMBER) + countryName = intent.getStringExtra(Constants.COUNTRY) + val email = intent.getStringExtra(Constants.GOOGLE_EMAIL) + val displayName = intent.getStringExtra(Constants.GOOGLE_DISPLAY_NAME) + val firstName = intent.getStringExtra(Constants.GOOGLE_GIVEN_NAME) + val lastName = intent.getStringExtra(Constants.GOOGLE_FAMILY_NAME) + val photoUri = intent.getParcelableExtra(Constants.GOOGLE_PHOTO_URI) + if (displayName != null) { + mEtBusinessShopName!!.setText(displayName) + } + if (email != null) { + mEtEmail!!.setText(email) + mEtUserName!!.setText(email.substring(0, email.indexOf('@'))) + } + if (firstName != null) { + mEtFirstName!!.setText(firstName) + } + if (lastName != null) { + mEtLastName!!.setText(lastName) + } + mEtPassword!!.addTextChangedListener(object : TextWatcher { + override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { + mPresenter!!.checkPasswordStrength(s.toString()) + } + + override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {} + override fun afterTextChanged(s: Editable) {} + }) + DebugUtil.log(mobileNumber, countryName, email, displayName, firstName, lastName, photoUri) + showProgressDialog(Constants.PLEASE_WAIT) + initSearchableStateSpinner() + } + + private fun initSearchableStateSpinner() { + var jsonObject: JSONObject? = null + try { + countryId = "" + jsonObject = FileUtils.readJson(this, "countries.json") + val countriesArray = jsonObject.getJSONArray("countries") + for (i in 0 until countriesArray.length()) { + if (countriesArray.getJSONObject(i).getString("name") == countryName) { + countryId = countriesArray.getJSONObject(i).getString("id") + break + } + } + jsonObject = FileUtils.readJson(this, "states.json") + val statesJson = jsonObject.getJSONArray("states") + val statesList = ArrayList() + for (i in 0 until statesJson.length()) { + val statesJsonObject = statesJson.getJSONObject(i) + if (statesJsonObject.getString("country_id") == countryId) { + statesList.add(statesJsonObject.getString("name")) + stateId = statesJsonObject.getString("id") + } + } + spinnerDialog = SpinnerDialog( + this@SignupActivity, statesList, + "Select or Search State", R.style.DialogAnimations_SmileWindow, "Close" + ) + spinnerDialog!!.bindOnSpinerListener { item, position -> mEtCity!!.setText(item) } + mEtCity!!.setOnClickListener { spinnerDialog!!.showSpinerDialog() } + hideProgressDialog() + } catch (e: Exception) { + Log.d("qxz", e.toString() + " " + e.message) + } + } + + @OnClick(R.id.fab_next) + fun onNextClicked() { + showProgressDialog(Constants.PLEASE_WAIT) + if (mifosSavingProductId + == org.mifos.mobilewallet.core.utils.Constants.MIFOS_MERCHANT_SAVINGS_PRODUCT_ID + && isEmpty(mEtBusinessShopName) + ) { + Toaster.showToast(this, "All fields are mandatory") + hideProgressDialog() + return + } + if (isEmpty(mEtFirstName) || isEmpty(mEtLastName) || isEmpty(mEtEmail) + || isEmpty(mEtAddressLine1) || isEmpty(mEtAddressLine2) + || isEmpty(mEtPinCode) || isEmpty(mEtCity) || isEmpty(mEtUserName) || isEmpty( + mEtPassword + ) || isEmpty(mEtConfirmPassword) + ) { + Toaster.showToast(this, "All fields are mandatory") + hideProgressDialog() + return + } + if (mEtPassword!!.text.toString().length < 6) { + showToast("Password should contain more than 6 characters") + return + } + val firstName = mEtFirstName!!.text.toString().trim { it <= ' ' } + val lastName = mEtLastName!!.text.toString().trim { it <= ' ' } + val email = mEtEmail!!.text.toString().trim { it <= ' ' } + val businessName = mEtBusinessShopName!!.text.toString().trim { it <= ' ' } + val addressline1 = mEtAddressLine1!!.text.toString().trim { it <= ' ' } + val addressline2 = mEtAddressLine2!!.text.toString().trim { it <= ' ' } + val pincode = mEtPinCode!!.text.toString().trim { it <= ' ' } + val city = mEtCity!!.text.toString().trim { it <= ' ' } + val username = mEtUserName!!.text.toString().trim { it <= ' ' } + val password = mEtPassword!!.text.toString() + val confirmPassword = mEtConfirmPassword!!.text.toString() + if (!email.isValidEmail()) { + Snackbar.make(container!!, R.string.validate_email, Snackbar.LENGTH_SHORT).show() + hideProgressDialog() + return + } + if (password != confirmPassword) { + Toaster.showToast(this, "Password is not same as Confirm Password") + hideProgressDialog() + return + } + mSignupPresenter!!.registerUser( + firstName, lastName, mobileNumber, email, businessName, + addressline1, addressline2, pincode, city, countryName, username, password, stateId, + countryId, mifosSavingProductId + ) + } + + override fun onRegisterSuccess(s: String?) { + // registered but unable to login or user not updated with client + // TODO :: Consider this case + // 1. User not updated: when logging in update user + // 2. User unable to login (must be caused due to server) + hideProgressDialog() + showToast("Registered successfully.") + startActivity(Intent(this@SignupActivity, LoginActivity::class.java)) + finish() + } + + override fun updatePasswordStrength(stringRes: Int, colorRes: Int, value: Int) { + TransitionManager.beginDelayedTransition(container!!) + passwordStrengthText!!.visibility = View.VISIBLE + if (value == 0) { + passwordStrengthText!!.text = "Password should contain more than 6 characters" + return + } + passwordStrengthProgress!!.visibility = View.VISIBLE + passwordStrengthProgress!!.progressDrawable.setColorFilter( + colorRes, PorterDuff.Mode.SRC_IN + ) + passwordStrengthProgress!!.progress = value + passwordStrengthText!!.setText(stringRes) + } + + override fun setPresenter(presenter: RegistrationContract.SignupPresenter?) { + mSignupPresenter = presenter + } + + override fun loginSuccess() { + hideProgressDialog() + showToast("Registered successfully") + val intent = Intent(this@SignupActivity, PassCodeActivity::class.java) + intent.putExtra(PassCodeConstants.PASSCODE_INITIAL_LOGIN, true) + startActivity(intent) + finish() + } + + override fun onRegisterFailed(message: String?) { + hideProgressDialog() + showToast(message) + } + + private fun isEmpty(etText: EditText?): Boolean { + return etText!!.text.toString().trim { it <= ' ' }.length == 0 + } + + override fun showToast(s: String?) { + Toaster.showToast(this, s) + } +} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/SignupMethod.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/SignupMethod.java deleted file mode 100644 index 0b1facb9b..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/SignupMethod.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.mifos.mobilewallet.mifospay.registration.ui; - -import android.app.Dialog; -import android.os.Bundle; -import com.google.android.material.bottomsheet.BottomSheetBehavior; -import com.google.android.material.bottomsheet.BottomSheetDialog; -import com.google.android.material.bottomsheet.BottomSheetDialogFragment; -import android.view.View; -import android.widget.CheckBox; - -import com.google.android.gms.auth.api.signin.GoogleSignInAccount; -import com.google.android.gms.auth.api.signin.GoogleSignInClient; - -import org.mifos.mobilewallet.core.utils.Constants; -import org.mifos.mobilewallet.mifospay.R; -import org.mifos.mobilewallet.mifospay.auth.ui.LoginActivity; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.OnClick; - -/** - * Created by ankur on 26/June/2018 - */ - -public class SignupMethod extends BottomSheetDialogFragment { - - @BindView(R.id.cb_google_account) - CheckBox mCbGoogleAccount; - private BottomSheetBehavior mBottomSheetBehavior; - private GoogleSignInClient googleSignInClient; - private GoogleSignInAccount account; - - @Override - public Dialog onCreateDialog(Bundle savedInstanceState) { - BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog(savedInstanceState); - - View view = View.inflate(getContext(), R.layout.dialog_choose_signup_method, null); - - dialog.setContentView(view); - mBottomSheetBehavior = BottomSheetBehavior.from((View) view.getParent()); - - ButterKnife.bind(this, view); - - return dialog; - } - - @Override - public void onStart() { - super.onStart(); - mBottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); - } - - @OnClick(R.id.btn_merchant) - public void onMerchantClicked() { - dismiss(); - if (getActivity() instanceof LoginActivity) { - if (mCbGoogleAccount.isChecked()) { - ((LoginActivity) getActivity()).signupUsingGoogleAccount( - Constants.MIFOS_MERCHANT_SAVINGS_PRODUCT_ID); - } else { - ((LoginActivity) getActivity()).signup(Constants.MIFOS_MERCHANT_SAVINGS_PRODUCT_ID); - } - } - } - - @OnClick(R.id.btn_customer) - public void onCustomerClicked() { - dismiss(); - if (getActivity() instanceof LoginActivity) { - if (mCbGoogleAccount.isChecked()) { - ((LoginActivity) getActivity()).signupUsingGoogleAccount( - Constants.MIFOS_CONSUMER_SAVINGS_PRODUCT_ID); - } else { - ((LoginActivity) getActivity()).signup(Constants.MIFOS_CONSUMER_SAVINGS_PRODUCT_ID); - } - } - } - -} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/SignupMethod.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/SignupMethod.kt new file mode 100644 index 000000000..04f7e4226 --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/registration/ui/SignupMethod.kt @@ -0,0 +1,70 @@ +package org.mifos.mobilewallet.mifospay.registration.ui + +import android.app.Dialog +import android.os.Bundle +import android.view.View +import android.widget.CheckBox +import butterknife.BindView +import butterknife.ButterKnife +import butterknife.OnClick +import com.google.android.gms.auth.api.signin.GoogleSignInAccount +import com.google.android.gms.auth.api.signin.GoogleSignInClient +import com.google.android.material.bottomsheet.BottomSheetBehavior +import com.google.android.material.bottomsheet.BottomSheetDialog +import com.google.android.material.bottomsheet.BottomSheetDialogFragment +import org.mifos.mobilewallet.core.utils.Constants +import org.mifos.mobilewallet.mifospay.R +import org.mifos.mobilewallet.mifospay.auth.ui.LoginActivity + +/** + * Created by ankur on 26/June/2018 + */ +class SignupMethod : BottomSheetDialogFragment() { + @JvmField + @BindView(R.id.cb_google_account) + var mCbGoogleAccount: CheckBox? = null + private var mBottomSheetBehavior: BottomSheetBehavior<*>? = null + private val googleSignInClient: GoogleSignInClient? = null + private val account: GoogleSignInAccount? = null + override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { + val dialog = super.onCreateDialog(savedInstanceState) as BottomSheetDialog + val view = View.inflate(context, R.layout.dialog_choose_signup_method, null) + dialog.setContentView(view) + mBottomSheetBehavior = BottomSheetBehavior.from(view.parent as View) + ButterKnife.bind(this, view) + return dialog + } + + override fun onStart() { + super.onStart() + mBottomSheetBehavior!!.state = BottomSheetBehavior.STATE_EXPANDED + } + + @OnClick(R.id.btn_merchant) + fun onMerchantClicked() { + dismiss() + if (activity is LoginActivity) { + if (mCbGoogleAccount!!.isChecked) { + (activity as LoginActivity?)!!.signupUsingGoogleAccount( + Constants.MIFOS_MERCHANT_SAVINGS_PRODUCT_ID + ) + } else { + (activity as LoginActivity?)!!.signup(Constants.MIFOS_MERCHANT_SAVINGS_PRODUCT_ID) + } + } + } + + @OnClick(R.id.btn_customer) + fun onCustomerClicked() { + dismiss() + if (activity is LoginActivity) { + if (mCbGoogleAccount!!.isChecked) { + (activity as LoginActivity?)!!.signupUsingGoogleAccount( + Constants.MIFOS_CONSUMER_SAVINGS_PRODUCT_ID + ) + } else { + (activity as LoginActivity?)!!.signup(Constants.MIFOS_CONSUMER_SAVINGS_PRODUCT_ID) + } + } + } +} \ No newline at end of file