Skip to content

Commit

Permalink
Update mobile phone number
Browse files Browse the repository at this point in the history
  • Loading branch information
SeniorZhai committed Oct 30, 2024
1 parent 7d0ac6b commit d5b91a2
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ data class AccountRequest(
val public_key_hex: String? = null,
val message_hex: String? = null,
val signature_hex: String? = null,
val salt_base64: String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.fragment.app.viewModels
import one.mixin.android.R
import one.mixin.android.databinding.FragmentComposeBinding
import one.mixin.android.extension.addFragment
import one.mixin.android.ui.landing.MobileFragment.Companion.FROM_LANDING_CREATE
import one.mixin.android.ui.landing.components.CreateAccountPage
import one.mixin.android.util.viewBinding

Expand All @@ -33,7 +34,7 @@ class CreateAccountFragment : Fragment(R.layout.fragment_compose) {
CreateAccountPage({
activity?.addFragment(
this@CreateAccountFragment,
MobileFragment.newInstance(),
MobileFragment.newInstance(from = FROM_LANDING_CREATE),
MobileFragment.TAG,
)
},{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import one.mixin.android.R
import one.mixin.android.databinding.FragmentLandingBinding
import one.mixin.android.extension.addFragment
import one.mixin.android.extension.navTo
import one.mixin.android.ui.landing.MobileFragment.Companion.FROM_LANDING
import one.mixin.android.ui.setting.diagnosis.DiagnosisFragment
import one.mixin.android.util.viewBinding
import one.mixin.android.widget.DebugClickListener
Expand Down Expand Up @@ -49,7 +50,7 @@ class LandingFragment : Fragment(R.layout.fragment_landing) {
binding.continueTv.setOnClickListener {
activity?.addFragment(
this@LandingFragment,
MobileFragment.newInstance(),
MobileFragment.newInstance(from = FROM_LANDING),
MobileFragment.TAG,
)
}
Expand Down
23 changes: 15 additions & 8 deletions app/src/main/java/one/mixin/android/ui/landing/MobileFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ import one.mixin.android.widget.Keyboard
import timber.log.Timber

@AndroidEntryPoint
class MobileFragment : BaseFragment(R.layout.fragment_mobile) {
class MobileFragment: BaseFragment(R.layout.fragment_mobile) {
companion object {
const val TAG: String = "MobileFragment"
const val ARGS_PHONE_NUM = "args_phone_num"
const val ARGS_FROM = "args_from"
const val FROM_LANDING = 0
const val FROM_CHANGE_PHONE_ACCOUNT = 1
const val FROM_DELETE_ACCOUNT = 2
const val FROM_LANDING_CREATE = 1
const val FROM_CHANGE_PHONE_ACCOUNT = 2
const val FROM_DELETE_ACCOUNT = 3

fun newInstance(
pin: String? = null,
Expand Down Expand Up @@ -120,6 +121,8 @@ class MobileFragment : BaseFragment(R.layout.fragment_mobile) {
policyWrapper,
arrayOf(policyUrl, termsUrl),
)
binding.orLl.isVisible = from == FROM_LANDING
binding.mnemonicPhrase.isVisible = from == FROM_LANDING

countryIconIv.setOnClickListener { showCountry() }
countryCodeEt.addTextChangedListener(countryCodeWatcher)
Expand Down Expand Up @@ -200,6 +203,7 @@ class MobileFragment : BaseFragment(R.layout.fragment_mobile) {
if (viewDestroyed()) return

binding.continueBn.isEnabled = true
binding.continueBn.displayedChild = 0
binding.mobileCover.isVisible = true
val phoneNum = anonymousNumber ?: phoneUtil.format(phoneNumber, PhoneNumberUtil.PhoneNumberFormat.E164)
val verificationRequest =
Expand All @@ -226,6 +230,7 @@ class MobileFragment : BaseFragment(R.layout.fragment_mobile) {
verificationRequest.hCaptchaResponse = captchaResponse.second
}
}
binding.continueBn.displayedChild = 1
mobileViewModel.loginVerification(verificationRequest)
.autoDispose(stopScope).subscribe(
{ r: MixinResponse<VerificationResponse> ->
Expand All @@ -239,6 +244,7 @@ class MobileFragment : BaseFragment(R.layout.fragment_mobile) {
return@subscribe
}
hideLoading()

val verificationResponse = r.data as VerificationResponse
if (!r.data?.deactivatedAt.isNullOrBlank() && from == FROM_LANDING) {
LandingDeleteAccountFragment.newInstance(r.data?.deactivatedAt)
Expand Down Expand Up @@ -288,6 +294,7 @@ class MobileFragment : BaseFragment(R.layout.fragment_mobile) {
if (viewDestroyed()) return

binding.continueBn.isEnabled = true
binding.continueBn.displayedChild = 0
binding.mobileCover.isVisible = false
}

Expand All @@ -303,8 +310,8 @@ class MobileFragment : BaseFragment(R.layout.fragment_mobile) {

private fun hideLoading() {
if (viewDestroyed()) return

binding.continueBn.isEnabled = true
binding.continueBn.displayedChild = 0
binding.mobileCover.isVisible = false
captchaView?.hide()
}
Expand Down Expand Up @@ -602,17 +609,17 @@ class MobileFragment : BaseFragment(R.layout.fragment_mobile) {
binding.keyboard.animate().translationY(0f).start()
} else {
if (binding.mobileEt.text.isNullOrEmpty()) {
binding.orLl.isVisible = true
binding.mnemonicPhrase.isVisible = true
binding.orLl.isVisible = from == FROM_LANDING
binding.mnemonicPhrase.isVisible = from == FROM_LANDING
}
binding.keyboard.animate().translationY(300.dp.toFloat()).start()
}
}

private fun handleTextChange(s: Editable?) {
if (s.isNullOrEmpty() && !binding.mobileEt.hasFocus() && !binding.countryCodeEt.hasFocus()) {
binding.orLl.isVisible = true
binding.mnemonicPhrase.isVisible = true
binding.orLl.isVisible = from == FROM_LANDING
binding.mnemonicPhrase.isVisible = from == FROM_LANDING
} else {
binding.orLl.isVisible = false
binding.mnemonicPhrase.isVisible = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@ internal constructor(
id: String,
verificationCode: String,
pin: String,
saltBase64:String? =null,
): MixinResponse<Account> =
accountRepository.changePhone(
id,
AccountRequest(
verificationCode,
purpose = VerificationPurpose.PHONE.name,
pin = pinCipher.encryptPin(pin, TipBody.forPhoneNumberUpdate(id, verificationCode)),
salt_base64 = saltBase64
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ import one.mixin.android.databinding.FragmentVerificationBinding
import one.mixin.android.databinding.ViewVerificationBottomBinding
import one.mixin.android.extension.alert
import one.mixin.android.extension.base64Encode
import one.mixin.android.extension.base64RawURLEncode
import one.mixin.android.extension.defaultSharedPreferences
import one.mixin.android.extension.navTo
import one.mixin.android.extension.openUrl
import one.mixin.android.extension.putInt
import one.mixin.android.session.Session
import one.mixin.android.tip.Tip
import one.mixin.android.tip.exception.TipNetworkException
import one.mixin.android.tip.getTipExceptionMsg
import one.mixin.android.ui.common.PinCodeFragment
import one.mixin.android.ui.landing.LandingActivity.Companion.ARGS_PIN
import one.mixin.android.ui.landing.MobileFragment.Companion.ARGS_FROM
Expand All @@ -47,12 +50,14 @@ import one.mixin.android.ui.landing.MobileFragment.Companion.FROM_DELETE_ACCOUNT
import one.mixin.android.ui.landing.MobileFragment.Companion.FROM_LANDING
import one.mixin.android.ui.setting.VerificationEmergencyIdFragment
import one.mixin.android.ui.setting.delete.DeleteAccountPinBottomSheetDialogFragment
import one.mixin.android.ui.tip.RetryRegister
import one.mixin.android.util.ErrorHandler
import one.mixin.android.util.ErrorHandler.Companion.NEED_CAPTCHA
import one.mixin.android.util.viewBinding
import one.mixin.android.vo.User
import one.mixin.android.widget.BottomSheet
import one.mixin.android.widget.CaptchaView
import javax.inject.Inject

@AndroidEntryPoint
class VerificationFragment : PinCodeFragment(R.layout.fragment_verification) {
Expand Down Expand Up @@ -82,6 +87,9 @@ class VerificationFragment : PinCodeFragment(R.layout.fragment_verification) {

private val viewModel by viewModels<MobileViewModel>()

@Inject
lateinit var tip: Tip

private var mCountDownTimer: CountDownTimer? = null

private val pin: String? by lazy {
Expand Down Expand Up @@ -191,7 +199,13 @@ class VerificationFragment : PinCodeFragment(R.layout.fragment_verification) {
showLoading()
handleMixinResponse(
invokeNetwork = {
viewModel.changePhone(requireArguments().getString(ARGS_ID)!!, binding.pinVerificationView.code(), pin = pin!!)
if (pin != null) {
val seed = tip.getOrRecoverTipPriv(requireContext(), pin!!).getOrThrow()
val (_, saltBase64) = tip.generateSaltAndEncryptedSaltBase64(pin!!, seed)
viewModel.changePhone(requireArguments().getString(ARGS_ID)!!, binding.pinVerificationView.code(), pin = pin!!, saltBase64)
} else {
viewModel.changePhone(requireArguments().getString(ARGS_ID)!!, binding.pinVerificationView.code(), pin = pin!!)
}
},
successBlock = {
withContext(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ class PinSettingFragment : BaseFragment(R.layout.fragment_pin_setting) {
biometricsRl.setOnClickListener(biometricsClickListener)
val open = defaultSharedPreferences.getBoolean(Constants.Account.PREF_BIOMETRICS, false)
if (open) {
biometricsRl.setBackgroundResource(R.drawable.ripple_round_window_top)
biometricsSc.isChecked = true
timeRl.visibility = VISIBLE
setTimeDesc()
} else {
biometricsRl.setBackgroundResource(R.drawable.ripple_round_window)
biometricsSc.isChecked = false
timeRl.visibility = GONE
}
Expand Down Expand Up @@ -118,6 +120,7 @@ class PinSettingFragment : BaseFragment(R.layout.fragment_pin_setting) {
private fun updateWhenSuccess() {
binding.biometricsSc.isChecked = true
binding.timeRl.visibility = VISIBLE
binding.biometricsRl.setBackgroundResource(R.drawable.ripple_round_window_top)
setTimeDesc()
defaultSharedPreferences.putLong(Constants.BIOMETRIC_PIN_CHECK, System.currentTimeMillis())
defaultSharedPreferences.putBoolean(Constants.Account.PREF_BIOMETRICS, true)
Expand All @@ -126,6 +129,7 @@ class PinSettingFragment : BaseFragment(R.layout.fragment_pin_setting) {
private fun resetBiometricLayout() {
binding.biometricsSc.isChecked = false
binding.timeRl.visibility = GONE
binding.biometricsRl.setBackgroundResource(R.drawable.ripple_round_window)
BiometricUtil.deleteKey(requireContext())
}
}
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/bg_round_window_bottom_8dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp" />
<solid android:color="?attr/bg_window" />
</shape>
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/bg_round_window_top_8dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<corners android:topLeftRadius="8dp"
android:topRightRadius="8dp"/>
<solid android:color="?attr/bg_window"/>
</shape>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ripple_round_window_bottom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item>
<shape android:shape="rectangle">
<corners
android:bottomRightRadius="8dp"
android:bottomLeftRadius="8dp" />
<solid android:color="?attr/bg_window" />
</shape>
</item>
</ripple>
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ripple_round_window_top.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?attr/colorControlHighlight">
<item>
<shape android:shape="rectangle">
<corners android:topRightRadius="8dp" android:topLeftRadius="8dp" />
<solid android:color="?attr/bg_window" />
</shape>
</item>
</ripple>
18 changes: 13 additions & 5 deletions app/src/main/res/layout/fragment_emergency_contact.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/bg_window"
android:background="?attr/bg_white"
android:orientation="vertical">

<one.mixin.android.widget.TitleView
Expand Down Expand Up @@ -58,7 +58,9 @@
android:id="@+id/enable_rl"
android:layout_width="match_parent"
android:layout_height="@dimen/item_contact_height"
android:background="?attr/bg_white"
android:background="@drawable/bg_round_window_8dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:foreground="?attr/selectableItemBackground">

<TextView
Expand All @@ -78,7 +80,9 @@
android:layout_width="match_parent"
android:layout_height="@dimen/item_contact_height"
android:layout_marginBottom="24dp"
android:background="?attr/bg_white"
android:background="@drawable/bg_round_window_8dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:foreground="?attr/selectableItemBackground"
android:visibility="gone">

Expand Down Expand Up @@ -109,7 +113,9 @@
android:layout_width="match_parent"
android:layout_height="@dimen/item_contact_height"
android:layout_marginBottom="24dp"
android:background="?attr/bg_white"
android:background="@drawable/bg_round_window_8dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:foreground="?attr/selectableItemBackground"
android:visibility="gone">

Expand All @@ -128,7 +134,9 @@
android:id="@+id/delete_rl"
android:layout_width="match_parent"
android:layout_height="@dimen/item_contact_height"
android:background="?attr/bg_white"
android:background="@drawable/bg_round_window_8dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:foreground="?attr/selectableItemBackground"
android:visibility="gone">

Expand Down
21 changes: 19 additions & 2 deletions app/src/main/res/layout/fragment_mobile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mobile_et" />

<Button
<ViewAnimator
style="@style/AppTheme.MaterialButton"
android:id="@+id/continue_bn"
android:layout_width="0dp"
Expand All @@ -134,7 +134,24 @@
android:enabled="false"
app:layout_constraintTop_toBottomOf="@id/introduction_tv"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
app:layout_constraintEnd_toEndOf="parent" >

<TextView
android:id="@+id/continue_tv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/Continue"
android:textColor="@color/white"
android:textSize="14sp" />

<ProgressBar
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:theme="@style/AppTheme.WhiteAccent" />
</ViewAnimator>

<LinearLayout
android:id="@+id/or_ll"
Expand Down
Loading

0 comments on commit d5b91a2

Please sign in to comment.