From 092bf21368ea824e9dc22467166960219165dc00 Mon Sep 17 00:00:00 2001 From: zuoxiao <470321431@qq.com> Date: 星期五, 21 二月 2025 17:32:59 +0800 Subject: [PATCH] 1.我的界面每个item添加点击效果。 2.更新本地数据添加二次确认。 --- expand_button/src/main/java/com/example/expand_button/ExpandButton.kt | 41 +++++++++++++++++++++++++++++++++++++---- 1 files changed, 37 insertions(+), 4 deletions(-) diff --git a/expand_button/src/main/java/com/example/expand_button/ExpandButton.kt b/expand_button/src/main/java/com/example/expand_button/ExpandButton.kt index 1ac7b29..007713c 100644 --- a/expand_button/src/main/java/com/example/expand_button/ExpandButton.kt +++ b/expand_button/src/main/java/com/example/expand_button/ExpandButton.kt @@ -86,6 +86,14 @@ // 娣诲姞涓�涓睘鎬у畾涔変笁瑙掑舰鍥炬爣鐨勭偣鍑诲尯鍩熸墿灞曡寖鍥� private val triangleClickPadding: Float = 15f * context.resources.displayMetrics.density // 20dp + // 娣诲姞涓�涓爣璇嗙锛岀敤浜庡尯鍒嗕笉鍚岀殑 ExpandButton 瀹炰緥 + private var buttonId: String = "default" + + companion object { + private const val PREFS_NAME = "expand_button_prefs" + private const val KEY_LEGEND_STATES = "legend_states" + } + init { // 淇濆瓨 XML 涓缃殑榛樿瀛椾綋澶у皬 defaultTextSize = textSize @@ -485,14 +493,25 @@ } /** + * 璁剧疆鎸夐挳鐨勫敮涓�鏍囪瘑绗� + * @param id 鏍囪瘑绗� + */ + fun setButtonId(id: String) { + this.buttonId = id + // 鍔犺浇淇濆瓨鐨勭姸鎬� + + } + + + /** * 璁剧疆鍥句緥鍐呭 */ @JvmName("setLegendsList") - fun setLegends(items: List<Triple<Drawable, Drawable, String>>) { - legendItems = items.map { (selectedIcon, unselectedIcon, description) -> + fun setLegends(items: List<Quadruple<Drawable, Drawable, String, Boolean>>) { + legendItems = items.map { (selectedIcon, unselectedIcon, description, isSelected) -> selectedIcon.setBounds(0, 0, iconSize, iconSize) unselectedIcon.setBounds(0, 0, iconSize, iconSize) - LegendItem(selectedIcon, unselectedIcon, description) + LegendItem(selectedIcon, unselectedIcon, description, isSelected) } if (!isExpanded) { @@ -505,8 +524,21 @@ // 娣诲姞涓�涓� Java 鍙嬪ソ鐨勬柟娉� @JvmName("setLegendsArray") - fun setLegends(vararg items: Triple<Drawable, Drawable, String>) { + fun setLegends(vararg items: Quadruple<Drawable, Drawable, String, Boolean>) { setLegends(items.toList()) + } + + // 娣诲姞涓�涓暟鎹被鏉ヨ〃绀哄洓鍏冪粍 + data class Quadruple<A, B, C, D>( + val first: A, + val second: B, + val third: C, + val fourth: D + ) + + // 娣诲姞涓�涓究鎹风殑鎵╁睍鍑芥暟鏉ュ垱寤� Quadruple + fun <A, B, C, D> quadrupleOf(first: A, second: B, third: C, fourth: D): Quadruple<A, B, C, D> { + return Quadruple(first, second, third, fourth) } /** @@ -587,6 +619,7 @@ index, legendItems[index].isSelected ) + invalidate() } -- Gitblit v1.8.0