Added dialog to allow user to attempt opening a file as plain text if no app is registered for the deduced mime type from it's extension

This commit is contained in:
Sylvain Berfini 2020-07-15 17:50:40 +02:00
parent fbe68d5bb8
commit 153ccab4ae
4 changed files with 25 additions and 3 deletions

View file

@ -542,8 +542,27 @@ class DetailChatRoomFragment : MasterFragment() {
startActivity(intent)
} catch (anfe: ActivityNotFoundException) {
Log.e("[Chat Message] Couldn't find an activity to handle MIME type: $type")
val activity = requireActivity() as MainActivity
activity.showSnackBar(R.string.chat_room_cant_open_file_no_app_found)
val dialogViewModel = DialogViewModel(getString(R.string.dialog_try_open_file_as_text_body), getString(R.string.dialog_try_open_file_as_text_title))
val dialog = DialogUtils.getDialog(requireContext(), dialogViewModel)
dialogViewModel.showCancelButton {
dialog.dismiss()
}
dialogViewModel.showOkButton({
dialog.dismiss()
intent.setDataAndType(contentUri, "text/plain")
try {
startActivity(intent)
} catch (anfe: ActivityNotFoundException) {
Log.e("[Chat Message] Couldn't find an activity to handle text/plain MIME type")
val activity = requireActivity() as MainActivity
activity.showSnackBar(R.string.chat_room_cant_open_file_no_app_found)
}
})
dialog.show()
}
}
}

View file

@ -41,6 +41,7 @@ class DialogViewModel(val message: String, val title: String = "") : ViewModel()
init {
doNotAskAgain.value = false
showTitle = title.isNotEmpty()
}
var showCancel: Boolean = false

View file

@ -79,7 +79,7 @@ class LinphoneUtils {
fun deleteFilesAttachedToChatMessage(chatMessage: ChatMessage) {
for (content in chatMessage.contents) {
val filePath = content.filePath
if (filePath != null) {
if (filePath != null && filePath.isNotEmpty()) {
Log.i("[Linphone Utils] Deleting file $filePath")
FileUtils.deleteFile(filePath)
}

View file

@ -560,6 +560,8 @@
<item quantity="other">@string/dialog_default_delete_many</item>
</plurals>
<string name="dialog_update_available">An update is available</string>
<string name="dialog_try_open_file_as_text_title">No app found for this kind of file</string>
<string name="dialog_try_open_file_as_text_body">Would you like to try opening it as a plain text file?</string>
<!-- Content description -->
<string name="content_description_add_sip_address_field">Add a SIP address field</string>