Skip to content

Commit eb1c8f7

Browse files
authored
teams: smoother list callback diffing (fixes #9034) (#9013)
1 parent ae3fc21 commit eb1c8f7

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ android {
99
applicationId "org.ole.planet.myplanet"
1010
minSdk = 26
1111
targetSdk = 36
12-
versionCode = 3721
13-
versionName = "0.37.21"
12+
versionCode = 3722
13+
versionName = "0.37.22"
1414
ndkVersion = '26.3.11579264'
1515
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1616
vectorDrawables.useSupportLibrary = true

app/src/main/java/org/ole/planet/myplanet/ui/team/AdapterTeamList.kt

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import org.ole.planet.myplanet.model.RealmUserModel
2929
import org.ole.planet.myplanet.repository.TeamRepository
3030
import org.ole.planet.myplanet.ui.feedback.FeedbackFragment
3131
import org.ole.planet.myplanet.ui.navigation.NavigationHelper
32+
import org.ole.planet.myplanet.utilities.DiffUtils
3233
import org.ole.planet.myplanet.utilities.SharedPrefManager
3334
import org.ole.planet.myplanet.utilities.TimeUtils
3435

@@ -251,7 +252,12 @@ class AdapterTeamList(
251252

252253
if (validTeams.isEmpty()) {
253254
val diffResult = withContext(Dispatchers.Default) {
254-
DiffUtil.calculateDiff(TeamDiffCallback(oldList, emptyList()))
255+
DiffUtils.calculateDiff(
256+
oldList,
257+
emptyList(),
258+
areItemsTheSame = { old, new -> old._id == new._id },
259+
areContentsTheSame = { old, new -> old == new }
260+
)
255261
}
256262
visitCounts = emptyMap()
257263
filteredList = emptyList()
@@ -334,7 +340,12 @@ class AdapterTeamList(
334340
}
335341

336342
val diffResult = withContext(Dispatchers.Default) {
337-
DiffUtil.calculateDiff(TeamDiffCallback(oldList, newList))
343+
DiffUtils.calculateDiff(
344+
oldList,
345+
newList,
346+
areItemsTheSame = { old, new -> old._id == new._id },
347+
areContentsTheSame = { old, new -> old == new }
348+
)
338349
}
339350

340351
visitCounts = allVisitCounts
@@ -344,20 +355,6 @@ class AdapterTeamList(
344355
}
345356
}
346357

347-
private class TeamDiffCallback(
348-
private val oldList: List<TeamData>, private val newList: List<TeamData>
349-
) : DiffUtil.Callback() {
350-
override fun getOldListSize(): Int = oldList.size
351-
override fun getNewListSize(): Int = newList.size
352-
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
353-
return oldList[oldItemPosition]._id == newList[newItemPosition]._id
354-
}
355-
356-
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
357-
return oldList[oldItemPosition] == newList[newItemPosition]
358-
}
359-
}
360-
361358
private fun requestToJoin(team: RealmMyTeam, user: RealmUserModel?) {
362359
val teamId = team._id ?: return
363360
val teamType = team.teamType

0 commit comments

Comments
 (0)