code review: remove unsafe casting to avoid app crash if a non-voice reply context leaks through
lint fixes
This commit is contained in:
+2
-3
@@ -20,7 +20,6 @@
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.ui.actions.uploads
|
||||
|
||||
import android.content.Context
|
||||
import android.media.MediaPlayer
|
||||
import android.util.Log
|
||||
import androidx.compose.foundation.background
|
||||
@@ -77,7 +76,7 @@ fun VoiceMessagePreview(
|
||||
|
||||
// Initialize MediaPlayer
|
||||
DisposableEffect(voiceMetadata.url, localFile) {
|
||||
val player = createMediaPlayer(context, voiceMetadata.url, localFile)
|
||||
val player = createMediaPlayer(voiceMetadata.url, localFile)
|
||||
player?.setOnCompletionListener {
|
||||
isPlaying = false
|
||||
progress = 0f
|
||||
@@ -242,7 +241,6 @@ fun VoiceMessagePreview(
|
||||
}
|
||||
|
||||
private fun createMediaPlayer(
|
||||
context: Context,
|
||||
url: String,
|
||||
localFile: File?,
|
||||
): MediaPlayer? =
|
||||
@@ -256,5 +254,6 @@ private fun createMediaPlayer(
|
||||
prepare()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.w("VoiceMessagePreview", "Failed to create MediaPlayer", e)
|
||||
null
|
||||
}
|
||||
|
||||
+2
-6
@@ -479,16 +479,12 @@ private fun NewPostScreenBody(
|
||||
)
|
||||
}
|
||||
|
||||
BottomRowActions(postViewModel, accountViewModel)
|
||||
BottomRowActions(postViewModel)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun BottomRowActions(
|
||||
postViewModel: ShortNotePostViewModel,
|
||||
accountViewModel: AccountViewModel,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
private fun BottomRowActions(postViewModel: ShortNotePostViewModel) {
|
||||
val scrollState = rememberScrollState()
|
||||
Row(
|
||||
modifier =
|
||||
|
||||
+6
-5
@@ -235,7 +235,7 @@ open class ShortNotePostViewModel :
|
||||
|
||||
fun hasLnAddress(): Boolean = account.userProfile().info?.lnAddress() != null
|
||||
|
||||
fun user(): User? = account.userProfile()
|
||||
fun user(): User = account.userProfile()
|
||||
|
||||
open fun init(accountVM: AccountViewModel) {
|
||||
this.accountViewModel = accountVM
|
||||
@@ -534,15 +534,16 @@ open class ShortNotePostViewModel :
|
||||
private suspend fun createTemplate(): EventTemplate<out Event>? {
|
||||
// Check if this is a voice message
|
||||
voiceMetadata?.let { audioMeta ->
|
||||
return if (originalNote != null) {
|
||||
// Only create voice reply if original note is also a VoiceEvent
|
||||
val originalVoiceHint = originalNote?.toEventHint<VoiceEvent>()
|
||||
return if (originalVoiceHint != null) {
|
||||
// Create voice reply event
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
VoiceReplyEvent.build(
|
||||
voiceMessage = audioMeta,
|
||||
replyingTo = originalNote!!.toEventHint<Event>() as com.vitorpamplona.quartz.nip01Core.hints.EventHintBundle<VoiceEvent>,
|
||||
replyingTo = originalVoiceHint,
|
||||
)
|
||||
} else {
|
||||
// Create root voice event
|
||||
// Create root voice event (no reply or original is not a voice message)
|
||||
VoiceEvent.build(
|
||||
voiceMessage = audioMeta,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user