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:
parent
fbe68d5bb8
commit
153ccab4ae
4 changed files with 25 additions and 3 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ class DialogViewModel(val message: String, val title: String = "") : ViewModel()
|
|||
|
||||
init {
|
||||
doNotAskAgain.value = false
|
||||
showTitle = title.isNotEmpty()
|
||||
}
|
||||
|
||||
var showCancel: Boolean = false
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue