Commit 2c357f4c authored by zhaopengxiang's avatar zhaopengxiang

处理跳转,代码优化

parent 928e7aa5
...@@ -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
...@@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity ...@@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity
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.miya.fastcashier.config.IntentExtra
import com.miya.fastcashier.databinding.ActivityAliPayCodeBinding import com.miya.fastcashier.databinding.ActivityAliPayCodeBinding
import com.miya.fastcashier.utils.CenterToasty import com.miya.fastcashier.utils.CenterToasty
import com.miya.fastcashier.utils.StringPriceFormat import com.miya.fastcashier.utils.StringPriceFormat
...@@ -27,6 +28,15 @@ class AliPayCodeActivity : AppCompatActivity() { ...@@ -27,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)
...@@ -40,7 +50,7 @@ class AliPayCodeActivity : AppCompatActivity() { ...@@ -40,7 +50,7 @@ class AliPayCodeActivity : AppCompatActivity() {
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))
...@@ -68,11 +78,7 @@ class AliPayCodeActivity : AppCompatActivity() { ...@@ -68,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)
} }
} }
}) })
......
package com.miya.fastcashier.ui package com.miya.fastcashier.ui
import android.content.Context
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
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.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.miya.fastcashier.databinding.ActivityMainBinding import com.miya.fastcashier.databinding.ActivityMainBinding
...@@ -29,7 +29,7 @@ class MainActivity : BaseActivity() { ...@@ -29,7 +29,7 @@ class MainActivity : BaseActivity() {
companion object { companion object {
@JvmStatic @JvmStatic
fun start(context: Context) { fun start(context: AppCompatActivity) {
val intent = Intent() val intent = Intent()
intent.setClass(context, MainActivity::class.java) intent.setClass(context, MainActivity::class.java)
context.startActivity(intent) context.startActivity(intent)
...@@ -66,8 +66,7 @@ class MainActivity : BaseActivity() { ...@@ -66,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 {
...@@ -127,7 +126,7 @@ class MainActivity : BaseActivity() { ...@@ -127,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() {
......
...@@ -5,6 +5,7 @@ import android.os.Bundle ...@@ -5,6 +5,7 @@ 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.utils.CenterToasty import com.miya.fastcashier.utils.CenterToasty
import com.miya.fastcashier.utils.ScanGunKeyEventHelper import com.miya.fastcashier.utils.ScanGunKeyEventHelper
...@@ -13,7 +14,6 @@ import com.miya.fastcashier.utils.manage.OrderRecordManageKit ...@@ -13,7 +14,6 @@ import com.miya.fastcashier.utils.manage.OrderRecordManageKit
import com.miya.fastcashier.viewmodel.PayViewModel import com.miya.fastcashier.viewmodel.PayViewModel
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
...@@ -21,13 +21,22 @@ class PayActivity : BaseActivity() { ...@@ -21,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()}"
...@@ -38,11 +47,7 @@ class PayActivity : BaseActivity() { ...@@ -38,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(
......
...@@ -89,16 +89,13 @@ class PriceInputActivity : BaseActivity() { ...@@ -89,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 {
...@@ -190,14 +187,11 @@ class PriceInputActivity : BaseActivity() { ...@@ -190,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)
} }
} }
}) })
......
...@@ -76,20 +76,26 @@ class ResetAuthorizePasswordActivity : BaseActivity() { ...@@ -76,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)
} }
} }
...@@ -97,7 +103,7 @@ class ResetAuthorizePasswordActivity : BaseActivity() { ...@@ -97,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
...@@ -33,6 +34,13 @@ import com.miya.fastcashier.viewmodel.SearchOrderViewModel ...@@ -33,6 +34,13 @@ import com.miya.fastcashier.viewmodel.SearchOrderViewModel
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))
......
...@@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity ...@@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity
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.miya.fastcashier.config.IntentExtra
import com.miya.fastcashier.databinding.ActivityWxPayCodeBinding import com.miya.fastcashier.databinding.ActivityWxPayCodeBinding
import com.miya.fastcashier.utils.CenterToasty import com.miya.fastcashier.utils.CenterToasty
import com.miya.fastcashier.utils.StringPriceFormat import com.miya.fastcashier.utils.StringPriceFormat
...@@ -26,6 +27,15 @@ class WxPayCodeActivity : AppCompatActivity() { ...@@ -26,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)
...@@ -39,7 +49,7 @@ class WxPayCodeActivity : AppCompatActivity() { ...@@ -39,7 +49,7 @@ class WxPayCodeActivity : AppCompatActivity() {
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))
...@@ -67,11 +77,7 @@ class WxPayCodeActivity : AppCompatActivity() { ...@@ -67,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.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