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) {
mutex.withLock {
val file = stateFile()
if (file.exists()) {
if (!file.delete()) {
Log.w(TAG) { "delete(): failed to remove ${file.absolutePath}" }
}
if (file.exists() && !file.delete()) {
Log.w(TAG) { "delete(): failed to remove ${file.absolutePath}" }
}
}
}
@@ -108,10 +108,8 @@ class AndroidMarmotMessageStore(
withContext(Dispatchers.IO) {
writeMutex.withLock {
val file = messagesFile(nostrGroupId)
if (file.exists()) {
if (!file.delete()) {
Log.w(TAG) { "delete($nostrGroupId): failed to remove ${file.absolutePath}" }
}
if (file.exists() && !file.delete()) {
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.TitleExplainer
import com.vitorpamplona.amethyst.ui.screen.loggedIn.settings.SettingsRow
import com.vitorpamplona.amethyst.ui.stringRes
import kotlinx.collections.immutable.toImmutableList
@Composable
@@ -35,8 +34,6 @@ fun FileServerSelectionRow(
selectedServer: ServerName?,
onSelect: (ServerName) -> Unit,
) {
val nip95description = stringRes(id = R.string.upload_server_relays_nip95)
val fileServerOptions =
remember(fileServers) {
fileServers
@@ -382,59 +382,59 @@ private fun DialogContent(
}
}
if (myContent is MediaUrlImage || myContent is MediaLocalImage || myContent is MediaUrlPdf) {
if (myContent !is MediaUrlContent || !isLiveStreaming(myContent.url)) {
val localContext = LocalContext.current
val isPdfOrStaticImage = myContent is MediaUrlImage || myContent is MediaLocalImage || myContent is MediaUrlPdf
val isNotLiveStream = myContent !is MediaUrlContent || !isLiveStreaming(myContent.url)
if (isPdfOrStaticImage && isNotLiveStream) {
val localContext = LocalContext.current
val scope = rememberCoroutineScope()
val scope = rememberCoroutineScope()
val writeStoragePermissionState =
rememberPermissionState(Manifest.permission.WRITE_EXTERNAL_STORAGE) { isGranted ->
if (isGranted) {
scope.launch {
saveMediaToGallery(myContent, localContext, accountViewModel)
}
scope.launch {
Toast
.makeText(
localContext,
stringRes(localContext, R.string.media_download_has_started_toast),
Toast.LENGTH_SHORT,
).show()
}
val writeStoragePermissionState =
rememberPermissionState(Manifest.permission.WRITE_EXTERNAL_STORAGE) { isGranted ->
if (isGranted) {
scope.launch {
saveMediaToGallery(myContent, localContext, accountViewModel)
}
scope.launch {
Toast
.makeText(
localContext,
stringRes(localContext, R.string.media_download_has_started_toast),
Toast.LENGTH_SHORT,
).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),
enabled = !isUploading,
onClick = {
val effectiveStripMetadata = if (isVideoWithCompression) false else stripMetadata
val effectiveStripMetadata = !isVideoWithCompression && stripMetadata
onAdd(message, selectedServer, sensitiveContent, mediaQualitySlider, useH265Codec, effectiveStripMetadata, convertGifToMp4)
},
shape = QuoteBorder,