From a916e581b7170a9f9217441502edec6cac395d59 Mon Sep 17 00:00:00 2001 From: Jorge Blacio Date: Mon, 21 Oct 2019 17:14:04 -0500 Subject: [PATCH] Added a 'no thanks' to the rate me dialog. Also fixed a couple of bugs. --- build.gradle | 4 +-- .../kotlin/com/criptext/mail/BaseActivity.kt | 36 +++++++++++++++++-- .../scenes/signup/SignUpSceneController.kt | 15 ++++++-- .../scenes/signup/data/RegisterUserWorker.kt | 4 +++ .../criptext/mail/utils/apputils/AppRater.kt | 8 +++-- .../utils/ui/GeneralDialogConfirmation.kt | 2 ++ .../res/drawable/label_button_center_bg.xml | 11 ++++++ .../layout/general_confirmation_dialog.xml | 13 +++++++ src/main/res/values-es/strings.xml | 5 +-- src/main/res/values/strings.xml | 5 +-- .../signup/data/RegisterUserWorkerTest.kt | 1 + 11 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 src/main/res/drawable/label_button_center_bg.xml diff --git a/build.gradle b/build.gradle index 19791a647..c1a52fd74 100644 --- a/build.gradle +++ b/build.gradle @@ -47,8 +47,8 @@ android { defaultConfig { minSdkVersion 21 targetSdkVersion 28 - versionCode 94 - versionName "0.21.17" + versionCode 95 + versionName "0.21.18" applicationId "com.criptext.mail" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" multiDexEnabled true diff --git a/src/main/kotlin/com/criptext/mail/BaseActivity.kt b/src/main/kotlin/com/criptext/mail/BaseActivity.kt index dedf79a53..8d422dc77 100644 --- a/src/main/kotlin/com/criptext/mail/BaseActivity.kt +++ b/src/main/kotlin/com/criptext/mail/BaseActivity.kt @@ -78,6 +78,10 @@ import com.criptext.mail.utils.mailtemplates.REMailTemplate import com.criptext.mail.utils.mailtemplates.SupportMailTemplate import com.criptext.mail.utils.ui.ActivityMenu import com.criptext.mail.utils.ui.StartGuideTapped +import com.criptext.mail.validation.AccountDataValidator +import com.criptext.mail.validation.FormData +import com.criptext.mail.validation.FormInputState +import com.criptext.mail.validation.TextInput import com.github.omadahealth.lollipin.lib.PinCompatActivity import com.github.omadahealth.lollipin.lib.managers.AppLock import com.google.android.gms.auth.api.signin.GoogleSignIn @@ -198,6 +202,25 @@ abstract class BaseActivity: PinCompatActivity(), IHostActivity { domain = savedInstanceState.getString("domain")!! ) } + SIGN_UP_MODEL -> { + val signUpModel = SignUpSceneModel( + isMultiple = savedInstanceState.getBoolean("isMultiple") + ) + val username = savedInstanceState.getString("username")!! + signUpModel.username.copy(value = username, + state = FormInputState.Unknown()) + val fullName = savedInstanceState.getString("fullName")!! + signUpModel.fullName.copy(value = fullName, + state = FormInputState.Unknown()) + signUpModel.password = savedInstanceState.getString("password")!! + signUpModel.confirmPassword = savedInstanceState.getString("confirmPassword")!! + signUpModel.passwordState = FormInputState.Unknown() + val recoveryEmail = savedInstanceState.getString("recoveryEmail")!! + signUpModel.recoveryEmail.copy(value = recoveryEmail, + state = FormInputState.Unknown()) + signUpModel.checkTermsAndConditions = savedInstanceState.getBoolean("checkTermsAndConditions") + signUpModel + } else -> null } }else @@ -342,6 +365,16 @@ abstract class BaseActivity: PinCompatActivity(), IHostActivity { outState.putString("recipientId", currentModel.recipientId) outState.putString("domain", currentModel.domain) } + is SignUpSceneModel -> { + outState.putString("type", SIGN_UP_MODEL) + outState.putBoolean("isMultiple", currentModel.isMultiple) + outState.putString("username", currentModel.username.value) + outState.putString("fullName", currentModel.fullName.value) + outState.putString("password", currentModel.password) + outState.putString("confirmPassword", currentModel.confirmPassword) + outState.putString("recoveryEmail", currentModel.recoveryEmail.value) + outState.putBoolean("checkTermsAndConditions", currentModel.checkTermsAndConditions) + } } } @@ -794,7 +827,6 @@ abstract class BaseActivity: PinCompatActivity(), IHostActivity { // set initial state cachedModels[MailboxActivity::class.java] = MailboxSceneModel() cachedModels[SignInActivity::class.java] = SignInSceneModel() - cachedModels[SignUpActivity::class.java] = SignUpSceneModel() cachedModels[SettingsActivity::class.java] = SettingsModel() cachedModels[ChangePasswordActivity::class.java] = ChangePasswordModel() } @@ -806,12 +838,12 @@ abstract class BaseActivity: PinCompatActivity(), IHostActivity { private const val EMAIL_DETAIL_MODEL = "EmailDetailModel" private const val COMPOSER_MODEL = "ComposerModel" - private const val PIN_LOCK_MODEL = "PinLockModel" private const val PRIVACY_MODEL = "PrivacyModel" private const val PROFILE_MODEL = "ProfileModel" private const val RECOVERY_EMAIL_MODEL = "RecoveryEmailModel" private const val REPLY_TO_MODEL = "ReplyToModel" private const val SIGNATURE_MODEL = "SignatureModel" + private const val SIGN_UP_MODEL = "SignUpModel" } enum class RequestCode { diff --git a/src/main/kotlin/com/criptext/mail/scenes/signup/SignUpSceneController.kt b/src/main/kotlin/com/criptext/mail/scenes/signup/SignUpSceneController.kt index cb79637d2..5101d3a15 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/signup/SignUpSceneController.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/signup/SignUpSceneController.kt @@ -224,9 +224,10 @@ class SignUpSceneController( private fun onCheckedUsernameAvailability(result: SignUpResult.CheckUsernameAvailability) { when (result) { is SignUpResult.CheckUsernameAvailability.Success -> { - if (result.isAvailable) + if (result.isAvailable) { scene.setUsernameState(FormInputState.Valid()) - else { + toggleCreateAccountButton() + } else { val newState = FormInputState.Error(UIMessage(R.string.taken_username_error)) model.username = model.username.copy(state = newState) scene.setUsernameState(newState) @@ -319,6 +320,16 @@ class SignUpSceneController( override fun onStart(activityMessage: ActivityMessage?): Boolean { dataSource.listener = dataSourceListener scene.showFormHolder() + if(model.username.value.isNotEmpty()) { + scene.resetSceneWidgetsFromModel(model.username, model.fullName, model.password, + model.confirmPassword, model.recoveryEmail, model.checkTermsAndConditions) + uiObserver.onUsernameChangedListener(model.username.value) + uiObserver.onFullNameTextChangeListener(model.fullName.value) + uiObserver.onPasswordChangedListener(model.password) + uiObserver.onConfirmPasswordChangedListener(model.confirmPassword) + uiObserver.onCheckedOptionChanged(model.checkTermsAndConditions) + toggleCreateAccountButton() + } scene.initListeners( uiObserver = uiObserver ) diff --git a/src/main/kotlin/com/criptext/mail/scenes/signup/data/RegisterUserWorker.kt b/src/main/kotlin/com/criptext/mail/scenes/signup/data/RegisterUserWorker.kt index 315654bb4..cac7b5e27 100644 --- a/src/main/kotlin/com/criptext/mail/scenes/signup/data/RegisterUserWorker.kt +++ b/src/main/kotlin/com/criptext/mail/scenes/signup/data/RegisterUserWorker.kt @@ -79,6 +79,10 @@ class RegisterUserWorker( } override fun work(reporter: ProgressReporter): RegisterUser? { + if(!isMultiple){ + db.clearAllTables() + keyValueStorage.clearAll() + } val registrationBundle = signalKeyGenerator.register( recipientId = incompleteAccount.username, deviceId = 1) diff --git a/src/main/kotlin/com/criptext/mail/utils/apputils/AppRater.kt b/src/main/kotlin/com/criptext/mail/utils/apputils/AppRater.kt index b5e8cd4ec..5fb0bcbff 100644 --- a/src/main/kotlin/com/criptext/mail/utils/apputils/AppRater.kt +++ b/src/main/kotlin/com/criptext/mail/utils/apputils/AppRater.kt @@ -17,7 +17,7 @@ object AppRater { private const val APP_NAME = "com.criptext.mail"// Package Name private const val DAYS_UNTIL_PROMPT = 3//Min number of days - private const val LAUNCHES_UNTIL_PROMPT = 3//Min number of launches + private const val LAUNCHES_UNTIL_PROMPT = 5//Min number of launches fun appLaunched(ctx: Context, storage: KeyValueStorage) { if (storage.getBool(KeyValueStorage.StringKey.RateDontShowAgain, false)) { @@ -52,12 +52,16 @@ object AppRater { generalDialogConfirmation.showDialog(null) generalDialogConfirmation.btnOk.text = mContext.getLocalizedUIMessage(UIMessage(R.string.rate_us)) generalDialogConfirmation.btnCancel.text = mContext.getLocalizedUIMessage(UIMessage(R.string.rate_remind_later)) + generalDialogConfirmation.btnNoThanks.visibility = View.VISIBLE generalDialogConfirmation.btnOk.setOnClickListener { mContext.startActivity(Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=$APP_NAME"))) storage.putBool(KeyValueStorage.StringKey.RateDontShowAgain, true) generalDialogConfirmation.dismissDialog() } - + generalDialogConfirmation.btnNoThanks.setOnClickListener { + storage.putBool(KeyValueStorage.StringKey.RateDontShowAgain, true) + generalDialogConfirmation.dismissDialog() + } generalDialogConfirmation.btnCancel.setOnClickListener { generalDialogConfirmation.dismissDialog() } diff --git a/src/main/kotlin/com/criptext/mail/utils/ui/GeneralDialogConfirmation.kt b/src/main/kotlin/com/criptext/mail/utils/ui/GeneralDialogConfirmation.kt index f6588eee4..432a18740 100644 --- a/src/main/kotlin/com/criptext/mail/utils/ui/GeneralDialogConfirmation.kt +++ b/src/main/kotlin/com/criptext/mail/utils/ui/GeneralDialogConfirmation.kt @@ -23,6 +23,7 @@ class GeneralDialogConfirmation(val context: Context, val data: DialogData.Dialo private val res = context.resources lateinit var btnOk: Button lateinit var btnCancel: Button + lateinit var btnNoThanks: Button private lateinit var view: View @@ -65,6 +66,7 @@ class GeneralDialogConfirmation(val context: Context, val data: DialogData.Dialo btnOk = view.findViewById(R.id.btn_ok) as Button btnCancel = view.findViewById(R.id.btn_cancel) as Button + btnNoThanks = view.findViewById(R.id.btn_no_thanks) as Button if(!btnOk.hasOnClickListeners()) { btnOk.setOnClickListener { diff --git a/src/main/res/drawable/label_button_center_bg.xml b/src/main/res/drawable/label_button_center_bg.xml new file mode 100644 index 000000000..36a925983 --- /dev/null +++ b/src/main/res/drawable/label_button_center_bg.xml @@ -0,0 +1,11 @@ + + + + + diff --git a/src/main/res/layout/general_confirmation_dialog.xml b/src/main/res/layout/general_confirmation_dialog.xml index e366b5048..58bffd03b 100644 --- a/src/main/res/layout/general_confirmation_dialog.xml +++ b/src/main/res/layout/general_confirmation_dialog.xml @@ -51,6 +51,19 @@ android:layout_weight="0.5" android:layout_height="wrap_content" android:text="@string/cancel" /> +