Skip to content

Commit

Permalink
Merge branch 'device-list-not-capitalized-droid-415'
Browse files Browse the repository at this point in the history
  • Loading branch information
Pururun committed Oct 18, 2023
2 parents 38bf0c5 + 5cbd9e4 commit b1271e7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ fun DeviceListScreen(
Column {
state.deviceUiItems.forEach { deviceUiState ->
ListItem(
text = deviceUiState.device.name,
text = deviceUiState.device.displayName(),
subText =
deviceUiState.device.created.parseAsDateTime()?.let {
creationDate ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class WelcomeViewModelTest {
// Arrange
val expectedAccountNumber = "4444555566667777"
val device: Device = mockk()
every { device.name } returns ""
every { device.displayName() } returns ""

// Act, Assert
viewModel.uiState.test {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ data class Device(val id: String, val name: String, val pubkey: ByteArray, val c
result = 31 * result + pubkey.contentHashCode()
return result
}

fun displayName(): String = name.capitalizeFirstCharOfEachWord()
}

private fun String.capitalizeFirstCharOfEachWord(): String {
return split(" ")
.joinToString(" ") { word -> word.replaceFirstChar { firstChar -> firstChar.uppercase() } }
.trimEnd()
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@ sealed class DeviceState : Parcelable {
}

fun deviceName(): String? {
return (this as? LoggedIn)?.accountAndDevice?.device?.name?.capitalizeFirstCharOfEachWord()
return (this as? LoggedIn)?.accountAndDevice?.device?.displayName()
}

fun token(): String? {
return (this as? LoggedIn)?.accountAndDevice?.account_token
}
}

private fun String.capitalizeFirstCharOfEachWord(): String {
return split(" ")
.joinToString(" ") { word -> word.replaceFirstChar { firstChar -> firstChar.uppercase() } }
.trimEnd()
}

0 comments on commit b1271e7

Please sign in to comment.