修改个人信息

This commit is contained in:
2026-05-21 09:49:02 +08:00
parent e6a3c1605f
commit c31be55fe6
7 changed files with 212 additions and 17 deletions

View File

@@ -12,6 +12,11 @@ import android.view.WindowManager
import androidx.fragment.app.DialogFragment
import com.example.defenseapplication.R
import com.example.defenseapplication.databinding.DialogPhoneModifyBinding
import com.example.defenseapplication.utils.RetrofitNetwork
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
//手机号弹窗
class PhoneModifyDialogFragment : DialogFragment() {
@@ -86,7 +91,7 @@ class PhoneModifyDialogFragment : DialogFragment() {
ToastUtils.showToast(requireContext(), getString(R.string.invalid_phone))
return@setOnClickListener
}
startCountDown()
sendCode(phone)
}
binding.btnNegative.setOnClickListener {
@@ -109,6 +114,27 @@ class PhoneModifyDialogFragment : DialogFragment() {
}
}
private fun sendCode(phone: String) {
CoroutineScope(Dispatchers.IO).launch {
try {
val response = RetrofitNetwork.getNetworkService().getCode(phone)
withContext(Dispatchers.Main) {
if (response.code == 200) {
ToastUtils.showToast(requireContext(), getString(R.string.code_sent_success))
startCountDown()
} else {
ToastUtils.showToast(requireContext(), getString(R.string.code_send_failed))
}
}
} catch (e: Exception) {
e.printStackTrace()
withContext(Dispatchers.Main) {
ToastUtils.showToast(requireContext(), getString(R.string.network_error))
}
}
}
}
private fun startCountDown() {
binding.tvSendCode.isEnabled = false
countDownTimer = object : CountDownTimer(60000, 1000) {