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
4315f774
Commit
4315f774
authored
Apr 29, 2022
by
赵鹏翔
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature_localdata_optimize' into 'develop'
Feature localdata optimize See merge request
!3
parents
b317908e
2c357f4c
Hide whitespace changes
Inline
Side-by-side
Showing
22 changed files
with
404 additions
and
326 deletions
+404
-326
BaseApplication.kt
app/src/main/java/com/miya/fastcashier/BaseApplication.kt
+2
-1
IntentExtra.kt
app/src/main/java/com/miya/fastcashier/config/IntentExtra.kt
+2
-0
AccountService.kt
.../main/java/com/miya/fastcashier/service/AccountService.kt
+6
-1
PrintService.kt
...rc/main/java/com/miya/fastcashier/service/PrintService.kt
+0
-7
AliPayCodeActivity.kt
...c/main/java/com/miya/fastcashier/ui/AliPayCodeActivity.kt
+13
-25
LoginActivity.kt
app/src/main/java/com/miya/fastcashier/ui/LoginActivity.kt
+16
-19
MainActivity.kt
app/src/main/java/com/miya/fastcashier/ui/MainActivity.kt
+26
-16
PayActivity.kt
app/src/main/java/com/miya/fastcashier/ui/PayActivity.kt
+12
-10
PayCodeActivity.kt
app/src/main/java/com/miya/fastcashier/ui/PayCodeActivity.kt
+4
-16
PayResultActivity.kt
...rc/main/java/com/miya/fastcashier/ui/PayResultActivity.kt
+11
-2
PriceInputActivity.kt
...c/main/java/com/miya/fastcashier/ui/PriceInputActivity.kt
+4
-15
ResetAuthorizePasswordActivity.kt
...com/miya/fastcashier/ui/ResetAuthorizePasswordActivity.kt
+17
-18
SearchOrderActivity.kt
.../main/java/com/miya/fastcashier/ui/SearchOrderActivity.kt
+10
-5
SettingActivity.kt
app/src/main/java/com/miya/fastcashier/ui/SettingActivity.kt
+0
-4
WxPayCodeActivity.kt
...rc/main/java/com/miya/fastcashier/ui/WxPayCodeActivity.kt
+13
-26
AuthorizePasswordInputDialog.kt
...iya/fastcashier/ui/dialog/AuthorizePasswordInputDialog.kt
+7
-7
DateUtils.java
app/src/main/java/com/miya/fastcashier/utils/DateUtils.java
+22
-2
AccountPasswordManageKit.java
...ya/fastcashier/utils/manage/AccountPasswordManageKit.java
+0
-138
AccountPasswordManageKit.kt
...miya/fastcashier/utils/manage/AccountPasswordManageKit.kt
+124
-0
LocalKeyDataMKManageKit.kt
.../miya/fastcashier/utils/manage/LocalKeyDataMKManageKit.kt
+106
-0
LoginViewModel.kt
...ain/java/com/miya/fastcashier/viewmodel/LoginViewModel.kt
+7
-11
PrintViewModel.kt
...ain/java/com/miya/fastcashier/viewmodel/PrintViewModel.kt
+2
-3
No files found.
app/src/main/java/com/miya/fastcashier/BaseApplication.kt
View file @
4315f774
...
...
@@ -18,6 +18,7 @@ import com.miya.fastcashier.utils.ContextUtils
import
com.miya.fastcashier.utils.DateUtils
import
com.miya.fastcashier.utils.DensityUtils
import
com.miya.fastcashier.utils.LogFileUtils
import
com.miya.fastcashier.utils.manage.LocalKeyDataMKManageKit
import
com.miya.fastcashier.utils.manage.OrderRecordManageKit
import
com.miya.print.PrinterManager
import
com.sdy.miya.moblie.component.pay.core.net.MiYaPayMobileApiClient
...
...
@@ -144,7 +145,7 @@ class BaseApplication : MultiDexApplication() {
}
fun
resetConfig
()
{
MMKV
.
defaultMMKV
().
clearAll
()
LocalKeyDataMKManageKit
.
clearCommonData
()
//清除本地订单昨天的流水信息
OrderRecordManageKit
.
clearOrderDataYeaterday
()
//清除本地个人信息
...
...
app/src/main/java/com/miya/fastcashier/config/IntentExtra.kt
View file @
4315f774
...
...
@@ -4,5 +4,7 @@ interface IntentExtra {
companion
object
{
const
val
KEY_EXTRA_DATA
=
"extra_data"
const
val
KEY_EXTRA_TYPE
=
"extra_type"
const
val
KEY_EXTRA_PAYSERVICERESPONSE
=
"payServiceResponse"
const
val
KEY_EXTRA_PRICE
=
"price"
}
}
\ No newline at end of file
app/src/main/java/com/miya/fastcashier/service/AccountService.kt
View file @
4315f774
...
...
@@ -33,9 +33,14 @@ object AccountService {
this
.
accountPassword
=
accountPassword
}
fun
clear
(){
fun
clear
()
{
selfCashierAccountInfo
=
null
userName
=
""
accountPassword
=
""
}
fun
init
(
selfCashierAccountInfo
:
SelfCashierAccountInfo
?,
userName
:
String
)
{
this
.
selfCashierAccountInfo
=
selfCashierAccountInfo
this
.
userName
=
userName
}
}
\ No newline at end of file
app/src/main/java/com/miya/fastcashier/service/PrintService.kt
View file @
4315f774
package
com.miya.fastcashier.service
import
android.text.TextUtils
import
com.blankj.utilcode.util.LogUtils
import
com.esc.LogUlit
import
com.miya.fastcashier.beans.SelfCashierAccountInfo
import
com.miya.fastcashier.beans.ViewOrderStatisticsInfo
import
com.miya.fastcashier.utils.DateUtils
...
...
@@ -10,15 +8,10 @@ import com.miya.fastcashier.utils.MiYaPayPlantformPayWayEnum
import
com.miya.fastcashier.utils.StringPriceFormat
import
com.miya.fastcashier.utils.isEmpty
import
com.miya.fastcashier.utils.manage.OrderRecordManageKit
import
com.miya.print.BuildConfig
import
com.miya.print.IPrinter
import
com.miya.print.PrinterManager
import
com.miya.print.utils.Page58MmPrintUtils
import
com.miya.print.utils.PrintLogger
import
com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import
com.tencent.mmkv.MMKV
import
java.lang.Exception
import
java.lang.RuntimeException
import
java.util.*
object
PrintService
{
...
...
app/src/main/java/com/miya/fastcashier/ui/AliPayCodeActivity.kt
View file @
4315f774
package
com.miya.fastcashier.ui
import
android.annotation.SuppressLint
import
android.content.Intent
import
android.os.Build
import
androidx.appcompat.app.AppCompatActivity
import
android.os.Bundle
import
android.os.Handler
import
android.widget.Toast
import
androidx.annotation.RequiresApi
import
androidx.appcompat.content.res.AppCompatResources
import
androidx.core.content.res.ResourcesCompat
import
androidx.appcompat.app.AppCompatActivity
import
androidx.lifecycle.ViewModelProvider
import
com.alibaba.fastjson.JSON
import
com.blankj.utilcode.util.LogUtils
import
com.blankj.utilcode.util.SizeUtils
import
com.miya.fastcashier.R
import
com.miya.fastcashier.R.mipmap.ic_alipay
import
com.miya.fastcashier.R.mipmap.ic_wxpay
import
com.miya.fastcashier.config.IntentExtra
import
com.miya.fastcashier.databinding.ActivityAliPayCodeBinding
import
com.miya.fastcashier.databinding.ActivityPayCodeBinding
import
com.miya.fastcashier.databinding.ActivityPriceInputBinding
import
com.miya.fastcashier.service.PrintService
import
com.miya.fastcashier.ui.dialog.PayChooseDialog
import
com.miya.fastcashier.utils.CenterToasty
import
com.miya.fastcashier.utils.DateUtils
import
com.miya.fastcashier.utils.StringPriceFormat
import
com.miya.fastcashier.utils.clickWithTrigger
import
com.miya.fastcashier.utils.manage.OrderRecordManageKit
import
com.miya.fastcashier.viewmodel.PayViewModel
import
com.miya.print.utils.BitmapUtils
import
com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import
com.tencent.mmkv.MMKV
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.runBlocking
import
java.util.*
...
...
@@ -43,6 +28,15 @@ class AliPayCodeActivity : AppCompatActivity() {
private
lateinit
var
viewModel
:
PayViewModel
private
lateinit
var
binding
:
ActivityAliPayCodeBinding
companion
object
{
fun
start
(
context
:
BaseActivity
,
payServiceResponse
:
PayServiceResponse
?)
{
val
intent
=
Intent
()
intent
.
setClass
(
context
,
AliPayCodeActivity
::
class
.
java
)
intent
.
putExtra
(
IntentExtra
.
KEY_EXTRA_PAYSERVICERESPONSE
,
payServiceResponse
)
context
.
startActivity
(
intent
)
}
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
...
...
@@ -54,11 +48,9 @@ class AliPayCodeActivity : AppCompatActivity() {
val
llBack
=
binding
.
llBack
val
tvPrice
=
binding
.
tvPrice
val
kv
=
MMKV
.
defaultMMKV
()
llBack
.
clickWithTrigger
{
finish
()
}
val
extra
=
intent
.
getSerializableExtra
(
"payServiceResponse"
)
val
extra
=
intent
.
getSerializableExtra
(
IntentExtra
.
KEY_EXTRA_PAYSERVICERESPONSE
)
extra
?.
let
{
val
payServiceResponse
=
it
as
PayServiceResponse
LogUtils
.
e
(
JSON
.
toJSONString
(
payServiceResponse
))
...
...
@@ -86,11 +78,7 @@ class AliPayCodeActivity : AppCompatActivity() {
result
.
getOrNull
().
also
{
it
?.
let
{
it1
->
OrderRecordManageKit
.
setSerialNumber
()
val
intent
=
Intent
()
intent
.
setClass
(
this
@AliPayCodeActivity
,
PayResultActivity
::
class
.
java
)
intent
.
putExtra
(
"payServiceResponse"
,
it1
)
startActivity
(
intent
)
PayResultActivity
.
start
(
this
@AliPayCodeActivity
,
it1
)
}
}
})
...
...
app/src/main/java/com/miya/fastcashier/ui/LoginActivity.kt
View file @
4315f774
...
...
@@ -13,15 +13,14 @@ import android.widget.EditText
import
androidx.appcompat.app.AppCompatActivity
import
androidx.lifecycle.Observer
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.service.AccountService
import
com.miya.fastcashier.utils.clickWithTrigger
import
com.miya.fastcashier.utils.manage.LocalKeyDataMKManageKit
import
com.miya.fastcashier.viewmodel.LoginViewModel
import
com.permissionx.guolindev.PermissionX
import
com.permissionx.guolindev.callback.RequestCallback
import
com.tencent.mmkv.MMKV
class
LoginActivity
:
AppCompatActivity
()
{
...
...
@@ -29,7 +28,7 @@ class LoginActivity : AppCompatActivity() {
private
lateinit
var
loginViewModel
:
LoginViewModel
private
lateinit
var
binding
:
ActivityLoginBinding
companion
object
{
companion
object
{
fun
start
(
context
:
Context
,
flags
:
Int
)
{
val
intent
=
Intent
(
context
,
LoginActivity
::
class
.
java
)
intent
.
flags
=
Intent
.
FLAG_ACTIVITY_NEW_TASK
or
flags
...
...
@@ -48,8 +47,6 @@ class LoginActivity : AppCompatActivity() {
val
login
=
binding
.
login
val
tvErrInfo
=
binding
.
tvErrInfo
val
kv
=
MMKV
.
defaultMMKV
()
loginViewModel
=
ViewModelProvider
(
this
)
.
get
(
LoginViewModel
::
class
.
java
)
...
...
@@ -66,16 +63,15 @@ class LoginActivity : AppCompatActivity() {
result
.
getOrNull
().
also
{
it
?.
let
{
it1
->
kv
.
encode
(
"username"
,
username
.
text
.
toString
())
kv
.
encode
(
"password"
,
password
.
text
.
toString
())
AccountService
.
setUserName
(
username
.
text
.
toString
())
AccountService
.
setAccountInfo
(
it1
)
val
userName
=
username
.
text
.
toString
()
val
passWord
=
password
.
text
.
toString
()
val
intent
=
Intent
()
intent
.
setClass
(
this
@LoginActivity
,
MainActivity
::
class
.
java
)
startActivity
(
intent
)
LocalKeyDataMKManageKit
.
putLoginIngfo
(
userName
,
passWord
)
AccountService
.
init
(
it1
,
userName
)
//根据本地存储时间,MMKV初始化合理的结算时间
LocalKeyDataMKManageKit
.
handleCompliantBalanceDate
()
MainActivity
.
start
(
this
@LoginActivity
)
finish
()
}
}
...
...
@@ -138,18 +134,19 @@ class LoginActivity : AppCompatActivity() {
}
}
kv
.
decodeString
(
"username"
)
?.
let
{
LocalKeyDataMKManageKit
.
getLoginUserName
(
)
?.
let
{
username
.
setText
(
it
)
}
kv
.
decodeString
(
"password"
)
?.
let
{
LocalKeyDataMKManageKit
.
getLoginUserPassword
(
)
?.
let
{
password
.
setText
(
it
)
}
if
(!
TextUtils
.
isEmpty
(
username
.
text
)
&&
!
TextUtils
.
isEmpty
(
password
.
text
)
)
{
if
(!
TextUtils
.
isEmpty
(
username
.
text
)
&&
!
TextUtils
.
isEmpty
(
password
.
text
))
{
loading
.
visibility
=
View
.
VISIBLE
;
loginViewModel
.
login
(
username
.
text
.
toString
(),
password
.
text
.
toString
())
loginViewModel
.
login
(
username
.
text
.
toString
(),
password
.
text
.
toString
()
)
}
}
...
...
app/src/main/java/com/miya/fastcashier/ui/MainActivity.kt
View file @
4315f774
package
com.miya.fastcashier.ui
import
android.content.Intent
import
androidx.appcompat.app.AppCompatActivity
import
android.os.Bundle
import
android.view.Gravity
import
android.widget.Toast
import
androidx.appcompat.app.AppCompatActivity
import
androidx.fragment.app.FragmentManager
import
androidx.lifecycle.Observer
import
androidx.lifecycle.ViewModelProvider
import
com.miya.fastcashier.R
import
com.miya.fastcashier.databinding.ActivityLoginBinding
import
com.miya.fastcashier.databinding.ActivityMainBinding
import
com.miya.fastcashier.service.AccountService
import
com.miya.fastcashier.service.PrintService
import
com.miya.fastcashier.ui.dialog.AuthorizePasswordInputDialog
import
com.miya.fastcashier.ui.dialog.CommonDialog
import
com.miya.fastcashier.ui.dialog.MessageDialog
import
com.miya.fastcashier.utils.CenterToasty
import
com.miya.fastcashier.utils.DateSelectHelper
import
com.miya.fastcashier.utils.DateUtils
import
com.miya.fastcashier.utils.clickWithTrigger
import
com.miya.fastcashier.utils.manage.AccountPasswordManageKit
import
com.miya.fastcashier.utils.manage.LocalKeyDataMKManageKit
import
com.miya.fastcashier.utils.manage.OrderRecordManageKit
import
com.miya.fastcashier.viewmodel.MainViewModel
import
com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import
com.tencent.mmkv.MMKV
import
java.lang.Exception
import
java.util.*
class
MainActivity
:
BaseActivity
()
{
...
...
@@ -34,6 +27,15 @@ class MainActivity : BaseActivity() {
private
lateinit
var
viewModel
:
MainViewModel
private
var
dateSelectHelper
:
DateSelectHelper
?
=
null
companion
object
{
@JvmStatic
fun
start
(
context
:
AppCompatActivity
)
{
val
intent
=
Intent
()
intent
.
setClass
(
context
,
MainActivity
::
class
.
java
)
context
.
startActivity
(
intent
)
}
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
binding
=
ActivityMainBinding
.
inflate
(
layoutInflater
)
...
...
@@ -64,8 +66,7 @@ class MainActivity : BaseActivity() {
}
}
binding
.
llSearchOrder
.
clickWithTrigger
{
val
intent
=
Intent
(
this
@MainActivity
,
SearchOrderActivity
::
class
.
java
)
startActivity
(
intent
)
SearchOrderActivity
.
start
(
this
@MainActivity
)
}
ivSetting
.
clickWithTrigger
{
...
...
@@ -83,9 +84,14 @@ class MainActivity : BaseActivity() {
binding
.
llBalance
.
clickWithTrigger
{
//上次记录的时间,或者当天0点
va
l
timeMillis
=
MMKV
.
defaultMMKV
().
getLong
(
"balanceDate"
,
0L
)
va
r
timeMillis
=
LocalKeyDataMKManageKit
.
getBalanceDate
(
)
if
(
timeMillis
>
0L
&&
timeMillis
<=
System
.
currentTimeMillis
())
{
viewModel
.
orderStatistics
(
Date
(
timeMillis
),
Date
(),
true
)
val
currentDate
=
Date
()
var
daysAgoCurrent
:
Long
=
DateUtils
.
getDaysAgoCurrent
(
currentDate
,
3
)
if
(
timeMillis
<=
daysAgoCurrent
)
{
timeMillis
=
daysAgoCurrent
}
viewModel
.
orderStatistics
(
Date
(
timeMillis
),
currentDate
,
true
)
}
else
{
val
startDate
=
Calendar
.
getInstance
()
startDate
.
set
(
...
...
@@ -100,6 +106,10 @@ class MainActivity : BaseActivity() {
}
}
binding
.
tvStoreName
.
clickWithTrigger
{
LocalKeyDataMKManageKit
.
putBalanceDate
(
2
)
}
initData
()
checkAccountPassword
()
OrderRecordManageKit
.
clearOrderDataYeaterday
()
...
...
@@ -116,7 +126,7 @@ class MainActivity : BaseActivity() {
}
private
fun
checkAccountPassword
()
{
AccountPasswordManageKit
.
get
Instance
().
checkAccountPassword
(
this
)
AccountPasswordManageKit
.
get
().
checkAccountPassword
(
this
)
}
private
fun
initData
()
{
...
...
@@ -131,7 +141,7 @@ class MainActivity : BaseActivity() {
viewModel
.
balanceLiveData
.
observe
(
this
,
{
result
->
result
.
onSuccess
{
MMKV
.
defaultMMKV
().
putLong
(
"balanceDate"
,
it
)
LocalKeyDataMKManageKit
.
putBalanceDate
(
it
)
}
result
.
onFailure
{
e
->
CenterToasty
.
error
(
this
@MainActivity
,
e
.
message
?:
""
).
show
()
...
...
app/src/main/java/com/miya/fastcashier/ui/PayActivity.kt
View file @
4315f774
...
...
@@ -5,18 +5,15 @@ import android.os.Bundle
import
android.view.KeyEvent
import
android.widget.Toast
import
androidx.lifecycle.ViewModelProvider
import
com.miya.fastcashier.config.IntentExtra
import
com.miya.fastcashier.databinding.ActivityPayBinding
import
com.miya.fastcashier.service.PrintService
import
com.miya.fastcashier.utils.CenterToasty
import
com.miya.fastcashier.utils.DateUtils
import
com.miya.fastcashier.utils.ScanGunKeyEventHelper
import
com.miya.fastcashier.utils.clickWithTrigger
import
com.miya.fastcashier.utils.manage.OrderRecordManageKit
import
com.miya.fastcashier.viewmodel.PayViewModel
import
com.tencent.mmkv.MMKV
import
java.util.*
class
PayActivity
:
BaseActivity
()
{
private
lateinit
var
viewModel
:
PayViewModel
private
lateinit
var
binding
:
ActivityPayBinding
...
...
@@ -24,13 +21,22 @@ class PayActivity : BaseActivity() {
private
lateinit
var
price
:
String
companion
object
{
fun
start
(
context
:
BaseActivity
,
price
:
String
)
{
val
intent
=
Intent
()
intent
.
setClass
(
context
,
PayActivity
::
class
.
java
)
intent
.
putExtra
(
IntentExtra
.
KEY_EXTRA_PRICE
,
price
)
context
.
startActivity
(
intent
)
}
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
binding
=
ActivityPayBinding
.
inflate
(
layoutInflater
)
setContentView
(
binding
.
root
)
viewModel
=
ViewModelProvider
(
this
).
get
(
PayViewModel
::
class
.
java
)
price
=
intent
.
getStringExtra
(
"price"
).
toString
()
price
=
intent
.
getStringExtra
(
IntentExtra
.
KEY_EXTRA_PRICE
).
toString
()
val
tvPayPrice
=
binding
.
tvPayPrice
tvPayPrice
.
text
=
"¥${price.toDouble()}"
...
...
@@ -41,11 +47,7 @@ class PayActivity : BaseActivity() {
}
payResult
.
onSuccess
{
OrderRecordManageKit
.
setSerialNumber
()
val
intent
=
Intent
()
intent
.
setClass
(
this
@PayActivity
,
PayResultActivity
::
class
.
java
)
intent
.
putExtra
(
"payServiceResponse"
,
it
)
startActivity
(
intent
)
PayResultActivity
.
start
(
this
@PayActivity
,
it
)
}
})
binding
.
clTitle
.
llBack
.
clickWithTrigger
{
finish
()
}
...
...
app/src/main/java/com/miya/fastcashier/ui/PayCodeActivity.kt
View file @
4315f774
package
com.miya.fastcashier.ui
import
android.annotation.SuppressLint
import
android.content.Intent
import
android.os.Build
import
androidx.appcompat.app.AppCompatActivity
import
android.os.Bundle
import
android.os.Handler
import
android.widget.Toast
import
androidx.a
nnotation.RequiresApi
import
androidx.a
ppcompat.app.AppCompatActivity
import
androidx.appcompat.content.res.AppCompatResources
import
androidx.core.content.res.ResourcesCompat
import
androidx.lifecycle.ViewModelProvider
import
com.alibaba.fastjson.JSON
import
com.blankj.utilcode.util.LogUtils
import
com.blankj.utilcode.util.SizeUtils
import
com.miya.fastcashier.R
import
com.miya.fastcashier.R.mipmap.ic_alipay
import
com.miya.fastcashier.R.mipmap.ic_wxpay
import
com.miya.fastcashier.config.IntentExtra
import
com.miya.fastcashier.databinding.ActivityPayCodeBinding
import
com.miya.fastcashier.databinding.ActivityPriceInputBinding
import
com.miya.fastcashier.ui.dialog.PayChooseDialog
import
com.miya.fastcashier.utils.CenterToasty
import
com.miya.fastcashier.utils.StringPriceFormat
import
com.miya.fastcashier.utils.clickWithTrigger
...
...
@@ -29,7 +21,6 @@ import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.runBlocking
import
java.util.*
import
kotlin.concurrent.timerTask
class
PayCodeActivity
:
AppCompatActivity
()
{
private
lateinit
var
viewModel
:
PayViewModel
...
...
@@ -52,7 +43,7 @@ class PayCodeActivity : AppCompatActivity() {
tvBack
.
clickWithTrigger
{
finish
()
}
ivBack
.
clickWithTrigger
{
finish
()
}
val
extra
=
intent
.
getSerializableExtra
(
"payServiceResponse"
)
val
extra
=
intent
.
getSerializableExtra
(
IntentExtra
.
KEY_EXTRA_PAYSERVICERESPONSE
)
extra
?.
let
{
val
payServiceResponse
=
it
as
PayServiceResponse
LogUtils
.
e
(
JSON
.
toJSONString
(
payServiceResponse
))
...
...
@@ -89,10 +80,7 @@ class PayCodeActivity : AppCompatActivity() {
result
.
getOrNull
().
also
{
it
?.
let
{
it1
->
val
intent
=
Intent
()
intent
.
setClass
(
this
@PayCodeActivity
,
PayResultActivity
::
class
.
java
)
intent
.
putExtra
(
"payServiceResponse"
,
it1
)
startActivity
(
intent
)
PayResultActivity
.
start
(
this
@PayCodeActivity
,
it1
)
}
}
})
...
...
app/src/main/java/com/miya/fastcashier/ui/PayResultActivity.kt
View file @
4315f774
...
...
@@ -6,6 +6,7 @@ import android.view.View
import
android.widget.Toast
import
androidx.appcompat.app.AppCompatActivity
import
androidx.lifecycle.ViewModelProvider
import
com.miya.fastcashier.config.IntentExtra
import
com.miya.fastcashier.databinding.ActivityPayResultBinding
import
com.miya.fastcashier.utils.CenterToasty
import
com.miya.fastcashier.utils.MiYaPayPlantformPayWayEnum
...
...
@@ -14,11 +15,19 @@ import com.miya.fastcashier.utils.clickWithTrigger
import
com.miya.fastcashier.viewmodel.PrintViewModel
import
com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
class
PayResultActivity
:
AppCompatActivity
()
{
private
lateinit
var
viewModel
:
PrintViewModel
private
lateinit
var
binding
:
ActivityPayResultBinding
companion
object
{
fun
start
(
context
:
AppCompatActivity
,
payServiceResponse
:
PayServiceResponse
?)
{
val
intent
=
Intent
()
intent
.
setClass
(
context
,
PayResultActivity
::
class
.
java
)
intent
.
putExtra
(
IntentExtra
.
KEY_EXTRA_PAYSERVICERESPONSE
,
payServiceResponse
)
context
.
startActivity
(
intent
)
}
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
...
...
@@ -35,7 +44,7 @@ class PayResultActivity : AppCompatActivity() {
val
tvRePrint
=
binding
.
tvRePrint
val
tvGoHome
=
binding
.
tvGoHome
val
extra
=
intent
.
getSerializableExtra
(
"payServiceResponse"
)
val
extra
=
intent
.
getSerializableExtra
(
IntentExtra
.
KEY_EXTRA_PAYSERVICERESPONSE
)
extra
?.
let
{
val
payServiceResponse
=
it
as
PayServiceResponse
tvPayPrice
.
text
=
"¥"
.
plus
(
StringPriceFormat
.
transStringPriceToDecimalString
(
...
...
app/src/main/java/com/miya/fastcashier/ui/PriceInputActivity.kt
View file @
4315f774
...
...
@@ -3,17 +3,13 @@ package com.miya.fastcashier.ui
import
android.content.Intent
import
android.os.Bundle
import
android.text.TextUtils
import
android.util.Log
import
android.view.Gravity
import
android.view.View
import
android.widget.Toast
import
androidx.lifecycle.ViewModelProvider
import
com.miya.fastcashier.R
import
com.miya.fastcashier.config.IntentExtra
import
com.miya.fastcashier.databinding.ActivityPriceInputBinding
import
com.miya.fastcashier.service.AccountService
import
com.miya.fastcashier.ui.dialog.CommonDialog
import
com.miya.fastcashier.ui.dialog.MessageDialog
import
com.miya.fastcashier.ui.dialog.PayChooseDialog
import
com.miya.fastcashier.ui.dialog.PayChooseDialog.GeneratePayCodeClickListener
import
com.miya.fastcashier.utils.CenterToasty
...
...
@@ -24,7 +20,6 @@ import com.miya.fastcashier.viewmodel.PayViewModel
import
com.miya.fastcashier.widget.DecimalKeyboard.DELETE
import
com.miya.fastcashier.widget.DecimalKeyboard.DOT
import
com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import
com.tencent.mmkv.MMKV
import
java.math.BigDecimal
...
...
@@ -94,16 +89,13 @@ class PriceInputActivity : BaseActivity() {
private
fun
initListener
()
{
binding
.
tvScanPayCode
.
clickWithTrigger
{
val
price
=
binding
.
etPrice
.
text
val
price
=
binding
.
etPrice
.
text
.
toString
()
if
(
TextUtils
.
isEmpty
(
price
))
{
CenterToasty
.
error
(
this
,
"请输入金额!"
,
Toast
.
LENGTH_LONG
).
show
()
return
@clickWithTrigger
}
val
intent
=
Intent
()
intent
.
setClass
(
this
@PriceInputActivity
,
PayActivity
::
class
.
java
)
intent
.
putExtra
(
"price"
,
price
)
startActivity
(
intent
)
PayActivity
.
start
(
this
@PriceInputActivity
,
price
)
}
binding
.
tvGeneratePayCode
.
clickWithTrigger
{
...
...
@@ -195,14 +187,11 @@ class PriceInputActivity : BaseActivity() {
result
.
getOrNull
().
also
{
it
?.
let
{
it1
->
val
intent
=
Intent
()
if
(
"1"
==
it1
.
chanelTag
)
{
intent
.
setClass
(
this
@PriceInputActivity
,
WxPayCodeActivity
::
class
.
java
)
WxPayCodeActivity
.
start
(
this
@PriceInputActivity
,
it1
)
}
else
{
intent
.
setClass
(
this
@PriceInputActivity
,
AliPayCodeActivity
::
class
.
java
)
AliPayCodeActivity
.
start
(
this
@PriceInputActivity
,
it1
)
}
intent
.
putExtra
(
"payServiceResponse"
,
it1
)
startActivity
(
intent
)
}
}
})
...
...
app/src/main/java/com/miya/fastcashier/ui/ResetAuthorizePasswordActivity.kt
View file @
4315f774
...
...
@@ -4,17 +4,10 @@ import android.content.Context
import
android.content.Intent
import
android.os.Bundle
import
android.text.TextUtils
import
android.view.Gravity
import
com.blankj.utilcode.util.ToastUtils
import
com.miya.fastcashier.R
import
com.miya.fastcashier.databinding.ActivityResetAuthorizePasswordBinding
import
com.miya.fastcashier.databinding.ActivitySettingBinding
import
com.miya.fastcashier.service.AccountService
import
com.miya.fastcashier.ui.dialog.CommonDialog
import
com.miya.fastcashier.utils.CenterToasty
import
com.miya.fastcashier.utils.clickWithTrigger
import
com.miya.fastcashier.utils.manage.AccountPasswordManageKit
import
com.tencent.mmkv.MMKV
class
ResetAuthorizePasswordActivity
:
BaseActivity
()
{
...
...
@@ -83,20 +76,26 @@ class ResetAuthorizePasswordActivity : BaseActivity() {
return
}
val
accountAuthorizePassword
=
AccountPasswordManageKit
.
get
Instance
().
accountPassword
val
accountAuthorizePassword
=
AccountPasswordManageKit
.
get
().
accountPassword
if
(
TextUtils
.
isEmpty
(
accountAuthorizePassword
))
{
AccountPasswordManageKit
.
getInstance
()
.
loadAccountPassword
(
this
)
{
if
(!
it
.
equals
(
originPassword
))
{
CenterToasty
.
error
(
this
,
"原始密码输入错误!"
).
show
()
}
else
{
updateAuthorizePasswordSucced
(
newPassword
)
}
}
AccountPasswordManageKit
.
get
()
.
loadAccountPassword
(
this
,
object
:
AccountPasswordManageKit
.
AccountPasswordManageCallback
{
override
fun
onPasswordGet
(
password
:
String
?)
{
if
(!
password
.
equals
(
originPassword
))
{
CenterToasty
.
error
(
this
@ResetAuthorizePasswordActivity
,
"原始密码输入错误!"
)
.
show
()
}
else
{
updateAuthorizePasswordSucced
(
newPassword
)
}
}
})
}
else
{
if
(!
accountAuthorizePassword
.
equals
(
originPassword
))
{
CenterToasty
.
error
(
this
,
"原始密码输入错误!"
).
show
()
}
else
{
}
else
{
updateAuthorizePasswordSucced
(
newPassword
)
}
}
...
...
@@ -104,7 +103,7 @@ class ResetAuthorizePasswordActivity : BaseActivity() {
private
fun
updateAuthorizePasswordSucced
(
newPassword
:
String
)
{
CenterToasty
.
success
(
this
,
"修改成功!"
,
1
).
show
()
AccountPasswordManageKit
.
get
Instance
().
updateAccountPassword
(
newPassword
)
AccountPasswordManageKit
.
get
().
updateAccountPassword
(
newPassword
)
finish
()
}
}
\ No newline at end of file
app/src/main/java/com/miya/fastcashier/ui/SearchOrderActivity.kt
View file @
4315f774
package
com.miya.fastcashier.ui
import
android.content.Context
import
android.content.Intent
import
android.graphics.Rect
import
android.os.Bundle
import
android.view.LayoutInflater
...
...
@@ -9,13 +10,11 @@ import android.view.ViewGroup
import
android.widget.Toast
import
androidx.core.content.res.ResourcesCompat
import
androidx.fragment.app.Fragment
import
androidx.lifecycle.Observer
import
androidx.lifecycle.ViewModelProvider
import
androidx.recyclerview.widget.LinearLayoutManager
import
androidx.recyclerview.widget.RecyclerView
import
androidx.viewpager2.adapter.FragmentStateAdapter
import
com.elvishew.xlog.XLog
import
com.google.android.material.tabs.TabLayout
import
com.google.android.material.tabs.TabLayoutMediator
import
com.miya.fastcashier.R
import
com.miya.fastcashier.beans.ViewPayOrderData
...
...
@@ -26,9 +25,8 @@ import com.miya.fastcashier.databinding.ItemSearchOrderListBinding
import
com.miya.fastcashier.service.AccountService
import
com.miya.fastcashier.service.PrintService
import
com.miya.fastcashier.utils.*
import
com.miya.fastcashier.utils.manage.LocalKeyDataMKManageKit
import
com.miya.fastcashier.viewmodel.SearchOrderViewModel
import
com.miya.fastcashier.widget.Divider
import
com.tencent.mmkv.MMKV
/**
* 查单列表
...
...
@@ -36,6 +34,13 @@ import com.tencent.mmkv.MMKV
class
SearchOrderActivity
:
BaseActivity
()
{
private
lateinit
var
binding
:
ActivitySearchOrderBinding
companion
object
{
fun
start
(
context
:
BaseActivity
)
{
val
intent
=
Intent
(
context
,
SearchOrderActivity
::
class
.
java
)
context
.
startActivity
(
intent
)
}
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
binding
=
ActivitySearchOrderBinding
.
inflate
(
LayoutInflater
.
from
(
this
))
...
...
@@ -95,7 +100,7 @@ class SearchOrderFragment(val payType: MiYaPayPlantformPayWayEnum.MiyaPayType) :
}
isEnd
=
false
// onLoading = false
balanceDate
=
MMKV
.
defaultMMKV
().
getLong
(
"balanceDate"
,
0L
)
balanceDate
=
LocalKeyDataMKManageKit
.
getBalanceDate
(
)
val
act
=
requireActivity
()
binding
?.
run
{
adapter
=
SearchOrderListAdapter
(
act
,
arrayListOf
())
...
...
app/src/main/java/com/miya/fastcashier/ui/SettingActivity.kt
View file @
4315f774
...
...
@@ -2,17 +2,13 @@ package com.miya.fastcashier.ui
import
android.content.Context
import
android.content.Intent
import
androidx.appcompat.app.AppCompatActivity
import
android.os.Bundle
import
android.view.Gravity
import
com.blankj.utilcode.util.ToastUtils
import
com.miya.fastcashier.BaseApplication
import
com.miya.fastcashier.R
import
com.miya.fastcashier.databinding.ActivitySettingBinding
import
com.miya.fastcashier.service.AccountService
import
com.miya.fastcashier.ui.dialog.CommonDialog
import
com.miya.fastcashier.utils.clickWithTrigger
import
com.tencent.mmkv.MMKV
class
SettingActivity
:
BaseActivity
()
{
...
...
app/src/main/java/com/miya/fastcashier/ui/WxPayCodeActivity.kt
View file @
4315f774
package
com.miya.fastcashier.ui
import
android.annotation.SuppressLint
import
android.content.Intent
import
android.os.Build
import
androidx.appcompat.app.AppCompatActivity
import
android.os.Bundle
import
android.os.Handler
import
android.widget.Toast
import
androidx.annotation.RequiresApi
import
androidx.appcompat.content.res.AppCompatResources
import
androidx.core.content.res.ResourcesCompat
import
androidx.appcompat.app.AppCompatActivity
import
androidx.lifecycle.ViewModelProvider
import
com.alibaba.fastjson.JSON
import
com.blankj.utilcode.util.LogUtils
import
com.blankj.utilcode.util.SizeUtils
import
com.miya.fastcashier.R
import
com.miya.fastcashier.R.mipmap.ic_alipay
import
com.miya.fastcashier.R.mipmap.ic_wxpay
import
com.miya.fastcashier.databinding.ActivityPayCodeBinding
import
com.miya.fastcashier.databinding.ActivityPriceInputBinding
import
com.miya.fastcashier.config.IntentExtra
import
com.miya.fastcashier.databinding.ActivityWxPayCodeBinding
import
com.miya.fastcashier.service.PrintService
import
com.miya.fastcashier.ui.dialog.PayChooseDialog
import
com.miya.fastcashier.utils.CenterToasty
import
com.miya.fastcashier.utils.DateUtils
import
com.miya.fastcashier.utils.StringPriceFormat
import
com.miya.fastcashier.utils.clickWithTrigger
import
com.miya.fastcashier.utils.manage.OrderRecordManageKit
import
com.miya.fastcashier.viewmodel.PayViewModel
import
com.miya.print.utils.BitmapUtils
import
com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import
com.tencent.mmkv.MMKV
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.runBlocking
import
java.util.*
import
kotlin.concurrent.timerTask
/**
* 微信付款码
...
...
@@ -43,6 +27,15 @@ class WxPayCodeActivity : AppCompatActivity() {
private
lateinit
var
viewModel
:
PayViewModel
private
lateinit
var
binding
:
ActivityWxPayCodeBinding
companion
object
{
fun
start
(
context
:
BaseActivity
,
payServiceResponse
:
PayServiceResponse
?)
{
val
intent
=
Intent
()
intent
.
setClass
(
context
,
WxPayCodeActivity
::
class
.
java
)
intent
.
putExtra
(
IntentExtra
.
KEY_EXTRA_PAYSERVICERESPONSE
,
payServiceResponse
)
context
.
startActivity
(
intent
)
}
}
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
...
...
@@ -54,11 +47,9 @@ class WxPayCodeActivity : AppCompatActivity() {
val
llBack
=
binding
.
llBack
val
tvPrice
=
binding
.
tvPrice
val
kv
=
MMKV
.
defaultMMKV
()
llBack
.
clickWithTrigger
{
finish
()
}
val
extra
=
intent
.
getSerializableExtra
(
"payServiceResponse"
)
val
extra
=
intent
.
getSerializableExtra
(
IntentExtra
.
KEY_EXTRA_PAYSERVICERESPONSE
)
extra
?.
let
{
val
payServiceResponse
=
it
as
PayServiceResponse
LogUtils
.
e
(
JSON
.
toJSONString
(
payServiceResponse
))
...
...
@@ -86,11 +77,7 @@ class WxPayCodeActivity : AppCompatActivity() {
result
.
getOrNull
().
also
{
it
?.
let
{
it1
->
OrderRecordManageKit
.
setSerialNumber
()
val
intent
=
Intent
()
intent
.
setClass
(
this
@WxPayCodeActivity
,
PayResultActivity
::
class
.
java
)
intent
.
putExtra
(
"payServiceResponse"
,
it1
)
startActivity
(
intent
)
PayResultActivity
.
start
(
this
@WxPayCodeActivity
,
it1
)
}
}
})
...
...
app/src/main/java/com/miya/fastcashier/ui/dialog/AuthorizePasswordInputDialog.kt
View file @
4315f774
package
com.miya.fastcashier.ui.dialog
import
android.content.Context
import
android.graphics.drawable.ColorDrawable
import
android.os.Bundle
import
android.text.Editable
...
...
@@ -82,13 +81,14 @@ class AuthorizePasswordInputDialog() : DialogFragment(), View.OnClickListener {
return
}
val
accountPassword
=
AccountPasswordManageKit
.
get
Instance
().
accountPassword
val
accountPassword
=
AccountPasswordManageKit
.
get
().
accountPassword
if
(
TextUtils
.
isEmpty
(
accountPassword
))
{
AccountPasswordManageKit
.
getInstance
()
.
loadAccountPassword
(
context
as
AppCompatActivity
?
)
{
checkPasswordAndDoNext
(
it
,
inputPassword
)
}
AccountPasswordManageKit
.
get
().
loadAccountPassword
(
context
as
AppCompatActivity
,
object
:
AccountPasswordManageKit
.
AccountPasswordManageCallback
{
override
fun
onPasswordGet
(
password
:
String
?)
{
password
?.
let
{
checkPasswordAndDoNext
(
it
,
inputPassword
)
}
}
})
}
else
{
checkPasswordAndDoNext
(
accountPassword
,
inputPassword
)
}
...
...
app/src/main/java/com/miya/fastcashier/utils/DateUtils.java
View file @
4315f774
package
com
.
miya
.
fastcashier
.
utils
;
import
com.blankj.utilcode.util.StringUtils
;
import
java.text.ParseException
;
...
...
@@ -153,6 +152,27 @@ public class DateUtils {
return
today
;
}
/**
* 获取某天的n天以前的0点
*/
public
static
long
getDaysAgo
(
Date
time
,
int
daysAgoNum
)
{
Calendar
calendar
=
Calendar
.
getInstance
();
calendar
.
setTime
(
time
);
calendar
.
add
(
calendar
.
DATE
,
-
daysAgoNum
);
calendar
.
set
(
Calendar
.
HOUR_OF_DAY
,
0
);
calendar
.
set
(
Calendar
.
MINUTE
,
0
);
calendar
.
set
(
Calendar
.
SECOND
,
0
);
calendar
.
set
(
Calendar
.
MILLISECOND
,
0
);
return
calendar
.
getTime
().
getTime
();
}
/**
* 获取某天的n天以前的当前时间
*/
public
static
long
getDaysAgoCurrent
(
Date
date
,
int
daysAgoNum
)
{
return
date
.
getTime
()
-
daysAgoNum
*
24
*
3600
*
1000
;
}
/**
* 得到前一天
*/
...
...
@@ -438,7 +458,7 @@ public class DateUtils {
try
{
SimpleDateFormat
format
=
new
SimpleDateFormat
(
"HH:mm"
);
Date
now
=
format
.
parse
(
format
(
new
Date
(),
DF_HHMM
));
Date
now
=
format
.
parse
(
format
(
new
Date
(),
DF_HHMM
));
Date
start
=
format
.
parse
(
startDate
);
Date
end
=
format
.
parse
(
endDate
);
long
nowTime
=
now
.
getTime
();
...
...
app/src/main/java/com/miya/fastcashier/utils/manage/AccountPasswordManageKit.java
deleted
100644 → 0
View file @
b317908e
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.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
)
{
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
);
}
}
});
}
});
return
;
}
AccountService
.
INSTANCE
.
setAccountPassword
(
ACCOUNT_DEFAULT_PASSWORD
);
if
(
callback
!=
null
){
callback
.
onPasswordGet
(
ACCOUNT_DEFAULT_PASSWORD
);
}
if
(
FileUtils
.
createOrExistsFile
(
getCurrentAccountFilePath
()))
{
Executors
.
newCachedThreadPool
().
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
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
);
}
}
}
public
String
getAccountPassword
()
{
return
AccountService
.
INSTANCE
.
getAccountPassword
();
}
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
);
}
});
}
}
}
app/src/main/java/com/miya/fastcashier/utils/manage/AccountPasswordManageKit.kt
0 → 100644
View file @
4315f774
package
com.miya.fastcashier.utils.manage
import
android.Manifest
import
android.os.Environment
import
android.text.TextUtils
import
androidx.appcompat.app.AppCompatActivity
import
com.blankj.utilcode.util.FileIOUtils
import
com.blankj.utilcode.util.FileUtils
import
com.blankj.utilcode.util.ToastUtils
import
com.miya.fastcashier.service.AccountService.getAccountPassword
import
com.miya.fastcashier.service.AccountService.getUserName
import
com.miya.fastcashier.service.AccountService.setAccountPassword
import
com.permissionx.guolindev.PermissionX
import
java.util.concurrent.Executors
/**
* 类描述:账户管理员密码管理
* 概述:
* 创建人:zpxiang
* 创建时间:2022/4/1
* 修改人:
* 修改时间:
*/
class
AccountPasswordManageKit
private
constructor
()
{
companion
object
{
private
val
FileDir
=
Environment
.
getExternalStorageDirectory
().
toString
()
+
"/fastcashier/"
const
val
ACCOUNT_DEFAULT_PASSWORD
=
"123456"
private
var
sInstance
:
AccountPasswordManageKit
?
=
null
val
instance
:
AccountPasswordManageKit
?
get
()
{
if
(
sInstance
==
null
)
{
sInstance
=
AccountPasswordManageKit
()
}
return
sInstance
}
@Synchronized
fun
get
():
AccountPasswordManageKit
{
return
instance
!!
}
}
interface
AccountPasswordManageCallback
{
fun
onPasswordGet
(
password
:
String
?)
}
fun
checkAccountPassword
(
context
:
AppCompatActivity
)
{
val
accountPassword
=
getAccountPassword
()
if
(!
TextUtils
.
isEmpty
(
accountPassword
))
return
PermissionX
.
init
(
context
)
.
permissions
(
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
)
.
request
{
allGranted
:
Boolean
,
grantedList
:
List
<
String
?
>?,
deniedList
:
List
<
String
?
>?
->
if
(
allGranted
)
{
initAccountPassword
(
context
,
null
)
}
else
{
ToastUtils
.
showShort
(
"请检查权限后重试"
)
}
}
}
val
currentAccountFilePath
:
String
get
()
=
FileDir
+
getUserName
()
fun
initAccountPassword
(
context
:
AppCompatActivity
,
callback
:
AccountPasswordManageCallback
?)
{
if
(
FileUtils
.
isFileExists
(
currentAccountFilePath
))
{
Executors
.
newCachedThreadPool
().
execute
{
val
password
=
FileIOUtils
.
readFile2String
(
currentAccountFilePath
)
setAccountPassword
(
password
)
context
.
runOnUiThread
{
callback
?.
onPasswordGet
(
password
)
}
}
return
}
setAccountPassword
(
ACCOUNT_DEFAULT_PASSWORD
)
callback
?.
onPasswordGet
(
ACCOUNT_DEFAULT_PASSWORD
)
if
(
FileUtils
.
createOrExistsFile
(
currentAccountFilePath
))
{
Executors
.
newCachedThreadPool
().
execute
{
FileIOUtils
.
writeFileFromString
(
currentAccountFilePath
,
ACCOUNT_DEFAULT_PASSWORD
)
}
}
}
fun
loadAccountPassword
(
context
:
AppCompatActivity
,
callback
:
AccountPasswordManageCallback
?)
{
val
accountPassword
=
getAccountPassword
()
if
(
TextUtils
.
isEmpty
(
accountPassword
))
{
PermissionX
.
init
(
context
)
.
permissions
(
Manifest
.
permission
.
WRITE_EXTERNAL_STORAGE
,
Manifest
.
permission
.
READ_EXTERNAL_STORAGE
)
.
request
{
allGranted
:
Boolean
,
grantedList
:
List
<
String
?
>?,
deniedList
:
List
<
String
?
>?
->
if
(
allGranted
)
{
initAccountPassword
(
context
,
callback
)
}
else
{
ToastUtils
.
showShort
(
"请检查权限后重试"
)
}
}
}
else
{
callback
?.
onPasswordGet
(
accountPassword
)
}
}
val
accountPassword
:
String
get
()
=
getAccountPassword
()
fun
updateAccountPassword
(
password
:
String
?)
{
if
(
TextUtils
.
isEmpty
(
password
))
return
setAccountPassword
(
password
!!
)
if
(
FileUtils
.
isFileExists
(
currentAccountFilePath
))
{
FileUtils
.
deleteAllInDir
(
currentAccountFilePath
)
}
if
(
FileUtils
.
createOrExistsFile
(
currentAccountFilePath
))
{
Executors
.
newCachedThreadPool
()
.
execute
{
FileIOUtils
.
writeFileFromString
(
currentAccountFilePath
,
password
)
}
}
}
}
\ No newline at end of file
app/src/main/java/com/miya/fastcashier/utils/manage/LocalKeyDataMKManageKit.kt
0 → 100644
View file @
4315f774
package
com.miya.fastcashier.utils.manage
import
com.blankj.utilcode.util.LogUtils
import
com.miya.fastcashier.service.AccountService
import
com.miya.fastcashier.utils.DateUtils
import
com.tencent.mmkv.MMKV
import
java.util.*
/**
* 类描述:本地关键数据MMKV统一管理
* 概述:涉及到的关键数据:balanceDate(结算时间)
* 创建人:zpxiang
* 创建时间:2022/4/24
* 修改人:
* 修改时间:
*/
class
LocalKeyDataMKManageKit
{
companion
object
{
/***************************************** 分账户的关键数据,分区存储ID为MMKV_ID *****************************************/
private
val
MMKV_ID
=
"fastcashier_key_data"
private
val
BALANCEDATE_ID
=
"balanceDate"
/**
* 存储结算时间
*/
fun
putBalanceDate
(
time
:
Long
)
{
getKeyDataMK
().
putLong
(
BALANCEDATE_ID
,
time
)
LogUtils
.
e
(
BALANCEDATE_ID
,
"putBalanceDate${getKeyDataMK().getLong(BALANCEDATE_ID, 0)}"
)
}
/**
* 获取结算时间
*/
fun
getBalanceDate
():
Long
{
LogUtils
.
e
(
BALANCEDATE_ID
,
"getBalanceDate${getKeyDataMK().getLong(BALANCEDATE_ID, 0)}"
)
return
getKeyDataMK
().
getLong
(
BALANCEDATE_ID
,
0
)
}
/**
* 结算时间合规化处理,适用于登录时
* 策略:
* ①当获取的结算时间=0(证明本地未存储过,第一次登陆)存储为当前时间
* ②当获取的结算时间小于三天前的当前时间,则将结算时间重置为3天前的时间
*/
fun
handleCompliantBalanceDate
()
{
LogUtils
.
e
(
BALANCEDATE_ID
,
"handleCompliantBalanceDate"
)
var
balanceTime
=
getBalanceDate
()
if
(
balanceTime
<=
0L
)
{
//todo 如果返回有服务器时间建议改成服务器时间
putBalanceDate
(
System
.
currentTimeMillis
())
return
}
var
minimumTime
:
Long
=
System
.
currentTimeMillis
()
-
3
*
24
*
3600
*
1000
if
(
balanceTime
<=
minimumTime
)
{
putBalanceDate
(
minimumTime
)
LogUtils
.
e
(
BALANCEDATE_ID
,
"minimumTime:${DateUtils.format18(Date(minimumTime))}"
)
}
}
/**
* 清除关键数据的mmkv存储
*/
fun
clearKeyData
()
{
getKeyDataMK
().
clearAll
()
}
private
fun
getKeyDataMK
():
MMKV
{
val
MMKV_ID_WITH_USER
=
MMKV_ID
.
plus
(
"_${AccountService.getUserName()}"
)
return
MMKV
.
mmkvWithID
(
MMKV_ID_WITH_USER
)
}
/***************************************** 普通存储的关键数据,分区存储ID为默认 *****************************************/
private
val
USERNAME_ID
=
"username"
private
val
USERPASSWORD_ID
=
"password"
/**
* 存储登录信息:姓名、密码
*/
fun
putLoginIngfo
(
userName
:
String
,
password
:
String
)
{
MMKV
.
defaultMMKV
().
encode
(
USERNAME_ID
,
userName
)
MMKV
.
defaultMMKV
().
encode
(
USERPASSWORD_ID
,
password
)
}
/**
* 获取登录姓名
*/
fun
getLoginUserName
():
String
?
{
return
MMKV
.
defaultMMKV
().
decodeString
(
USERNAME_ID
)
}
/**
* 获取登录密码
*/
fun
getLoginUserPassword
():
String
?
{
return
MMKV
.
defaultMMKV
().
decodeString
(
USERPASSWORD_ID
)
}
fun
clearCommonData
()
{
MMKV
.
defaultMMKV
().
clearAll
()
}
}
}
\ No newline at end of file
app/src/main/java/com/miya/fastcashier/viewmodel/LoginViewModel.kt
View file @
4315f774
package
com.miya.fastcashier.viewmodel
import
android.util.Patterns
import
androidx.lifecycle.LiveData
import
androidx.lifecycle.MutableLiveData
import
androidx.lifecycle.ViewModel
import
androidx.lifecycle.viewModelScope
import
com.miya.fastcashier.R
import
com.miya.fastcashier.beans.LoginFormState
import
com.miya.fastcashier.beans.LoginRequest
import
com.miya.fastcashier.beans.SelfCashierAccountInfo
import
com.miya.fastcashier.net.BaseResult
import
com.miya.fastcashier.service.LoginService
import
com.miya.fastcashier.beans.LoginFormState
import
com.tencent.mmkv.MMKV
import
com.miya.fastcashier.utils.manage.LocalKeyDataMKManageKit
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.launch
import
java.lang.RuntimeException
class
LoginViewModel
:
ViewModel
()
{
...
...
@@ -30,13 +28,11 @@ class LoginViewModel : ViewModel() {
errorHandle
(
LoginService
.
getApi
().
login
(
LoginRequest
(
userName
,
passWord
,
""
)))
)
//MMKV记录结算时间
val
balanceDate
=
MMKV
.
defaultMMKV
().
getLong
(
"balanceDate"
,
0L
)
if
(
balanceDate
<=
0L
)
{
//todo 改成服务器时间
MMKV
.
defaultMMKV
().
putLong
(
"balanceDate"
,
System
.
currentTimeMillis
())
}
// val balanceDate = LocalKeyDataMKManageKit.getBalanceDate()
// if (balanceDate <= 0L) {
// //todo 改成服务器时间
// LocalKeyDataMKManageKit.putBalanceDate(System.currentTimeMillis())
// }
loginLiveData
.
postValue
(
result
)
}
catch
(
e
:
Exception
)
{
loginLiveData
.
postValue
(
Result
.
failure
(
e
))
...
...
app/src/main/java/com/miya/fastcashier/viewmodel/PrintViewModel.kt
View file @
4315f774
...
...
@@ -6,13 +6,12 @@ import androidx.lifecycle.viewModelScope
import
com.miya.fastcashier.service.AccountService
import
com.miya.fastcashier.service.PrintService
import
com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import
com.tencent.mmkv.MMKV
import
kotlinx.coroutines.
*
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.
launch
class
PrintViewModel
:
ViewModel
()
{
val
printResultLiveData
:
MutableLiveData
<
Result
<
Any
>>
=
MutableLiveData
()
val
kv
=
MMKV
.
defaultMMKV
()
fun
printOrder
(
payServiceResponse
:
PayServiceResponse
){
//todo 检查参数
...
...
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