| | |
| | | import android.annotation.SuppressLint |
| | | import android.app.AlertDialog |
| | | import android.content.Intent |
| | | import android.os.Build |
| | | import android.os.Bundle |
| | | import android.os.Handler |
| | | import android.os.Looper |
| | | import android.view.Gravity |
| | | import android.view.LayoutInflater |
| | | import android.view.MenuItem |
| | | import android.view.MotionEvent |
| | | import android.view.View |
| | | import android.view.WindowInsets |
| | | import android.widget.LinearLayout |
| | | import android.widget.TextView |
| | | import androidx.appcompat.widget.Toolbar |
| | | import android.widget.Button |
| | | import androidx.lifecycle.ViewModelProvider |
| | | import androidx.lifecycle.lifecycleScope |
| | | import com.example.firstapp.databinding.ActivitySettingBinding |
| | | import com.example.firstapp.R |
| | | import com.example.firstapp.core.Core |
| | | import com.example.firstapp.database.service.RetrofitClient |
| | | import com.example.firstapp.ui.home.HomeViewModel |
| | | import com.example.firstapp.utils.Log |
| | | import kotlinx.coroutines.launch |
| | | |
| | | /** |
| | | * An example full-screen activity that shows and hides the system UI (i.e. |
| | |
| | | // |
| | | // }) |
| | | |
| | | |
| | | // 退出登录 |
| | | logout() |
| | | |
| | | // 账号注销 |
| | | accountClose() |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | private fun accountClose(){ |
| | | |
| | | |
| | | binding.accountClose.setOnClickListener { |
| | | |
| | | val dialogView = LayoutInflater.from(this).inflate(R.layout.account_close_dialog_custom, null) |
| | | |
| | | val dialog = AlertDialog.Builder(this) |
| | | .setView(dialogView) |
| | | .create() |
| | | |
| | | dialog.window?.setBackgroundDrawableResource(R.drawable.dialog_background) |
| | | |
| | | val btnConfirm = dialogView.findViewById<Button>(R.id.btnConfirm) |
| | | btnConfirm.setOnClickListener { |
| | | dialog.dismiss() |
| | | } |
| | | |
| | | val btnCancel = dialogView.findViewById<Button>(R.id.btnCancel) |
| | | btnCancel.setOnClickListener { |
| | | // 关闭账户 |
| | | lifecycleScope.launch { |
| | | try { |
| | | // 清除本地的数据库 |
| | | RetrofitClient.apiService.closeAccount() |
| | | |
| | | Core.code.deleteAll() |
| | | Core.msg.deleteAll() |
| | | Core.keyword.deleteAll() |
| | | // Core.reminder.deleteAll() |
| | | |
| | | dialog.dismiss() |
| | | // 跳转到 LoginActivity 并清除之前的任务栈 |
| | | var intent = Intent(this@SettingActivity, LoginActivity::class.java) |
| | | intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK |
| | | startActivity(intent) |
| | | // 关闭当前页面 |
| | | finish() |
| | | |
| | | } catch (ex: Exception) { |
| | | Log.e("关闭账户", ex.message ?: "关闭账户报错") |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | dialog.show() |
| | | |
| | | } |
| | | } |
| | | |
| | | private fun logout(){ |
| | | |
| | | binding.settingExit.setOnClickListener { |
| | | // 弹出确认退出的对话框 |
| | | val alertDialog = AlertDialog.Builder(this) |
| | |
| | | val intent = Intent(this, LoginActivity::class.java) |
| | | intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK |
| | | startActivity(intent) |
| | | |
| | | // 关闭当前页面 |
| | | finish() |
| | | } |
| | |
| | | // 显示对话框 |
| | | alertDialog.show() |
| | | } |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | // 点击返回按钮时调用 |