|
@@ -13,16 +13,21 @@ 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.CrUtil
|
|
|
import com.cr.dialog.DialogNormal
|
|
|
import com.cr.dialog.DialogNormal.DialogNormalListener
|
|
|
import com.cr.event.EventFragmentBarAction
|
|
|
+import com.cr.models.UserModel
|
|
|
import com.cr.pages.FragmentSetIpAndCom
|
|
|
+import com.cr.widget.CrEditTextWidget
|
|
|
import com.squareup.otto.Subscribe
|
|
|
import kotlinx.android.synthetic.main.av_login.*
|
|
|
|
|
@@ -53,6 +58,12 @@ class AvLogin : CrActivity(), OnClickListener {
|
|
|
// define: 2023/3/30 设置页面
|
|
|
var fragIpAndCom: FragmentSetIpAndCom? = null
|
|
|
|
|
|
+ // define: 2023/4/6 初始化控件
|
|
|
+ var lblVersion: TextView? = null
|
|
|
+ var txtUserName: CrEditTextWidget? = null
|
|
|
+ var txtPassword: CrEditTextWidget? = null
|
|
|
+ var switchSavePassword :Switch? = null
|
|
|
+
|
|
|
/**
|
|
|
* 创建视图
|
|
|
* @param savedInstanceState Bundle?
|
|
@@ -66,6 +77,8 @@ class AvLogin : CrActivity(), OnClickListener {
|
|
|
addFragment(it, R.id.av_frm_left_panel)
|
|
|
hideFragment(it)
|
|
|
}
|
|
|
+ // todo: 2023/4/6 初始化控件
|
|
|
+ joinControls()
|
|
|
// todo: 2023/3/30 注册事件
|
|
|
registerListener();
|
|
|
// todo: 2023/3/31 检测权限
|
|
@@ -91,6 +104,30 @@ class AvLogin : CrActivity(), OnClickListener {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 重写挂载控件事件
|
|
|
+ */
|
|
|
+ override fun joinControls() {
|
|
|
+ super.joinControls()
|
|
|
+ // todo: 2023/4/6 初始化版本信息
|
|
|
+ lblVersion = findViewById(R.id.login_version)
|
|
|
+ lblVersion?.text = "{${CrUtil.getVersionName(this)}}"
|
|
|
+ // todo: 2023/4/6 初始化账号密码
|
|
|
+ txtUserName = findViewById(R.id.login_username)
|
|
|
+ txtPassword = findViewById(R.id.login_password)
|
|
|
+ switchSavePassword = findViewById(R.id.switch_password)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 页面初始化
|
|
|
+ */
|
|
|
+ private fun initPage(){
|
|
|
+ // todo: 2023/4/6 获取存储的用户并显示
|
|
|
+ var user:UserModel = DataManager.getUser()
|
|
|
+ txtUserName?.setContent(user.userId!!)
|
|
|
+ txtPassword?.setContent(user.userPwd!!)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 重写注册事件
|
|
|
*/
|
|
|
override fun registerListener() {
|
|
@@ -112,10 +149,13 @@ class AvLogin : CrActivity(), OnClickListener {
|
|
|
*/
|
|
|
override fun onClick(p0: View?) {
|
|
|
when (p0!!.id) {
|
|
|
- R.id.login_btn_login ->
|
|
|
- CrUtil.showMessage("登录")
|
|
|
+ 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!!)
|
|
|
+ }
|
|
|
R.id.login_btn_set -> {
|
|
|
- CrUtil.showMessage("设置")
|
|
|
fragIpAndCom?.let {
|
|
|
showFragment(it)
|
|
|
}
|
|
@@ -125,6 +165,23 @@ class AvLogin : CrActivity(), OnClickListener {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 登录验证
|
|
|
+ * @param userName String 账号
|
|
|
+ * @param password String 密码
|
|
|
+ * @param isSave Boolean 是否保存
|
|
|
+ */
|
|
|
+ private fun login(userName:String,password:String,isSave:Boolean){
|
|
|
+ if(isSave){
|
|
|
+ if(DataManager.saveUser(userName,password)) {
|
|
|
+ CrUtil.showMessage("登录成功并保存")
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if(DataManager.deleteUser())
|
|
|
+ CrUtil.showMessage("登录成功不保存")
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 检测权限
|
|
|
*/
|
|
|
private fun checkAndRequestPermissions() {
|
|
@@ -191,7 +248,7 @@ class AvLogin : CrActivity(), OnClickListener {
|
|
|
// todo: 2023/4/3 拷贝配置库
|
|
|
FileManager.MoveDataBase(this)
|
|
|
// todo: 2023/4/3 判断数据库是否存在 存在则启动
|
|
|
- var databaseIsOpen:Boolean = DatabaseManager.getInstance().openConfigDatabase()
|
|
|
+ var databaseIsOpen: Boolean = DatabaseManager.getInstance().openConfigDatabase()
|
|
|
// todo: 2023/4/3 最终判断是否可以正常使用App
|
|
|
if (FileManager.isExists(CrUtil.PROJECT_PATH) && FileManager.isExists(CrUtil.IMAGE_PATH) && FileManager.isExists(
|
|
|
CrUtil.PROJECT_CACHE_PATH
|
|
@@ -199,7 +256,9 @@ class AvLogin : CrActivity(), OnClickListener {
|
|
|
) {
|
|
|
// todo: 2023/4/3 自检通过 可正常使用
|
|
|
DialogNormal(this, "操作提示", "系统自检通过,可正常使用!").show()
|
|
|
- }else{
|
|
|
+ // todo: 2023/4/6 页面初始化显示
|
|
|
+ initPage()
|
|
|
+ } else {
|
|
|
// todo: 2023/4/3 自检异常 重启App自检
|
|
|
DialogNormal(this, "操作提示", "系统自检异常,请重启App!", object : DialogNormalListener {
|
|
|
override fun completion() {
|
|
@@ -218,7 +277,7 @@ class AvLogin : CrActivity(), OnClickListener {
|
|
|
* @param event EventFragmentBarAction
|
|
|
*/
|
|
|
@Subscribe
|
|
|
- fun onFragmentBar(event:EventFragmentBarAction){
|
|
|
+ fun onFragmentBar(event: EventFragmentBarAction) {
|
|
|
hideFragment(fragIpAndCom!!)
|
|
|
}
|
|
|
|