refactor(amethyst): address Sonar code-smell warnings

- Merge nested if statements in marmot stores' delete() and in
  ZoomableContentDialog's MediaUrl* gating block (S1066).
- Replace `if (cond) false else x` with `!cond && x` in
  ImageVideoDescription's effectiveStripMetadata (S1125).
- Remove unused `nip95description` local in FileServerSelectionRow.

All changes are body-internal with identical behaviour.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
davotoula
2026-05-09 10:05:07 +02:00
parent 2a9b5bc17d
commit 5dec9e665a
5 changed files with 53 additions and 60 deletions
@@ -99,10 +99,8 @@ class AndroidKeyPackageBundleStore(
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
mutex.withLock { mutex.withLock {
val file = stateFile() val file = stateFile()
if (file.exists()) { if (file.exists() && !file.delete()) {
if (!file.delete()) { Log.w(TAG) { "delete(): failed to remove ${file.absolutePath}" }
Log.w(TAG) { "delete(): failed to remove ${file.absolutePath}" }
}
} }
} }
} }
@@ -108,10 +108,8 @@ class AndroidMarmotMessageStore(
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
writeMutex.withLock { writeMutex.withLock {
val file = messagesFile(nostrGroupId) val file = messagesFile(nostrGroupId)
if (file.exists()) { if (file.exists() && !file.delete()) {
if (!file.delete()) { Log.w(TAG) { "delete($nostrGroupId): failed to remove ${file.absolutePath}" }
Log.w(TAG) { "delete($nostrGroupId): failed to remove ${file.absolutePath}" }
}
} }
} }
} }
@@ -26,7 +26,6 @@ import com.vitorpamplona.amethyst.R
import com.vitorpamplona.amethyst.ui.components.TextSpinner import com.vitorpamplona.amethyst.ui.components.TextSpinner
import com.vitorpamplona.amethyst.ui.components.TitleExplainer import com.vitorpamplona.amethyst.ui.components.TitleExplainer
import com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.SettingsRow import com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.SettingsRow
import com.vitorpamplona.amethyst.ui.stringRes
import kotlinx.collections.immutable.toImmutableList import kotlinx.collections.immutable.toImmutableList
@Composable @Composable
@@ -35,8 +34,6 @@ fun FileServerSelectionRow(
selectedServer: ServerName?, selectedServer: ServerName?,
onSelect: (ServerName) -> Unit, onSelect: (ServerName) -> Unit,
) { ) {
val nip95description = stringRes(id = R.string.upload_server_relays_nip95)
val fileServerOptions = val fileServerOptions =
remember(fileServers) { remember(fileServers) {
fileServers fileServers
@@ -382,59 +382,59 @@ private fun DialogContent(
} }
} }
if (myContent is MediaUrlImage || myContent is MediaLocalImage || myContent is MediaUrlPdf) { val isPdfOrStaticImage = myContent is MediaUrlImage || myContent is MediaLocalImage || myContent is MediaUrlPdf
if (myContent !is MediaUrlContent || !isLiveStreaming(myContent.url)) { val isNotLiveStream = myContent !is MediaUrlContent || !isLiveStreaming(myContent.url)
val localContext = LocalContext.current if (isPdfOrStaticImage && isNotLiveStream) {
val localContext = LocalContext.current
val scope = rememberCoroutineScope() val scope = rememberCoroutineScope()
val writeStoragePermissionState = val writeStoragePermissionState =
rememberPermissionState(Manifest.permission.WRITE_EXTERNAL_STORAGE) { isGranted -> rememberPermissionState(Manifest.permission.WRITE_EXTERNAL_STORAGE) { isGranted ->
if (isGranted) { if (isGranted) {
scope.launch { scope.launch {
saveMediaToGallery(myContent, localContext, accountViewModel) saveMediaToGallery(myContent, localContext, accountViewModel)
} }
scope.launch { scope.launch {
Toast Toast
.makeText( .makeText(
localContext, localContext,
stringRes(localContext, R.string.media_download_has_started_toast), stringRes(localContext, R.string.media_download_has_started_toast),
Toast.LENGTH_SHORT, Toast.LENGTH_SHORT,
).show() ).show()
}
} }
} }
OutlinedButton(
onClick = {
if (
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ||
writeStoragePermissionState.status.isGranted
) {
scope.launch(Dispatchers.IO) {
saveMediaToGallery(myContent, localContext, accountViewModel)
}
scope.launch {
Toast
.makeText(
localContext,
stringRes(localContext, R.string.media_download_has_started_toast),
Toast.LENGTH_SHORT,
).show()
}
} else {
writeStoragePermissionState.launchPermissionRequest()
}
},
contentPadding = PaddingValues(horizontal = Size5dp),
colors = ButtonDefaults.outlinedButtonColors().copy(containerColor = MaterialTheme.colorScheme.background),
) {
Icon(
symbol = MaterialSymbols.Download,
modifier = Size20Modifier,
contentDescription = stringRes(R.string.download_to_phone),
)
} }
OutlinedButton(
onClick = {
if (
Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q ||
writeStoragePermissionState.status.isGranted
) {
scope.launch(Dispatchers.IO) {
saveMediaToGallery(myContent, localContext, accountViewModel)
}
scope.launch {
Toast
.makeText(
localContext,
stringRes(localContext, R.string.media_download_has_started_toast),
Toast.LENGTH_SHORT,
).show()
}
} else {
writeStoragePermissionState.launchPermissionRequest()
}
},
contentPadding = PaddingValues(horizontal = Size5dp),
colors = ButtonDefaults.outlinedButtonColors().copy(containerColor = MaterialTheme.colorScheme.background),
) {
Icon(
symbol = MaterialSymbols.Download,
modifier = Size20Modifier,
contentDescription = stringRes(R.string.download_to_phone),
)
} }
} }
} }
@@ -438,7 +438,7 @@ fun ImageVideoDescription(
.padding(vertical = 10.dp), .padding(vertical = 10.dp),
enabled = !isUploading, enabled = !isUploading,
onClick = { onClick = {
val effectiveStripMetadata = if (isVideoWithCompression) false else stripMetadata val effectiveStripMetadata = !isVideoWithCompression && stripMetadata
onAdd(message, selectedServer, sensitiveContent, mediaQualitySlider, useH265Codec, effectiveStripMetadata, convertGifToMp4) onAdd(message, selectedServer, sensitiveContent, mediaQualitySlider, useH265Codec, effectiveStripMetadata, convertGifToMp4)
}, },
shape = QuoteBorder, shape = QuoteBorder,