Skip to content

Commit dc7342c

Browse files
committed
CodeListAdapter: 修复代码置顶问题 #1
1 parent 24da4ff commit dc7342c

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

app/src/main/kotlin/com/rayfantasy/icode/ui/adapter/CodeListAdapter.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package com.rayfantasy.icode.ui.adapter
1818

1919
import android.app.Activity
20-
import android.graphics.Color
2120
import android.support.v7.widget.RecyclerView
2221
import android.view.View
2322
import android.view.ViewGroup
@@ -50,12 +49,13 @@ class CodeListAdapter(val activity: Activity, var codeGoods: MutableList<CodeGoo
5049
holder.pic.onClick {
5150
activity.startActivity<UserActivity>("username" to codeGood.username.toString())
5251
}
53-
if (codeGood.highlight ?: false) {
52+
holder.binding.highlight = codeGood.highlight ?: false
53+
/*if (codeGood.highlight ?: false) {
5454
holder.title.setTextColor(Color.RED)
5555
holder.username.setTextColor(Color.RED)
5656
holder.subTitle.setTextColor(Color.RED)
5757
holder.username.append("被管理员临时高亮!")
58-
}
58+
}*/
5959

6060
holder.bg.onClick {
6161
activity.startActivity<BlocksActivity>("codeGood" to codeGood)
@@ -72,9 +72,11 @@ class CodeListAdapter(val activity: Activity, var codeGoods: MutableList<CodeGoo
7272
val title = itemView.title
7373
val subTitle = itemView.sub_title
7474
val bg = itemView.element_bg
75+
val binding: ItemRecyclerCodeListBinding
7576

7677
init {
77-
ItemRecyclerCodeListBinding.bind(itemView).theme = ICodeTheme
78+
binding = ItemRecyclerCodeListBinding.bind(itemView)
79+
binding.theme = ICodeTheme
7880
}
7981
}
8082
}

app/src/main/res/layout/item_recycler_code_list.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
<variable
2323
name="theme"
2424
type="com.rayfantasy.icode.model.ICodeTheme"/>
25+
26+
<variable name="highlight" type="boolean"/>
2527
</data>
2628
<android.support.v7.widget.CardView
2729
android:id="@+id/element_bg"
@@ -57,7 +59,7 @@
5759
android:layout_marginLeft="16dp"
5860
android:gravity="center"
5961
android:text="User"
60-
android:textColor="#8C8C8C"
62+
android:textColor="@{highlight ? theme.colorAccent : 0xFF8C8C8C}"
6163
android:textSize="15sp"
6264
android:layout_centerVertical="true"
6365
android:layout_toRightOf="@+id/pic"
@@ -76,7 +78,7 @@
7678
android:paddingLeft="5dp"
7779
android:paddingRight="5dp"
7880
android:text="Time"
79-
android:textColor="#8C8C8C"
81+
android:textColor="@{highlight ? theme.colorAccent : 0xFF8C8C8C}"
8082
android:textSize="15sp"/>
8183
</RelativeLayout>
8284

@@ -86,7 +88,7 @@
8688
android:layout_height="wrap_content"
8789
android:gravity="center_vertical"
8890
android:text="Title"
89-
android:textColor="@{theme.colorPrimaryDark}"
91+
android:textColor="@{highlight ? theme.colorAccent : theme.colorPrimaryDark}"
9092
android:textSize="17sp"
9193
android:textStyle="bold"
9294
android:layout_marginLeft="16dp"
@@ -103,7 +105,7 @@
103105
android:paddingLeft="5dp"
104106
android:paddingRight="5dp"
105107
android:text="Message"
106-
android:textColor="#8C8C8C"
108+
android:textColor="@{highlight ? theme.colorAccent : 0xFF8C8C8C}"
107109
android:textSize="15sp"
108110
android:layout_marginTop="16dp"/>
109111
</LinearLayout>

0 commit comments

Comments
 (0)