fix: Sort lists by title wherever they occur

This commit is contained in:
Nik Clayton 2024-03-12 19:07:24 +01:00
parent 7da4bc090b
commit 006c358053
4 changed files with 17 additions and 4 deletions

View File

@ -43,6 +43,7 @@ import app.pachli.core.common.extensions.hide
import app.pachli.core.common.extensions.show
import app.pachli.core.common.extensions.viewBinding
import app.pachli.core.data.repository.Lists
import app.pachli.core.data.repository.ListsRepository.Companion.compareByListTitle
import app.pachli.core.navigation.StatusListActivityIntent
import app.pachli.core.network.model.MastoList
import app.pachli.core.network.retrofit.apiresult.ApiError
@ -210,7 +211,7 @@ class ListsActivity : BaseActivity(), MenuProvider {
state.onSuccess { lists ->
when (lists) {
is Lists.Loaded -> {
adapter.submitList(lists.lists.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.title }))
adapter.submitList(lists.lists.sortedWith(compareByListTitle))
binding.swipeRefreshLayout.isRefreshing = false
if (lists.lists.isEmpty()) {
binding.messageView.show()

View File

@ -76,6 +76,7 @@ import app.pachli.core.common.extensions.show
import app.pachli.core.common.extensions.viewBinding
import app.pachli.core.data.repository.Lists
import app.pachli.core.data.repository.ListsRepository
import app.pachli.core.data.repository.ListsRepository.Companion.compareByListTitle
import app.pachli.core.database.model.AccountEntity
import app.pachli.core.database.model.TabData
import app.pachli.core.designsystem.EmbeddedFontFamily
@ -605,8 +606,7 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, MenuProvider {
when (result) {
Lists.Loading -> Pair(emptyList(), R.string.title_lists_loading)
is Lists.Loaded -> Pair(
result.lists
.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.title })
result.lists.sortedWith(compareByListTitle)
.map { list ->
primaryDrawerItem {
nameText = list.title

View File

@ -48,6 +48,7 @@ import app.pachli.core.common.extensions.viewBinding
import app.pachli.core.common.extensions.visible
import app.pachli.core.data.repository.Lists
import app.pachli.core.data.repository.ListsRepository
import app.pachli.core.data.repository.ListsRepository.Companion.compareByListTitle
import app.pachli.core.database.model.TabData
import app.pachli.core.designsystem.R as DR
import app.pachli.core.navigation.ListActivityIntent
@ -345,7 +346,7 @@ class TabPreferenceActivity : BaseActivity(), ItemInteractionListener {
if (lists is Lists.Loaded) {
showProgressBarJob.cancel()
adapter.clear()
adapter.addAll(lists.lists)
adapter.addAll(lists.lists.sortedWith(compareByListTitle))
if (lists.lists.isEmpty()) noListsText.show()
}
}

View File

@ -21,6 +21,7 @@ import app.pachli.core.network.model.MastoList
import app.pachli.core.network.model.TimelineAccount
import app.pachli.core.network.retrofit.apiresult.ApiError
import com.github.michaelbull.result.Result
import java.text.Collator
import kotlinx.coroutines.flow.StateFlow
sealed interface Lists {
@ -122,4 +123,14 @@ interface ListsRepository {
* @return A successful result, or an error
*/
suspend fun deleteAccountsFromList(listId: String, accountIds: List<String>): Result<Unit, ListsError.DeleteAccounts>
companion object {
/**
* Locale-aware comparator for lists. Case-insenstive comparison by
* the list's title.
*/
val compareByListTitle: Comparator<MastoList> = compareBy(
Collator.getInstance().apply { strength = Collator.SECONDARY },
) { it.title }
}
}