|
@@ -2,9 +2,7 @@ package com.cr.cruav
|
|
|
|
|
|
import android.Manifest
|
|
|
import android.app.Activity
|
|
|
-import android.app.ActivityManager
|
|
|
import android.content.Context
|
|
|
-import android.content.Intent
|
|
|
import android.content.pm.PackageManager
|
|
|
import android.os.Build
|
|
|
import android.os.Bundle
|
|
@@ -12,16 +10,16 @@ import android.util.DisplayMetrics
|
|
|
import android.util.Log
|
|
|
import android.view.View
|
|
|
import android.view.View.OnClickListener
|
|
|
-import android.view.WindowManager
|
|
|
import android.widget.Switch
|
|
|
import android.widget.TextView
|
|
|
import androidx.core.app.ActivityCompat
|
|
|
import androidx.core.content.ContextCompat
|
|
|
-import androidx.core.content.PermissionChecker
|
|
|
import com.cr.common.DataManager
|
|
|
import com.cr.common.DatabaseManager
|
|
|
import com.cr.common.FileManager
|
|
|
+import com.cr.data.CrConfig
|
|
|
import com.cr.data.CrUtil
|
|
|
+import com.cr.data.CrUtil.Companion.onStart
|
|
|
import com.cr.dialog.DialogNormal
|
|
|
import com.cr.dialog.DialogNormal.DialogNormalListener
|
|
|
import com.cr.event.EventFragmentBarAction
|
|
@@ -53,10 +51,10 @@ class AvLogin : CrActivity(), OnClickListener {
|
|
|
)
|
|
|
|
|
|
// define: 2023/3/31 动态权限列表
|
|
|
- val missingPermission = arrayListOf<String>()
|
|
|
+ private val missingPermission = arrayListOf<String>()
|
|
|
|
|
|
// define: 2023/3/31 权限检测返回码
|
|
|
- val REQUEST_PERMISSION_CODE: Int = 12345
|
|
|
+ private val REQUEST_PERMISSION_CODE: Int = 12345
|
|
|
|
|
|
// define: 2023/3/30 设置页面
|
|
|
var fragIpAndCom: FragmentSetIpAndCom? = null
|
|
@@ -65,7 +63,7 @@ class AvLogin : CrActivity(), OnClickListener {
|
|
|
var lblVersion: TextView? = null
|
|
|
var txtUserName: CrEditTextWidget? = null
|
|
|
var txtPassword: CrEditTextWidget? = null
|
|
|
- var switchSavePassword :Switch? = null
|
|
|
+ var switchSavePassword: Switch? = null
|
|
|
|
|
|
/**
|
|
|
* 创建视图
|
|
@@ -74,6 +72,8 @@ class AvLogin : CrActivity(), OnClickListener {
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
setContentView(R.layout.av_login)
|
|
|
+ // todo: 2023/4/10 初始化上下文
|
|
|
+ this.context = this
|
|
|
// todo: 2023/3/30 初始化页面
|
|
|
fragIpAndCom = FragmentSetIpAndCom()
|
|
|
fragIpAndCom?.let {
|
|
@@ -117,15 +117,16 @@ class AvLogin : CrActivity(), OnClickListener {
|
|
|
// todo: 2023/4/6 初始化账号密码
|
|
|
txtUserName = findViewById(R.id.login_username)
|
|
|
txtPassword = findViewById(R.id.login_password)
|
|
|
+ txtPassword?.setIsPassword(true)
|
|
|
switchSavePassword = findViewById(R.id.switch_password)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 页面初始化
|
|
|
*/
|
|
|
- private fun initPage(){
|
|
|
+ private fun initPage() {
|
|
|
// todo: 2023/4/6 获取存储的用户并显示
|
|
|
- var user:UserModel = DataManager.getUser()
|
|
|
+ var user: UserModel = DataManager.getUser()
|
|
|
txtUserName?.setContent(user.userId!!)
|
|
|
txtPassword?.setContent(user.userPwd!!)
|
|
|
}
|
|
@@ -155,8 +156,8 @@ class AvLogin : CrActivity(), OnClickListener {
|
|
|
R.id.login_btn_login -> {
|
|
|
var userName: String? = txtUserName?.checkBlank("请输入账号!") ?: return
|
|
|
var passWord: String? = txtPassword?.checkBlank("请输入密码!") ?: return
|
|
|
- var isSave:Boolean? = switchSavePassword?.isChecked
|
|
|
- login(userName!!,passWord!!,isSave!!)
|
|
|
+ var isSave: Boolean? = switchSavePassword?.isChecked
|
|
|
+ checkUserInfo(userName!!, passWord!!, isSave!!)
|
|
|
}
|
|
|
R.id.login_btn_set -> {
|
|
|
fragIpAndCom?.let {
|
|
@@ -173,27 +174,46 @@ class AvLogin : CrActivity(), OnClickListener {
|
|
|
* @param password String 密码
|
|
|
* @param isSave Boolean 是否保存
|
|
|
*/
|
|
|
- private fun login(userName:String,password:String,isSave:Boolean){
|
|
|
- if(isSave){
|
|
|
- if(DataManager.saveUser(userName,password)) {
|
|
|
- CrUtil.showMessage("登录成功并保存")
|
|
|
- var user:UserModel = UserModel(userName, password)
|
|
|
- TCPDataTask.getInstance().sendJSON(NetManager.getServerUrl("appQueryUser"),user,object :TCPDataTask.OnChangeListener{
|
|
|
- override fun onSuccess(jsonArray: JSONArray) {
|
|
|
- CrUtil.print(jsonArray.optString(0))
|
|
|
- }
|
|
|
- override fun onFailed(message: String) {
|
|
|
- CrUtil.print(message)
|
|
|
- }
|
|
|
- })
|
|
|
+ private fun checkUserInfo(userName: String, password: String, isSave: Boolean) {
|
|
|
+ if (isSave) {
|
|
|
+ if (DataManager.saveUser(userName, password)) {
|
|
|
+ // todo: 2023/4/10 登录系统
|
|
|
+ login(userName, password)
|
|
|
}
|
|
|
- }else{
|
|
|
- if(DataManager.deleteUser())
|
|
|
- CrUtil.showMessage("登录成功不保存")
|
|
|
+ } else {
|
|
|
+ if (DataManager.deleteUser())
|
|
|
+ // todo: 2023/4/10 登录系统
|
|
|
+ login(userName, password)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 登录系统
|
|
|
+ * @param userName String 账号Id
|
|
|
+ * @param password String 密码
|
|
|
+ */
|
|
|
+ private fun login(userName: String, password: String) {
|
|
|
+ var user = UserModel(userName, password)
|
|
|
+ // todo: 2023/4/10 向服务器发起认证消息
|
|
|
+ TCPDataTask.getInstance().sendJSON(
|
|
|
+ NetManager.getServerUrl("appQueryUser"),
|
|
|
+ user,
|
|
|
+ object : TCPDataTask.OnChangeListener {
|
|
|
+ // todo: 2023/4/10 成功
|
|
|
+ override fun onSuccess(jsonArray: JSONArray) {
|
|
|
+ CrConfig.user = UserModel.toModel(jsonArray.optString(0))
|
|
|
+ context!!.onStart<AvMain>()
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo: 2023/4/10 失败
|
|
|
+ override fun onFailed(message: String) {
|
|
|
+ showError(message)
|
|
|
+ }
|
|
|
+ },context,"认证中...")
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
* 检测权限
|
|
|
*/
|
|
|
private fun checkAndRequestPermissions() {
|