Skip to content

Commit

Permalink
added sorting function
Browse files Browse the repository at this point in the history
  • Loading branch information
deeppp15 committed Jan 6, 2025
1 parent 8e36415 commit 90b735e
Showing 1 changed file with 15 additions and 2 deletions.
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 @@ -199,8 +199,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 @@ -249,6 +250,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 @@ -257,7 +269,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 90b735e

Please sign in to comment.