Skip to content
This repository was archived by the owner on Feb 17, 2020. It is now read-only.

Commit f4bd865

Browse files
committed
offset the speaker ids to not overlaps the event ones
1 parent 044229f commit f4bd865

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

app/src/main/java/net/squanchy/search/view/SearchAdapter.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ internal class SearchAdapter(activity: AppCompatActivity) : RecyclerView.Adapter
5151
val item = searchResult.elements[position]
5252
return when (item) {
5353
is EventElement -> item.event.numericId
54-
is SpeakerElement -> item.speaker.numericId
54+
is SpeakerElement -> speakerIdOffsetter(item.speaker.numericId)
5555
is SearchListElement.EventHeader -> ITEM_ID_EVENTS_HEADER
5656
is SearchListElement.SpeakerHeader -> ITEM_ID_SPEAKERS_HEADER
5757
is SearchListElement.AlgoliaLogo -> ITEM_ID_ALGOLIA_LOGO
@@ -115,8 +115,13 @@ internal class SearchAdapter(activity: AppCompatActivity) : RecyclerView.Adapter
115115
// random values that are used for non-hardcoded numeric IDs (for events
116116
// and speakers). This is a reasonable assumption in the Long range.
117117
// In addition, the CRC32 values we use as numeric IDs are always positive.
118-
private const val ITEM_ID_EVENTS_HEADER: Long = -100
119-
private const val ITEM_ID_SPEAKERS_HEADER: Long = -101
120-
private const val ITEM_ID_ALGOLIA_LOGO: Long = -102
118+
private const val ITEM_ID_EVENTS_HEADER: Long = -1
119+
private const val ITEM_ID_SPEAKERS_HEADER: Long = -2
120+
private const val ITEM_ID_ALGOLIA_LOGO: Long = -3
121+
122+
// As we cannot guarantee that the speaker ids are going to be unique compared
123+
// to the ones for the events, we are making them negatives and offsetting them by 4,
124+
// to be sure they do not overlap the ids for the two headers and the logo
125+
private val speakerIdOffsetter: (Long) -> Long = { (it * -1) - 4 }
121126
}
122127
}

0 commit comments

Comments
 (0)