diff --git a/app/src/main/java/awais/instagrabber/fragments/FollowViewerFragment.kt b/app/src/main/java/awais/instagrabber/fragments/FollowViewerFragment.kt index f0f9aa3b..1130dabd 100644 --- a/app/src/main/java/awais/instagrabber/fragments/FollowViewerFragment.kt +++ b/app/src/main/java/awais/instagrabber/fragments/FollowViewerFragment.kt @@ -153,14 +153,18 @@ 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) } + return true + } + if (isCompare && searching) { + adapter!!.filter.filter("") + return true } - searching = false - return true } searching = true if (isCompare && adapter != null) { diff --git a/app/src/main/java/awais/instagrabber/viewmodels/FollowViewModel.kt b/app/src/main/java/awais/instagrabber/viewmodels/FollowViewModel.kt index a0a89b72..567e12a3 100644 --- a/app/src/main/java/awais/instagrabber/viewmodels/FollowViewModel.kt +++ b/app/src/main/java/awais/instagrabber/viewmodels/FollowViewModel.kt @@ -45,21 +45,15 @@ class FollowViewModel : ViewModel() { if (it.first && it.second) { val followersList = followers.value!! val followingList = followings.value!! - val allUsers: MutableList = mutableListOf() - allUsers.addAll(followersList) - allUsers.addAll(followingList) - val followersMap = followersList.groupBy { it.pk } val followingMap = followingList.groupBy { it.pk } val mutual: MutableList = mutableListOf() - val onlyFollowing: MutableList = mutableListOf() val onlyFollowers: MutableList = 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)) } }