1
0
mirror of https://github.com/KokaKiwi/BarInsta synced 2024-11-24 07:37:30 +00:00

fix follower comparison issues

This commit is contained in:
Austin Huang 2021-07-24 10:28:32 -04:00
parent 52d53c5ad1
commit 9358309c89
No known key found for this signature in database
GPG Key ID: 84C23AA04587A91F
2 changed files with 11 additions and 13 deletions

View File

@ -153,15 +153,19 @@ class FollowViewerFragment : Fragment(), SwipeRefreshLayout.OnRefreshListener {
override fun onQueryTextChange(query: String): Boolean {
if (query.isEmpty()) {
if (!isCompare && searching) {
searching = false
viewModel.setQuery(null, isFollowersList)
viewModel.getSearch().removeObservers(viewLifecycleOwner)
viewModel.getList(isFollowersList).observe(viewLifecycleOwner) {
refreshAdapter(it, null, null, null)
}
}
searching = false
return true
}
if (isCompare && searching) {
adapter!!.filter.filter("")
return true
}
}
searching = true
if (isCompare && adapter != null) {
adapter!!.filter.filter(query)

View File

@ -45,21 +45,15 @@ class FollowViewModel : ViewModel() {
if (it.first && it.second) {
val followersList = followers.value!!
val followingList = followings.value!!
val allUsers: MutableList<User> = mutableListOf()
allUsers.addAll(followersList)
allUsers.addAll(followingList)
val followersMap = followersList.groupBy { it.pk }
val followingMap = followingList.groupBy { it.pk }
val mutual: MutableList<User> = mutableListOf()
val onlyFollowing: MutableList<User> = mutableListOf()
val onlyFollowers: MutableList<User> = mutableListOf()
allUsers.forEach {
val isFollowing = followingMap.get(it.pk) != null
val isFollower = followersMap.get(it.pk) != null
if (isFollowing && isFollower) mutual.add(it)
else if (isFollowing) onlyFollowing.add(it)
else if (isFollower) onlyFollowers.add(it)
followersList.forEach {
if (followingMap.get(it.pk) != null) mutual.add(it)
else onlyFollowers.add(it)
}
val mutualMap = mutual.groupBy { it.pk }
val onlyFollowing = followingList.filter { mutualMap.get(it.pk) == null }
postValue(Triple(mutual, onlyFollowing, onlyFollowers))
}
}