MediaViewer: improve actions (save on disk and share)
This commit is contained in:
parent
89d4b81f80
commit
fa63ed1faf
7 changed files with 22 additions and 15 deletions
|
|
@ -113,16 +113,9 @@ class AndroidLocalMediaActions @Inject constructor(
|
|||
}
|
||||
|
||||
/**
|
||||
* Tries to extract a file from the uri and rename it using the local media name if defined.
|
||||
* Tries to extract a file from the uri.
|
||||
*/
|
||||
private fun LocalMedia.toFile(): File {
|
||||
val uriAsFile = uri.toFile()
|
||||
return if (name != null) {
|
||||
File(uriAsFile.parentFile, name).apply {
|
||||
uriAsFile.renameTo(this)
|
||||
}
|
||||
} else {
|
||||
uriAsFile
|
||||
}
|
||||
return uri.toFile()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,11 @@ class MediaViewerPresenter @AssistedInject constructor(
|
|||
|
||||
private fun CoroutineScope.downloadMedia(mediaFile: MutableState<MediaFile?>, localMedia: MutableState<Async<LocalMedia>>) = launch {
|
||||
localMedia.value = Async.Loading()
|
||||
mediaLoader.downloadMediaFile(inputs.mediaSource, inputs.mimeType)
|
||||
mediaLoader.downloadMediaFile(
|
||||
source = inputs.mediaSource,
|
||||
mimeType = inputs.mimeType,
|
||||
body = inputs.name
|
||||
)
|
||||
.onSuccess {
|
||||
mediaFile.value = it
|
||||
}.mapCatching { mediaFile ->
|
||||
|
|
|
|||
|
|
@ -104,7 +104,11 @@ fun MediaViewerView(
|
|||
|
||||
Scaffold(modifier,
|
||||
topBar = {
|
||||
MediaViewerTopBar(onBackPressed, state.eventSink)
|
||||
MediaViewerTopBar(
|
||||
actionsEnabled = state.downloadedMedia is Async.Success,
|
||||
onBackPressed = onBackPressed,
|
||||
eventSink = state.eventSink
|
||||
)
|
||||
},
|
||||
snackbarHost = {
|
||||
SnackbarHost(snackbarHostState) { data ->
|
||||
|
|
@ -145,6 +149,7 @@ fun MediaViewerView(
|
|||
|
||||
@Composable
|
||||
private fun MediaViewerTopBar(
|
||||
actionsEnabled : Boolean,
|
||||
onBackPressed: () -> Unit,
|
||||
eventSink: (MediaViewerEvents) -> Unit,
|
||||
) {
|
||||
|
|
@ -153,6 +158,7 @@ private fun MediaViewerTopBar(
|
|||
navigationIcon = { BackButton(onClick = onBackPressed) },
|
||||
actions = {
|
||||
IconButton(
|
||||
enabled = actionsEnabled,
|
||||
onClick = {
|
||||
eventSink(MediaViewerEvents.Share)
|
||||
},
|
||||
|
|
@ -160,6 +166,7 @@ private fun MediaViewerTopBar(
|
|||
Icon(imageVector = Icons.Default.Share, contentDescription = stringResource(id = string.action_share))
|
||||
}
|
||||
IconButton(
|
||||
enabled = actionsEnabled,
|
||||
onClick = {
|
||||
eventSink(MediaViewerEvents.SaveOnDisk)
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue