-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add voice message recording duration indicator and limit (#1628)
--------- Co-authored-by: ElementBot <[email protected]>
- Loading branch information
1 parent
8c0d9cc
commit f1b142f
Showing
22 changed files
with
263 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (c) 2023 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
plugins { | ||
id("io.element.android-library") | ||
} | ||
|
||
android { | ||
namespace = "io.element.android.libraries.ui.utils" | ||
|
||
dependencies { | ||
testImplementation(libs.test.junit) | ||
testImplementation(libs.test.truth) | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
libraries/ui-utils/src/main/kotlin/io/element/android/libraries/ui/utils/time/DurationExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) 2023 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.element.android.libraries.ui.utils.time | ||
|
||
import kotlin.time.Duration | ||
|
||
/** | ||
* Format a duration as minutes:seconds. | ||
* | ||
* For example, | ||
* - 0 seconds will be formatted as "0:00". | ||
* - 65 seconds will be formatted as "1:05". | ||
* - 2 hours will be formatted as "120:00". | ||
* - negative 10 seconds will be formatted as "-0:10". | ||
* | ||
* @return the formatted duration. | ||
*/ | ||
fun Duration.formatShort(): String { | ||
// Format as minutes:seconds | ||
val seconds = (absoluteValue.inWholeSeconds % 60) | ||
.toString() | ||
.padStart(2, '0') | ||
|
||
val sign = isNegative().let { if (it) "-" else "" } | ||
|
||
return "$sign${absoluteValue.inWholeMinutes}:$seconds" | ||
} |
52 changes: 52 additions & 0 deletions
52
...ui-utils/src/test/kotlin/io/element/android/libraries/ui/utils/time/DurationFormatTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2023 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.element.android.libraries.ui.utils.time | ||
|
||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.Parameterized | ||
import kotlin.time.Duration.Companion.seconds | ||
|
||
@RunWith(value = Parameterized::class) | ||
class DurationFormatTest( | ||
private val seconds: Double, | ||
private val output: String, | ||
) { | ||
companion object { | ||
@Parameterized.Parameters(name = "{index}: format({0})={1}") | ||
@JvmStatic | ||
fun data(): Iterable<Array<Any>> { | ||
return arrayListOf( | ||
arrayOf<Any>(0, "0:00"), | ||
arrayOf<Any>(1, "0:01"), | ||
arrayOf<Any>(10, "0:10"), | ||
arrayOf<Any>(59.9, "0:59"), | ||
arrayOf<Any>(60, "1:00"), | ||
arrayOf<Any>(61, "1:01"), | ||
arrayOf<Any>(60 * 60, "60:00"), | ||
arrayOf<Any>(-60, "-1:00"), | ||
arrayOf<Any>(-1, "-0:01"), | ||
).toList() | ||
} | ||
} | ||
|
||
@Test | ||
fun formatShort() { | ||
assertEquals(output, seconds.seconds.formatShort()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.