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
e279fc5c
Commit
e279fc5c
authored
Apr 02, 2022
by
zhaopengxiang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
提交管理员密码权限管理功能
parent
74b77308
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
229 additions
and
27 deletions
+229
-27
build.gradle
app/build.gradle
+1
-0
AccountService.kt
.../main/java/com/miya/fastcashier/service/AccountService.kt
+22
-7
LoginActivity.kt
app/src/main/java/com/miya/fastcashier/ui/LoginActivity.kt
+35
-14
MainActivity.kt
app/src/main/java/com/miya/fastcashier/ui/MainActivity.kt
+21
-6
RefundActivity.kt
app/src/main/java/com/miya/fastcashier/ui/RefundActivity.kt
+10
-0
AccountPasswordManageKit.java
...ya/fastcashier/utils/manage/AccountPasswordManageKit.java
+140
-0
No files found.
app/build.gradle
View file @
e279fc5c
...
@@ -86,4 +86,5 @@ dependencies {
...
@@ -86,4 +86,5 @@ dependencies {
implementation
'com.elvishew:xlog:1.10.1'
implementation
'com.elvishew:xlog:1.10.1'
debugImplementation
'com.squareup.leakcanary:leakcanary-android:2.7'
debugImplementation
'com.squareup.leakcanary:leakcanary-android:2.7'
implementation
'com.contrarywind:Android-PickerView:4.1.9'
implementation
'com.contrarywind:Android-PickerView:4.1.9'
implementation
'com.guolindev.permissionx:permissionx:1.6.1'
}
}
\ No newline at end of file
app/src/main/java/com/miya/fastcashier/service/AccountService.kt
View file @
e279fc5c
...
@@ -3,12 +3,13 @@ package com.miya.fastcashier.service
...
@@ -3,12 +3,13 @@ package com.miya.fastcashier.service
import
com.miya.fastcashier.beans.SelfCashierAccountInfo
import
com.miya.fastcashier.beans.SelfCashierAccountInfo
import
com.sdy.miya.moblie.component.pay.platform.bean.MiyaOrderRefundResponse
import
com.sdy.miya.moblie.component.pay.platform.bean.MiyaOrderRefundResponse
object
AccountService
{
object
AccountService
{
private
var
selfCashierAccountInfo
:
SelfCashierAccountInfo
?
=
null
;
private
var
selfCashierAccountInfo
:
SelfCashierAccountInfo
?
=
null
;
private
var
userName
:
String
?
=
""
private
var
userName
:
String
?
=
""
private
var
accountPassword
:
String
?
=
""
fun
setAccountInfo
(
selfCashierAccountInfo
:
SelfCashierAccountInfo
?)
{
fun
setAccountInfo
(
selfCashierAccountInfo
:
SelfCashierAccountInfo
?)
{
this
.
selfCashierAccountInfo
=
selfCashierAccountInfo
this
.
selfCashierAccountInfo
=
selfCashierAccountInfo
}
}
...
@@ -16,11 +17,25 @@ object AccountService{
...
@@ -16,11 +17,25 @@ object AccountService{
return
selfCashierAccountInfo
;
return
selfCashierAccountInfo
;
}
}
fun
setUserName
(
userName
:
String
)
{
fun
setUserName
(
userName
:
String
)
{
this
.
userName
=
userName
this
.
userName
=
userName
}
}
fun
getUserName
():
String
{
fun
getUserName
():
String
{
return
userName
.
toString
();
return
userName
.
toString
();
}
}
fun
getAccountPassword
():
String
{
return
accountPassword
.
toString
();
}
fun
setAccountPassword
(
accountPassword
:
String
)
{
this
.
accountPassword
=
accountPassword
}
fun
clear
(){
selfCashierAccountInfo
=
null
userName
=
""
accountPassword
=
""
}
}
}
\ No newline at end of file
app/src/main/java/com/miya/fastcashier/ui/LoginActivity.kt
View file @
e279fc5c
package
com.miya.fastcashier.ui
package
com.miya.fastcashier.ui
import
android.Manifest
import
android.content.Intent
import
android.content.Intent
import
android.os.Bundle
import
android.os.Bundle
import
android.text.Editable
import
android.text.Editable
...
@@ -11,16 +12,17 @@ import android.widget.EditText
...
@@ -11,16 +12,17 @@ import android.widget.EditText
import
androidx.appcompat.app.AppCompatActivity
import
androidx.appcompat.app.AppCompatActivity
import
androidx.lifecycle.Observer
import
androidx.lifecycle.Observer
import
androidx.lifecycle.ViewModelProvider
import
androidx.lifecycle.ViewModelProvider
import
com.blankj.utilcode.util.FileUtils
import
com.blankj.utilcode.util.ToastUtils
import
com.miya.fastcashier.databinding.ActivityLoginBinding
import
com.miya.fastcashier.databinding.ActivityLoginBinding
import
com.miya.fastcashier.service.AccountService
import
com.miya.fastcashier.service.AccountService
import
com.miya.fastcashier.utils.clickWithTrigger
import
com.miya.fastcashier.utils.clickWithTrigger
import
com.miya.fastcashier.utils.withTrigger
import
com.miya.fastcashier.viewmodel.LoginViewModel
import
com.miya.fastcashier.viewmodel.LoginViewModel
import
com.permissionx.guolindev.PermissionX
import
com.permissionx.guolindev.callback.RequestCallback
import
com.tencent.mmkv.MMKV
import
com.tencent.mmkv.MMKV
class
LoginActivity
:
AppCompatActivity
()
{
class
LoginActivity
:
AppCompatActivity
()
{
private
lateinit
var
loginViewModel
:
LoginViewModel
private
lateinit
var
loginViewModel
:
LoginViewModel
...
@@ -55,8 +57,8 @@ class LoginActivity : AppCompatActivity() {
...
@@ -55,8 +57,8 @@ class LoginActivity : AppCompatActivity() {
result
.
getOrNull
().
also
{
result
.
getOrNull
().
also
{
it
?.
let
{
it1
->
it
?.
let
{
it1
->
kv
.
encode
(
"username"
,
username
.
text
.
toString
())
kv
.
encode
(
"username"
,
username
.
text
.
toString
())
kv
.
encode
(
"password"
,
password
.
text
.
toString
())
kv
.
encode
(
"password"
,
password
.
text
.
toString
())
AccountService
.
setUserName
(
username
.
text
.
toString
())
AccountService
.
setUserName
(
username
.
text
.
toString
())
AccountService
.
setAccountInfo
(
it1
)
AccountService
.
setAccountInfo
(
it1
)
...
@@ -92,7 +94,7 @@ class LoginActivity : AppCompatActivity() {
...
@@ -92,7 +94,7 @@ class LoginActivity : AppCompatActivity() {
}
}
setOnEditorActionListener
{
_
,
actionId
,
_
->
setOnEditorActionListener
{
_
,
actionId
,
_
->
when
(
actionId
)
{
when
(
actionId
)
{
EditorInfo
.
IME_ACTION_NEXT
->{
EditorInfo
.
IME_ACTION_NEXT
->
{
password
.
requestFocus
()
password
.
requestFocus
()
password
.
text
?.
let
{
password
.
setSelection
(
it
.
length
)
};
password
.
text
?.
let
{
password
.
setSelection
(
it
.
length
)
};
}
}
...
@@ -111,7 +113,7 @@ class LoginActivity : AppCompatActivity() {
...
@@ -111,7 +113,7 @@ class LoginActivity : AppCompatActivity() {
setOnEditorActionListener
{
_
,
actionId
,
_
->
setOnEditorActionListener
{
_
,
actionId
,
_
->
when
(
actionId
)
{
when
(
actionId
)
{
EditorInfo
.
IME_ACTION_DONE
->{
EditorInfo
.
IME_ACTION_DONE
->
{
loading
.
visibility
=
View
.
VISIBLE
;
loading
.
visibility
=
View
.
VISIBLE
;
loginViewModel
.
login
(
loginViewModel
.
login
(
username
.
text
.
toString
(),
username
.
text
.
toString
(),
...
@@ -123,8 +125,7 @@ class LoginActivity : AppCompatActivity() {
...
@@ -123,8 +125,7 @@ class LoginActivity : AppCompatActivity() {
}
}
binding
.
login
.
clickWithTrigger
{
binding
.
login
.
clickWithTrigger
{
loading
.
visibility
=
View
.
VISIBLE
checkPermissions
()
loginViewModel
.
login
(
username
.
text
.
toString
(),
password
.
text
.
toString
())
}
}
}
}
...
@@ -135,14 +136,34 @@ class LoginActivity : AppCompatActivity() {
...
@@ -135,14 +136,34 @@ class LoginActivity : AppCompatActivity() {
password
.
setText
(
it
)
password
.
setText
(
it
)
}
}
if
(!
TextUtils
.
isEmpty
(
username
.
text
)
if
(!
TextUtils
.
isEmpty
(
username
.
text
)
&&
!
TextUtils
.
isEmpty
(
password
.
text
)){
&&
!
TextUtils
.
isEmpty
(
password
.
text
)
)
{
loading
.
visibility
=
View
.
VISIBLE
;
loading
.
visibility
=
View
.
VISIBLE
;
loginViewModel
.
login
(
username
.
text
.
toString
(),
password
.
text
.
toString
())
loginViewModel
.
login
(
username
.
text
.
toString
(),
password
.
text
.
toString
())
}
}
}
}
private
fun
checkPermissions
()
{
PermissionX
.
init
(
this
)
.
permissions
(
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
)
.
request
(
RequestCallback
{
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
()
)
}
else
{
ToastUtils
.
showShort
(
"请检查权限后重试"
)
}
})
}
/**
/**
* Extension function to simplify setting an afterTextChanged action to EditText components.
* Extension function to simplify setting an afterTextChanged action to EditText components.
*/
*/
...
...
app/src/main/java/com/miya/fastcashier/ui/MainActivity.kt
View file @
e279fc5c
...
@@ -17,6 +17,7 @@ import com.miya.fastcashier.ui.dialog.MessageDialog
...
@@ -17,6 +17,7 @@ import com.miya.fastcashier.ui.dialog.MessageDialog
import
com.miya.fastcashier.utils.CenterToasty
import
com.miya.fastcashier.utils.CenterToasty
import
com.miya.fastcashier.utils.DateSelectHelper
import
com.miya.fastcashier.utils.DateSelectHelper
import
com.miya.fastcashier.utils.clickWithTrigger
import
com.miya.fastcashier.utils.clickWithTrigger
import
com.miya.fastcashier.utils.manage.AccountPasswordManageKit
import
com.miya.fastcashier.viewmodel.MainViewModel
import
com.miya.fastcashier.viewmodel.MainViewModel
import
com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import
com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import
com.tencent.mmkv.MMKV
import
com.tencent.mmkv.MMKV
...
@@ -51,9 +52,7 @@ class MainActivity : BaseActivity() {
...
@@ -51,9 +52,7 @@ class MainActivity : BaseActivity() {
PriceInputActivity
.
start
(
this
@MainActivity
)
PriceInputActivity
.
start
(
this
@MainActivity
)
}
}
llRefund
.
clickWithTrigger
{
llRefund
.
clickWithTrigger
{
val
intent
=
Intent
()
toRefund
()
intent
.
setClass
(
this
@MainActivity
,
RefundActivity
::
class
.
java
)
startActivity
(
intent
)
}
}
tvPrintLast
.
clickWithTrigger
{
tvPrintLast
.
clickWithTrigger
{
try
{
try
{
...
@@ -100,6 +99,20 @@ class MainActivity : BaseActivity() {
...
@@ -100,6 +99,20 @@ class MainActivity : BaseActivity() {
}
}
initData
()
initData
()
checkAccountPassword
()
}
private
fun
toRefund
()
{
AccountPasswordManageKit
.
getInstance
()
.
loadAccountPassword
(
this
,
AccountPasswordManageKit
.
AccountPasswordManageCallback
{
if
(
"121212"
.
equals
(
it
))
RefundActivity
.
start
(
this
@MainActivity
)
else
CenterToasty
.
error
(
this
@MainActivity
,
"密码错误"
).
show
()
})
}
private
fun
checkAccountPassword
()
{
AccountPasswordManageKit
.
getInstance
().
checkAccountPassword
(
this
)
}
}
private
fun
initData
()
{
private
fun
initData
()
{
...
@@ -140,10 +153,12 @@ class MainActivity : BaseActivity() {
...
@@ -140,10 +153,12 @@ class MainActivity : BaseActivity() {
alertDialog
=
null
alertDialog
=
null
run
{
run
{
MMKV
.
defaultMMKV
().
clearAll
()
MMKV
.
defaultMMKV
().
clearAll
()
AccountService
.
setAccountInfo
(
null
)
AccountService
.
clear
(
)
val
intent
=
Intent
()
val
intent
=
Intent
()
intent
.
setClass
(
this
@MainActivity
,
intent
.
setClass
(
LoginActivity
::
class
.
java
)
this
@MainActivity
,
LoginActivity
::
class
.
java
)
startActivity
(
intent
)
startActivity
(
intent
)
finish
()
finish
()
}
}
...
...
app/src/main/java/com/miya/fastcashier/ui/RefundActivity.kt
View file @
e279fc5c
package
com.miya.fastcashier.ui
package
com.miya.fastcashier.ui
import
android.content.Intent
import
android.os.Bundle
import
android.os.Bundle
import
android.view.KeyEvent
import
android.view.KeyEvent
import
android.widget.Toast
import
android.widget.Toast
import
androidx.lifecycle.ViewModelProvider
import
androidx.lifecycle.ViewModelProvider
import
com.miya.fastcashier.config.IntentExtra
import
com.miya.fastcashier.databinding.ActivityRefundBinding
import
com.miya.fastcashier.databinding.ActivityRefundBinding
import
com.miya.fastcashier.ui.dialog.MessageDialog
import
com.miya.fastcashier.ui.dialog.MessageDialog
import
com.miya.fastcashier.ui.dialog.NumberManualDialog
import
com.miya.fastcashier.ui.dialog.NumberManualDialog
...
@@ -12,6 +14,7 @@ import com.miya.fastcashier.utils.CenterToasty
...
@@ -12,6 +14,7 @@ import com.miya.fastcashier.utils.CenterToasty
import
com.miya.fastcashier.utils.ScanGunKeyEventHelper
import
com.miya.fastcashier.utils.ScanGunKeyEventHelper
import
com.miya.fastcashier.utils.clickWithTrigger
import
com.miya.fastcashier.utils.clickWithTrigger
import
com.miya.fastcashier.viewmodel.PayViewModel
import
com.miya.fastcashier.viewmodel.PayViewModel
import
com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
class
RefundActivity
:
BaseActivity
()
{
class
RefundActivity
:
BaseActivity
()
{
...
@@ -22,6 +25,13 @@ class RefundActivity : BaseActivity() {
...
@@ -22,6 +25,13 @@ class RefundActivity : BaseActivity() {
private
var
scanGunKeyEventHelper
:
ScanGunKeyEventHelper
=
ScanGunKeyEventHelper
()
private
var
scanGunKeyEventHelper
:
ScanGunKeyEventHelper
=
ScanGunKeyEventHelper
()
companion
object
{
fun
start
(
context
:
BaseActivity
)
{
val
intent
=
Intent
(
context
,
RefundActivity
::
class
.
java
)
context
.
startActivity
(
intent
)
}
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
super
.
onCreate
(
savedInstanceState
)
...
...
app/src/main/java/com/miya/fastcashier/utils/manage/AccountPasswordManageKit.java
0 → 100644
View file @
e279fc5c
package
com
.
miya
.
fastcashier
.
utils
.
manage
;
import
android.Manifest
;
import
android.os.Environment
;
import
android.text.TextUtils
;
import
com.blankj.utilcode.util.FileIOUtils
;
import
com.blankj.utilcode.util.FileUtils
;
import
com.blankj.utilcode.util.LogUtils
;
import
com.blankj.utilcode.util.ToastUtils
;
import
com.miya.fastcashier.service.AccountService
;
import
com.permissionx.guolindev.PermissionX
;
import
java.util.concurrent.Executors
;
import
androidx.appcompat.app.AppCompatActivity
;
/**
* 类描述:账户管理员密码管理
* 概述:
* 创建人:zpxiang
* 创建时间:2022/4/1
* 修改人:
* 修改时间:
*/
public
class
AccountPasswordManageKit
{
private
static
final
String
FileDir
=
Environment
.
getExternalStorageDirectory
()
+
"/fastcashier/"
;
public
static
final
String
ACCOUNT_DEFAULT_PASSWORD
=
"123456"
;
private
static
AccountPasswordManageKit
sInstance
;
private
AccountPasswordManageKit
()
{
}
public
interface
AccountPasswordManageCallback
{
void
onPasswordGet
(
String
password
);
}
public
static
AccountPasswordManageKit
getInstance
()
{
if
(
sInstance
==
null
)
{
sInstance
=
new
AccountPasswordManageKit
();
}
return
sInstance
;
}
public
void
checkAccountPassword
(
AppCompatActivity
context
)
{
String
accountPassword
=
AccountService
.
INSTANCE
.
getAccountPassword
();
if
(!
TextUtils
.
isEmpty
(
accountPassword
))
return
;
PermissionX
.
init
(
context
)
.
permissions
(
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
)
.
request
((
allGranted
,
grantedList
,
deniedList
)
->
{
if
(
allGranted
)
{
initAccountPassword
(
context
,
null
);
}
else
{
ToastUtils
.
showShort
(
"请检查权限后重试"
);
}
});
}
public
String
getCurrentAccountFilePath
(){
return
FileDir
.
concat
(
AccountService
.
INSTANCE
.
getUserName
());
}
public
void
initAccountPassword
(
AppCompatActivity
context
,
AccountPasswordManageCallback
callback
)
{
LogUtils
.
e
(
"path"
,
getCurrentAccountFilePath
());
if
(
FileUtils
.
isFileExists
(
getCurrentAccountFilePath
()))
{
Executors
.
newCachedThreadPool
().
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
String
password
=
FileIOUtils
.
readFile2String
(
getCurrentAccountFilePath
());
AccountService
.
INSTANCE
.
setAccountPassword
(
password
);
context
.
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
if
(
callback
!=
null
){
callback
.
onPasswordGet
(
password
);
}
LogUtils
.
e
(
"FileExists"
,
password
);
}
});
}
});
return
;
}
AccountService
.
INSTANCE
.
setAccountPassword
(
ACCOUNT_DEFAULT_PASSWORD
);
if
(
callback
!=
null
){
callback
.
onPasswordGet
(
ACCOUNT_DEFAULT_PASSWORD
);
LogUtils
.
e
(
"FileNoExists"
,
ACCOUNT_DEFAULT_PASSWORD
);
}
if
(
FileUtils
.
createOrExistsFile
(
getCurrentAccountFilePath
()))
{
Executors
.
newCachedThreadPool
().
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
LogUtils
.
e
(
"creat File"
,
ACCOUNT_DEFAULT_PASSWORD
);
FileIOUtils
.
writeFileFromString
(
getCurrentAccountFilePath
(),
ACCOUNT_DEFAULT_PASSWORD
);
}
});
}
}
public
void
loadAccountPassword
(
AppCompatActivity
context
,
AccountPasswordManageCallback
callback
)
{
String
accountPassword
=
AccountService
.
INSTANCE
.
getAccountPassword
();
if
(
TextUtils
.
isEmpty
(
accountPassword
)){
PermissionX
.
init
(
context
)
.
permissions
(
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
)
.
request
((
allGranted
,
grantedList
,
deniedList
)
->
{
if
(
allGranted
)
{
initAccountPassword
(
context
,
callback
);
}
else
{
ToastUtils
.
showShort
(
"请检查权限后重试"
);
}
});
}
else
{
if
(
callback
!=
null
){
callback
.
onPasswordGet
(
accountPassword
);
LogUtils
.
e
(
"loadAccountPassword"
,
accountPassword
);
}
}
}
public
void
updateAccountPassword
(
String
password
)
{
if
(
TextUtils
.
isEmpty
(
password
))
return
;
AccountService
.
INSTANCE
.
setAccountPassword
(
password
);
if
(
FileUtils
.
isFileExists
(
getCurrentAccountFilePath
()))
{
FileUtils
.
deleteAllInDir
(
getCurrentAccountFilePath
());
}
if
(
FileUtils
.
createOrExistsFile
(
getCurrentAccountFilePath
()))
{
Executors
.
newCachedThreadPool
().
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
FileIOUtils
.
writeFileFromString
(
getCurrentAccountFilePath
(),
password
);
}
});
}
}
}
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