Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
MiYaFastCashier
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jiangjiantao
MiYaFastCashier
Commits
95fa53f2
Commit
95fa53f2
authored
Jul 05, 2022
by
赵鹏翔
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
业务逻辑调整
parent
1f94afb6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
54 deletions
+47
-54
LoginActivity.kt
app/src/main/java/com/miya/fastcashier/ui/LoginActivity.kt
+37
-45
activity_login.xml
app/src/main/res/layout/activity_login.xml
+10
-9
No files found.
app/src/main/java/com/miya/fastcashier/ui/LoginActivity.kt
View file @
95fa53f2
...
@@ -41,30 +41,24 @@ class LoginActivity : AppCompatActivity() {
...
@@ -41,30 +41,24 @@ class LoginActivity : AppCompatActivity() {
binding
=
ActivityLoginBinding
.
inflate
(
layoutInflater
)
binding
=
ActivityLoginBinding
.
inflate
(
layoutInflater
)
setContentView
(
binding
.
root
)
setContentView
(
binding
.
root
)
val
username
=
binding
.
username
val
password
=
binding
.
password
val
loading
=
binding
.
loading
val
login
=
binding
.
login
val
tvErrInfo
=
binding
.
tvErrInfo
loginViewModel
=
ViewModelProvider
(
this
)
loginViewModel
=
ViewModelProvider
(
this
)
.
get
(
LoginViewModel
::
class
.
java
)
.
get
(
LoginViewModel
::
class
.
java
)
loginViewModel
.
loginLiveData
.
observe
(
this
)
{
result
->
loginViewModel
.
loginLiveData
.
observe
(
this
)
{
result
->
l
oading
.
visibility
=
View
.
GONE
binding
.
vL
oading
.
visibility
=
View
.
GONE
result
.
getOrElse
{
result
.
getOrElse
{
tvEr
rInfo
.
text
=
it
.
message
binding
.
tvErro
rInfo
.
text
=
it
.
message
tvEr
rInfo
.
visibility
=
View
.
VISIBLE
binding
.
tvErro
rInfo
.
visibility
=
View
.
VISIBLE
return
@observe
return
@observe
}
}
result
.
getOrNull
().
also
{
result
.
getOrNull
().
also
{
it
?.
let
{
it1
->
it
?.
let
{
it1
->
val
userName
=
u
sername
.
text
.
toString
()
val
userName
=
binding
.
etU
sername
.
text
.
toString
()
val
passWord
=
p
assword
.
text
.
toString
()
val
passWord
=
binding
.
etP
assword
.
text
.
toString
()
LocalKeyDataMKManageKit
.
putLoginIngfo
(
userName
,
passWord
)
LocalKeyDataMKManageKit
.
putLoginIngfo
(
userName
,
passWord
)
AccountService
.
init
(
it1
,
userName
)
AccountService
.
init
(
it1
,
userName
)
...
@@ -80,75 +74,68 @@ class LoginActivity : AppCompatActivity() {
...
@@ -80,75 +74,68 @@ class LoginActivity : AppCompatActivity() {
loginViewModel
.
loginFormState
.
observe
(
this
@LoginActivity
,
Observer
{
loginViewModel
.
loginFormState
.
observe
(
this
@LoginActivity
,
Observer
{
val
loginState
=
it
?:
return
@Observer
val
loginState
=
it
?:
return
@Observer
l
ogin
.
isEnabled
=
loginState
.
isDataValid
binding
.
btnL
ogin
.
isEnabled
=
loginState
.
isDataValid
if
(
loginState
.
usernameError
!=
null
)
{
if
(
loginState
.
usernameError
!=
null
)
{
u
sername
.
error
=
getString
(
loginState
.
usernameError
)
binding
.
etU
sername
.
error
=
getString
(
loginState
.
usernameError
)
}
}
if
(
loginState
.
passwordError
!=
null
&&
!
TextUtils
.
isEmpty
(
p
assword
.
text
))
{
if
(
loginState
.
passwordError
!=
null
&&
!
TextUtils
.
isEmpty
(
binding
.
etP
assword
.
text
))
{
p
assword
.
error
=
getString
(
loginState
.
passwordError
)
binding
.
etP
assword
.
error
=
getString
(
loginState
.
passwordError
)
}
}
})
})
u
sername
.
apply
{
binding
.
etU
sername
.
apply
{
afterTextChanged
{
afterTextChanged
{
loginViewModel
.
loginDataChanged
(
loginViewModel
.
loginDataChanged
(
u
sername
.
text
.
toString
(),
binding
.
etU
sername
.
text
.
toString
(),
p
assword
.
text
.
toString
()
binding
.
etP
assword
.
text
.
toString
()
)
)
}
}
setOnEditorActionListener
{
_
,
actionId
,
_
->
setOnEditorActionListener
{
_
,
actionId
,
_
->
when
(
actionId
)
{
when
(
actionId
)
{
EditorInfo
.
IME_ACTION_NEXT
->
{
EditorInfo
.
IME_ACTION_NEXT
->
{
p
assword
.
requestFocus
()
binding
.
etP
assword
.
requestFocus
()
password
.
text
?.
let
{
p
assword
.
setSelection
(
it
.
length
)
};
binding
.
etPassword
.
text
?.
let
{
binding
.
etP
assword
.
setSelection
(
it
.
length
)
};
}
}
}
}
false
false
}
}
}
}
p
assword
.
apply
{
binding
.
etP
assword
.
apply
{
afterTextChanged
{
afterTextChanged
{
loginViewModel
.
loginDataChanged
(
loginViewModel
.
loginDataChanged
(
u
sername
.
text
.
toString
(),
binding
.
etU
sername
.
text
.
toString
(),
p
assword
.
text
.
toString
()
binding
.
etP
assword
.
text
.
toString
()
)
)
}
}
setOnEditorActionListener
{
_
,
actionId
,
_
->
setOnEditorActionListener
{
_
,
actionId
,
_
->
when
(
actionId
)
{
when
(
actionId
)
{
EditorInfo
.
IME_ACTION_DONE
->
{
EditorInfo
.
IME_ACTION_DONE
->
{
loading
.
visibility
=
View
.
VISIBLE
;
if
(!
TextUtils
.
isEmpty
(
binding
.
etUsername
.
text
.
toString
())){
loginViewModel
.
login
(
checkPermissions
()
username
.
text
.
toString
(),
}
password
.
text
.
toString
()
)
}
}
}
}
false
false
}
}
binding
.
l
ogin
.
clickWithTrigger
{
binding
.
btnL
ogin
.
clickWithTrigger
{
checkPermissions
()
checkPermissions
()
}
}
}
}
LocalKeyDataMKManageKit
.
getLoginUserName
()
?.
let
{
LocalKeyDataMKManageKit
.
getLoginUserName
()
?.
let
{
u
sername
.
setText
(
it
)
binding
.
etU
sername
.
setText
(
it
)
}
}
LocalKeyDataMKManageKit
.
getLoginUserPassword
()
?.
let
{
LocalKeyDataMKManageKit
.
getLoginUserPassword
()
?.
let
{
p
assword
.
setText
(
it
)
binding
.
etP
assword
.
setText
(
it
)
}
}
if
(!
TextUtils
.
isEmpty
(
username
.
text
)
&&
!
TextUtils
.
isEmpty
(
password
.
text
))
{
if
(!
TextUtils
.
isEmpty
(
binding
.
etUsername
.
text
)
&&
!
TextUtils
.
isEmpty
(
binding
.
etPassword
.
text
))
{
loading
.
visibility
=
View
.
VISIBLE
;
checkPermissions
()
loginViewModel
.
login
(
username
.
text
.
toString
(),
password
.
text
.
toString
()
)
}
}
}
}
private
fun
checkPermissions
()
{
private
fun
checkPermissions
()
{
...
@@ -157,23 +144,28 @@ class LoginActivity : AppCompatActivity() {
...
@@ -157,23 +144,28 @@ class LoginActivity : AppCompatActivity() {
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
)
)
.
request
(
RequestCallback
{
allGranted
:
Boolean
,
grantedList
:
List
<
String
?
>?,
deniedList
:
List
<
String
?
>?
->
.
request
{
allGranted
:
Boolean
,
grantedList
:
List
<
String
?
>?,
deniedList
:
List
<
String
?
>?
->
if
(
allGranted
)
{
if
(
allGranted
)
{
binding
.
loading
.
visibility
=
View
.
VISIBLE
login
()
loginViewModel
.
login
(
binding
.
username
.
text
.
toString
(),
binding
.
password
.
text
.
toString
()
)
}
else
{
}
else
{
ToastUtils
.
showShort
(
"请检查权限后重试"
)
ToastUtils
.
showShort
(
"请检查权限后重试"
)
}
}
})
}
}
private
fun
login
(){
binding
.
vLoading
.
visibility
=
View
.
VISIBLE
loginViewModel
.
login
(
binding
.
etUsername
.
text
.
toString
(),
binding
.
etPassword
.
text
.
toString
()
)
}
}
/**
/**
* Extension function to simplify setting an afterTextChanged action to EditText components.
* Extension function to simplify setting an afterTextChanged action to EditText components.
*/
*/
private
fun
EditText
.
afterTextChanged
(
afterTextChanged
:
(
String
)
->
Unit
)
{
private
fun
EditText
.
afterTextChanged
(
afterTextChanged
:
(
String
)
->
Unit
)
{
this
.
addTextChangedListener
(
object
:
TextWatcher
{
this
.
addTextChangedListener
(
object
:
TextWatcher
{
override
fun
afterTextChanged
(
editable
:
Editable
?)
{
override
fun
afterTextChanged
(
editable
:
Editable
?)
{
afterTextChanged
.
invoke
(
editable
.
toString
())
afterTextChanged
.
invoke
(
editable
.
toString
())
...
...
app/src/main/res/layout/activity_login.xml
View file @
95fa53f2
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
tools:context=
".ui.LoginActivity"
>
tools:context=
".ui.LoginActivity"
>
<com.rengwuxian.materialedittext.MaterialEditText
<com.rengwuxian.materialedittext.MaterialEditText
android:id=
"@+id/username"
android:id=
"@+id/
et_
username"
android:layout_width=
"0dp"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"46dp"
android:layout_marginStart=
"46dp"
...
@@ -25,7 +25,7 @@
...
@@ -25,7 +25,7 @@
app:met_bottomTextSize=
"26sp"
/>
app:met_bottomTextSize=
"26sp"
/>
<com.rengwuxian.materialedittext.MaterialEditText
<com.rengwuxian.materialedittext.MaterialEditText
android:id=
"@+id/password"
android:id=
"@+id/
et_
password"
android:layout_width=
"0dp"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"46dp"
android:layout_marginStart=
"46dp"
...
@@ -39,11 +39,11 @@
...
@@ -39,11 +39,11 @@
android:textSize=
"32sp"
android:textSize=
"32sp"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/username"
app:layout_constraintTop_toBottomOf=
"@+id/
et_
username"
app:met_bottomTextSize=
"26sp"
/>
app:met_bottomTextSize=
"26sp"
/>
<Button
<Button
android:id=
"@+id/login"
android:id=
"@+id/
btn_
login"
android:layout_width=
"656dp"
android:layout_width=
"656dp"
android:layout_height=
"100dp"
android:layout_height=
"100dp"
android:layout_gravity=
"start"
android:layout_gravity=
"start"
...
@@ -56,7 +56,7 @@
...
@@ -56,7 +56,7 @@
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/password"
app:layout_constraintTop_toBottomOf=
"@+id/
et_
password"
app:layout_constraintVertical_bias=
"0.2"
/>
app:layout_constraintVertical_bias=
"0.2"
/>
<ImageView
<ImageView
...
@@ -94,7 +94,7 @@
...
@@ -94,7 +94,7 @@
app:layout_constraintStart_toEndOf=
"@+id/ivLogo"
/>
app:layout_constraintStart_toEndOf=
"@+id/ivLogo"
/>
<TextView
<TextView
android:id=
"@+id/tv
ErrI
nfo"
android:id=
"@+id/tv
_error_i
nfo"
android:layout_width=
"wrap_content"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"账号或密码输入错误,请重新输入"
android:text=
"账号或密码输入错误,请重新输入"
...
@@ -102,13 +102,13 @@
...
@@ -102,13 +102,13 @@
android:textSize=
"24sp"
android:textSize=
"24sp"
android:visibility=
"gone"
android:visibility=
"gone"
app:layout_constraintStart_toEndOf=
"@+id/ivLogo"
app:layout_constraintStart_toEndOf=
"@+id/ivLogo"
app:layout_constraintStart_toStartOf=
"@+id/username"
app:layout_constraintStart_toStartOf=
"@+id/
et_
username"
app:layout_constraintTop_toBottomOf=
"@+id/password"
/>
app:layout_constraintTop_toBottomOf=
"@+id/
et_
password"
/>
<!--封装成一个View-->
<!--封装成一个View-->
<androidx.constraintlayout.widget.ConstraintLayout
<androidx.constraintlayout.widget.ConstraintLayout
android:id=
"@+id/loading"
android:id=
"@+id/
v_
loading"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:visibility=
"gone"
>
android:visibility=
"gone"
>
...
@@ -148,6 +148,7 @@
...
@@ -148,6 +148,7 @@
app:SpinKit_Color=
"@color/white"
/>
app:SpinKit_Color=
"@color/white"
/>
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment