Commit 2c357f4c authored by zhaopengxiang's avatar zhaopengxiang

处理跳转,代码优化

parent 928e7aa5
......@@ -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
......@@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider
import com.alibaba.fastjson.JSON
import com.blankj.utilcode.util.LogUtils
import com.miya.fastcashier.config.IntentExtra
import com.miya.fastcashier.databinding.ActivityAliPayCodeBinding
import com.miya.fastcashier.utils.CenterToasty
import com.miya.fastcashier.utils.StringPriceFormat
......@@ -27,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)
......@@ -40,7 +50,7 @@ class AliPayCodeActivity : AppCompatActivity() {
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))
......@@ -68,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)
}
}
})
......
package com.miya.fastcashier.ui
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.ViewModelProvider
import com.miya.fastcashier.databinding.ActivityMainBinding
......@@ -29,7 +29,7 @@ class MainActivity : BaseActivity() {
companion object {
@JvmStatic
fun start(context: Context) {
fun start(context: AppCompatActivity) {
val intent = Intent()
intent.setClass(context, MainActivity::class.java)
context.startActivity(intent)
......@@ -66,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 {
......@@ -127,7 +126,7 @@ class MainActivity : BaseActivity() {
}
private fun checkAccountPassword() {
AccountPasswordManageKit.getInstance().checkAccountPassword(this)
AccountPasswordManageKit.get().checkAccountPassword(this)
}
private fun initData() {
......
......@@ -5,6 +5,7 @@ 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.utils.CenterToasty
import com.miya.fastcashier.utils.ScanGunKeyEventHelper
......@@ -13,7 +14,6 @@ import com.miya.fastcashier.utils.manage.OrderRecordManageKit
import com.miya.fastcashier.viewmodel.PayViewModel
import java.util.*
class PayActivity : BaseActivity() {
private lateinit var viewModel: PayViewModel
private lateinit var binding: ActivityPayBinding
......@@ -21,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()}"
......@@ -38,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() }
......
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.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)
}
}
})
......
......@@ -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(
......
......@@ -89,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 {
......@@ -190,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)
}
}
})
......
......@@ -76,20 +76,26 @@ class ResetAuthorizePasswordActivity : BaseActivity() {
return
}
val accountAuthorizePassword = AccountPasswordManageKit.getInstance().accountPassword
val accountAuthorizePassword = AccountPasswordManageKit.get().accountPassword
if (TextUtils.isEmpty(accountAuthorizePassword)) {
AccountPasswordManageKit.getInstance()
.loadAccountPassword(this) {
if (!it.equals(originPassword)) {
CenterToasty.error(this, "原始密码输入错误!").show()
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)
}
}
......@@ -97,7 +103,7 @@ class ResetAuthorizePasswordActivity : BaseActivity() {
private fun updateAuthorizePasswordSucced(newPassword: String) {
CenterToasty.success(this, "修改成功!", 1).show()
AccountPasswordManageKit.getInstance().updateAccountPassword(newPassword)
AccountPasswordManageKit.get().updateAccountPassword(newPassword)
finish()
}
}
\ No newline at end of file
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
......@@ -33,6 +34,13 @@ import com.miya.fastcashier.viewmodel.SearchOrderViewModel
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))
......
......@@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider
import com.alibaba.fastjson.JSON
import com.blankj.utilcode.util.LogUtils
import com.miya.fastcashier.config.IntentExtra
import com.miya.fastcashier.databinding.ActivityWxPayCodeBinding
import com.miya.fastcashier.utils.CenterToasty
import com.miya.fastcashier.utils.StringPriceFormat
......@@ -26,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)
......@@ -39,7 +49,7 @@ class WxPayCodeActivity : AppCompatActivity() {
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))
......@@ -67,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)
}
}
})
......
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.getInstance().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)
}
......
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
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