cloudroam
2025-04-02 754063ec4a78fd80e9db6db12b3bb74653cddf7f
fix : 默认手机号
已修改3个文件
16 ■■■■■ 文件已修改
app/src/main/java/com/example/firstapp/activity/PhoneLoginActivity.kt 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/firstapp/utils/PreferencesManager.kt 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/layout/activity_phone_login.xml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/example/firstapp/activity/PhoneLoginActivity.kt
@@ -10,6 +10,7 @@
import com.example.firstapp.databinding.ActivityPhoneLoginBinding
import com.example.firstapp.ui.login.LoginViewModel
import com.example.firstapp.utils.Log
import com.example.firstapp.utils.PreferencesManager
class PhoneLoginActivity : AppCompatActivity() {
    private lateinit var binding: ActivityPhoneLoginBinding
@@ -28,6 +29,9 @@
    private fun setupViews() {
        binding.apply {
            // 设置上次登录的手机号
            etPhone.setText(PreferencesManager.getLastLoginPhone())
            btnBack.setOnClickListener {
                startActivity(Intent(this@PhoneLoginActivity, LoginActivity::class.java))
                finish()
@@ -48,6 +52,8 @@
                val phone = etPhone.text.toString()
                val code = etCode.text.toString()
                if (phone.length == 11 && code.length == 6) {
                    // 保存登录的手机号
                    PreferencesManager.saveLastLoginPhone(phone)
                    viewModel.login(phone, code)
                } else {
                    Toast.makeText(this@PhoneLoginActivity,
app/src/main/java/com/example/firstapp/utils/PreferencesManager.kt
@@ -8,6 +8,7 @@
    private const val KEY_TOKEN = "user_token"
    private const val KEY_PHONE = "user_phone"
    private const val KEY_FIRST_INSTALL = "first_install"
    private const val LAST_LOGIN_PHONE = "last_login_phone"
    private lateinit var preferences: SharedPreferences
@@ -46,4 +47,12 @@
    fun setFirstInstall(isFirst: Boolean) {
        preferences.edit().putBoolean(KEY_FIRST_INSTALL, isFirst).apply()
    }
    fun saveLastLoginPhone(phone: String) {
        preferences.edit().putString(LAST_LOGIN_PHONE, phone).apply()
    }
    fun getLastLoginPhone(): String {
        return preferences.getString(LAST_LOGIN_PHONE, "") ?: ""
    }
app/src/main/res/layout/activity_phone_login.xml
@@ -43,7 +43,6 @@
            android:layout_height="wrap_content"
            android:background="@null"
            android:hint="请输入手机号"
            android:text="15288241342"
            android:inputType="phone"
            android:maxLength="11"
            android:textSize="16sp"