Skip to content

Commit e448e4e

Browse files
committed
Fix transactions header
1 parent eeba32c commit e448e4e

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

app/src/main/java/com/concordium/wallet/uicore/recyclerview/pinnedheader/PinnedHeaderItemDecoration.kt

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,45 @@ class PinnedHeaderItemDecoration(private val listener: PinnedHeaderListener) :
1010
RecyclerView.ItemDecoration() {
1111

1212
private var headerHeight: Int = 0
13+
private var cachedHeader: View? = null
14+
private var cachedHeaderPosition: Int = RecyclerView.NO_POSITION
1315

1416
override fun onDrawOver(c: Canvas, parent: RecyclerView, state: RecyclerView.State) {
1517
super.onDrawOver(c, parent, state)
1618

1719
val topChild = parent.getChildAt(0) ?: return
18-
1920
val topChildPosition = parent.getChildAdapterPosition(topChild)
20-
if (topChildPosition == RecyclerView.NO_POSITION) {
21-
return
21+
if (topChildPosition == RecyclerView.NO_POSITION) return
22+
23+
val headerPosition = listener.getHeaderPositionForItem(topChildPosition)
24+
val currentHeader = if (cachedHeaderPosition == headerPosition && cachedHeader != null) {
25+
cachedHeader!!
26+
} else {
27+
getHeaderViewForItem(headerPosition, parent)
2228
}
2329

24-
val currentHeader = getHeaderViewForItem(topChildPosition, parent)
2530
fixLayoutSize(parent, currentHeader)
2631
val contactPoint = currentHeader.bottom
27-
val childInContact = getChildInContact(parent, contactPoint) ?: return
32+
val childInContact = getChildInContact(parent, contactPoint)
2833

29-
if (listener.isHeader(parent.getChildAdapterPosition(childInContact))) {
34+
if (childInContact != null && listener.isHeader(parent.getChildAdapterPosition(childInContact))) {
3035
moveHeader(c, currentHeader, childInContact)
31-
return
36+
} else {
37+
drawHeader(c, currentHeader)
3238
}
33-
34-
drawHeader(c, currentHeader)
3539
}
3640

3741
private fun getHeaderViewForItem(itemPosition: Int, parent: RecyclerView): View {
3842
val headerPosition = listener.getHeaderPositionForItem(itemPosition)
39-
val layoutResId = listener.getHeaderLayout(headerPosition)
40-
val header = LayoutInflater.from(parent.context).inflate(layoutResId, parent, false)
41-
listener.bindHeaderData(header, headerPosition)
42-
return header
43+
44+
if (cachedHeaderPosition != headerPosition || cachedHeader == null) {
45+
val layoutResId = listener.getHeaderLayout(headerPosition)
46+
val header = LayoutInflater.from(parent.context).inflate(layoutResId, parent, false)
47+
listener.bindHeaderData(header, headerPosition)
48+
cachedHeader = header
49+
cachedHeaderPosition = headerPosition
50+
}
51+
return cachedHeader!!
4352
}
4453

4554
private fun drawHeader(c: Canvas, header: View) {
@@ -57,18 +66,9 @@ class PinnedHeaderItemDecoration(private val listener: PinnedHeaderListener) :
5766
}
5867

5968
private fun getChildInContact(parent: RecyclerView, contactPoint: Int): View? {
60-
var childInContact: View? = null
61-
for (i in 0 until parent.childCount) {
62-
val child = parent.getChildAt(i)
63-
if (child.bottom > contactPoint) {
64-
if (child.top <= contactPoint) {
65-
// This child overlaps the contactPoint
66-
childInContact = child
67-
break
68-
}
69-
}
70-
}
71-
return childInContact
69+
return (0 until parent.childCount)
70+
.map { parent.getChildAt(it) }
71+
.firstOrNull { it.bottom > contactPoint && it.top <= contactPoint }
7272
}
7373

7474
/**

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
33
xmlns:tools="http://schemas.android.com/tools"
44
style="@style/MW24_Typography_Additional_Capture_Small"
5+
android:layout_width="match_parent"
56
android:layout_height="wrap_content"
6-
android:layout_width="wrap_content"
7-
android:textColor="@color/mw24_blue_3"
8-
android:gravity="center"
7+
android:background="@color/cryptox_black_main"
8+
android:gravity="start"
99
android:paddingTop="16dp"
1010
android:paddingBottom="8dp"
11+
android:textColor="@color/mw24_blue_3"
1112
tools:text="Today" />

0 commit comments

Comments
 (0)