summaryrefslogtreecommitdiffhomepage
path: root/android/app/src
diff options
context:
space:
mode:
authorJonatan Rhodin <jonatan.rhodin@mullvad.net>2025-09-30 15:41:10 +0200
committerJonatan Rhodin <jonatan.rhodin@mullvad.net>2025-10-01 08:59:39 +0200
commite5e5ddce0b0e83da75e6e47aa63999ad8eb96f05 (patch)
treeb443eefd7ef4733824d4d70c7aa2bec8b959f4fb /android/app/src
parent7a29bd5ff6214ecde832539942e02f6dde22b15f (diff)
downloadmullvadvpn-e5e5ddce0b0e83da75e6e47aa63999ad8eb96f05.tar.xz
mullvadvpn-e5e5ddce0b0e83da75e6e47aa63999ad8eb96f05.zip
Sort custom lists alphabetically
Diffstat (limited to 'android/app/src')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt5
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepositoryTest.kt36
2 files changed, 40 insertions, 1 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt
index 06d74eed3f..c7d2ee3414 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt
@@ -26,7 +26,7 @@ class CustomListsRepository(
) {
val customLists: StateFlow<List<CustomList>?> =
managementService.settings
- .mapNotNull { it.customLists }
+ .mapNotNull { it.customLists.sortedByName() }
.stateIn(CoroutineScope(dispatcher), SharingStarted.Eagerly, null)
suspend fun createCustomList(
@@ -75,4 +75,7 @@ class CustomListsRepository(
GetCustomListError(id)
}
}
+
+ private fun List<CustomList>.sortedByName() =
+ this.sortedWith(compareBy(String.CASE_INSENSITIVE_ORDER) { it.name.value })
}
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepositoryTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepositoryTest.kt
index dc34a19430..1c8687f3b0 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepositoryTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepositoryTest.kt
@@ -239,6 +239,42 @@ class CustomListsRepositoryTest {
assertEquals(expectedResult, result)
}
+ @Test
+ fun `custom lists should be sorted alphabetically by name`() = runTest {
+ // Arrange
+ val customListId1 = CustomListId("1")
+ val customListId2 = CustomListId("2")
+ val customListId3 = CustomListId("3")
+ val customList1 =
+ CustomList(
+ id = customListId1,
+ name = CustomListName.fromString("Z List"),
+ locations = emptyList(),
+ )
+ val customList2 =
+ CustomList(
+ id = customListId2,
+ name = CustomListName.fromString("A List"),
+ locations = emptyList(),
+ )
+ val customList3 =
+ CustomList(
+ id = customListId3,
+ name = CustomListName.fromString("M List"),
+ locations = emptyList(),
+ )
+ val mockSettings: Settings = mockk()
+ every { mockSettings.customLists } returns listOf(customList1, customList2, customList3)
+ settingsFlow.value = mockSettings
+
+ // Act
+ val result = customListsRepository.customLists.value
+
+ // Assert
+ val expectedOrder = listOf(customList2, customList3, customList1)
+ assertEquals(expectedOrder, result)
+ }
+
companion object {
private const val RELAY_LIST_EXTENSIONS =
"net.mullvad.mullvadvpn.relaylist.RelayListExtensionsKt"