mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-01-30 10:54:58 +01:00
Give user a toast after adding media file to the gallery.
This commit is contained in:
parent
8434f9326e
commit
26bb8ce2be
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 -->
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user