Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7741fa7

Browse files
authored
feat: Audio messages new design #WPB-11723 (#3718)
1 parentf1c158b commit7741fa7

File tree

29 files changed

+861
-154
lines changed

29 files changed

+861
-154
lines changed

‎app/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ dependencies {
259259
implementation(libs.aboutLibraries.core)
260260
implementation(libs.aboutLibraries.ui)
261261
implementation(libs.compose.qr.code)
262+
implementation(libs.audio.amplituda)
262263

263264
// screenshot testing
264265
screenshotTestImplementation(libs.compose.ui.tooling)

‎app/src/main/kotlin/com/wire/android/di/AppModule.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import dagger.Provides
3838
importdagger.hilt.InstallIn
3939
importdagger.hilt.android.qualifiers.ApplicationContext
4040
importdagger.hilt.components.SingletonComponent
41+
importlinc.com.amplituda.Amplituda
4142
importjavax.inject.Qualifier
4243
importjavax.inject.Singleton
4344

@@ -84,6 +85,9 @@ object AppModule {
8485
}
8586
}
8687

88+
@Provides
89+
funprovideAmplituda(appContext:Context):Amplituda=Amplituda(appContext)
90+
8791
@Singleton
8892
@Provides
8993
funprovideCurrentTimestampProvider():CurrentTimestampProvider= {System.currentTimeMillis() }

‎app/src/main/kotlin/com/wire/android/di/accountScoped/MessageModule.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import com.wire.kalium.logic.feature.message.GetNotificationsUseCase
3535
importcom.wire.kalium.logic.feature.message.GetPaginatedFlowOfMessagesByConversationUseCase
3636
importcom.wire.kalium.logic.feature.message.GetPaginatedFlowOfMessagesBySearchQueryAndConversationIdUseCase
3737
importcom.wire.kalium.logic.feature.message.GetSearchedConversationMessagePositionUseCase
38+
importcom.wire.kalium.logic.feature.message.GetSenderNameByMessageIdUseCase
3839
importcom.wire.kalium.logic.feature.message.MarkMessagesAsNotifiedUseCase
3940
importcom.wire.kalium.logic.feature.message.MessageScope
4041
importcom.wire.kalium.logic.feature.message.ObserveMessageReactionsUseCase
@@ -222,4 +223,9 @@ class MessageModule {
222223
@Provides
223224
funprovideSendInCallReactionUseCase(messageScope:MessageScope):SendInCallReactionUseCase=
224225
messageScope.sendInCallReactionUseCase
226+
227+
@ViewModelScoped
228+
@Provides
229+
funprovideGetSenderNameByMessageIdUseCase(messageScope:MessageScope):GetSenderNameByMessageIdUseCase=
230+
messageScope.getSenderNameByMessageId
225231
}

‎app/src/main/kotlin/com/wire/android/media/audiomessage/AudioState.kt

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,24 @@
1717
*/
1818
packagecom.wire.android.media.audiomessage
1919

20+
importandroidx.annotation.StringRes
21+
importcom.wire.android.R
22+
2023
data classAudioState(
2124
valaudioMediaPlayingState:AudioMediaPlayingState,
2225
valcurrentPositionInMs:Int,
23-
valtotalTimeInMs:TotalTimeInMs
26+
valtotalTimeInMs:TotalTimeInMs,
27+
valwavesMask:List<Int>
2428
) {
2529
companionobject {
26-
valDEFAULT=AudioState(AudioMediaPlayingState.Stopped,0,TotalTimeInMs.NotKnown)
30+
valDEFAULT=AudioState(AudioMediaPlayingState.Stopped,0,TotalTimeInMs.NotKnown,listOf())
2731
}
2832

2933
// if the back-end returned the total time, we use that, in case it didn't we use what we get from
3034
// the [ConversationAudioMessagePlayer.kt] which will emit the time once the users play the audio.
3135
funsanitizeTotalTime(otherClientTotalTime:Int):TotalTimeInMs {
3236
if (otherClientTotalTime!=0) {
33-
returnTotalTimeInMs.Known(otherClientTotalTime)
37+
returnTotalTimeInMs.Known(otherClientTotalTime)
3438
}
3539

3640
return totalTimeInMs
@@ -43,6 +47,27 @@ data class AudioState(
4347
}
4448
}
4549

50+
@Suppress("MagicNumber")
51+
enumclassAudioSpeed(valvalue:Float, @StringResvaltitleRes:Int) {
52+
NORMAL(1f,R.string.audio_speed_1),
53+
FAST(1.5f,R.string.audio_speed_1_5),
54+
MAX(2f,R.string.audio_speed_2);
55+
56+
funtoggle():AudioSpeed=when (this) {
57+
NORMAL->FAST
58+
FAST->MAX
59+
MAX->NORMAL
60+
}
61+
62+
companionobject {
63+
funfromFloat(speed:Float):AudioSpeed=when {
64+
(speed<FAST.value)->NORMAL
65+
(speed<MAX.value)->FAST
66+
else->MAX
67+
}
68+
}
69+
}
70+
4671
sealedclassAudioMediaPlayingState {
4772
object Playing : AudioMediaPlayingState()
4873
object Stopped : AudioMediaPlayingState()
@@ -75,6 +100,11 @@ sealed class AudioMediaPlayerStateUpdate(
75100
overridevalmessageId:String,
76101
valtotalTimeInMs:Int
77102
) : AudioMediaPlayerStateUpdate(messageId)
103+
104+
data classWaveMaskUpdate(
105+
overridevalmessageId:String,
106+
valwaveMask:List<Int>
107+
) : AudioMediaPlayerStateUpdate(messageId)
78108
}
79109

80110
sealedclassRecordAudioMediaPlayerStateUpdate {
@@ -89,4 +119,8 @@ sealed class RecordAudioMediaPlayerStateUpdate {
89119
data classTotalTimeUpdate(
90120
valtotalTimeInMs:Int
91121
) : RecordAudioMediaPlayerStateUpdate()
122+
123+
data classWaveMaskUpdate(
124+
valwaveMask:List<Int>
125+
) : RecordAudioMediaPlayerStateUpdate()
92126
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Wire
3+
* Copyright (C) 2024 Wire Swiss GmbH
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see http://www.gnu.org/licenses/.
17+
*/
18+
packagecom.wire.android.media.audiomessage
19+
20+
importlinc.com.amplituda.Amplituda
21+
importlinc.com.amplituda.Cache
22+
importokio.Path
23+
importjava.io.File
24+
importjavax.inject.Inject
25+
importkotlin.math.roundToInt
26+
27+
classAudioWavesMaskHelper @Inject constructor(
28+
privatevalamplituda:Amplituda
29+
) {
30+
31+
companionobject {
32+
privateconstvalWAVES_AMOUNT=75
33+
privateconstvalWAVE_MAX=32
34+
}
35+
36+
fungetWaveMask(decodedAssetPath:Path):List<Int>= getWaveMask(File(decodedAssetPath.toString()))
37+
38+
fungetWaveMask(file:File):List<Int>= amplituda
39+
.processAudio(file,Cache.withParams(Cache.REUSE))
40+
.get()
41+
.amplitudesAsList()
42+
.averageWavesMask()
43+
.equalizeWavesMask()
44+
45+
privatefun List<Double>.equalizeWavesMask():List<Int> {
46+
if (this.isEmpty())returnlistOf()
47+
48+
val divider= max()/ (WAVE_MAX-1)
49+
return map { (it/ divider).roundToInt()+1 }
50+
}
51+
52+
privatefun List<Int>.averageWavesMask():List<Double> {
53+
val wavesSize= size
54+
val sectionSize= (wavesSize.toFloat()/WAVES_AMOUNT).roundToInt()
55+
56+
if (wavesSize<WAVES_AMOUNT|| sectionSize==1)return map { it.toDouble() }
57+
58+
val averagedWaves= mutableListOf<Double>()
59+
for (iin0..<(wavesSize/ sectionSize)) {
60+
val startIndex= (i* sectionSize)
61+
if (startIndex>= wavesSize)continue
62+
val endIndex= (startIndex+ sectionSize).coerceAtMost(wavesSize-1)
63+
averagedWaves.add(subList(startIndex, endIndex).averageInt())
64+
}
65+
return averagedWaves
66+
}
67+
68+
privatefun List<Int>.averageInt():Double {
69+
if (isEmpty())return0.0
70+
return sum().toDouble()/ size
71+
}
72+
73+
funclear() {
74+
amplituda.clearCache()
75+
}
76+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp