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() {
binding
=
ActivityLoginBinding
.
inflate
(
layoutInflater
)
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
)
.
get
(
LoginViewModel
::
class
.
java
)
loginViewModel
.
loginLiveData
.
observe
(
this
)
{
result
->
l
oading
.
visibility
=
View
.
GONE
binding
.
vL
oading
.
visibility
=
View
.
GONE
result
.
getOrElse
{
tvEr
rInfo
.
text
=
it
.
message
tvEr
rInfo
.
visibility
=
View
.
VISIBLE
binding
.
tvErro
rInfo
.
text
=
it
.
message
binding
.
tvErro
rInfo
.
visibility
=
View
.
VISIBLE
return
@observe
}
result
.
getOrNull
().
also
{
it
?.
let
{
it1
->
val
userName
=
u
sername
.
text
.
toString
()
val
passWord
=
p
assword
.
text
.
toString
()
val
userName
=
binding
.
etU
sername
.
text
.
toString
()
val
passWord
=
binding
.
etP
assword
.
text
.
toString
()
LocalKeyDataMKManageKit
.
putLoginIngfo
(
userName
,
passWord
)
AccountService
.
init
(
it1
,
userName
)
...
...
@@ -80,75 +74,68 @@ class LoginActivity : AppCompatActivity() {
loginViewModel
.
loginFormState
.
observe
(
this
@LoginActivity
,
Observer
{
val
loginState
=
it
?:
return
@Observer
l
ogin
.
isEnabled
=
loginState
.
isDataValid
binding
.
btnL
ogin
.
isEnabled
=
loginState
.
isDataValid
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
))
{
p
assword
.
error
=
getString
(
loginState
.
passwordError
)
if
(
loginState
.
passwordError
!=
null
&&
!
TextUtils
.
isEmpty
(
binding
.
etP
assword
.
text
))
{
binding
.
etP
assword
.
error
=
getString
(
loginState
.
passwordError
)
}
})
u
sername
.
apply
{
binding
.
etU
sername
.
apply
{
afterTextChanged
{
loginViewModel
.
loginDataChanged
(
u
sername
.
text
.
toString
(),
p
assword
.
text
.
toString
()
binding
.
etU
sername
.
text
.
toString
(),
binding
.
etP
assword
.
text
.
toString
()
)
}
setOnEditorActionListener
{
_
,
actionId
,
_
->
when
(
actionId
)
{
EditorInfo
.
IME_ACTION_NEXT
->
{
p
assword
.
requestFocus
()
password
.
text
?.
let
{
p
assword
.
setSelection
(
it
.
length
)
};
binding
.
etP
assword
.
requestFocus
()
binding
.
etPassword
.
text
?.
let
{
binding
.
etP
assword
.
setSelection
(
it
.
length
)
};
}
}
false
}
}
p
assword
.
apply
{
binding
.
etP
assword
.
apply
{
afterTextChanged
{
loginViewModel
.
loginDataChanged
(
u
sername
.
text
.
toString
(),
p
assword
.
text
.
toString
()
binding
.
etU
sername
.
text
.
toString
(),
binding
.
etP
assword
.
text
.
toString
()
)
}
setOnEditorActionListener
{
_
,
actionId
,
_
->
when
(
actionId
)
{
EditorInfo
.
IME_ACTION_DONE
->
{
loading
.
visibility
=
View
.
VISIBLE
;
loginViewModel
.
login
(
username
.
text
.
toString
(),
password
.
text
.
toString
()
)
if
(!
TextUtils
.
isEmpty
(
binding
.
etUsername
.
text
.
toString
())){
checkPermissions
()
}
}
}
false
}
binding
.
l
ogin
.
clickWithTrigger
{
binding
.
btnL
ogin
.
clickWithTrigger
{
checkPermissions
()
}
}
LocalKeyDataMKManageKit
.
getLoginUserName
()
?.
let
{
u
sername
.
setText
(
it
)
binding
.
etU
sername
.
setText
(
it
)
}
LocalKeyDataMKManageKit
.
getLoginUserPassword
()
?.
let
{
p
assword
.
setText
(
it
)
binding
.
etP
assword
.
setText
(
it
)
}
if
(!
TextUtils
.
isEmpty
(
username
.
text
)
&&
!
TextUtils
.
isEmpty
(
password
.
text
))
{
loading
.
visibility
=
View
.
VISIBLE
;
loginViewModel
.
login
(
username
.
text
.
toString
(),
password
.
text
.
toString
()
)
if
(!
TextUtils
.
isEmpty
(
binding
.
etUsername
.
text
)
&&
!
TextUtils
.
isEmpty
(
binding
.
etPassword
.
text
))
{
checkPermissions
()
}
}
private
fun
checkPermissions
()
{
...
...
@@ -157,23 +144,28 @@ class LoginActivity : AppCompatActivity() {
Manifest
.
permission
.
WRITE_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
)
{
binding
.
loading
.
visibility
=
View
.
VISIBLE
loginViewModel
.
login
(
binding
.
username
.
text
.
toString
(),
binding
.
password
.
text
.
toString
()
)
login
()
}
else
{
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.
*/
private
fun
EditText
.
afterTextChanged
(
afterTextChanged
:
(
String
)
->
Unit
)
{
this
.
addTextChangedListener
(
object
:
TextWatcher
{
override
fun
afterTextChanged
(
editable
:
Editable
?)
{
afterTextChanged
.
invoke
(
editable
.
toString
())
...
...
app/src/main/res/layout/activity_login.xml
View file @
95fa53f2
...
...
@@ -8,7 +8,7 @@
tools:context=
".ui.LoginActivity"
>
<com.rengwuxian.materialedittext.MaterialEditText
android:id=
"@+id/username"
android:id=
"@+id/
et_
username"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"46dp"
...
...
@@ -25,7 +25,7 @@
app:met_bottomTextSize=
"26sp"
/>
<com.rengwuxian.materialedittext.MaterialEditText
android:id=
"@+id/password"
android:id=
"@+id/
et_
password"
android:layout_width=
"0dp"
android:layout_height=
"wrap_content"
android:layout_marginStart=
"46dp"
...
...
@@ -39,11 +39,11 @@
android:textSize=
"32sp"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/username"
app:layout_constraintTop_toBottomOf=
"@+id/
et_
username"
app:met_bottomTextSize=
"26sp"
/>
<Button
android:id=
"@+id/login"
android:id=
"@+id/
btn_
login"
android:layout_width=
"656dp"
android:layout_height=
"100dp"
android:layout_gravity=
"start"
...
...
@@ -56,7 +56,7 @@
app:layout_constraintBottom_toBottomOf=
"parent"
app:layout_constraintEnd_toEndOf=
"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"
/>
<ImageView
...
...
@@ -94,7 +94,7 @@
app:layout_constraintStart_toEndOf=
"@+id/ivLogo"
/>
<TextView
android:id=
"@+id/tv
ErrI
nfo"
android:id=
"@+id/tv
_error_i
nfo"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:text=
"账号或密码输入错误,请重新输入"
...
...
@@ -102,13 +102,13 @@
android:textSize=
"24sp"
android:visibility=
"gone"
app:layout_constraintStart_toEndOf=
"@+id/ivLogo"
app:layout_constraintStart_toStartOf=
"@+id/username"
app:layout_constraintTop_toBottomOf=
"@+id/password"
/>
app:layout_constraintStart_toStartOf=
"@+id/
et_
username"
app:layout_constraintTop_toBottomOf=
"@+id/
et_
password"
/>
<!--封装成一个View-->
<androidx.constraintlayout.widget.ConstraintLayout
android:id=
"@+id/loading"
android:id=
"@+id/
v_
loading"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:visibility=
"gone"
>
...
...
@@ -148,6 +148,7 @@
app:SpinKit_Color=
"@color/white"
/>
</LinearLayout>
</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