-
Notifications
You must be signed in to change notification settings - Fork 739
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3598 from vector-im/feature/ons/voice_message
Voice Message
- Loading branch information
Showing
74 changed files
with
2,607 additions
and
57 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
8 changes: 8 additions & 0 deletions
8
library/ui-styles/src/main/res/drawable/bg_round_corner_8dp.xml
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,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<solid android:color="#F00" /> | ||
|
||
<corners android:radius="8dp" /> | ||
|
||
</shape> |
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<integer name="rtl_x_multiplier">-1</integer> | ||
<integer name="rtl_mirror_flip">180</integer> | ||
|
||
</resources> |
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
26 changes: 26 additions & 0 deletions
26
library/ui-styles/src/main/res/values/styles_voice_message.xml
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,26 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<style name="VoicePlaybackWaveform"> | ||
<item name="chunkColor">?vctr_content_secondary</item> | ||
<item name="chunkAlignTo">center</item> | ||
<item name="chunkMinHeight">1dp</item> | ||
<item name="chunkRoundedCorners">true</item> | ||
<item name="chunkSoftTransition">true</item> | ||
<item name="chunkSpace">2dp</item> | ||
<item name="chunkWidth">2dp</item> | ||
<item name="direction">rightToLeft</item> | ||
</style> | ||
|
||
<style name="Widget.Vector.TextView.Caption.Toast"> | ||
<item name="android:paddingTop">8dp</item> | ||
<item name="android:paddingBottom">8dp</item> | ||
<item name="android:paddingStart">12dp</item> | ||
<item name="android:paddingEnd">12dp</item> | ||
<item name="android:background">@drawable/bg_round_corner_8dp</item> | ||
<item name="android:backgroundTint">?vctr_voice_message_toast_background</item> | ||
<item name="android:textColor">@color/palette_white</item> | ||
<item name="android:gravity">center</item> | ||
</style> | ||
|
||
</resources> |
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
36 changes: 36 additions & 0 deletions
36
.../src/main/java/org/matrix/android/sdk/api/session/room/model/message/AudioWaveformInfo.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,36 @@ | ||
/* | ||
* Copyright 2020 The Matrix.org Foundation C.I.C. | ||
* | ||
* 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 org.matrix.android.sdk.api.session.room.model.message | ||
|
||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonClass | ||
|
||
/** | ||
* See https://github.com/matrix-org/matrix-doc/blob/travis/msc/audio-waveform/proposals/3246-audio-waveform.md | ||
*/ | ||
@JsonClass(generateAdapter = true) | ||
data class AudioWaveformInfo( | ||
@Json(name = "duration") | ||
val duration: Int? = null, | ||
|
||
/** | ||
* The array should have no less than 30 elements and no more than 120. | ||
* List of integers between zero and 1024, inclusive. | ||
*/ | ||
@Json(name = "waveform") | ||
val waveform: List<Int>? = null | ||
) |
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
86 changes: 86 additions & 0 deletions
86
...roid/src/main/java/org/matrix/android/sdk/internal/session/room/send/WaveFormSanitizer.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,86 @@ | ||
/* | ||
* Copyright (c) 2021 The Matrix.org Foundation C.I.C. | ||
* | ||
* 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 org.matrix.android.sdk.internal.session.room.send | ||
|
||
import timber.log.Timber | ||
import javax.inject.Inject | ||
import kotlin.math.abs | ||
import kotlin.math.ceil | ||
|
||
internal class WaveFormSanitizer @Inject constructor() { | ||
private companion object { | ||
const val MIN_NUMBER_OF_VALUES = 30 | ||
const val MAX_NUMBER_OF_VALUES = 120 | ||
|
||
const val MAX_VALUE = 1024 | ||
} | ||
|
||
/** | ||
* The array should have no less than 30 elements and no more than 120. | ||
* List of integers between zero and 1024, inclusive. | ||
*/ | ||
fun sanitize(waveForm: List<Int>?): List<Int>? { | ||
if (waveForm.isNullOrEmpty()) { | ||
return null | ||
} | ||
|
||
// Limit the number of items | ||
val sizeInRangeList = mutableListOf<Int>() | ||
when { | ||
waveForm.size < MIN_NUMBER_OF_VALUES -> { | ||
// Repeat the same value to have at least 30 items | ||
val repeatTimes = ceil(MIN_NUMBER_OF_VALUES / waveForm.size.toDouble()).toInt() | ||
waveForm.map { value -> | ||
repeat(repeatTimes) { | ||
sizeInRangeList.add(value) | ||
} | ||
} | ||
} | ||
waveForm.size > MAX_NUMBER_OF_VALUES -> { | ||
val keepOneOf = ceil(waveForm.size.toDouble() / MAX_NUMBER_OF_VALUES).toInt() | ||
waveForm.mapIndexed { idx, value -> | ||
if (idx % keepOneOf == 0) { | ||
sizeInRangeList.add(value) | ||
} | ||
} | ||
} | ||
else -> { | ||
sizeInRangeList.addAll(waveForm) | ||
} | ||
} | ||
|
||
// OK, ensure all items are positive | ||
val positiveList = sizeInRangeList.map { | ||
abs(it) | ||
} | ||
|
||
// Ensure max is not above MAX_VALUE | ||
val max = positiveList.maxOrNull() ?: MAX_VALUE | ||
|
||
val finalList = if (max > MAX_VALUE) { | ||
// Reduce the values | ||
positiveList.map { | ||
it * MAX_VALUE / max | ||
} | ||
} else { | ||
positiveList | ||
} | ||
|
||
Timber.d("Sanitize from ${waveForm.size} items to ${finalList.size} items. Max value was $max") | ||
return finalList | ||
} | ||
} |
Oops, something went wrong.