Skip to content

Commit

Permalink
✨ 账单编辑悬浮窗美化
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkioTomas committed Dec 28, 2023
1 parent a7c70e0 commit 7cebff4
Show file tree
Hide file tree
Showing 18 changed files with 482 additions and 124 deletions.
15 changes: 1 addition & 14 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/misc.xml
100755 → 100644

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions app/src/main/java/net/ankio/auto/app/BillUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package net.ankio.auto.app
import net.ankio.auto.database.Db
import net.ankio.auto.database.table.BillInfo
import net.ankio.auto.utils.ActiveUtils
import net.ankio.auto.utils.SpUtils
import java.lang.Exception

object BillUtils {
Expand Down Expand Up @@ -123,4 +124,17 @@ object BillUtils {
}
return account
}

/**
* 生成备注信息
*/
fun getRemark(billInfo: BillInfo): String {
return SpUtils.getString("remarkTpl","[商户名称] - [商品名称]")
.replace("[商户名称]",billInfo.shopName)
.replace("[币种类型]",billInfo.currency.currencyName)
.replace("[金额]",billInfo.money.toString())
.replace("[分类]",billInfo.cateName)
.replace("[账本]",billInfo.bookName)
.replace("[来源]",billInfo.from)
}
}
1 change: 0 additions & 1 deletion app/src/main/java/net/ankio/auto/app/Engine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ object Engine {
billInfo.cateName = cateJson.getString("category")
billInfo.bookName = cateJson.getString("book")
hookUtils?.logD("分类脚本执行结果", billInfo.cateName)

} catch (e: Exception) {
hookUtils?.logD("执行脚本失败", e.stackTraceToString())
billInfo = null
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/net/ankio/auto/constant/BillType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ enum class BillType(val type: Int) {
Expend(0),//支出
Income(1),//收入
Transfer(2),//转账
Debt(3) //债务
}
2 changes: 2 additions & 0 deletions app/src/main/java/net/ankio/auto/database/dao/AccountDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ interface AccountDao {

@Query("UPDATE Account set sort=:sort WHERE id=:id")
suspend fun setSort(id: Int, sort: Int)
@Query("SELECT * FROM Account WHERE name=:account limit 1")
suspend fun get(account: String):Account?
}
2 changes: 2 additions & 0 deletions app/src/main/java/net/ankio/auto/database/dao/CategoryDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ interface CategoryDao {

@Insert
suspend fun add(data: Category)
@Query("SELECT * FROM Category where name=:cateName limit 1")
suspend fun get(cateName: String): Category?
}
45 changes: 41 additions & 4 deletions app/src/main/java/net/ankio/auto/database/table/BillInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class BillInfo {
var reimbursement: Boolean = false

/**
* 远程id,就是记账App中对应的账单ID
* 销账的账单id或者报销的账单id
*/
var remoteId: String = "-1"

Expand Down Expand Up @@ -136,6 +136,20 @@ class BillInfo {
* 是否已从App同步
*/
var syncFromApp:Boolean = false

/**
* 这笔账单是否为债务
*/
var debt:Boolean = false
/**
* 是否为债务销账
*/
var debtOver:Boolean = false

/**
* 备注信息
*/
var remark:String = ""
fun toJSON(): String {
return Gson().toJson(this)
}
Expand All @@ -146,9 +160,18 @@ class BillInfo {
fun fromJSON(json:String):BillInfo{
return Gson().fromJson(json,BillInfo::class.java)
}
suspend fun getCategoryDrawable(cateName: String,context: Context): Drawable? {
//TODO 根据分类名称获取对应的分类图标
return AppCompatResources.getDrawable(context, R.drawable.default_cate)
suspend fun getCategoryDrawable(cateName: String,context: Context,onGet:(drawable:Drawable)->Unit) {
val categoryInfo = Db.get().CategoryDao().get(cateName)
ImageUtils.get(context, categoryInfo?.icon ?:"",{
onGet(it)
},{
ResourcesCompat.getDrawable(context.resources,R.drawable.default_cate,context.theme)
?.let { it1 ->
onGet(
it1
)
}
})
}
suspend fun getBookDrawable(bookName: String,context: Context,imageView: ImageView) {

Expand All @@ -160,5 +183,19 @@ class BillInfo {
)
})
}

suspend fun getAccountDrawable(account:String,context: Context,onGet:(drawable:Drawable)->Unit) {
val accountInfo = Db.get().AccountDao().get(account)
ImageUtils.get(context, accountInfo?.icon ?:"",{
onGet(it)
},{
ResourcesCompat.getDrawable(context.resources,R.mipmap.ic_launcher_round,context.theme)
?.let { it1 ->
onGet(
it1
)
}
})
}
}
}
20 changes: 0 additions & 20 deletions app/src/main/java/net/ankio/auto/exceptions/UnsupportedUri.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class FloatingWindowService : Service(), CoroutineScope {
val value = intent.getStringExtra("data") ?: return START_NOT_STICKY
val timeCount: Int = SpUtils.getInt("float_timeout",10)
val billInfo = BillInfo.fromJSON(value)
billInfo.remark = BillUtils.getRemark(billInfo)
val defaultTheme = ContextThemeWrapper(this,R.style.AppTheme)
val themedContext = ContextThemeWrapper(defaultTheme, ThemeEngine.getInstance(applicationContext).getTheme())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class FloatingWindowTriggerActivity : AppCompatActivity() {
return
}
val billInfo = BillInfo.fromJSON(data)
billInfo.remark = BillUtils.getRemark(billInfo)
// 如果是全自动记账,则不会显示这个窗口,直接弹出记账成功
if(SpUtils.getBoolean("float_auto")){
lifecycleScope.launch {
Expand Down
13 changes: 6 additions & 7 deletions app/src/main/java/net/ankio/auto/ui/componets/IconView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class IconView @JvmOverloads constructor(

private var imageView: ImageView
private var textView: TextView
private var color:Int

init {
orientation = HORIZONTAL
Expand All @@ -55,18 +56,17 @@ class IconView @JvmOverloads constructor(
val iconTintEnabled = getBoolean(R.styleable.IconView_iconTintEnabled, true)
val icon = getDrawable(R.styleable.IconView_iconSrc)
val text = getString(R.styleable.IconView_text)
val textColor = getColor(R.styleable.IconView_textColor, Color.BLACK)
color = getColor(R.styleable.IconView_textColor, Color.BLACK)

setIcon(icon, iconTintEnabled,textColor)
setIcon(icon, iconTintEnabled)
setText(text)
setTextColor(textColor)
} finally {
recycle()
}
}
}

fun setIcon(icon: Drawable?, tintEnabled: Boolean,color: Int) {
fun setIcon(icon: Drawable?, tintEnabled: Boolean = false) {
imageView.setImageDrawable(icon)
if (!tintEnabled) {
imageView.clearColorFilter()
Expand All @@ -76,10 +76,9 @@ class IconView @JvmOverloads constructor(
}

fun setText(text: CharSequence?) {
textView.setTextColor(color)
textView.text = text
}

fun setTextColor(color: Int) {
textView.setTextColor(color)
}

}
Loading

0 comments on commit 7cebff4

Please sign in to comment.