Commit 4315f774 authored by 赵鹏翔's avatar 赵鹏翔

Merge branch 'feature_localdata_optimize' into 'develop'

Feature localdata optimize

See merge request !3
parents b317908e 2c357f4c
...@@ -18,6 +18,7 @@ import com.miya.fastcashier.utils.ContextUtils ...@@ -18,6 +18,7 @@ import com.miya.fastcashier.utils.ContextUtils
import com.miya.fastcashier.utils.DateUtils import com.miya.fastcashier.utils.DateUtils
import com.miya.fastcashier.utils.DensityUtils import com.miya.fastcashier.utils.DensityUtils
import com.miya.fastcashier.utils.LogFileUtils import com.miya.fastcashier.utils.LogFileUtils
import com.miya.fastcashier.utils.manage.LocalKeyDataMKManageKit
import com.miya.fastcashier.utils.manage.OrderRecordManageKit import com.miya.fastcashier.utils.manage.OrderRecordManageKit
import com.miya.print.PrinterManager import com.miya.print.PrinterManager
import com.sdy.miya.moblie.component.pay.core.net.MiYaPayMobileApiClient import com.sdy.miya.moblie.component.pay.core.net.MiYaPayMobileApiClient
...@@ -144,7 +145,7 @@ class BaseApplication : MultiDexApplication() { ...@@ -144,7 +145,7 @@ class BaseApplication : MultiDexApplication() {
} }
fun resetConfig() { fun resetConfig() {
MMKV.defaultMMKV().clearAll() LocalKeyDataMKManageKit.clearCommonData()
//清除本地订单昨天的流水信息 //清除本地订单昨天的流水信息
OrderRecordManageKit.clearOrderDataYeaterday() OrderRecordManageKit.clearOrderDataYeaterday()
//清除本地个人信息 //清除本地个人信息
......
...@@ -4,5 +4,7 @@ interface IntentExtra { ...@@ -4,5 +4,7 @@ interface IntentExtra {
companion object { companion object {
const val KEY_EXTRA_DATA = "extra_data" const val KEY_EXTRA_DATA = "extra_data"
const val KEY_EXTRA_TYPE = "extra_type" 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
...@@ -33,9 +33,14 @@ object AccountService { ...@@ -33,9 +33,14 @@ object AccountService {
this.accountPassword = accountPassword this.accountPassword = accountPassword
} }
fun clear(){ fun clear() {
selfCashierAccountInfo = null selfCashierAccountInfo = null
userName = "" userName = ""
accountPassword = "" accountPassword = ""
} }
fun init(selfCashierAccountInfo: SelfCashierAccountInfo?, userName: String) {
this.selfCashierAccountInfo = selfCashierAccountInfo
this.userName = userName
}
} }
\ No newline at end of file
package com.miya.fastcashier.service package com.miya.fastcashier.service
import android.text.TextUtils 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.SelfCashierAccountInfo
import com.miya.fastcashier.beans.ViewOrderStatisticsInfo import com.miya.fastcashier.beans.ViewOrderStatisticsInfo
import com.miya.fastcashier.utils.DateUtils import com.miya.fastcashier.utils.DateUtils
...@@ -10,15 +8,10 @@ import com.miya.fastcashier.utils.MiYaPayPlantformPayWayEnum ...@@ -10,15 +8,10 @@ import com.miya.fastcashier.utils.MiYaPayPlantformPayWayEnum
import com.miya.fastcashier.utils.StringPriceFormat import com.miya.fastcashier.utils.StringPriceFormat
import com.miya.fastcashier.utils.isEmpty import com.miya.fastcashier.utils.isEmpty
import com.miya.fastcashier.utils.manage.OrderRecordManageKit import com.miya.fastcashier.utils.manage.OrderRecordManageKit
import com.miya.print.BuildConfig
import com.miya.print.IPrinter import com.miya.print.IPrinter
import com.miya.print.PrinterManager import com.miya.print.PrinterManager
import com.miya.print.utils.Page58MmPrintUtils import com.miya.print.utils.Page58MmPrintUtils
import com.miya.print.utils.PrintLogger
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 java.lang.Exception
import java.lang.RuntimeException
import java.util.* import java.util.*
object PrintService { object PrintService {
......
package com.miya.fastcashier.ui package com.miya.fastcashier.ui
import android.annotation.SuppressLint
import android.content.Intent import android.content.Intent
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.os.Handler
import android.widget.Toast import android.widget.Toast
import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.res.ResourcesCompat
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.alibaba.fastjson.JSON import com.alibaba.fastjson.JSON
import com.blankj.utilcode.util.LogUtils import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.SizeUtils import com.miya.fastcashier.config.IntentExtra
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.ActivityAliPayCodeBinding 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.CenterToasty
import com.miya.fastcashier.utils.DateUtils
import com.miya.fastcashier.utils.StringPriceFormat import com.miya.fastcashier.utils.StringPriceFormat
import com.miya.fastcashier.utils.clickWithTrigger import com.miya.fastcashier.utils.clickWithTrigger
import com.miya.fastcashier.utils.manage.OrderRecordManageKit import com.miya.fastcashier.utils.manage.OrderRecordManageKit
import com.miya.fastcashier.viewmodel.PayViewModel import com.miya.fastcashier.viewmodel.PayViewModel
import com.miya.print.utils.BitmapUtils import com.miya.print.utils.BitmapUtils
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 kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import java.util.* import java.util.*
...@@ -43,6 +28,15 @@ class AliPayCodeActivity : AppCompatActivity() { ...@@ -43,6 +28,15 @@ class AliPayCodeActivity : AppCompatActivity() {
private lateinit var viewModel: PayViewModel private lateinit var viewModel: PayViewModel
private lateinit var binding: ActivityAliPayCodeBinding 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?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
...@@ -54,11 +48,9 @@ class AliPayCodeActivity : AppCompatActivity() { ...@@ -54,11 +48,9 @@ class AliPayCodeActivity : AppCompatActivity() {
val llBack = binding.llBack val llBack = binding.llBack
val tvPrice = binding.tvPrice val tvPrice = binding.tvPrice
val kv = MMKV.defaultMMKV()
llBack.clickWithTrigger { finish() } llBack.clickWithTrigger { finish() }
val extra = intent.getSerializableExtra("payServiceResponse") val extra = intent.getSerializableExtra(IntentExtra.KEY_EXTRA_PAYSERVICERESPONSE)
extra?.let { extra?.let {
val payServiceResponse = it as PayServiceResponse val payServiceResponse = it as PayServiceResponse
LogUtils.e(JSON.toJSONString(payServiceResponse)) LogUtils.e(JSON.toJSONString(payServiceResponse))
...@@ -86,11 +78,7 @@ class AliPayCodeActivity : AppCompatActivity() { ...@@ -86,11 +78,7 @@ class AliPayCodeActivity : AppCompatActivity() {
result.getOrNull().also { result.getOrNull().also {
it?.let { it1 -> it?.let { it1 ->
OrderRecordManageKit.setSerialNumber() OrderRecordManageKit.setSerialNumber()
PayResultActivity.start(this@AliPayCodeActivity,it1)
val intent = Intent()
intent.setClass(this@AliPayCodeActivity, PayResultActivity::class.java)
intent.putExtra("payServiceResponse",it1)
startActivity(intent)
} }
} }
}) })
......
...@@ -13,15 +13,14 @@ import android.widget.EditText ...@@ -13,15 +13,14 @@ 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.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.manage.LocalKeyDataMKManageKit
import com.miya.fastcashier.viewmodel.LoginViewModel import com.miya.fastcashier.viewmodel.LoginViewModel
import com.permissionx.guolindev.PermissionX import com.permissionx.guolindev.PermissionX
import com.permissionx.guolindev.callback.RequestCallback import com.permissionx.guolindev.callback.RequestCallback
import com.tencent.mmkv.MMKV
class LoginActivity : AppCompatActivity() { class LoginActivity : AppCompatActivity() {
...@@ -29,7 +28,7 @@ class LoginActivity : AppCompatActivity() { ...@@ -29,7 +28,7 @@ class LoginActivity : AppCompatActivity() {
private lateinit var loginViewModel: LoginViewModel private lateinit var loginViewModel: LoginViewModel
private lateinit var binding: ActivityLoginBinding private lateinit var binding: ActivityLoginBinding
companion object{ companion object {
fun start(context: Context, flags: Int) { fun start(context: Context, flags: Int) {
val intent = Intent(context, LoginActivity::class.java) val intent = Intent(context, LoginActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or flags intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or flags
...@@ -48,8 +47,6 @@ class LoginActivity : AppCompatActivity() { ...@@ -48,8 +47,6 @@ class LoginActivity : AppCompatActivity() {
val login = binding.login val login = binding.login
val tvErrInfo = binding.tvErrInfo val tvErrInfo = binding.tvErrInfo
val kv = MMKV.defaultMMKV()
loginViewModel = ViewModelProvider(this) loginViewModel = ViewModelProvider(this)
.get(LoginViewModel::class.java) .get(LoginViewModel::class.java)
...@@ -66,16 +63,15 @@ class LoginActivity : AppCompatActivity() { ...@@ -66,16 +63,15 @@ class LoginActivity : AppCompatActivity() {
result.getOrNull().also { result.getOrNull().also {
it?.let { it1 -> it?.let { it1 ->
kv.encode("username", username.text.toString()) val userName = username.text.toString()
kv.encode("password", password.text.toString()) val passWord = password.text.toString()
AccountService.setUserName(username.text.toString())
AccountService.setAccountInfo(it1)
val intent = Intent() LocalKeyDataMKManageKit.putLoginIngfo(userName, passWord)
intent.setClass(this@LoginActivity, MainActivity::class.java) AccountService.init(it1, userName)
startActivity(intent) //根据本地存储时间,MMKV初始化合理的结算时间
LocalKeyDataMKManageKit.handleCompliantBalanceDate()
MainActivity.start(this@LoginActivity)
finish() finish()
} }
} }
...@@ -138,18 +134,19 @@ class LoginActivity : AppCompatActivity() { ...@@ -138,18 +134,19 @@ class LoginActivity : AppCompatActivity() {
} }
} }
kv.decodeString("username")?.let { LocalKeyDataMKManageKit.getLoginUserName()?.let {
username.setText(it) username.setText(it)
} }
kv.decodeString("password")?.let { LocalKeyDataMKManageKit.getLoginUserPassword()?.let {
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()
)
} }
} }
......
package com.miya.fastcashier.ui package com.miya.fastcashier.ui
import android.content.Intent import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.view.Gravity
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider 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.databinding.ActivityMainBinding
import com.miya.fastcashier.service.AccountService import com.miya.fastcashier.service.AccountService
import com.miya.fastcashier.service.PrintService import com.miya.fastcashier.service.PrintService
import com.miya.fastcashier.ui.dialog.AuthorizePasswordInputDialog 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.CenterToasty
import com.miya.fastcashier.utils.DateSelectHelper import com.miya.fastcashier.utils.DateSelectHelper
import com.miya.fastcashier.utils.DateUtils
import com.miya.fastcashier.utils.clickWithTrigger import com.miya.fastcashier.utils.clickWithTrigger
import com.miya.fastcashier.utils.manage.AccountPasswordManageKit 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.utils.manage.OrderRecordManageKit
import com.miya.fastcashier.viewmodel.MainViewModel 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.* import java.util.*
class MainActivity : BaseActivity() { class MainActivity : BaseActivity() {
...@@ -34,6 +27,15 @@ class MainActivity : BaseActivity() { ...@@ -34,6 +27,15 @@ class MainActivity : BaseActivity() {
private lateinit var viewModel: MainViewModel private lateinit var viewModel: MainViewModel
private var dateSelectHelper: DateSelectHelper? = null 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?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater) binding = ActivityMainBinding.inflate(layoutInflater)
...@@ -64,8 +66,7 @@ class MainActivity : BaseActivity() { ...@@ -64,8 +66,7 @@ class MainActivity : BaseActivity() {
} }
} }
binding.llSearchOrder.clickWithTrigger { binding.llSearchOrder.clickWithTrigger {
val intent = Intent(this@MainActivity, SearchOrderActivity::class.java) SearchOrderActivity.start(this@MainActivity)
startActivity(intent)
} }
ivSetting.clickWithTrigger { ivSetting.clickWithTrigger {
...@@ -83,9 +84,14 @@ class MainActivity : BaseActivity() { ...@@ -83,9 +84,14 @@ class MainActivity : BaseActivity() {
binding.llBalance.clickWithTrigger { binding.llBalance.clickWithTrigger {
//上次记录的时间,或者当天0点 //上次记录的时间,或者当天0点
val timeMillis = MMKV.defaultMMKV().getLong("balanceDate", 0L) var timeMillis = LocalKeyDataMKManageKit.getBalanceDate()
if (timeMillis > 0L && timeMillis <= System.currentTimeMillis()) { 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 { } else {
val startDate = Calendar.getInstance() val startDate = Calendar.getInstance()
startDate.set( startDate.set(
...@@ -100,6 +106,10 @@ class MainActivity : BaseActivity() { ...@@ -100,6 +106,10 @@ class MainActivity : BaseActivity() {
} }
} }
binding.tvStoreName.clickWithTrigger{
LocalKeyDataMKManageKit.putBalanceDate(2)
}
initData() initData()
checkAccountPassword() checkAccountPassword()
OrderRecordManageKit.clearOrderDataYeaterday() OrderRecordManageKit.clearOrderDataYeaterday()
...@@ -116,7 +126,7 @@ class MainActivity : BaseActivity() { ...@@ -116,7 +126,7 @@ class MainActivity : BaseActivity() {
} }
private fun checkAccountPassword() { private fun checkAccountPassword() {
AccountPasswordManageKit.getInstance().checkAccountPassword(this) AccountPasswordManageKit.get().checkAccountPassword(this)
} }
private fun initData() { private fun initData() {
...@@ -131,7 +141,7 @@ class MainActivity : BaseActivity() { ...@@ -131,7 +141,7 @@ class MainActivity : BaseActivity() {
viewModel.balanceLiveData.observe(this, { result -> viewModel.balanceLiveData.observe(this, { result ->
result.onSuccess { result.onSuccess {
MMKV.defaultMMKV().putLong("balanceDate", it) LocalKeyDataMKManageKit.putBalanceDate(it)
} }
result.onFailure { e -> result.onFailure { e ->
CenterToasty.error(this@MainActivity, e.message ?: "").show() CenterToasty.error(this@MainActivity, e.message ?: "").show()
......
...@@ -5,18 +5,15 @@ import android.os.Bundle ...@@ -5,18 +5,15 @@ 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.ActivityPayBinding import com.miya.fastcashier.databinding.ActivityPayBinding
import com.miya.fastcashier.service.PrintService
import com.miya.fastcashier.utils.CenterToasty import com.miya.fastcashier.utils.CenterToasty
import com.miya.fastcashier.utils.DateUtils
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.utils.manage.OrderRecordManageKit import com.miya.fastcashier.utils.manage.OrderRecordManageKit
import com.miya.fastcashier.viewmodel.PayViewModel import com.miya.fastcashier.viewmodel.PayViewModel
import com.tencent.mmkv.MMKV
import java.util.* import java.util.*
class PayActivity : BaseActivity() { class PayActivity : BaseActivity() {
private lateinit var viewModel: PayViewModel private lateinit var viewModel: PayViewModel
private lateinit var binding: ActivityPayBinding private lateinit var binding: ActivityPayBinding
...@@ -24,13 +21,22 @@ class PayActivity : BaseActivity() { ...@@ -24,13 +21,22 @@ class PayActivity : BaseActivity() {
private lateinit var price: String 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?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = ActivityPayBinding.inflate(layoutInflater) binding = ActivityPayBinding.inflate(layoutInflater)
setContentView(binding.root) setContentView(binding.root)
viewModel = ViewModelProvider(this).get(PayViewModel::class.java) viewModel = ViewModelProvider(this).get(PayViewModel::class.java)
price = intent.getStringExtra("price").toString() price = intent.getStringExtra(IntentExtra.KEY_EXTRA_PRICE).toString()
val tvPayPrice = binding.tvPayPrice val tvPayPrice = binding.tvPayPrice
tvPayPrice.text = "¥${price.toDouble()}" tvPayPrice.text = "¥${price.toDouble()}"
...@@ -41,11 +47,7 @@ class PayActivity : BaseActivity() { ...@@ -41,11 +47,7 @@ class PayActivity : BaseActivity() {
} }
payResult.onSuccess { payResult.onSuccess {
OrderRecordManageKit.setSerialNumber() OrderRecordManageKit.setSerialNumber()
PayResultActivity.start(this@PayActivity, it)
val intent = Intent()
intent.setClass(this@PayActivity, PayResultActivity::class.java)
intent.putExtra("payServiceResponse", it)
startActivity(intent)
} }
}) })
binding.clTitle.llBack.clickWithTrigger { finish() } binding.clTitle.llBack.clickWithTrigger { finish() }
......
package com.miya.fastcashier.ui 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.Bundle
import android.os.Handler
import android.widget.Toast import android.widget.Toast
import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.res.ResourcesCompat
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.alibaba.fastjson.JSON import com.alibaba.fastjson.JSON
import com.blankj.utilcode.util.LogUtils import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.SizeUtils
import com.miya.fastcashier.R import com.miya.fastcashier.R
import com.miya.fastcashier.R.mipmap.ic_alipay import com.miya.fastcashier.R.mipmap.ic_alipay
import com.miya.fastcashier.R.mipmap.ic_wxpay 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.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.CenterToasty
import com.miya.fastcashier.utils.StringPriceFormat import com.miya.fastcashier.utils.StringPriceFormat
import com.miya.fastcashier.utils.clickWithTrigger import com.miya.fastcashier.utils.clickWithTrigger
...@@ -29,7 +21,6 @@ import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse ...@@ -29,7 +21,6 @@ import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import java.util.* import java.util.*
import kotlin.concurrent.timerTask
class PayCodeActivity : AppCompatActivity() { class PayCodeActivity : AppCompatActivity() {
private lateinit var viewModel: PayViewModel private lateinit var viewModel: PayViewModel
...@@ -52,7 +43,7 @@ class PayCodeActivity : AppCompatActivity() { ...@@ -52,7 +43,7 @@ class PayCodeActivity : AppCompatActivity() {
tvBack.clickWithTrigger { finish() } tvBack.clickWithTrigger { finish() }
ivBack.clickWithTrigger { finish() } ivBack.clickWithTrigger { finish() }
val extra = intent.getSerializableExtra("payServiceResponse") val extra = intent.getSerializableExtra(IntentExtra.KEY_EXTRA_PAYSERVICERESPONSE)
extra?.let { extra?.let {
val payServiceResponse = it as PayServiceResponse val payServiceResponse = it as PayServiceResponse
LogUtils.e(JSON.toJSONString(payServiceResponse)) LogUtils.e(JSON.toJSONString(payServiceResponse))
...@@ -89,10 +80,7 @@ class PayCodeActivity : AppCompatActivity() { ...@@ -89,10 +80,7 @@ class PayCodeActivity : AppCompatActivity() {
result.getOrNull().also { result.getOrNull().also {
it?.let { it1 -> it?.let { it1 ->
val intent = Intent() PayResultActivity.start(this@PayCodeActivity,it1)
intent.setClass(this@PayCodeActivity, PayResultActivity::class.java)
intent.putExtra("payServiceResponse",it1)
startActivity(intent)
} }
} }
}) })
......
...@@ -6,6 +6,7 @@ import android.view.View ...@@ -6,6 +6,7 @@ import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.miya.fastcashier.config.IntentExtra
import com.miya.fastcashier.databinding.ActivityPayResultBinding import com.miya.fastcashier.databinding.ActivityPayResultBinding
import com.miya.fastcashier.utils.CenterToasty import com.miya.fastcashier.utils.CenterToasty
import com.miya.fastcashier.utils.MiYaPayPlantformPayWayEnum import com.miya.fastcashier.utils.MiYaPayPlantformPayWayEnum
...@@ -14,11 +15,19 @@ import com.miya.fastcashier.utils.clickWithTrigger ...@@ -14,11 +15,19 @@ import com.miya.fastcashier.utils.clickWithTrigger
import com.miya.fastcashier.viewmodel.PrintViewModel import com.miya.fastcashier.viewmodel.PrintViewModel
import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse import com.sdy.miya.moblie.component.pay.platform.bean.PayServiceResponse
class PayResultActivity : AppCompatActivity() { class PayResultActivity : AppCompatActivity() {
private lateinit var viewModel: PrintViewModel private lateinit var viewModel: PrintViewModel
private lateinit var binding: ActivityPayResultBinding 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?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
...@@ -35,7 +44,7 @@ class PayResultActivity : AppCompatActivity() { ...@@ -35,7 +44,7 @@ class PayResultActivity : AppCompatActivity() {
val tvRePrint = binding.tvRePrint val tvRePrint = binding.tvRePrint
val tvGoHome = binding.tvGoHome val tvGoHome = binding.tvGoHome
val extra = intent.getSerializableExtra("payServiceResponse") val extra = intent.getSerializableExtra(IntentExtra.KEY_EXTRA_PAYSERVICERESPONSE)
extra?.let { extra?.let {
val payServiceResponse = it as PayServiceResponse val payServiceResponse = it as PayServiceResponse
tvPayPrice.text = "¥".plus(StringPriceFormat.transStringPriceToDecimalString( tvPayPrice.text = "¥".plus(StringPriceFormat.transStringPriceToDecimalString(
......
...@@ -3,17 +3,13 @@ package com.miya.fastcashier.ui ...@@ -3,17 +3,13 @@ package com.miya.fastcashier.ui
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.text.TextUtils import android.text.TextUtils
import android.util.Log
import android.view.Gravity
import android.view.View import android.view.View
import android.widget.Toast import android.widget.Toast
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.miya.fastcashier.R import com.miya.fastcashier.R
import com.miya.fastcashier.config.IntentExtra import com.miya.fastcashier.config.IntentExtra
import com.miya.fastcashier.databinding.ActivityPriceInputBinding 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.CommonDialog
import com.miya.fastcashier.ui.dialog.MessageDialog
import com.miya.fastcashier.ui.dialog.PayChooseDialog import com.miya.fastcashier.ui.dialog.PayChooseDialog
import com.miya.fastcashier.ui.dialog.PayChooseDialog.GeneratePayCodeClickListener import com.miya.fastcashier.ui.dialog.PayChooseDialog.GeneratePayCodeClickListener
import com.miya.fastcashier.utils.CenterToasty import com.miya.fastcashier.utils.CenterToasty
...@@ -24,7 +20,6 @@ import com.miya.fastcashier.viewmodel.PayViewModel ...@@ -24,7 +20,6 @@ import com.miya.fastcashier.viewmodel.PayViewModel
import com.miya.fastcashier.widget.DecimalKeyboard.DELETE import com.miya.fastcashier.widget.DecimalKeyboard.DELETE
import com.miya.fastcashier.widget.DecimalKeyboard.DOT import com.miya.fastcashier.widget.DecimalKeyboard.DOT
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 java.math.BigDecimal import java.math.BigDecimal
...@@ -94,16 +89,13 @@ class PriceInputActivity : BaseActivity() { ...@@ -94,16 +89,13 @@ class PriceInputActivity : BaseActivity() {
private fun initListener() { private fun initListener() {
binding.tvScanPayCode.clickWithTrigger { binding.tvScanPayCode.clickWithTrigger {
val price = binding.etPrice.text val price = binding.etPrice.text.toString()
if (TextUtils.isEmpty(price)) { if (TextUtils.isEmpty(price)) {
CenterToasty.error(this, "请输入金额!", Toast.LENGTH_LONG).show() CenterToasty.error(this, "请输入金额!", Toast.LENGTH_LONG).show()
return@clickWithTrigger return@clickWithTrigger
} }
val intent = Intent() PayActivity.start(this@PriceInputActivity, price)
intent.setClass(this@PriceInputActivity, PayActivity::class.java)
intent.putExtra("price", price)
startActivity(intent)
} }
binding.tvGeneratePayCode.clickWithTrigger { binding.tvGeneratePayCode.clickWithTrigger {
...@@ -195,14 +187,11 @@ class PriceInputActivity : BaseActivity() { ...@@ -195,14 +187,11 @@ class PriceInputActivity : BaseActivity() {
result.getOrNull().also { result.getOrNull().also {
it?.let { it1 -> it?.let { it1 ->
val intent = Intent()
if ("1" == it1.chanelTag) { if ("1" == it1.chanelTag) {
intent.setClass(this@PriceInputActivity, WxPayCodeActivity::class.java) WxPayCodeActivity.start(this@PriceInputActivity,it1)
} else { } else {
intent.setClass(this@PriceInputActivity, AliPayCodeActivity::class.java) AliPayCodeActivity.start(this@PriceInputActivity,it1)
} }
intent.putExtra("payServiceResponse", it1)
startActivity(intent)
} }
} }
}) })
......
...@@ -4,17 +4,10 @@ import android.content.Context ...@@ -4,17 +4,10 @@ import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.text.TextUtils 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.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.CenterToasty
import com.miya.fastcashier.utils.clickWithTrigger import com.miya.fastcashier.utils.clickWithTrigger
import com.miya.fastcashier.utils.manage.AccountPasswordManageKit import com.miya.fastcashier.utils.manage.AccountPasswordManageKit
import com.tencent.mmkv.MMKV
class ResetAuthorizePasswordActivity : BaseActivity() { class ResetAuthorizePasswordActivity : BaseActivity() {
...@@ -83,20 +76,26 @@ class ResetAuthorizePasswordActivity : BaseActivity() { ...@@ -83,20 +76,26 @@ class ResetAuthorizePasswordActivity : BaseActivity() {
return return
} }
val accountAuthorizePassword = AccountPasswordManageKit.getInstance().accountPassword val accountAuthorizePassword = AccountPasswordManageKit.get().accountPassword
if (TextUtils.isEmpty(accountAuthorizePassword)) { if (TextUtils.isEmpty(accountAuthorizePassword)) {
AccountPasswordManageKit.getInstance() AccountPasswordManageKit.get()
.loadAccountPassword(this) { .loadAccountPassword(
if (!it.equals(originPassword)) { this,
CenterToasty.error(this, "原始密码输入错误!").show() object : AccountPasswordManageKit.AccountPasswordManageCallback {
} else { override fun onPasswordGet(password: String?) {
updateAuthorizePasswordSucced(newPassword) if (!password.equals(originPassword)) {
} CenterToasty.error(this@ResetAuthorizePasswordActivity, "原始密码输入错误!")
} .show()
} else {
updateAuthorizePasswordSucced(newPassword)
}
}
})
} else { } else {
if (!accountAuthorizePassword.equals(originPassword)) { if (!accountAuthorizePassword.equals(originPassword)) {
CenterToasty.error(this, "原始密码输入错误!").show() CenterToasty.error(this, "原始密码输入错误!").show()
}else{ } else {
updateAuthorizePasswordSucced(newPassword) updateAuthorizePasswordSucced(newPassword)
} }
} }
...@@ -104,7 +103,7 @@ class ResetAuthorizePasswordActivity : BaseActivity() { ...@@ -104,7 +103,7 @@ class ResetAuthorizePasswordActivity : BaseActivity() {
private fun updateAuthorizePasswordSucced(newPassword: String) { private fun updateAuthorizePasswordSucced(newPassword: String) {
CenterToasty.success(this, "修改成功!", 1).show() CenterToasty.success(this, "修改成功!", 1).show()
AccountPasswordManageKit.getInstance().updateAccountPassword(newPassword) AccountPasswordManageKit.get().updateAccountPassword(newPassword)
finish() finish()
} }
} }
\ No newline at end of file
package com.miya.fastcashier.ui package com.miya.fastcashier.ui
import android.content.Context import android.content.Context
import android.content.Intent
import android.graphics.Rect import android.graphics.Rect
import android.os.Bundle import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
...@@ -9,13 +10,11 @@ import android.view.ViewGroup ...@@ -9,13 +10,11 @@ import android.view.ViewGroup
import android.widget.Toast import android.widget.Toast
import androidx.core.content.res.ResourcesCompat import androidx.core.content.res.ResourcesCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.adapter.FragmentStateAdapter
import com.elvishew.xlog.XLog import com.elvishew.xlog.XLog
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator import com.google.android.material.tabs.TabLayoutMediator
import com.miya.fastcashier.R import com.miya.fastcashier.R
import com.miya.fastcashier.beans.ViewPayOrderData import com.miya.fastcashier.beans.ViewPayOrderData
...@@ -26,9 +25,8 @@ import com.miya.fastcashier.databinding.ItemSearchOrderListBinding ...@@ -26,9 +25,8 @@ import com.miya.fastcashier.databinding.ItemSearchOrderListBinding
import com.miya.fastcashier.service.AccountService import com.miya.fastcashier.service.AccountService
import com.miya.fastcashier.service.PrintService import com.miya.fastcashier.service.PrintService
import com.miya.fastcashier.utils.* import com.miya.fastcashier.utils.*
import com.miya.fastcashier.utils.manage.LocalKeyDataMKManageKit
import com.miya.fastcashier.viewmodel.SearchOrderViewModel 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 ...@@ -36,6 +34,13 @@ import com.tencent.mmkv.MMKV
class SearchOrderActivity : BaseActivity() { class SearchOrderActivity : BaseActivity() {
private lateinit var binding: ActivitySearchOrderBinding 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?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
binding = ActivitySearchOrderBinding.inflate(LayoutInflater.from(this)) binding = ActivitySearchOrderBinding.inflate(LayoutInflater.from(this))
...@@ -95,7 +100,7 @@ class SearchOrderFragment(val payType: MiYaPayPlantformPayWayEnum.MiyaPayType) : ...@@ -95,7 +100,7 @@ class SearchOrderFragment(val payType: MiYaPayPlantformPayWayEnum.MiyaPayType) :
} }
isEnd = false isEnd = false
// onLoading = false // onLoading = false
balanceDate = MMKV.defaultMMKV().getLong("balanceDate", 0L) balanceDate = LocalKeyDataMKManageKit.getBalanceDate()
val act = requireActivity() val act = requireActivity()
binding?.run { binding?.run {
adapter = SearchOrderListAdapter(act, arrayListOf()) adapter = SearchOrderListAdapter(act, arrayListOf())
......
...@@ -2,17 +2,13 @@ package com.miya.fastcashier.ui ...@@ -2,17 +2,13 @@ package com.miya.fastcashier.ui
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.view.Gravity import android.view.Gravity
import com.blankj.utilcode.util.ToastUtils
import com.miya.fastcashier.BaseApplication import com.miya.fastcashier.BaseApplication
import com.miya.fastcashier.R import com.miya.fastcashier.R
import com.miya.fastcashier.databinding.ActivitySettingBinding import com.miya.fastcashier.databinding.ActivitySettingBinding
import com.miya.fastcashier.service.AccountService
import com.miya.fastcashier.ui.dialog.CommonDialog import com.miya.fastcashier.ui.dialog.CommonDialog
import com.miya.fastcashier.utils.clickWithTrigger import com.miya.fastcashier.utils.clickWithTrigger
import com.tencent.mmkv.MMKV
class SettingActivity : BaseActivity() { class SettingActivity : BaseActivity() {
......
package com.miya.fastcashier.ui package com.miya.fastcashier.ui
import android.annotation.SuppressLint
import android.content.Intent import android.content.Intent
import android.os.Build
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle import android.os.Bundle
import android.os.Handler
import android.widget.Toast import android.widget.Toast
import androidx.annotation.RequiresApi import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.content.res.AppCompatResources
import androidx.core.content.res.ResourcesCompat
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.alibaba.fastjson.JSON import com.alibaba.fastjson.JSON
import com.blankj.utilcode.util.LogUtils import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.SizeUtils import com.miya.fastcashier.config.IntentExtra
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.databinding.ActivityWxPayCodeBinding 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.CenterToasty
import com.miya.fastcashier.utils.DateUtils
import com.miya.fastcashier.utils.StringPriceFormat import com.miya.fastcashier.utils.StringPriceFormat
import com.miya.fastcashier.utils.clickWithTrigger import com.miya.fastcashier.utils.clickWithTrigger
import com.miya.fastcashier.utils.manage.OrderRecordManageKit import com.miya.fastcashier.utils.manage.OrderRecordManageKit
import com.miya.fastcashier.viewmodel.PayViewModel import com.miya.fastcashier.viewmodel.PayViewModel
import com.miya.print.utils.BitmapUtils import com.miya.print.utils.BitmapUtils
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 kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import java.util.* import java.util.*
import kotlin.concurrent.timerTask
/** /**
* 微信付款码 * 微信付款码
...@@ -43,6 +27,15 @@ class WxPayCodeActivity : AppCompatActivity() { ...@@ -43,6 +27,15 @@ class WxPayCodeActivity : AppCompatActivity() {
private lateinit var viewModel: PayViewModel private lateinit var viewModel: PayViewModel
private lateinit var binding: ActivityWxPayCodeBinding 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?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
...@@ -54,11 +47,9 @@ class WxPayCodeActivity : AppCompatActivity() { ...@@ -54,11 +47,9 @@ class WxPayCodeActivity : AppCompatActivity() {
val llBack = binding.llBack val llBack = binding.llBack
val tvPrice = binding.tvPrice val tvPrice = binding.tvPrice
val kv = MMKV.defaultMMKV()
llBack.clickWithTrigger { finish() } llBack.clickWithTrigger { finish() }
val extra = intent.getSerializableExtra("payServiceResponse") val extra = intent.getSerializableExtra(IntentExtra.KEY_EXTRA_PAYSERVICERESPONSE)
extra?.let { extra?.let {
val payServiceResponse = it as PayServiceResponse val payServiceResponse = it as PayServiceResponse
LogUtils.e(JSON.toJSONString(payServiceResponse)) LogUtils.e(JSON.toJSONString(payServiceResponse))
...@@ -86,11 +77,7 @@ class WxPayCodeActivity : AppCompatActivity() { ...@@ -86,11 +77,7 @@ class WxPayCodeActivity : AppCompatActivity() {
result.getOrNull().also { result.getOrNull().also {
it?.let { it1 -> it?.let { it1 ->
OrderRecordManageKit.setSerialNumber() OrderRecordManageKit.setSerialNumber()
PayResultActivity.start(this@WxPayCodeActivity,it1)
val intent = Intent()
intent.setClass(this@WxPayCodeActivity, PayResultActivity::class.java)
intent.putExtra("payServiceResponse",it1)
startActivity(intent)
} }
} }
}) })
......
package com.miya.fastcashier.ui.dialog package com.miya.fastcashier.ui.dialog
import android.content.Context
import android.graphics.drawable.ColorDrawable import android.graphics.drawable.ColorDrawable
import android.os.Bundle import android.os.Bundle
import android.text.Editable import android.text.Editable
...@@ -82,13 +81,14 @@ class AuthorizePasswordInputDialog() : DialogFragment(), View.OnClickListener { ...@@ -82,13 +81,14 @@ class AuthorizePasswordInputDialog() : DialogFragment(), View.OnClickListener {
return return
} }
val accountPassword = AccountPasswordManageKit.getInstance().accountPassword val accountPassword = AccountPasswordManageKit.get().accountPassword
if (TextUtils.isEmpty(accountPassword)) { if (TextUtils.isEmpty(accountPassword)) {
AccountPasswordManageKit.getInstance() AccountPasswordManageKit.get().loadAccountPassword(context as AppCompatActivity,
.loadAccountPassword(context as AppCompatActivity? object :AccountPasswordManageKit.AccountPasswordManageCallback{
) { override fun onPasswordGet(password: String?) {
checkPasswordAndDoNext(it, inputPassword) password?.let { checkPasswordAndDoNext(it, inputPassword) }
} }
})
} else { } else {
checkPasswordAndDoNext(accountPassword, inputPassword) checkPasswordAndDoNext(accountPassword, inputPassword)
} }
......
package com.miya.fastcashier.utils; package com.miya.fastcashier.utils;
import com.blankj.utilcode.util.StringUtils; import com.blankj.utilcode.util.StringUtils;
import java.text.ParseException; import java.text.ParseException;
...@@ -153,6 +152,27 @@ public class DateUtils { ...@@ -153,6 +152,27 @@ public class DateUtils {
return today; 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 { ...@@ -438,7 +458,7 @@ public class DateUtils {
try { try {
SimpleDateFormat format = new SimpleDateFormat("HH:mm"); 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 start = format.parse(startDate);
Date end = format.parse(endDate); Date end = format.parse(endDate);
long nowTime = now.getTime(); long nowTime = now.getTime();
......
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);
}
});
}
}
}
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
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
package com.miya.fastcashier.viewmodel package com.miya.fastcashier.viewmodel
import android.util.Patterns
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope import androidx.lifecycle.viewModelScope
import com.miya.fastcashier.R import com.miya.fastcashier.R
import com.miya.fastcashier.beans.LoginFormState
import com.miya.fastcashier.beans.LoginRequest import com.miya.fastcashier.beans.LoginRequest
import com.miya.fastcashier.beans.SelfCashierAccountInfo import com.miya.fastcashier.beans.SelfCashierAccountInfo
import com.miya.fastcashier.net.BaseResult import com.miya.fastcashier.net.BaseResult
import com.miya.fastcashier.service.LoginService import com.miya.fastcashier.service.LoginService
import com.miya.fastcashier.beans.LoginFormState import com.miya.fastcashier.utils.manage.LocalKeyDataMKManageKit
import com.tencent.mmkv.MMKV
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import java.lang.RuntimeException
class LoginViewModel : ViewModel() { class LoginViewModel : ViewModel() {
...@@ -30,13 +28,11 @@ class LoginViewModel : ViewModel() { ...@@ -30,13 +28,11 @@ class LoginViewModel : ViewModel() {
errorHandle(LoginService.getApi().login(LoginRequest(userName, passWord, ""))) errorHandle(LoginService.getApi().login(LoginRequest(userName, passWord, "")))
) )
//MMKV记录结算时间 // val balanceDate = LocalKeyDataMKManageKit.getBalanceDate()
val balanceDate = // if (balanceDate <= 0L) {
MMKV.defaultMMKV().getLong("balanceDate", 0L) // //todo 改成服务器时间
if (balanceDate <= 0L) { // LocalKeyDataMKManageKit.putBalanceDate(System.currentTimeMillis())
//todo 改成服务器时间 // }
MMKV.defaultMMKV().putLong("balanceDate", System.currentTimeMillis())
}
loginLiveData.postValue(result) loginLiveData.postValue(result)
} catch (e: Exception) { } catch (e: Exception) {
loginLiveData.postValue(Result.failure(e)) loginLiveData.postValue(Result.failure(e))
......
...@@ -6,13 +6,12 @@ import androidx.lifecycle.viewModelScope ...@@ -6,13 +6,12 @@ import androidx.lifecycle.viewModelScope
import com.miya.fastcashier.service.AccountService import com.miya.fastcashier.service.AccountService
import com.miya.fastcashier.service.PrintService import com.miya.fastcashier.service.PrintService
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 kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.* import kotlinx.coroutines.launch
class PrintViewModel : ViewModel() { class PrintViewModel : ViewModel() {
val printResultLiveData: MutableLiveData<Result<Any>> = MutableLiveData() val printResultLiveData: MutableLiveData<Result<Any>> = MutableLiveData()
val kv = MMKV.defaultMMKV()
fun printOrder(payServiceResponse: PayServiceResponse){ fun printOrder(payServiceResponse: PayServiceResponse){
//todo 检查参数 //todo 检查参数
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment