Skip to content

Commit 9382e9e

Browse files
committed
[feat] 资产账户新增图标
1 parent ef0110a commit 9382e9e

File tree

52 files changed

+697
-90
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+697
-90
lines changed

app/build.gradle.kts

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ dependencies {
2727
/**-------------------第三方库依赖--------------------**/
2828

2929
implementation(Libs.swipeRefreshLayout)
30-
implementation(Libs.coil)
3130

3231
// 内存泄漏
3332
debugImplementation(Libs.leakCanary)

buildSrc/src/main/java/Dependencies.kt

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ object Version {
4141
const val bus = "1.7.3"
4242
const val chart = "3.1.0"
4343
const val dateTimePicker = "0.5.7"
44+
const val flexLayout = "3.0.0"
4445
}
4546

4647
/**
@@ -50,6 +51,7 @@ object Libs {
5051
// base
5152
const val core_ktx = "androidx.core:core-ktx:${Version.core_ktx}"
5253
const val appcompat = "androidx.appcompat:appcompat:${Version.appcompat}"
54+
5355
// const val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-android:${Version.coroutines}"
5456
const val recyclerview = "androidx.recyclerview:recyclerview:${Version.recyclerview}"
5557
const val coil = "io.coil-kt:coil:${Version.coil}"
@@ -129,5 +131,8 @@ object Libs {
129131

130132
// DateTimePicker
131133
const val dateTimePicker = "com.github.loperSeven:DateTimePicker:${Version.dateTimePicker}"
134+
135+
// flexLayout
136+
const val flexLayout = "com.google.android.flexbox:flexbox:${Version.flexLayout}"
132137
}
133138

module_common/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,5 @@ dependencies {
4343
api(Libs.room_runtime)
4444
implementation(Libs.room)
4545
kapt(Libs.room_compiler)
46+
api(Libs.coil)
4647
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
package life.chenshi.keepaccounts.module.common.constant
22

3-
const val CATEGORY = "category"
3+
const val CATEGORY = "category"
4+
const val ASSET_ICON ="asset_icon"

module_common/src/main/kotlin/life/chenshi/keepaccounts/module/common/database/entity/AssetsAccount.kt

+1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ data class AssetsAccount constructor(
3131
val includedInAllAsset: Boolean,
3232
@ColumnInfo(name = "expire_time")
3333
val expireTime: Date,
34+
val type: String
3435
) : BaseEntity()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package life.chenshi.keepaccounts.module.common.utils
2+
3+
import android.animation.TimeInterpolator
4+
import androidx.core.view.animation.PathInterpolatorCompat
5+
import androidx.transition.Transition
6+
import androidx.transition.TransitionSet
7+
8+
inline fun transitionTogether(crossinline body: TransitionSet.() -> Unit): TransitionSet {
9+
return TransitionSet().apply {
10+
ordering = TransitionSet.ORDERING_TOGETHER
11+
body()
12+
}
13+
}
14+
15+
operator fun TransitionSet.plusAssign(transition: Transition) {
16+
addTransition(transition)
17+
}
18+
19+
20+
val FAST_OUT_SLOW_IN: TimeInterpolator by lazy(LazyThreadSafetyMode.NONE) {
21+
PathInterpolatorCompat.create(0.4f, 0f, 0.2f, 1f)
22+
}
23+
24+
/**
25+
* Decelerate easing.
26+
*
27+
* Incoming elements are animated using deceleration easing, which starts a transition at peak
28+
* velocity (the fastest point of an element’s movement) and ends at rest.
29+
*/
30+
val LINEAR_OUT_SLOW_IN: TimeInterpolator by lazy(LazyThreadSafetyMode.NONE) {
31+
PathInterpolatorCompat.create(0f, 0f, 0.2f, 1f)
32+
}
33+
34+
/**
35+
* Accelerate easing.
36+
*
37+
* Elements exiting a screen use acceleration easing, where they start at rest and end at peak
38+
* velocity.
39+
*/
40+
val FAST_OUT_LINEAR_IN: TimeInterpolator by lazy(LazyThreadSafetyMode.NONE) {
41+
PathInterpolatorCompat.create(0.4f, 0f, 1f, 1f)
42+
}

module_common/src/main/kotlin/life/chenshi/keepaccounts/module/common/utils/BindingAdapters.kt

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
package life.chenshi.keepaccounts.module.common.utils
22

3+
import android.graphics.Color
34
import android.view.View
5+
import android.widget.ImageView
46
import android.widget.TextView
7+
import androidx.annotation.DrawableRes
58
import androidx.databinding.BindingAdapter
9+
import coil.load
10+
import life.chenshi.keepaccounts.module.common.R
611
import java.text.DateFormat
712
import java.util.*
813

@@ -20,8 +25,8 @@ fun bindTextWithVisibility(view: TextView, text: CharSequence?) {
2025
}
2126

2227
@BindingAdapter("nullableText", "defaultText", requireAll = true)
23-
fun bindDefaultTextIfNullOrEmpty(view: TextView, nullableText: CharSequence?, defaultText:CharSequence) {
24-
view.text = nullableText.takeUnless { it.isNullOrEmpty() } ?: defaultText
28+
fun bindDefaultTextIfNullOrEmpty(view: TextView, nullableText: CharSequence?, defaultText: CharSequence) {
29+
view.text = nullableText.takeUnless { it.isNullOrBlank() } ?: defaultText
2530
}
2631

2732
/**
@@ -30,4 +35,23 @@ fun bindDefaultTextIfNullOrEmpty(view: TextView, nullableText: CharSequence?, de
3035
@BindingAdapter("timestamp", "format", requireAll = true)
3136
fun bindTimeStampToText(view: TextView, timestamp: Long, format: DateFormat) {
3237
view.text = DateUtil.date2String(Date(timestamp), format)
38+
}
39+
40+
@BindingAdapter("drawableInt")
41+
fun bindDrawableRes(imageView: ImageView, @DrawableRes drawableInt: Int) {
42+
imageView.load(drawableInt)
43+
}
44+
45+
@BindingAdapter("gradientColorStr")
46+
fun bindGradientColorStr(view: View, colorStr: String?) {
47+
if (colorStr == null) {
48+
view.setBackgroundResource(R.drawable.common_corner_all_large_primary_gradient)
49+
return
50+
}
51+
view.setShapeWithRippleBackground(
52+
view.context.resources.getDimension(R.dimen.common_large_corner_size),
53+
Color.parseColor(colorStr),
54+
Color.parseColor("#27707070"),
55+
true
56+
)
3357
}

module_common/src/main/kotlin/life/chenshi/keepaccounts/module/common/utils/StringExt.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package life.chenshi.keepaccounts.module.common.utils
22

3-
fun String?.ifNullOrEmpty(defaultValue: () -> String): String = if (this.isNullOrEmpty()) {
3+
fun String?.ifNullOrBlank(defaultValue: () -> String?): String? = if (this.isNullOrBlank()) {
44
defaultValue()
55
} else {
66
this

module_common/src/main/kotlin/life/chenshi/keepaccounts/module/common/utils/ViewExt.kt

+23-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import android.content.res.Resources
77
import android.graphics.Color
88
import android.graphics.Paint
99
import android.graphics.drawable.Drawable
10+
import android.graphics.drawable.GradientDrawable
1011
import android.graphics.drawable.RippleDrawable
1112
import android.graphics.drawable.ShapeDrawable
1213
import android.graphics.drawable.shapes.RoundRectShape
@@ -16,6 +17,7 @@ import android.view.View
1617
import android.widget.ImageView
1718
import android.widget.TextView
1819
import androidx.annotation.ColorInt
20+
import androidx.core.graphics.ColorUtils
1921
import life.chenshi.keepaccounts.module.common.R
2022

2123
/*------------------属性-------------------------*/
@@ -89,7 +91,8 @@ fun ImageView.setVisibleWithDrawable(drawable: Drawable? = null) {
8991
fun View.setShapeWithRippleBackground(
9092
cornerSize: Float,
9193
@ColorInt backgroundColor: Int,
92-
@ColorInt rippleColor: Int
94+
@ColorInt rippleColor: Int,
95+
isGradient: Boolean = false
9396
) {
9497
val stateList = arrayOf(
9598
intArrayOf(android.R.attr.state_pressed),
@@ -117,10 +120,25 @@ fun View.setShapeWithRippleBackground(
117120
// maskDrawable.paint.style = Paint.Style.FILL
118121

119122
// 内容
120-
val contentDrawable = ShapeDrawable()
121-
contentDrawable.shape = roundRectShape
122-
contentDrawable.paint.color = backgroundColor
123-
contentDrawable.paint.style = Paint.Style.FILL
123+
val contentDrawable = if (isGradient) {
124+
GradientDrawable(
125+
GradientDrawable.Orientation.LEFT_RIGHT, intArrayOf(
126+
backgroundColor,
127+
ColorUtils.setAlphaComponent(backgroundColor, 180)
128+
)
129+
).apply {
130+
shape = GradientDrawable.RECTANGLE
131+
cornerRadius = cornerSize
132+
}
133+
} else {
134+
ShapeDrawable().apply {
135+
shape = roundRectShape
136+
paint.color = backgroundColor
137+
paint.style = Paint.Style.FILL
138+
}
139+
}
140+
141+
124142

125143
this.background = RippleDrawable(colorStateList, contentDrawable, null)
126144
}

module_common/src/main/res/drawable/common_arrow_more.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
android:viewportWidth="1024"
55
android:viewportHeight="1024">
66
<path
7-
android:fillColor="#FF000000"
7+
android:fillColor="?colorOnSurface"
88
android:pathData="M326.6,852.6c110.4,-112 219.3,-223.3 329.3,-333.6 13.8,-13.9 16.1,-20.9 0.8,-35.9 -105.5,-104.2 -209.6,-209.7 -314.7,-314.2 -11.3,-11.3 -14.7,-17.6 -0.8,-29.6 19.6,-16.8 37.1,-36 54.8,-54.8 7.4,-7.8 11.8,-10 20.9,-0.9C551.9,219.4 687.4,354.8 823.1,490c8.2,8.2 8.7,12.7 0.2,21.2A149528.8,149528.8 0,0 0,419.8 913.7c-8.6,8.6 -13.5,10.4 -23.3,1.1 -23.6,-22.4 -48.5,-43.4 -69.9,-62.3z"/>
99
</vector>
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<!-- Duration (in milliseconds) for slide transition animation -->
4-
<integer name="common_duration">300 </integer>
4+
<integer name="common_duration">300</integer>
55
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<dimen name="common_text_body">16sp</dimen>
4+
<dimen name="common_text_button">14sp</dimen>
5+
<dimen name="common_text_title">20sp</dimen>
6+
<dimen name="common_text_subtitle">16sp</dimen>
7+
</resources>

module_record/src/main/kotlin/life/chenshi/keepaccounts/module/record/ui/EditRecordFragment.kt

+6-7
Original file line numberDiff line numberDiff line change
@@ -412,13 +412,12 @@ class EditRecordFragment : NavBindingFragment<RecordFragmentEditRecordBinding>()
412412
}
413413

414414
// 监听类型选中
415-
LiveEventBus.get(CATEGORY, AbstractCategory::class.java)
416-
.observe(this) { abstractCategory ->
417-
// 先更新集合
418-
mEditRecordViewModel.insertIfNotExistInCommonCategory(abstractCategory)
419-
// 后更新选中
420-
mEditRecordViewModel.currentAbstractCategory.value = abstractCategory
421-
}
415+
LiveEventBus.get(CATEGORY, AbstractCategory::class.java).observe(viewLifecycleOwner) { abstractCategory ->
416+
// 先更新集合
417+
mEditRecordViewModel.insertIfNotExistInCommonCategory(abstractCategory)
418+
// 后更新选中
419+
mEditRecordViewModel.currentAbstractCategory.value = abstractCategory
420+
}
422421
}
423422

424423
/**

module_setting/build.gradle.kts

+4
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ android {
77
buildFeatures {
88
dataBinding = true
99
}
10+
}
11+
12+
dependencies {
13+
implementation(Libs.flexLayout)
1014
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package life.chenshi.keepaccounts.module.setting.adapter
2+
3+
import androidx.recyclerview.widget.GridLayoutManager
4+
import coil.load
5+
import com.jeremyliao.liveeventbus.LiveEventBus
6+
import life.chenshi.keepaccounts.module.common.base.BaseAdapter
7+
import life.chenshi.keepaccounts.module.common.constant.ASSET_ICON
8+
import life.chenshi.keepaccounts.module.setting.R
9+
import life.chenshi.keepaccounts.module.setting.bean.AssetIconGroupBean
10+
import life.chenshi.keepaccounts.module.setting.bean.assets.IAssetIcon
11+
import life.chenshi.keepaccounts.module.setting.databinding.SettingItemAssetsIconBinding
12+
import life.chenshi.keepaccounts.module.setting.databinding.SettingItemAssetsIconGroupBinding
13+
import javax.inject.Inject
14+
15+
class AssetIconGroupAdapter @Inject constructor() : BaseAdapter<AssetIconGroupBean, SettingItemAssetsIconGroupBinding>
16+
(emptyList()) {
17+
18+
override fun setResLayoutId(): Int = R.layout.setting_item_assets_icon_group
19+
20+
override fun onBindViewHolder(binding: SettingItemAssetsIconGroupBinding, itemData: AssetIconGroupBean) {
21+
binding.tvSelectAssetIconTitle.text = itemData.groupName
22+
binding.rvAssetIcons.layoutManager = GridLayoutManager(binding.root.context, 5)
23+
val adapter = IconAdapter()
24+
binding.rvAssetIcons.adapter = adapter
25+
binding.rvAssetIcons.setHasFixedSize(true)
26+
adapter.setData(itemData.icons)
27+
adapter.setOnItemClickListener { _, iAssetIcon, _ ->
28+
LiveEventBus.get(ASSET_ICON, IAssetIcon::class.java).post(iAssetIcon)
29+
}
30+
}
31+
}
32+
33+
class IconAdapter() : BaseAdapter<IAssetIcon, SettingItemAssetsIconBinding>(emptyList()) {
34+
35+
override fun onBindViewHolder(binding: SettingItemAssetsIconBinding, itemData: IAssetIcon) {
36+
binding.sivItemAssetsLogo.load(itemData.icon)
37+
binding.tvItemAssetsName.text = itemData.name
38+
}
39+
40+
override fun setResLayoutId(): Int = R.layout.setting_item_assets_icon
41+
}

module_setting/src/main/kotlin/life/chenshi/keepaccounts/module/setting/adapter/AssetsAccountAdapter.kt

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package life.chenshi.keepaccounts.module.setting.adapter
22

3+
import androidx.core.view.ViewCompat
34
import life.chenshi.keepaccounts.module.common.base.BaseAdapter
45
import life.chenshi.keepaccounts.module.common.database.entity.AssetsAccount
5-
import life.chenshi.keepaccounts.module.common.utils.DateUtil
6-
import life.chenshi.keepaccounts.module.common.utils.ifNullOrEmpty
6+
import life.chenshi.keepaccounts.module.common.utils.ifNullOrBlank
77
import life.chenshi.keepaccounts.module.setting.R
88
import life.chenshi.keepaccounts.module.setting.databinding.SettingItemAssetsAccountBinding
99
import life.chenshi.keepaccounts.module.setting.databinding.SettingItemAssetsAccountFooterBinding
@@ -15,11 +15,19 @@ import javax.inject.Inject
1515
class AssetsAccountAdapter @Inject constructor() :
1616
BaseAdapter<AssetsAccount, SettingItemAssetsAccountBinding>(emptyList()) {
1717

18+
companion object {
19+
const val TRANSITION_NAME_BACKGROUND = "background"
20+
const val TRANSITION_NAME_LOGO = "logo"
21+
const val TRANSITION_NAME_TITLE = "title"
22+
}
23+
1824
override fun onBindViewHolder(binding: SettingItemAssetsAccountBinding, itemData: AssetsAccount) {
19-
binding.tvAssetsName.text = itemData.name
20-
binding.tvAssetsNumber.text = itemData.number.ifNullOrEmpty { " / " }
21-
binding.tvAssetsBalance.text = itemData.balance.toPlainString()
22-
binding.tvAssetsExpireDate.text = DateUtil.date2String(itemData.expireTime, DateUtil.MONTH_DAY_FORMAT_2)
25+
binding.item = itemData
26+
binding.tvAssetsNumber.text = itemData.number.ifNullOrBlank { " / " }
27+
28+
ViewCompat.setTransitionName(binding.card, TRANSITION_NAME_BACKGROUND + "-${itemData.id}")
29+
ViewCompat.setTransitionName(binding.sivAssetsLogo, TRANSITION_NAME_LOGO + "-${itemData.id}")
30+
ViewCompat.setTransitionName(binding.tvAssetsName, TRANSITION_NAME_TITLE + "-${itemData.id}")
2331
}
2432

2533
override fun setResLayoutId() = R.layout.setting_item_assets_account
@@ -28,7 +36,7 @@ class AssetsAccountAdapter @Inject constructor() :
2836
class AssetsAccountFooterAdapter @Inject constructor() :
2937
BaseAdapter<AssetsAccount, SettingItemAssetsAccountFooterBinding>(
3038
listOf(
31-
AssetsAccount(null, "", BigDecimal(0), null, null, false, Date())
39+
AssetsAccount(null, "", BigDecimal(0), null, null, false, Date(), "")
3240
)
3341
) {
3442

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package life.chenshi.keepaccounts.module.setting.bean
2+
3+
import life.chenshi.keepaccounts.module.setting.bean.assets.IAssetIcon
4+
5+
data class AssetIconGroupBean(val groupName: String, val icons: List<IAssetIcon>)
6+
7+
8+
fun assetIconGroup(name: String, vararg icon: IAssetIcon): AssetIconGroupBean {
9+
return AssetIconGroupBean(name, icon.toList())
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package life.chenshi.keepaccounts.module.setting.bean.assets
2+
3+
import life.chenshi.keepaccounts.module.setting.R
4+
5+
object AgriculturalBank : IAssetIcon {
6+
override val name: String
7+
get() = "农业银行"
8+
override val icon: Int
9+
get() = R.drawable.setting_icon_bank_agricultural
10+
override val primaryColor: String
11+
get() = "#009C96"
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package life.chenshi.keepaccounts.module.setting.bean.assets
2+
3+
import life.chenshi.keepaccounts.module.setting.R
4+
5+
object Alipay : IAssetIcon {
6+
override val name: String
7+
get() = "支付宝"
8+
override val icon: Int
9+
get() = R.drawable.setting_icon_alipay
10+
override val primaryColor: String
11+
get() = "#03A9F4"
12+
}

0 commit comments

Comments
 (0)