Skip to content

Commit

Permalink
teams: smoother list (fixes #4949) (#4950)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
deeppp15 and dogi authored Jan 7, 2025
1 parent 8957fe2 commit ebe67f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 26
targetSdkVersion 34
versionCode 2171
versionName "0.21.71"
versionCode 2172
versionName "0.21.72"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down
17 changes: 15 additions & 2 deletions app/src/main/java/org/ole/planet/myplanet/ui/team/TeamFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,9 @@ class TeamFragment : Fragment(), AdapterTeamList.OnClickTeamItem {
.notEqualTo("status", "archived")
.contains("name", charSequence.toString(), Case.INSENSITIVE)
val (list, conditionApplied) = getList(query)
val sortedList = sortTeams(list)
val adapterTeamList = AdapterTeamList(
activity as Context, list, mRealm, childFragmentManager
activity as Context, sortedList, mRealm, childFragmentManager
)
adapterTeamList.setTeamListener(this@TeamFragment)
fragmentTeamBinding.rvTeamList.adapter = adapterTeamList
Expand Down Expand Up @@ -253,6 +254,17 @@ class TeamFragment : Fragment(), AdapterTeamList.OnClickTeamItem {
}
}

private fun sortTeams(list: List<RealmMyTeam>): List<RealmMyTeam> {
val user = user?.id
return list.sortedWith(compareByDescending<RealmMyTeam> { team ->
when {
RealmMyTeam.isTeamLeader(team.teamId, user, mRealm) -> 3
team.isMyTeam(user, mRealm) -> 2
else -> 1
}
})
}

override fun onEditTeam(team: RealmMyTeam?) {
createTeamAlert(team!!)
}
Expand All @@ -261,7 +273,8 @@ class TeamFragment : Fragment(), AdapterTeamList.OnClickTeamItem {
activity?.runOnUiThread {
val query = mRealm.where(RealmMyTeam::class.java).isEmpty("teamId").notEqualTo("status", "archived")
val (filteredList, conditionApplied) = getList(query)
val adapterTeamList = AdapterTeamList(activity as Context, filteredList, mRealm, childFragmentManager).apply {
val sortedList = sortTeams(filteredList)
val adapterTeamList = AdapterTeamList(activity as Context, sortedList, mRealm, childFragmentManager).apply {
setType(type)
setTeamListener(this@TeamFragment)
}
Expand Down

0 comments on commit ebe67f8

Please sign in to comment.