From 0a0347ac40db9e267bb45f375a8ee35fc932bd69 Mon Sep 17 00:00:00 2001 From: Pratyush Singh Date: Sun, 7 Jan 2024 12:34:17 +0530 Subject: [PATCH] refactor #1450: edit profile migrated from java to kotlin --- .../editprofile/EditProfileContract.java | 75 --- .../editprofile/EditProfileContract.kt | 44 ++ .../presenter/EditProfilePresenter.java | 188 ------- .../presenter/EditProfilePresenter.kt | 166 ++++++ .../editprofile/ui/EditProfileActivity.java | 528 ------------------ .../editprofile/ui/EditProfileActivity.kt | 522 +++++++++++++++++ 6 files changed, 732 insertions(+), 791 deletions(-) delete mode 100644 mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/EditProfileContract.java create mode 100644 mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/EditProfileContract.kt delete mode 100644 mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/presenter/EditProfilePresenter.java create mode 100644 mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/presenter/EditProfilePresenter.kt delete mode 100644 mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/ui/EditProfileActivity.java create mode 100644 mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/ui/EditProfileActivity.kt diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/EditProfileContract.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/EditProfileContract.java deleted file mode 100644 index c1c83b998..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/EditProfileContract.java +++ /dev/null @@ -1,75 +0,0 @@ -package org.mifos.mobilewallet.mifospay.editprofile; - -import org.mifos.mobilewallet.mifospay.base.BasePresenter; -import org.mifos.mobilewallet.mifospay.base.BaseView; - -/** - * Created by ankur on 27/June/2018 - */ - -public interface EditProfileContract { - - interface EditProfilePresenter extends BasePresenter { - - void fetchUserDetails(); - - void handleNecessaryDataSave(); - - void updateInputById(int id, String content); - - void updateEmail(String email); - - void updateMobile(String fullNumber); - - void handleProfileImageChangeRequest(); - - void handleProfileImageRemoved(); - - void handleClickProfileImageRequest(); - - void handleExitOnUnsavedChanges(); - - void onDialogNegative(); - - void onDialogPositive(); - } - - interface EditProfileView extends BaseView { - - void showDefaultImageByUsername(String fullName); - - void showUsername(String username); - - void showEmail(String email); - - void showVpa(String vpa); - - void showMobileNumber(String mobileNumber); - - void removeProfileImage(); - - void changeProfileImage(); - - void clickProfileImage(); - - void onUpdateEmailError(String message); - - void onUpdateMobileError(String message); - - void showToast(String message); - - void showFab(); - - void hideFab(); - - void hideKeyboard(); - - void startProgressBar(); - - void stopProgressBar(); - - void showDiscardChangesDialog(); - - void closeActivity(); - } -} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/EditProfileContract.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/EditProfileContract.kt new file mode 100644 index 000000000..91c7c799b --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/EditProfileContract.kt @@ -0,0 +1,44 @@ +package org.mifos.mobilewallet.mifospay.editprofile + +import org.mifos.mobilewallet.mifospay.base.BasePresenter +import org.mifos.mobilewallet.mifospay.base.BaseView + +/** + * Created by ankur on 27/June/2018 + */ +interface EditProfileContract { + interface EditProfilePresenter : BasePresenter { + fun fetchUserDetails() + fun handleNecessaryDataSave() + fun updateInputById(id: Int, content: String?) + fun updateEmail(email: String?) + fun updateMobile(fullNumber: String?) + fun handleProfileImageChangeRequest() + fun handleProfileImageRemoved() + fun handleClickProfileImageRequest() + fun handleExitOnUnsavedChanges() + fun onDialogNegative() + fun onDialogPositive() + } + + interface EditProfileView : BaseView { + fun showDefaultImageByUsername(fullName: String?) + fun showUsername(username: String?) + fun showEmail(email: String?) + fun showVpa(vpa: String?) + fun showMobileNumber(mobileNumber: String?) + fun removeProfileImage() + fun changeProfileImage() + fun clickProfileImage() + fun onUpdateEmailError(message: String?) + fun onUpdateMobileError(message: String?) + fun showToast(message: String?) + fun showFab() + fun hideFab() + fun hideKeyboard() + fun startProgressBar() + fun stopProgressBar() + fun showDiscardChangesDialog() + fun closeActivity() + } +} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/presenter/EditProfilePresenter.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/presenter/EditProfilePresenter.java deleted file mode 100644 index 2cee29711..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/presenter/EditProfilePresenter.java +++ /dev/null @@ -1,188 +0,0 @@ -package org.mifos.mobilewallet.mifospay.editprofile.presenter; - -import org.mifos.mobilewallet.core.base.UseCase; -import org.mifos.mobilewallet.core.base.UseCaseHandler; -import org.mifos.mobilewallet.core.domain.model.client.UpdateClientEntityMobile; -import org.mifos.mobilewallet.core.domain.model.user.UpdateUserEntityEmail; -import org.mifos.mobilewallet.core.domain.usecase.client.UpdateClient; -import org.mifos.mobilewallet.core.domain.usecase.user.AuthenticateUser; -import org.mifos.mobilewallet.core.domain.usecase.user.UpdateUser; -import org.mifos.mobilewallet.mifospay.R; -import org.mifos.mobilewallet.mifospay.base.BaseView; -import org.mifos.mobilewallet.mifospay.data.local.PreferencesHelper; -import org.mifos.mobilewallet.mifospay.editprofile.EditProfileContract; - -import javax.inject.Inject; - -/** - * Created by ankur on 27/June/2018 - */ - -public class EditProfilePresenter implements EditProfileContract.EditProfilePresenter { - - private final UseCaseHandler mUseCaseHandler; - private final PreferencesHelper mPreferencesHelper; - @Inject - UpdateUser updateUserUseCase; - @Inject - UpdateClient updateClientUseCase; - @Inject - AuthenticateUser authenticateUserUseCase; - private EditProfileContract.EditProfileView mEditProfileView; - - @Inject - public EditProfilePresenter(UseCaseHandler useCaseHandler, - PreferencesHelper preferencesHelper) { - mUseCaseHandler = useCaseHandler; - mPreferencesHelper = preferencesHelper; - } - - @Override - public void attachView(BaseView baseView) { - mEditProfileView = (EditProfileContract.EditProfileView) baseView; - mEditProfileView.setPresenter(this); - } - - @Override - public void fetchUserDetails() { - showUserImageOrDefault(); - showUsernameIfNotEmpty(); - showEmailIfNotEmpty(); - showVpaIfNotEmpty(); - showMobielIfNotEmpty(); - } - - private void showUserImageOrDefault() { - /* - TODO: - - We could check if user has a custom image and then fetch it from the db here - and show the custom image on success or default on error/if user doesn't have one - - */ - mEditProfileView.showDefaultImageByUsername(mPreferencesHelper.getFullName()); - } - - private void showUsernameIfNotEmpty() { - if (!mPreferencesHelper.getUsername().isEmpty()) { - mEditProfileView.showUsername(mPreferencesHelper.getUsername()); - } - } - - private void showEmailIfNotEmpty() { - if (!mPreferencesHelper.getEmail().isEmpty()) { - mEditProfileView.showEmail(mPreferencesHelper.getEmail()); - } - } - - private void showVpaIfNotEmpty() { - if (!mPreferencesHelper.getClientVpa().isEmpty()) { - mEditProfileView.showVpa(mPreferencesHelper.getClientVpa()); - } - } - - private void showMobielIfNotEmpty() { - if (!mPreferencesHelper.getMobile().isEmpty()) { - mEditProfileView.showMobileNumber(mPreferencesHelper.getMobile()); - } - } - - @Override - public void updateInputById(int id, String content) { - switch (id) { - case R.id.et_edit_profile_username: - break; - case R.id.et_edit_profile_email: - updateEmail(content); - break; - case R.id.et_edit_profile_vpa: - break; - case R.id.et_edit_profile_mobile: - updateMobile(content); - break; - } - } - - @Override - public void updateEmail(final String email) { - mEditProfileView.startProgressBar(); - mUseCaseHandler.execute(updateUserUseCase, - new UpdateUser.RequestValues(new UpdateUserEntityEmail(email), - (int) mPreferencesHelper.getUserId()), - new UseCase.UseCaseCallback() { - @Override - public void onSuccess(UpdateUser.ResponseValue response) { - mPreferencesHelper.saveEmail(email); - showEmailIfNotEmpty(); - mEditProfileView.stopProgressBar(); - } - - @Override - public void onError(String message) { - mEditProfileView.onUpdateEmailError(message); - mEditProfileView.showFab(); - mEditProfileView.stopProgressBar(); - } - }); - } - - @Override - public void updateMobile(final String fullNumber) { - mEditProfileView.startProgressBar(); - mUseCaseHandler.execute(updateClientUseCase, - new UpdateClient.RequestValues(new UpdateClientEntityMobile(fullNumber), - (int) mPreferencesHelper.getClientId()), - new UseCase.UseCaseCallback() { - @Override - public void onSuccess(UpdateClient.ResponseValue response) { - mPreferencesHelper.saveMobile(fullNumber); - showMobielIfNotEmpty(); - mEditProfileView.stopProgressBar(); - } - - @Override - public void onError(String message) { - mEditProfileView.onUpdateMobileError(message); - mEditProfileView.showFab(); - mEditProfileView.stopProgressBar(); - } - }); - } - - @Override - public void handleProfileImageChangeRequest() { - mEditProfileView.changeProfileImage(); - } - - @Override - public void handleProfileImageRemoved() { - mEditProfileView.removeProfileImage(); - mEditProfileView.showDefaultImageByUsername(mPreferencesHelper.getFullName()); - } - - @Override - public void handleClickProfileImageRequest() { - mEditProfileView.clickProfileImage(); - } - - @Override - public void handleNecessaryDataSave() { - mEditProfileView.showFab(); - } - - @Override - public void handleExitOnUnsavedChanges() { - mEditProfileView.hideFab(); - mEditProfileView.showDiscardChangesDialog(); - } - - @Override - public void onDialogNegative() { - mEditProfileView.showFab(); - } - - @Override - public void onDialogPositive() { - mEditProfileView.closeActivity(); - } -} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/presenter/EditProfilePresenter.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/presenter/EditProfilePresenter.kt new file mode 100644 index 000000000..99e84becb --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/presenter/EditProfilePresenter.kt @@ -0,0 +1,166 @@ +package org.mifos.mobilewallet.mifospay.editprofile.presenter + +import org.mifos.mobilewallet.core.base.UseCase.UseCaseCallback +import org.mifos.mobilewallet.core.base.UseCaseHandler +import org.mifos.mobilewallet.core.domain.model.client.UpdateClientEntityMobile +import org.mifos.mobilewallet.core.domain.model.user.UpdateUserEntityEmail +import org.mifos.mobilewallet.core.domain.usecase.client.UpdateClient +import org.mifos.mobilewallet.core.domain.usecase.user.AuthenticateUser +import org.mifos.mobilewallet.core.domain.usecase.user.UpdateUser +import org.mifos.mobilewallet.mifospay.R +import org.mifos.mobilewallet.mifospay.base.BaseView +import org.mifos.mobilewallet.mifospay.data.local.PreferencesHelper +import org.mifos.mobilewallet.mifospay.editprofile.EditProfileContract +import org.mifos.mobilewallet.mifospay.editprofile.EditProfileContract.EditProfileView +import javax.inject.Inject + +/** + * Created by ankur on 27/June/2018 + */ +class EditProfilePresenter @Inject constructor( + private val mUseCaseHandler: UseCaseHandler, + private val mPreferencesHelper: PreferencesHelper +) : EditProfileContract.EditProfilePresenter { + @JvmField + @Inject + var updateUserUseCase: UpdateUser? = null + + @JvmField + @Inject + var updateClientUseCase: UpdateClient? = null + + @JvmField + @Inject + var authenticateUserUseCase: AuthenticateUser? = null + private var mEditProfileView: EditProfileView? = null + override fun attachView(baseView: BaseView<*>?) { + mEditProfileView = baseView as EditProfileView? + mEditProfileView!!.setPresenter(this) + } + + override fun fetchUserDetails() { + showUserImageOrDefault() + showUsernameIfNotEmpty() + showEmailIfNotEmpty() + showVpaIfNotEmpty() + showMobielIfNotEmpty() + } + + private fun showUserImageOrDefault() { + /* + TODO: + + We could check if user has a custom image and then fetch it from the db here + and show the custom image on success or default on error/if user doesn't have one + + */ + mEditProfileView!!.showDefaultImageByUsername(mPreferencesHelper.fullName) + } + + private fun showUsernameIfNotEmpty() { + if (!mPreferencesHelper.username.isEmpty()) { + mEditProfileView!!.showUsername(mPreferencesHelper.username) + } + } + + private fun showEmailIfNotEmpty() { + if (!mPreferencesHelper.email.isEmpty()) { + mEditProfileView!!.showEmail(mPreferencesHelper.email) + } + } + + private fun showVpaIfNotEmpty() { + if (!mPreferencesHelper.clientVpa.isEmpty()) { + mEditProfileView!!.showVpa(mPreferencesHelper.clientVpa) + } + } + + private fun showMobielIfNotEmpty() { + if (!mPreferencesHelper.mobile.isEmpty()) { + mEditProfileView!!.showMobileNumber(mPreferencesHelper.mobile) + } + } + + override fun updateInputById(id: Int, content: String?) { + when (id) { + R.id.et_edit_profile_username -> {} + R.id.et_edit_profile_email -> updateEmail(content) + R.id.et_edit_profile_vpa -> {} + R.id.et_edit_profile_mobile -> updateMobile(content) + } + } + + override fun updateEmail(email: String?) { + mEditProfileView!!.startProgressBar() + mUseCaseHandler.execute(updateUserUseCase, + UpdateUser.RequestValues( + UpdateUserEntityEmail(email), + mPreferencesHelper.userId.toInt() + ), + object : UseCaseCallback { + override fun onSuccess(response: UpdateUser.ResponseValue?) { + mPreferencesHelper.saveEmail(email) + showEmailIfNotEmpty() + mEditProfileView!!.stopProgressBar() + } + + override fun onError(message: String) { + mEditProfileView!!.onUpdateEmailError(message) + mEditProfileView!!.showFab() + mEditProfileView!!.stopProgressBar() + } + }) + } + + override fun updateMobile(fullNumber: String?) { + mEditProfileView!!.startProgressBar() + mUseCaseHandler.execute(updateClientUseCase, + UpdateClient.RequestValues( + UpdateClientEntityMobile(fullNumber), + mPreferencesHelper.clientId.toInt().toLong() + ), + object : UseCaseCallback { + override fun onSuccess(response: UpdateClient.ResponseValue?) { + mPreferencesHelper.saveMobile(fullNumber) + showMobielIfNotEmpty() + mEditProfileView!!.stopProgressBar() + } + + override fun onError(message: String) { + mEditProfileView!!.onUpdateMobileError(message) + mEditProfileView!!.showFab() + mEditProfileView!!.stopProgressBar() + } + }) + } + + override fun handleProfileImageChangeRequest() { + mEditProfileView!!.changeProfileImage() + } + + override fun handleProfileImageRemoved() { + mEditProfileView!!.removeProfileImage() + mEditProfileView!!.showDefaultImageByUsername(mPreferencesHelper.fullName) + } + + override fun handleClickProfileImageRequest() { + mEditProfileView!!.clickProfileImage() + } + + override fun handleNecessaryDataSave() { + mEditProfileView!!.showFab() + } + + override fun handleExitOnUnsavedChanges() { + mEditProfileView!!.hideFab() + mEditProfileView!!.showDiscardChangesDialog() + } + + override fun onDialogNegative() { + mEditProfileView!!.showFab() + } + + override fun onDialogPositive() { + mEditProfileView!!.closeActivity() + } +} \ No newline at end of file diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/ui/EditProfileActivity.java b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/ui/EditProfileActivity.java deleted file mode 100644 index 36c621a03..000000000 --- a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/ui/EditProfileActivity.java +++ /dev/null @@ -1,528 +0,0 @@ -package org.mifos.mobilewallet.mifospay.editprofile.ui; - -import android.Manifest; -import android.app.Activity; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.graphics.Bitmap; -import android.net.Uri; -import android.os.Build; -import android.os.Bundle; -import android.provider.MediaStore; -import androidx.annotation.NonNull; -import com.google.android.material.bottomsheet.BottomSheetDialog; -import com.google.android.material.floatingactionbutton.FloatingActionButton; -import com.google.android.material.textfield.TextInputLayout; -import androidx.core.content.ContextCompat; -import androidx.core.content.FileProvider; -import android.text.TextUtils; -import android.view.View; -import android.view.inputmethod.InputMethodManager; -import android.widget.EditText; -import android.widget.ImageView; - -import com.hbb20.CountryCodePicker; -import com.mifos.mobile.passcode.utils.PasscodePreferencesHelper; -import com.yalantis.ucrop.UCrop; - -import org.mifos.mobilewallet.mifospay.R; -import org.mifos.mobilewallet.mifospay.base.BaseActivity; -import org.mifos.mobilewallet.mifospay.editprofile.EditProfileContract; -import org.mifos.mobilewallet.mifospay.editprofile.presenter.EditProfilePresenter; -import org.mifos.mobilewallet.mifospay.passcode.ui.PassCodeActivity; -import org.mifos.mobilewallet.mifospay.password.ui.EditPasswordActivity; -import org.mifos.mobilewallet.mifospay.utils.Constants; -import org.mifos.mobilewallet.mifospay.utils.DialogBox; -import org.mifos.mobilewallet.mifospay.utils.TextDrawable; -import org.mifos.mobilewallet.mifospay.utils.Toaster; - -import java.io.File; -import java.util.List; -import java.util.UUID; - -import javax.inject.Inject; - -import butterknife.BindView; -import butterknife.BindViews; -import butterknife.ButterKnife; -import butterknife.OnClick; -import butterknife.OnFocusChange; -import butterknife.OnTextChanged; -import dagger.hilt.android.AndroidEntryPoint; - -@AndroidEntryPoint -public class EditProfileActivity extends BaseActivity implements - EditProfileContract.EditProfileView { - - private static final int REQUEST_READ_IMAGE = 1; - private static final int REQUEST_READ_EXTERNAL_STORAGE = 7; - private static final int REQUEST_CAMERA = 0; - private Uri capturedImageUri; - - @Inject - EditProfilePresenter mPresenter; - - EditProfileContract.EditProfilePresenter mEditProfilePresenter; - - @BindView(R.id.ccp_new_code) - CountryCodePicker ccpCountryCode; - - @BindView(R.id.iv_user_image) - ImageView ivUserImage; - - @BindView(R.id.til_edit_profile_username) - TextInputLayout tilUsername; - - @BindView(R.id.til_edit_profile_email) - TextInputLayout tilEmail; - - @BindView(R.id.til_edit_profile_vpa) - TextInputLayout tilVpa; - - @BindView(R.id.til_edit_profile_mobile) - TextInputLayout tilMobileNumber; - - @BindView(R.id.et_edit_profile_username) - EditText etUsername; - - @BindView(R.id.et_edit_profile_email) - EditText etEmail; - - @BindView(R.id.et_edit_profile_vpa) - EditText etVpa; - - @BindView(R.id.et_edit_profile_mobile) - EditText etMobileNumber; - - @BindView(R.id.fab_edit_profile_save_changes) - FloatingActionButton fabSaveChanges; - - @BindViews({R.id.et_edit_profile_username, R.id.et_edit_profile_email, - R.id.et_edit_profile_vpa, R.id.et_edit_profile_mobile}) - List userDetailsInputs; - - private BottomSheetDialog bottomSheetDialog; - public DialogBox dialogBox = new DialogBox(); - private PasscodePreferencesHelper passcodePreferencesHelper; - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_edit_profile); - ButterKnife.bind(this); - setupUi(); - mPresenter.attachView(this); - ccpCountryCode.registerCarrierNumberEditText(etMobileNumber); - mEditProfilePresenter.fetchUserDetails(); - passcodePreferencesHelper = new PasscodePreferencesHelper(this); - if (isChangeImageRequestFromProfile()) { - bottomSheetDialog.show(); - } - } - - private void setupUi() { - hideFab(); - showCloseButton(); - setToolbarTitle(Constants.EDIT_PROFILE); - setupBottomSheetDialog(); - } - - private void setupBottomSheetDialog() { - bottomSheetDialog = new BottomSheetDialog(EditProfileActivity.this); - View sheetView = getLayoutInflater() - .inflate(R.layout.dialog_change_profile_picture, null); - bottomSheetDialog.setContentView(sheetView); - BottomSheetViews bsv = new BottomSheetViews(); - ButterKnife.bind(bsv, sheetView); - } - - private boolean isChangeImageRequestFromProfile() { - return getIntent().getStringExtra(Constants.CHANGE_PROFILE_IMAGE_KEY) != null; - } - - @Override - public void setPresenter(EditProfileContract.EditProfilePresenter presenter) { - mEditProfilePresenter = presenter; - } - - @OnClick(R.id.fab_edit_profile_save_changes) - public void onSaveChangesClicked() { - for (EditText input : userDetailsInputs) { - if (isDataSaveNecessary(input)) { - mPresenter.updateInputById(input.getId(), input.getText().toString().trim()); - } - } - hideFab(); - hideKeyboard(); - } - - @OnClick(R.id.iv_user_image) - public void onProfileImageClicked() { - bottomSheetDialog.show(); - } - - @OnClick(R.id.btn_change_password) - public void onChangePasswordClicked() { - startActivity(new Intent(getApplicationContext(), EditPasswordActivity.class)); - } - - @OnClick(R.id.btn_change_passcode) - public void onChangePasscodeClicked() { - String currentPasscode = passcodePreferencesHelper.getPassCode(); - // for re-initiating passcode generation process - passcodePreferencesHelper.savePassCode(""); - Intent intent = new Intent(this, PassCodeActivity.class ); - intent.putExtra(Constants.CURRENT_PASSCODE, currentPasscode); - intent.putExtra(Constants.UPDATE_PASSCODE, true); - startActivity(intent); - } - - @OnTextChanged({R.id.et_edit_profile_username, R.id.et_edit_profile_email, - R.id.et_edit_profile_vpa, R.id.et_edit_profile_mobile}) - public void onUserDetailsChanged() { - for (EditText et : userDetailsInputs) { - if (isDataSaveNecessary(et)) { - mPresenter.handleNecessaryDataSave(); - break; - } else { - hideFab(); - } - } - } - - private boolean isDataSaveNecessary(EditText input) { - String content = input.getText().toString().trim(); - String currentContent = input.getHint().toString().trim(); - return !(TextUtils.isEmpty(content) || content.equals(currentContent)); - } - - @OnFocusChange({R.id.et_edit_profile_username, R.id.et_edit_profile_email, - R.id.et_edit_profile_vpa, R.id.et_edit_profile_mobile}) - public void onUserDetailsFocusChanged(EditText input, boolean isFocused) { - if (!isDataSaveNecessary((input))) { - if (isFocused) { - input.setText(input.getHint().toString()); - } else { - input.getText().clear(); - } - } - } - - @Override - public void showDefaultImageByUsername(String fullName) { - TextDrawable drawable = TextDrawable.builder().beginConfig() - .width((int) getResources().getDimension(R.dimen.user_profile_image_size)) - .height((int) getResources().getDimension(R.dimen.user_profile_image_size)) - .endConfig().buildRound(fullName.substring(0, 1), R.color.colorPrimary); - ivUserImage.setImageDrawable(drawable); - } - - @Override - public void showUsername(String username) { - tilUsername.setHint(username); - handleUpdatedInput(etUsername); - } - - @Override - public void showEmail(String email) { - tilEmail.setHint(email); - handleUpdatedInput(etEmail); - } - - @Override - public void showVpa(String vpa) { - tilVpa.setHint(vpa); - handleUpdatedInput(etVpa); - } - - @Override - public void showMobileNumber(String mobileNumber) { - tilMobileNumber.setHint(mobileNumber); - handleUpdatedInput(etMobileNumber); - } - - private void handleUpdatedInput(EditText input) { - input.clearFocus(); - input.getText().clear(); - } - - @Override - public void showFab() { - fabSaveChanges.show(); - } - - @Override - public void hideFab() { - fabSaveChanges.hide(); - } - - public void hideKeyboard() { - InputMethodManager imm - = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE); - View view = getCurrentFocus(); - if (imm != null) { - if (view == null) { - view = new View(this); - } - imm.hideSoftInputFromWindow(view.getWindowToken(), 0); - } - } - - @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, - @NonNull int[] grantResults) { - switch (requestCode) { - case REQUEST_CAMERA: { - // If request is cancelled, the result arrays are empty. - if (grantResults.length > 0 - && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - // permission was granted, yay! Do the - // camera-related task you need to do. - Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - String destinationFileName = UUID.randomUUID().toString() + ".jpg"; - File destinationFile = new File(getCacheDir(), destinationFileName); - capturedImageUri = FileProvider.getUriForFile( - this, - "org.mifos.mobilewallet.mifospay.provider", - destinationFile); - intent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri); - startActivityForResult(intent, REQUEST_CAMERA); - - } else { - // permission denied, boo! Disable the - // functionality that depends on this permission. - Toaster.showToast(this, - getString(R.string.need_camera_permission_to_click_profile_picture)); - } - return; - } - case REQUEST_READ_EXTERNAL_STORAGE: { - // If request is cancelled, the result arrays are empty. - if (grantResults.length > 0 - && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - // permission was granted, yay! Do the - // storage-related task you need to do. - - Intent i = new Intent(Intent.ACTION_PICK, - android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); - - startActivityForResult(i, REQUEST_READ_IMAGE); - } else { - // permission denied, boo! Disable the - // functionality that depends on this permission. - showToast(Constants.NEED_EXTERNAL_STORAGE_PERMISSION_TO_BROWSE_IMAGES); - } - } - // other 'case' lines to check for other - // permissions this app might request. - } - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - - if (resultCode == RESULT_OK) { - if (requestCode == REQUEST_READ_IMAGE && data != null) { - Uri selectedImageUri = data.getData(); - if (selectedImageUri != null) { - startCrop(selectedImageUri); - } - } else if (requestCode == UCrop.REQUEST_CROP) { - handleCropResult(data); - } else if (requestCode == REQUEST_CAMERA && capturedImageUri != null) { - startCrop(capturedImageUri); - } - } - } - - private void startCrop(@NonNull Uri uri) { - String destinationFileName = UUID.randomUUID().toString() + ".jpg"; - - UCrop uCrop = UCrop.of(uri, Uri.fromFile(new File(getCacheDir(), destinationFileName))); - uCrop = getConfiguredUCrop(uCrop); - uCrop.start(EditProfileActivity.this); - } - - private UCrop getConfiguredUCrop(UCrop uCrop) { - uCrop = uCrop.withAspectRatio(1, 1); - - int size = (int) getResources().getDimension(R.dimen.user_profile_image_size); - if (size > UCrop.MIN_SIZE) { - uCrop = uCrop.withMaxResultSize(size, size); - } - - UCrop.Options options = new UCrop.Options(); - options.setCompressionFormat(Bitmap.CompressFormat.JPEG); - options.setCompressionQuality(80); - - options.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary)); - options.setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)); - options.setActiveWidgetColor(ContextCompat.getColor(this, R.color.primaryBlue)); - options.setToolbarWidgetColor(ContextCompat.getColor(this, R.color.black)); - options.setCropFrameColor(ContextCompat.getColor(this, R.color.clickedblue)); - options.setCircleDimmedLayer(true); - options.setShowCropFrame(true); - options.setShowCropGrid(true); - options.setCropGridColumnCount(2); - options.setCropGridRowCount(2); - return uCrop.withOptions(options); - } - - @Override - public void removeProfileImage() { - // TODO: Remove image from database - } - - @Override - public void changeProfileImage() { - pickImageFromGallery(); - } - - @Override - public void clickProfileImage() { - clickProfilePicFromCamera(); - } - - private void pickImageFromGallery() { - if (Build.VERSION.SDK_INT >= 23 && - ContextCompat.checkSelfPermission(getApplicationContext(), - Manifest.permission.READ_EXTERNAL_STORAGE) - != PackageManager.PERMISSION_GRANTED) { - requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, - REQUEST_READ_EXTERNAL_STORAGE); - } else { - Intent i = new Intent(Intent.ACTION_GET_CONTENT) - .setType("image/*") - .addCategory(Intent.CATEGORY_OPENABLE); - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - String[] mimeTypes = {"image/jpeg", "image/png"}; - i.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes); - } - - startActivityForResult(Intent.createChooser(i, - getString(R.string.label_select_picture)), REQUEST_READ_IMAGE); - } - } - - private void handleCropResult(@NonNull Intent result) { - final Uri resultUri = UCrop.getOutput(result); - if (resultUri != null) { - ivUserImage.setImageURI(resultUri); - } - } - - public void clickProfilePicFromCamera() { - - if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(this, - Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) { - - // Permission is not granted - requestPermissions(new String[]{Manifest.permission.CAMERA}, REQUEST_CAMERA); - } else { - - // Permission has already been granted - Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); - String destinationFileName = UUID.randomUUID().toString() + ".jpg"; - File destinationFile = new File(getCacheDir(), destinationFileName); - capturedImageUri = FileProvider.getUriForFile( - this, - "org.mifos.mobilewallet.mifospay.provider", - destinationFile); - intent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri); - startActivityForResult(intent, REQUEST_CAMERA); - } - } - - @Override - public void showDiscardChangesDialog() { - dialogBox.setOnPositiveListener(new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - mPresenter.onDialogPositive(); - dialog.dismiss(); - } - }); - dialogBox.setOnNegativeListener(new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - mPresenter.onDialogNegative(); - dialog.dismiss(); - } - }); - dialogBox.show(this, R.string.discard_changes_and_exit, - R.string.discard_changes_and_exit_description, R.string.accept, R.string.cancel); - } - - @Override - public void onUpdateEmailError(String message) { - showToast(message); - } - - @Override - public void onUpdateMobileError(String message) { - showToast(message); - } - - @Override - public void showToast(String message) { - Toaster.showToast(this, message); - } - - @Override - public void startProgressBar() { - showProgressDialog(Constants.PLEASE_WAIT); - } - - @Override - public void stopProgressBar() { - hideProgressDialog(); - } - - @Override - public void closeActivity() { - finish(); - } - - @Override - public void onBackPressed() { - if (fabSaveChanges.isOrWillBeShown()) { - mPresenter.handleExitOnUnsavedChanges(); - } else { - super.onBackPressed(); - } - } - - @Override - public void onPause() { - super.onPause(); - - cancelProgressDialog(); - - if (dialogBox != null) { - dialogBox.dismiss(); - } - } - - class BottomSheetViews { - @OnClick(R.id.ll_change_profile_image_dialog_row) - public void onChangeProfileImageClicked() { - mPresenter.handleProfileImageChangeRequest(); - bottomSheetDialog.dismiss(); - } - - @OnClick(R.id.ll_remove_profile_image_dialog_row) - public void onRemoveProfileImageClicked() { - mEditProfilePresenter.handleProfileImageRemoved(); - bottomSheetDialog.dismiss(); - } - - @OnClick(R.id.ll_click_profile_image_dialog_row) - public void onClickProfileImageClicked() { - mEditProfilePresenter.handleClickProfileImageRequest(); - bottomSheetDialog.dismiss(); - } - } -} diff --git a/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/ui/EditProfileActivity.kt b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/ui/EditProfileActivity.kt new file mode 100644 index 000000000..3fce5ba19 --- /dev/null +++ b/mifospay/src/main/java/org/mifos/mobilewallet/mifospay/editprofile/ui/EditProfileActivity.kt @@ -0,0 +1,522 @@ +package org.mifos.mobilewallet.mifospay.editprofile.ui + +import android.Manifest +import android.content.Intent +import android.content.pm.PackageManager +import android.graphics.Bitmap +import android.net.Uri +import android.os.Build +import android.os.Bundle +import android.provider.MediaStore +import android.text.TextUtils +import android.view.View +import android.view.inputmethod.InputMethodManager +import android.widget.EditText +import android.widget.ImageView +import androidx.core.content.ContextCompat +import androidx.core.content.FileProvider +import butterknife.BindView +import butterknife.BindViews +import butterknife.ButterKnife +import butterknife.OnClick +import butterknife.OnFocusChange +import butterknife.OnTextChanged +import com.google.android.material.bottomsheet.BottomSheetDialog +import com.google.android.material.floatingactionbutton.FloatingActionButton +import com.google.android.material.textfield.TextInputLayout +import com.hbb20.CountryCodePicker +import com.mifos.mobile.passcode.utils.PasscodePreferencesHelper +import com.yalantis.ucrop.UCrop +import dagger.hilt.android.AndroidEntryPoint +import org.mifos.mobilewallet.mifospay.R +import org.mifos.mobilewallet.mifospay.base.BaseActivity +import org.mifos.mobilewallet.mifospay.editprofile.EditProfileContract +import org.mifos.mobilewallet.mifospay.editprofile.EditProfileContract.EditProfileView +import org.mifos.mobilewallet.mifospay.editprofile.presenter.EditProfilePresenter +import org.mifos.mobilewallet.mifospay.passcode.ui.PassCodeActivity +import org.mifos.mobilewallet.mifospay.password.ui.EditPasswordActivity +import org.mifos.mobilewallet.mifospay.utils.Constants +import org.mifos.mobilewallet.mifospay.utils.DialogBox +import org.mifos.mobilewallet.mifospay.utils.TextDrawable +import org.mifos.mobilewallet.mifospay.utils.Toaster +import java.io.File +import java.util.UUID +import javax.inject.Inject + +@AndroidEntryPoint +class EditProfileActivity : BaseActivity(), EditProfileView { + private var capturedImageUri: Uri? = null + + @JvmField + @Inject + var mPresenter: EditProfilePresenter? = null + var mEditProfilePresenter: EditProfileContract.EditProfilePresenter? = null + + @JvmField + @BindView(R.id.ccp_new_code) + var ccpCountryCode: CountryCodePicker? = null + + @JvmField + @BindView(R.id.iv_user_image) + var ivUserImage: ImageView? = null + + @JvmField + @BindView(R.id.til_edit_profile_username) + var tilUsername: TextInputLayout? = null + + @JvmField + @BindView(R.id.til_edit_profile_email) + var tilEmail: TextInputLayout? = null + + @JvmField + @BindView(R.id.til_edit_profile_vpa) + var tilVpa: TextInputLayout? = null + + @JvmField + @BindView(R.id.til_edit_profile_mobile) + var tilMobileNumber: TextInputLayout? = null + + @JvmField + @BindView(R.id.et_edit_profile_username) + var etUsername: EditText? = null + + @JvmField + @BindView(R.id.et_edit_profile_email) + var etEmail: EditText? = null + + @JvmField + @BindView(R.id.et_edit_profile_vpa) + var etVpa: EditText? = null + + @JvmField + @BindView(R.id.et_edit_profile_mobile) + var etMobileNumber: EditText? = null + + @JvmField + @BindView(R.id.fab_edit_profile_save_changes) + var fabSaveChanges: FloatingActionButton? = null + + @JvmField + @BindViews( + R.id.et_edit_profile_username, + R.id.et_edit_profile_email, + R.id.et_edit_profile_vpa, + R.id.et_edit_profile_mobile + ) + var userDetailsInputs: MutableList? = null + private var bottomSheetDialog: BottomSheetDialog? = null + var dialogBox: DialogBox? = DialogBox() + private var passcodePreferencesHelper: PasscodePreferencesHelper? = null + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_edit_profile) + ButterKnife.bind(this) + setupUi() + mPresenter!!.attachView(this) + ccpCountryCode!!.registerCarrierNumberEditText(etMobileNumber) + mEditProfilePresenter!!.fetchUserDetails() + passcodePreferencesHelper = PasscodePreferencesHelper(this) + if (isChangeImageRequestFromProfile) { + bottomSheetDialog!!.show() + } + } + + private fun setupUi() { + hideFab() + showCloseButton() + setToolbarTitle(Constants.EDIT_PROFILE) + setupBottomSheetDialog() + } + + private fun setupBottomSheetDialog() { + bottomSheetDialog = BottomSheetDialog(this@EditProfileActivity) + val sheetView = layoutInflater + .inflate(R.layout.dialog_change_profile_picture, null) + bottomSheetDialog!!.setContentView(sheetView) + val bsv = BottomSheetViews() + ButterKnife.bind(bsv, sheetView) + } + + private val isChangeImageRequestFromProfile: Boolean + private get() = intent.getStringExtra(Constants.CHANGE_PROFILE_IMAGE_KEY) != null + + @OnClick(R.id.fab_edit_profile_save_changes) + fun onSaveChangesClicked() { + for (input in userDetailsInputs!!) { + if (isDataSaveNecessary(input)) { + mPresenter!!.updateInputById(input.id, input.text.toString().trim { it <= ' ' }) + } + } + hideFab() + hideKeyboard() + } + + @OnClick(R.id.iv_user_image) + fun onProfileImageClicked() { + bottomSheetDialog!!.show() + } + + @OnClick(R.id.btn_change_password) + fun onChangePasswordClicked() { + startActivity(Intent(applicationContext, EditPasswordActivity::class.java)) + } + + @OnClick(R.id.btn_change_passcode) + fun onChangePasscodeClicked() { + val currentPasscode = passcodePreferencesHelper!!.passCode + // for re-initiating passcode generation process + passcodePreferencesHelper!!.savePassCode("") + val intent = Intent(this, PassCodeActivity::class.java) + intent.putExtra(Constants.CURRENT_PASSCODE, currentPasscode) + intent.putExtra(Constants.UPDATE_PASSCODE, true) + startActivity(intent) + } + + @OnTextChanged( + R.id.et_edit_profile_username, + R.id.et_edit_profile_email, + R.id.et_edit_profile_vpa, + R.id.et_edit_profile_mobile + ) + fun onUserDetailsChanged() { + for (et in userDetailsInputs!!) { + if (isDataSaveNecessary(et)) { + mPresenter!!.handleNecessaryDataSave() + break + } else { + hideFab() + } + } + } + + private fun isDataSaveNecessary(input: EditText): Boolean { + val content = input.text.toString().trim { it <= ' ' } + val currentContent = input.hint.toString().trim { it <= ' ' } + return !(TextUtils.isEmpty(content) || content == currentContent) + } + + @OnFocusChange( + R.id.et_edit_profile_username, + R.id.et_edit_profile_email, + R.id.et_edit_profile_vpa, + R.id.et_edit_profile_mobile + ) + fun onUserDetailsFocusChanged(input: EditText, isFocused: Boolean) { + if (!isDataSaveNecessary(input)) { + if (isFocused) { + input.setText(input.hint.toString()) + } else { + input.text.clear() + } + } + } + + override fun showDefaultImageByUsername(fullName: String?) { + val drawable = TextDrawable.builder().beginConfig() + .width(resources.getDimension(R.dimen.user_profile_image_size).toInt()) + .height(resources.getDimension(R.dimen.user_profile_image_size).toInt()) + .endConfig().buildRound(fullName!!.substring(0, 1), R.color.colorPrimary) + ivUserImage!!.setImageDrawable(drawable) + } + + override fun showUsername(username: String?) { + tilUsername!!.hint = username + handleUpdatedInput(etUsername) + } + + override fun showEmail(email: String?) { + tilEmail!!.hint = email + handleUpdatedInput(etEmail) + } + + override fun showVpa(vpa: String?) { + tilVpa!!.hint = vpa + handleUpdatedInput(etVpa) + } + + override fun showMobileNumber(mobileNumber: String?) { + tilMobileNumber!!.hint = mobileNumber + handleUpdatedInput(etMobileNumber) + } + + private fun handleUpdatedInput(input: EditText?) { + input!!.clearFocus() + input.text.clear() + } + + override fun showFab() { + fabSaveChanges!!.show() + } + + override fun hideFab() { + fabSaveChanges!!.hide() + } + + override fun hideKeyboard() { + val imm = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager + var view = currentFocus + if (view == null) { + view = View(this) + } + imm.hideSoftInputFromWindow(view.windowToken, 0) + } + + override fun onRequestPermissionsResult( + requestCode: Int, permissions: Array, + grantResults: IntArray + ) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults) + when (requestCode) { + REQUEST_CAMERA -> { + + // If request is cancelled, the result arrays are empty. + if (grantResults.isNotEmpty() + && grantResults[0] == PackageManager.PERMISSION_GRANTED + ) { + // permission was granted, yay! Do the + // camera-related task you need to do. + val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE) + val destinationFileName = UUID.randomUUID().toString() + ".jpg" + val destinationFile = File(cacheDir, destinationFileName) + capturedImageUri = FileProvider.getUriForFile( + this, + "org.mifos.mobilewallet.mifospay.provider", + destinationFile + ) + intent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri) + startActivityForResult(intent, REQUEST_CAMERA) + } else { + // permission denied, boo! Disable the + // functionality that depends on this permission. + Toaster.showToast( + this, + getString(R.string.need_camera_permission_to_click_profile_picture) + ) + } + return + } + + REQUEST_READ_EXTERNAL_STORAGE -> { + + // If request is cancelled, the result arrays are empty. + if (grantResults.isNotEmpty() + && grantResults[0] == PackageManager.PERMISSION_GRANTED + ) { + // permission was granted, yay! Do the + // storage-related task you need to do. + val i = Intent( + Intent.ACTION_PICK, + MediaStore.Images.Media.EXTERNAL_CONTENT_URI + ) + startActivityForResult(i, REQUEST_READ_IMAGE) + } else { + // permission denied, boo! Disable the + // functionality that depends on this permission. + showToast(Constants.NEED_EXTERNAL_STORAGE_PERMISSION_TO_BROWSE_IMAGES) + } + } + } + } + + override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { + super.onActivityResult(requestCode, resultCode, data) + if (resultCode == RESULT_OK) { + if (requestCode == REQUEST_READ_IMAGE && data != null) { + val selectedImageUri = data.data + selectedImageUri?.let { startCrop(it) } + } else if (requestCode == UCrop.REQUEST_CROP) { + handleCropResult(data!!) + } else if (requestCode == REQUEST_CAMERA && capturedImageUri != null) { + startCrop(capturedImageUri!!) + } + } + } + + private fun startCrop(uri: Uri) { + val destinationFileName = UUID.randomUUID().toString() + ".jpg" + var uCrop = UCrop.of(uri, Uri.fromFile(File(cacheDir, destinationFileName))) + uCrop = getConfiguredUCrop(uCrop) + uCrop.start(this@EditProfileActivity) + } + + private fun getConfiguredUCrop(uCrop: UCrop): UCrop { + var uCrop = uCrop + uCrop = uCrop.withAspectRatio(1f, 1f) + val size = resources.getDimension(R.dimen.user_profile_image_size).toInt() + if (size > UCrop.MIN_SIZE) { + uCrop = uCrop.withMaxResultSize(size, size) + } + val options = UCrop.Options() + options.setCompressionFormat(Bitmap.CompressFormat.JPEG) + options.setCompressionQuality(80) + options.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary)) + options.setStatusBarColor(ContextCompat.getColor(this, R.color.colorPrimaryDark)) + options.setActiveWidgetColor(ContextCompat.getColor(this, R.color.primaryBlue)) + options.setToolbarWidgetColor(ContextCompat.getColor(this, R.color.black)) + options.setCropFrameColor(ContextCompat.getColor(this, R.color.clickedblue)) + options.setCircleDimmedLayer(true) + options.setShowCropFrame(true) + options.setShowCropGrid(true) + options.setCropGridColumnCount(2) + options.setCropGridRowCount(2) + return uCrop.withOptions(options) + } + + override fun removeProfileImage() { + // TODO: Remove image from database + } + + override fun changeProfileImage() { + pickImageFromGallery() + } + + override fun clickProfileImage() { + clickProfilePicFromCamera() + } + + private fun pickImageFromGallery() { + if (Build.VERSION.SDK_INT >= 23 && + ContextCompat.checkSelfPermission( + applicationContext, + Manifest.permission.READ_EXTERNAL_STORAGE + ) + != PackageManager.PERMISSION_GRANTED + ) { + requestPermissions( + arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), + REQUEST_READ_EXTERNAL_STORAGE + ) + } else { + val i = Intent(Intent.ACTION_GET_CONTENT) + .setType("image/*") + .addCategory(Intent.CATEGORY_OPENABLE) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + val mimeTypes = arrayOf("image/jpeg", "image/png") + i.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes) + } + startActivityForResult( + Intent.createChooser( + i, + getString(R.string.label_select_picture) + ), REQUEST_READ_IMAGE + ) + } + } + + private fun handleCropResult(result: Intent) { + val resultUri = UCrop.getOutput(result) + if (resultUri != null) { + ivUserImage!!.setImageURI(resultUri) + } + } + + private fun clickProfilePicFromCamera() { + if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission( + this, + Manifest.permission.CAMERA + ) != PackageManager.PERMISSION_GRANTED + ) { + + // Permission is not granted + requestPermissions(arrayOf(Manifest.permission.CAMERA), REQUEST_CAMERA) + } else { + + // Permission has already been granted + val intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE) + val destinationFileName = UUID.randomUUID().toString() + ".jpg" + val destinationFile = File(cacheDir, destinationFileName) + capturedImageUri = FileProvider.getUriForFile( + this, + "org.mifos.mobilewallet.mifospay.provider", + destinationFile + ) + intent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri) + startActivityForResult(intent, REQUEST_CAMERA) + } + } + + override fun showDiscardChangesDialog() { + dialogBox!!.setOnPositiveListener { dialog, _ -> + mPresenter!!.onDialogPositive() + dialog.dismiss() + } + dialogBox!!.setOnNegativeListener { dialog, which -> + mPresenter!!.onDialogNegative() + dialog.dismiss() + } + dialogBox!!.show( + this, R.string.discard_changes_and_exit, + R.string.discard_changes_and_exit_description, R.string.accept, R.string.cancel + ) + } + + override fun onUpdateEmailError(message: String?) { + showToast(message) + } + + override fun onUpdateMobileError(message: String?) { + showToast(message) + } + + override fun showToast(message: String?) { + Toaster.showToast(this, message) + } + + override fun startProgressBar() { + showProgressDialog(Constants.PLEASE_WAIT) + } + + override fun stopProgressBar() { + hideProgressDialog() + } + + override fun closeActivity() { + finish() + } + + override fun setPresenter(presenter: EditProfileContract.EditProfilePresenter?) { + mEditProfilePresenter = presenter + } + + override fun onBackPressed() { + if (fabSaveChanges!!.isOrWillBeShown) { + mPresenter!!.handleExitOnUnsavedChanges() + } else { + super.onBackPressed() + } + } + + public override fun onPause() { + super.onPause() + cancelProgressDialog() + if (dialogBox != null) { + dialogBox!!.dismiss() + } + } + + internal inner class BottomSheetViews { + @OnClick(R.id.ll_change_profile_image_dialog_row) + fun onChangeProfileImageClicked() { + mPresenter!!.handleProfileImageChangeRequest() + bottomSheetDialog!!.dismiss() + } + + @OnClick(R.id.ll_remove_profile_image_dialog_row) + fun onRemoveProfileImageClicked() { + mEditProfilePresenter!!.handleProfileImageRemoved() + bottomSheetDialog!!.dismiss() + } + + @OnClick(R.id.ll_click_profile_image_dialog_row) + fun onClickProfileImageClicked() { + mEditProfilePresenter!!.handleClickProfileImageRequest() + bottomSheetDialog!!.dismiss() + } + } + + companion object { + private const val REQUEST_READ_IMAGE = 1 + private const val REQUEST_READ_EXTERNAL_STORAGE = 7 + private const val REQUEST_CAMERA = 0 + } +} \ No newline at end of file