Give user a toast after adding media file to the gallery.

This commit is contained in:
onurays 2020-04-17 16:53:40 +03:00
parent 8434f9326e
commit 26bb8ce2be
3 changed files with 12 additions and 3 deletions

View File

@ -260,7 +260,7 @@ fun shareMedia(context: Context, file: File, mediaMimeType: String?) {
}
}
fun saveMedia(context: Context, file: File, title: String, mediaMimeType: String?) {
fun saveMedia(context: Context, file: File, title: String, mediaMimeType: String?): Boolean {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val externalContentUri: Uri
val values = ContentValues()
@ -301,6 +301,7 @@ fun saveMedia(context: Context, file: File, title: String, mediaMimeType: String
context.contentResolver.insert(externalContentUri, values)?.let { uri ->
context.contentResolver.openOutputStream(uri)?.use { outputStream ->
outputStream.sink().buffer().write(file.inputStream().use { it.readBytes() })
return true
}
}
} else {
@ -309,7 +310,9 @@ fun saveMedia(context: Context, file: File, title: String, mediaMimeType: String
mediaScanIntent.data = Uri.fromFile(file)
context.sendBroadcast(mediaScanIntent)
}
return true
}
return false
}
/**

View File

@ -1164,12 +1164,17 @@ class RoomDetailFragment @Inject constructor(
object : MatrixCallback<File> {
override fun onSuccess(data: File) {
if (isAdded) {
saveMedia(
val saved = saveMedia(
context = requireContext(),
file = data,
title = action.messageContent.body,
mediaMimeType = getMimeTypeFromUri(requireContext(), data.toUri())
)
if (saved) {
Toast.makeText(requireContext(), R.string.media_file_added_to_gallery, Toast.LENGTH_LONG).show()
} else {
Toast.makeText(requireContext(), R.string.error_adding_media_file_to_gallery, Toast.LENGTH_LONG).show()
}
}
}
}

View File

@ -21,7 +21,8 @@
<!-- BEGIN Strings added by Onuray -->
<string name="media_file_added_to_gallery">Media file added to the Gallery</string>
<string name="error_adding_media_file_to_gallery">Could not add media file to the Gallery</string>
<!-- END Strings added by Onuray -->