From 3eed571ee524836e1499f9aad309baee03cf7ae7 Mon Sep 17 00:00:00 2001 From: Adlyq <45322943+Adlyq@users.noreply.github.com> Date: Tue, 3 Dec 2024 17:57:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=98=9F=E5=88=97=E5=8C=96=E5=BC=B9?= =?UTF-8?q?=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/net/ankio/auto/App.kt | 8 +- .../auto/service/FloatingWindowService.kt | 133 +++++----- .../ankio/auto/ui/dialog/FloatEditorDialog.kt | 249 +++++++++++------- 3 files changed, 221 insertions(+), 169 deletions(-) diff --git a/app/src/main/java/net/ankio/auto/App.kt b/app/src/main/java/net/ankio/auto/App.kt index 4137781ed..4eb445407 100755 --- a/app/src/main/java/net/ankio/auto/App.kt +++ b/app/src/main/java/net/ankio/auto/App.kt @@ -22,7 +22,6 @@ import android.content.Context import android.content.Intent import android.content.Intent.FLAG_ACTIVITY_NEW_TASK import android.content.pm.PackageManager -import android.content.res.Resources import android.graphics.Color import android.os.Build import android.os.Process @@ -43,6 +42,8 @@ import net.ankio.auto.utils.ExceptionHandler import org.ezbook.server.constant.Setting import java.math.BigInteger import java.security.MessageDigest +import kotlin.coroutines.CoroutineContext +import kotlin.coroutines.EmptyCoroutineContext class App : Application() { @@ -67,8 +68,8 @@ class App : Application() { /** * 获取全局协程 */ - fun launch(block: suspend CoroutineScope.() -> Unit) { - scope.launch(block = block) + fun launch(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> Unit) { + scope.launch(context = context, block = block) } /** @@ -203,7 +204,6 @@ class App : Application() { } - /** * 打开记账软件应用 */ diff --git a/app/src/main/java/net/ankio/auto/service/FloatingWindowService.kt b/app/src/main/java/net/ankio/auto/service/FloatingWindowService.kt index cff67a217..c83f76ff1 100755 --- a/app/src/main/java/net/ankio/auto/service/FloatingWindowService.kt +++ b/app/src/main/java/net/ankio/auto/service/FloatingWindowService.kt @@ -15,25 +15,21 @@ package net.ankio.auto.service -import android.app.Notification -import android.app.NotificationChannel -import android.app.NotificationManager import android.app.Service import android.content.Context import android.content.Intent import android.graphics.PixelFormat -import android.os.Bundle import android.os.CountDownTimer import android.os.IBinder -import android.view.ContextThemeWrapper -import android.view.Gravity -import android.view.LayoutInflater -import android.view.View -import android.view.WindowManager +import android.view.* import androidx.core.content.ContextCompat import com.google.gson.Gson import com.quickersilver.themeengine.ThemeEngine +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.channels.BufferOverflow +import kotlinx.coroutines.channels.Channel +import kotlinx.coroutines.newSingleThreadContext import kotlinx.coroutines.withContext import net.ankio.auto.App import net.ankio.auto.R @@ -49,6 +45,7 @@ import net.ankio.auto.utils.BillTool import org.ezbook.server.constant.BillState import org.ezbook.server.constant.Setting import org.ezbook.server.db.model.BillInfoModel +import java.util.concurrent.Executors class FloatingWindowService : Service() { @@ -63,8 +60,8 @@ class FloatingWindowService : Service() { private var timeCount: Int = 0 private var lastTheme = ThemeEngine.getInstance(App.app).getTheme() - - + private val billChannel = Channel>() // array 是 processBillInfo 的参数 + private val stopMsg = Channel(capacity = 1, BufferOverflow.DROP_LATEST) override fun onCreate() { super.onCreate() @@ -80,10 +77,38 @@ class FloatingWindowService : Service() { Logger.i("FloatingWindowService Start,Timeout:$timeCount s") + App.launch(Dispatchers.Main) { + for (args in billChannel) { + runCatching { + val billInfoModel = args[0] as BillInfoModel + val showWaitTip = args[1] as Boolean + + processBillInfo(billInfoModel, showWaitTip) + }.onFailure { + // 提醒用户报告错误 + Logger.e("Failed to record bill", it) + // 跳转错误页面 + val intent2 = Intent(App.app, ErrorActivity::class.java) + intent2.flags = Intent.FLAG_ACTIVITY_NEW_TASK + val sb = StringBuilder() + sb.append("自动记账未获取到悬浮窗权限,记账失败!\n") + sb.append("请在设置中手动授予该权限!\n") + sb.append(it.message).append("\n") + it.stackTrace.forEach { message -> + sb.append(message.toString()) + sb.append("\n") + } + intent2.putExtra("msg", sb.toString()) + startActivity(intent2) + }.onSuccess { + stopMsg.receive() + } + } + } } - companion object{ + companion object { val updateBills = mutableListOf() } @@ -100,16 +125,14 @@ class FloatingWindowService : Service() { } - val billInfoModel = - Gson().fromJson(intent.getStringExtra("billInfo"), BillInfoModel::class.java) - val from = intent.getStringExtra("from")?:"Unknown" + val billInfoModel = Gson().fromJson(intent.getStringExtra("billInfo"), BillInfoModel::class.java) + val from = intent.getStringExtra("from") ?: "Unknown" Logger.i("Server start => $intent, From = $from") Logger.i("BillInfo:$billInfoModel") val parent = runCatching { Gson().fromJson( - intent.getStringExtra("parent"), - BillInfoModel::class.java + intent.getStringExtra("parent"), BillInfoModel::class.java ) }.getOrNull() Logger.i("parent:$parent") @@ -121,27 +144,12 @@ class FloatingWindowService : Service() { updateBills.add(parent) LocalBroadcastHelper.sendBroadcast(LocalBroadcastHelper.ACTION_UPDATE_BILL) Logger.i("Repeat Bill, Parent: $parent") - return START_NOT_STICKY + return START_NOT_STICKY } - runCatching { - processBillInfo(billInfoModel, showWaitTip) - }.onFailure { - // 提醒用户报告错误 - Logger.e("Failed to record bill", it) - // 跳转错误页面 - val intent2 = Intent(App.app, ErrorActivity::class.java) - intent2.flags = Intent.FLAG_ACTIVITY_NEW_TASK - val sb = StringBuilder() - sb.append("自动记账未获取到悬浮窗权限,记账失败!\n") - sb.append("请在设置中手动授予该权限!\n") - sb.append(it.message).append("\n") - it.stackTrace.forEach { message -> - sb.append(message.toString()) - sb.append("\n") - } - intent2.putExtra("msg", sb.toString()) - startActivity(intent2) + App.launch { + Logger.i("send to billChannel, ${billChannel.isEmpty}") + billChannel.send(arrayOf(billInfoModel, showWaitTip)) } return START_NOT_STICKY @@ -166,19 +174,17 @@ class FloatingWindowService : Service() { binding.money.setTextColor(color) binding.time.text = String.format("%ss", timeCount.toString()) - val countDownTimer = - object : CountDownTimer(timeCount * 1000L, 1000) { - override fun onTick(millisUntilFinished: Long) { - binding.time.text = - String.format("%ss", (millisUntilFinished / 1000).toString()) - } + val countDownTimer = object : CountDownTimer(timeCount * 1000L, 1000) { + override fun onTick(millisUntilFinished: Long) { + binding.time.text = String.format("%ss", (millisUntilFinished / 1000).toString()) + } - override fun onFinish() { - // 取消倒计时 - removeTips(binding) - callBillInfoEditor(Setting.FLOAT_TIMEOUT_ACTION, billInfoModel) - } + override fun onFinish() { + // 取消倒计时 + removeTips(binding) + callBillInfoEditor(Setting.FLOAT_TIMEOUT_ACTION, billInfoModel) } + } binding.root.setOnClickListener { @@ -196,24 +202,22 @@ class FloatingWindowService : Service() { } // 设置 WindowManager.LayoutParams - val params = - WindowManager.LayoutParams( - WindowManager.LayoutParams.WRAP_CONTENT, - WindowManager.LayoutParams.WRAP_CONTENT, - WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, - WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, - PixelFormat.TRANSLUCENT, - ).apply { - x = 0 // 居中 - y = -120 // 居中偏上 - gravity = Gravity.CENTER or Gravity.END - } + val params = WindowManager.LayoutParams( + WindowManager.LayoutParams.WRAP_CONTENT, + WindowManager.LayoutParams.WRAP_CONTENT, + WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, + WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, + PixelFormat.TRANSLUCENT, + ).apply { + x = 0 // 居中 + y = -120 // 居中偏上 + gravity = Gravity.CENTER or Gravity.END + } // 将视图添加到 WindowManager windowManager.addView(binding.root, params) binding.root.post { - val widthInner = - binding.logo.width + binding.money.width + binding.time.width + 150 // logo间隔 + val widthInner = binding.logo.width + binding.money.width + binding.time.width + 150 // logo间隔 // 更新悬浮窗的宽度和高度 params.width = widthInner // 新宽度,单位:像素 params.height = binding.logo.height + 60 // 新高度,单位:像素 @@ -289,9 +293,10 @@ class FloatingWindowService : Service() { } - - private fun stopNotify(){ - + private fun stopNotify() { + App.launch { + stopMsg.send(Unit) + } } diff --git a/app/src/main/java/net/ankio/auto/ui/dialog/FloatEditorDialog.kt b/app/src/main/java/net/ankio/auto/ui/dialog/FloatEditorDialog.kt index bf27ad795..75335c518 100644 --- a/app/src/main/java/net/ankio/auto/ui/dialog/FloatEditorDialog.kt +++ b/app/src/main/java/net/ankio/auto/ui/dialog/FloatEditorDialog.kt @@ -47,17 +47,13 @@ import net.ankio.auto.ui.utils.ResourceUtils import net.ankio.auto.ui.utils.ToastUtils import net.ankio.auto.utils.BillTool import net.ankio.auto.utils.DateUtils -import org.ezbook.server.constant.AssetsType -import org.ezbook.server.constant.BillState -import org.ezbook.server.constant.BillType +import org.ezbook.server.constant.* import org.ezbook.server.constant.Currency -import org.ezbook.server.constant.Setting -import org.ezbook.server.constant.SyncType import org.ezbook.server.db.model.AssetsMapModel import org.ezbook.server.db.model.AssetsModel import org.ezbook.server.db.model.BillInfoModel import org.ezbook.server.db.model.BookNameModel -import java.util.Calendar +import java.util.* class FloatEditorDialog( private val context: Context, @@ -81,10 +77,10 @@ class FloatEditorDialog( private lateinit var broadcastReceiver: BroadcastReceiver - private fun checkUpdateBills():Boolean{ - val bill = FloatingWindowService.updateBills.find { rawBillInfo.id == it.id } - if (bill == null)return false - FloatingWindowService.updateBills.remove(bill) + private fun checkUpdateBills(): Boolean { + val bill = FloatingWindowService.updateBills.find { rawBillInfo.id == it.id } + if (bill == null) return false + FloatingWindowService.updateBills.remove(bill) billInfoModel = bill.copy() rawBillInfo = bill.copy() convertBillInfo = bill.copy() @@ -93,15 +89,17 @@ class FloatEditorDialog( bindUI() return true } + override fun onCreateView(inflater: LayoutInflater): View { - broadcastReceiver = LocalBroadcastHelper.registerReceiver(LocalBroadcastHelper.ACTION_UPDATE_BILL) { action, bundle -> - Logger.i("更新账单") - checkUpdateBills() - } + broadcastReceiver = + LocalBroadcastHelper.registerReceiver(LocalBroadcastHelper.ACTION_UPDATE_BILL) { action, bundle -> + Logger.i("更新账单") + checkUpdateBills() + } binding = FloatEditorBinding.inflate(inflater) cardView = binding.editorCard - if (!checkUpdateBills()){ + if (!checkUpdateBills()) { Logger.d("Raw BillInfo => $rawBillInfo") billTypeLevel1 = BillTool.getType(rawBillInfo.type) billTypeLevel2 = rawBillInfo.type @@ -115,22 +113,27 @@ class FloatEditorDialog( // 综合以上内容,应用到billInfo对象上 - private fun getBillData(assets :List): BillInfoModel { - val assetManager = ConfigUtils.getBoolean(Setting.SETTING_ASSET_MANAGER,true) + private fun getBillData(assets: List): BillInfoModel { + val assetManager = ConfigUtils.getBoolean(Setting.SETTING_ASSET_MANAGER, true) Logger.d("Get Bill Data, type=> $billTypeLevel2, type1=> $billTypeLevel1") - return billInfoModel.copy().apply { + return billInfoModel.copy().apply { this.type = billTypeLevel2 when (billTypeLevel2) { BillType.Expend -> { this.accountNameFrom = binding.payFrom.getText() this.accountNameTo = "" - if (assetManager){ - if(this.accountNameFrom.isEmpty()){ + if (assetManager) { + if (this.accountNameFrom.isEmpty()) { throw BillException(context.getString(R.string.expend_account_empty)) } - if(assets.find { it.name == this.accountNameFrom } == null){ - throw BillException(context.getString(R.string.expend_account_not_exist,this.accountNameFrom)) + if (assets.find { it.name == this.accountNameFrom } == null) { + throw BillException( + context.getString( + R.string.expend_account_not_exist, + this.accountNameFrom + ) + ) } } @@ -139,12 +142,17 @@ class FloatEditorDialog( BillType.Income -> { this.accountNameFrom = binding.payFrom.getText() this.accountNameTo = "" - if (assetManager){ - if(this.accountNameFrom.isEmpty()){ + if (assetManager) { + if (this.accountNameFrom.isEmpty()) { throw BillException(context.getString(R.string.income_account_empty)) } - if(assets.find { it.name == this.accountNameFrom } == null){ - throw BillException(context.getString(R.string.expend_account_not_exist,this.accountNameFrom)) + if (assets.find { it.name == this.accountNameFrom } == null) { + throw BillException( + context.getString( + R.string.expend_account_not_exist, + this.accountNameFrom + ) + ) } } @@ -153,24 +161,34 @@ class FloatEditorDialog( BillType.Transfer -> { this.accountNameFrom = binding.transferFrom.getText() this.accountNameTo = binding.transferTo.getText() - if (assetManager){ - if(this.accountNameFrom.isEmpty()){ + if (assetManager) { + if (this.accountNameFrom.isEmpty()) { throw BillException(context.getString(R.string.transfer_from_empty)) } - if(this.accountNameTo.isEmpty()){ + if (this.accountNameTo.isEmpty()) { throw BillException(context.getString(R.string.transfer_to_empty)) } - if (this.accountNameFrom == this.accountNameTo){ + if (this.accountNameFrom == this.accountNameTo) { throw BillException(context.getString(R.string.transfer_same_account)) } - if(assets.find { it.name == this.accountNameFrom } == null){ - throw BillException(context.getString(R.string.expend_account_not_exist,this.accountNameFrom)) + if (assets.find { it.name == this.accountNameFrom } == null) { + throw BillException( + context.getString( + R.string.expend_account_not_exist, + this.accountNameFrom + ) + ) } - if(assets.find { it.name == this.accountNameTo } == null){ - throw BillException(context.getString(R.string.expend_account_not_exist,this.accountNameTo)) + if (assets.find { it.name == this.accountNameTo } == null) { + throw BillException( + context.getString( + R.string.expend_account_not_exist, + this.accountNameTo + ) + ) } } @@ -179,12 +197,17 @@ class FloatEditorDialog( BillType.ExpendReimbursement -> { this.accountNameFrom = binding.payFrom.getText() this.accountNameTo = "" - if (assetManager){ - if(this.accountNameFrom.isEmpty()){ + if (assetManager) { + if (this.accountNameFrom.isEmpty()) { throw BillException(context.getString(R.string.reimbursement_account_empty)) } - if(assets.find { it.name == this.accountNameFrom } == null){ - throw BillException(context.getString(R.string.expend_account_not_exist,this.accountNameFrom)) + if (assets.find { it.name == this.accountNameFrom } == null) { + throw BillException( + context.getString( + R.string.expend_account_not_exist, + this.accountNameFrom + ) + ) } } @@ -194,32 +217,45 @@ class FloatEditorDialog( BillType.IncomeReimbursement -> { this.accountNameFrom = binding.payFrom.getText() this.extendData = selectedBills.joinToString { it } - if (assetManager){ - if(this.accountNameFrom.isEmpty()){ + if (assetManager) { + if (this.accountNameFrom.isEmpty()) { throw BillException(context.getString(R.string.reimbursement_income_account_empty)) } - if (selectedBills.isEmpty()){ + if (selectedBills.isEmpty()) { throw BillException(context.getString(R.string.reimbursement_bill_empty)) } - if(assets.find { it.name == this.accountNameFrom } == null){ - throw BillException(context.getString(R.string.expend_account_not_exist,this.accountNameFrom)) + if (assets.find { it.name == this.accountNameFrom } == null) { + throw BillException( + context.getString( + R.string.expend_account_not_exist, + this.accountNameFrom + ) + ) } } } // 借出,还款 - BillType.ExpendLending,BillType.ExpendRepayment -> { + BillType.ExpendLending, BillType.ExpendRepayment -> { this.accountNameFrom = binding.debtExpendFrom.getText() this.accountNameTo = binding.debtExpendTo.getText().toString() - if (assetManager){ - if(this.accountNameFrom.isEmpty()){ - throw BillException(if(BillType.ExpendLending==billTypeLevel2) context.getString(R.string.expend_debt_empty) else context.getString(R.string.repayment_account_empty)) + if (assetManager) { + if (this.accountNameFrom.isEmpty()) { + throw BillException( + if (BillType.ExpendLending == billTypeLevel2) context.getString(R.string.expend_debt_empty) else context.getString( + R.string.repayment_account_empty + ) + ) } - if(this.accountNameTo.isEmpty()){ - throw BillException(if(BillType.ExpendLending==billTypeLevel2) context.getString(R.string.debt_account_empty) else context.getString(R.string.repayment_account2_empty)) + if (this.accountNameTo.isEmpty()) { + throw BillException( + if (BillType.ExpendLending == billTypeLevel2) context.getString(R.string.debt_account_empty) else context.getString( + R.string.repayment_account2_empty + ) + ) } - if (this.accountNameFrom == this.accountNameTo){ + if (this.accountNameFrom == this.accountNameTo) { throw BillException(context.getString(R.string.lending_same_account)) } @@ -232,14 +268,22 @@ class FloatEditorDialog( BillType.IncomeLending, BillType.IncomeRepayment -> { this.accountNameFrom = binding.debtIncomeFrom.getText().toString() this.accountNameTo = binding.debtIncomeTo.getText() - if (assetManager){ - if(this.accountNameFrom.isEmpty()){ - throw BillException(if(BillType.IncomeLending==billTypeLevel2) context.getString(R.string.income_debt_empty) else context.getString(R.string.income_lending_account_empty)) + if (assetManager) { + if (this.accountNameFrom.isEmpty()) { + throw BillException( + if (BillType.IncomeLending == billTypeLevel2) context.getString(R.string.income_debt_empty) else context.getString( + R.string.income_lending_account_empty + ) + ) } - if(this.accountNameTo.isEmpty()){ - throw BillException(if(BillType.IncomeLending==billTypeLevel2) context.getString(R.string.income_lending_account2_empty) else context.getString(R.string.income_repayment_account_empty)) + if (this.accountNameTo.isEmpty()) { + throw BillException( + if (BillType.IncomeLending == billTypeLevel2) context.getString(R.string.income_lending_account2_empty) else context.getString( + R.string.income_repayment_account_empty + ) + ) } - if (this.accountNameFrom == this.accountNameTo){ + if (this.accountNameFrom == this.accountNameTo) { throw BillException(context.getString(R.string.lending_same_account)) } @@ -253,7 +297,7 @@ class FloatEditorDialog( } override fun dismiss() { - if (::broadcastReceiver.isInitialized){ + if (::broadcastReceiver.isInitialized) { LocalBroadcastHelper.unregisterReceiver(broadcastReceiver) } super.dismiss() @@ -271,11 +315,11 @@ class FloatEditorDialog( lifecycleScope.launch { val assets = AssetsModel.list() - try{ + try { convertBillInfo = getBillData(assets) - }catch (e:BillException){ - ToastUtils.error(e.message?:"未知错误") - Logger.e("Failed to get bill data",e) + } catch (e: BillException) { + ToastUtils.error(e.message ?: "未知错误") + Logger.e("Failed to get bill data", e) return@launch } @@ -299,7 +343,7 @@ class FloatEditorDialog( ) ) { // 弹出询问框 - BillCategoryDialog(context, convertBillInfo).show(float,cancel = true) + BillCategoryDialog(context, convertBillInfo).show(float, cancel = true) } if (ConfigUtils.getBoolean(Setting.AUTO_ASSET, false)) { @@ -310,7 +354,7 @@ class FloatEditorDialog( val syncType = ConfigUtils.getString(Setting.SYNC_TYPE, SyncType.WhenOpenApp.name) if (syncType != SyncType.WhenOpenApp.name) { - val bills = BillInfoModel.sync() + val bills = BillInfoModel.sync() if ((syncType == SyncType.BillsLimit10.name && bills.size >= 10) || (syncType == SyncType.BillsLimit5.name && bills.size >= 5)) { App.startBookApp() } @@ -330,21 +374,22 @@ class FloatEditorDialog( } - private suspend fun setAccountMap(assets: List, accountName:String, eqAccountName:String)= withContext(Dispatchers.IO){ + private suspend fun setAccountMap(assets: List, accountName: String, eqAccountName: String) = + withContext(Dispatchers.IO) { - if (accountName.isEmpty()) return@withContext - if (accountName == eqAccountName) return@withContext - //非标准资产需要映射 - val find = assets.find { it.name == accountName } - if (find == null)return@withContext - Logger.d("Create new asset map => $accountName -> $eqAccountName") - AssetsMapModel.put(AssetsMapModel().apply { - this.name = accountName - this.mapName = eqAccountName - }) + if (accountName.isEmpty()) return@withContext + if (accountName == eqAccountName) return@withContext + //非标准资产需要映射 + val find = assets.find { it.name == accountName } + if (find == null) return@withContext + Logger.d("Create new asset map => $accountName -> $eqAccountName") + AssetsMapModel.put(AssetsMapModel().apply { + this.name = accountName + this.mapName = eqAccountName + }) - } + } private fun bindingTypePopupUI() { binding.priceContainer.text = billInfoModel.money.toString() @@ -352,7 +397,7 @@ class FloatEditorDialog( private fun bindingTypePopupEvents() { val stringList: HashMap = - if (ConfigUtils.getBoolean(Setting.SETTING_ASSET_MANAGER,true)) + if (ConfigUtils.getBoolean(Setting.SETTING_ASSET_MANAGER, true)) hashMapOf( context.getString(R.string.float_expend) to BillType.Expend, context.getString(R.string.float_income) to BillType.Income, @@ -385,7 +430,7 @@ class FloatEditorDialog( * */ if ( - !ConfigUtils.getBoolean(Setting.SETTING_FEE,false) || + !ConfigUtils.getBoolean(Setting.SETTING_FEE, false) || billTypeLevel1 != BillType.Transfer || billInfoModel.fee == 0.0 ) { @@ -416,11 +461,11 @@ class FloatEditorDialog( */ private fun bindingBookNameEvents() { binding.bookImageClick.setOnClickListener { - if (!ConfigUtils.getBoolean(Setting.SETTING_BOOK_MANAGER,true)) return@setOnClickListener + if (!ConfigUtils.getBoolean(Setting.SETTING_BOOK_MANAGER, true)) return@setOnClickListener BookSelectorDialog(context) { book, _ -> billInfoModel.bookName = book.name bindingBookNameUI() - }.show(float,cancel = true) + }.show(float, cancel = true) } } @@ -485,14 +530,14 @@ class FloatEditorDialog( BillTool.getCateName(parent.name ?: "", child?.name) bindingCategoryUI() - }.show(float,cancel = true) + }.show(float, cancel = true) } } } } private fun bindingMoneyTypeUI() { - if (!ConfigUtils.getBoolean(Setting.SETTING_CURRENCY_MANAGER,false)) { + if (!ConfigUtils.getBoolean(Setting.SETTING_CURRENCY_MANAGER, false)) { binding.moneyType.visibility = View.GONE return } @@ -502,7 +547,7 @@ class FloatEditorDialog( } private fun bindingMoneyTypeEvents() { - if (!ConfigUtils.getBoolean(Setting.SETTING_CURRENCY_MANAGER,false)) return + if (!ConfigUtils.getBoolean(Setting.SETTING_CURRENCY_MANAGER, false)) return binding.moneyType.setOnClickListener { val hashMap = Currency.getCurrencyMap(context) val popupUtils = @@ -755,7 +800,7 @@ class FloatEditorDialog( } - if (!ConfigUtils.getBoolean(Setting.SETTING_ASSET_MANAGER,true)) { + if (!ConfigUtils.getBoolean(Setting.SETTING_ASSET_MANAGER, true)) { binding.chipLend.visibility = View.GONE binding.chipBorrow.visibility = View.GONE binding.chipRepayment.visibility = View.GONE @@ -765,13 +810,13 @@ class FloatEditorDialog( binding.debtIncome.visibility = View.GONE } - if (!ConfigUtils.getBoolean(Setting.SETTING_DEBT,true)) { + if (!ConfigUtils.getBoolean(Setting.SETTING_DEBT, true)) { binding.chipLend.visibility = View.GONE binding.chipBorrow.visibility = View.GONE binding.chipRepayment.visibility = View.GONE } - if (!ConfigUtils.getBoolean(Setting.SETTING_REIMBURSEMENT,true)) { + if (!ConfigUtils.getBoolean(Setting.SETTING_REIMBURSEMENT, true)) { binding.chipReimbursement.visibility = View.GONE } } @@ -828,7 +873,7 @@ class FloatEditorDialog( BillSelectorDialog(context, selectedBills) { bindingSelectBillsUi() - }.show(float,cancel = true) + }.show(float, cancel = true) } } @@ -836,16 +881,18 @@ class FloatEditorDialog( setBillType(billTypeLevel1) binding.chipGroup.clearCheck() - if (billTypeLevel1!=BillType.Transfer && billTypeLevel1 != rawBillInfo.type) { - binding.chipGroup.check(when (rawBillInfo.type) { - BillType.ExpendReimbursement -> R.id.chipReimbursement - BillType.ExpendLending -> R.id.chipLend - BillType.ExpendRepayment -> R.id.chipRepayment - BillType.IncomeLending -> R.id.chipBorrow - BillType.IncomeRepayment -> R.id.chipRepayment - BillType.IncomeReimbursement -> R.id.chipReimbursement - else -> -1 - }) + if (billTypeLevel1 != BillType.Transfer && billTypeLevel1 != rawBillInfo.type) { + binding.chipGroup.check( + when (rawBillInfo.type) { + BillType.ExpendReimbursement -> R.id.chipReimbursement + BillType.ExpendLending -> R.id.chipLend + BillType.ExpendRepayment -> R.id.chipRepayment + BillType.IncomeLending -> R.id.chipBorrow + BillType.IncomeRepayment -> R.id.chipRepayment + BillType.IncomeReimbursement -> R.id.chipReimbursement + else -> -1 + } + ) setBillTypeLevel2(rawBillInfo.type) } @@ -876,30 +923,30 @@ class FloatEditorDialog( binding.payFrom.setOnClickListener { AssetsSelectorDialog(context) { model -> setAssetItem(model.name, model.icon, binding.payFrom) - }.show(float = float,cancel = true) + }.show(float = float, cancel = true) } binding.transferFrom.setOnClickListener { AssetsSelectorDialog(context) { model -> setAssetItem(model.name, model.icon, binding.transferFrom) - }.show(float = float,cancel = true) + }.show(float = float, cancel = true) } binding.transferTo.setOnClickListener { AssetsSelectorDialog(context) { model -> setAssetItem(model.name, model.icon, binding.transferTo) - }.show(float = float,cancel = true) + }.show(float = float, cancel = true) } binding.debtExpendFrom.setOnClickListener { AssetsSelectorDialog(context) { model -> setAssetItem(model.name, model.icon, binding.debtExpendFrom) - }.show(float = float,cancel = true) + }.show(float = float, cancel = true) } binding.debtIncomeTo.setOnClickListener { AssetsSelectorDialog(context) { model -> setAssetItem(model.name, model.icon, binding.debtIncomeTo) - }.show(float = float,cancel = true) + }.show(float = float, cancel = true) } }