Inform user when the download of a file starts

This commit is contained in:
Benoit Marty 2020-01-16 12:20:39 +01:00
parent d72f1ac576
commit b0aa9fbd8f

View file

@ -251,7 +251,7 @@ class RoomDetailFragment @Inject constructor(
roomDetailViewModel.sendMessageResultLiveData.observeEvent(viewLifecycleOwner) { renderSendMessageResult(it) }
roomDetailViewModel.nonBlockingPopAlert.observeEvent(this) { pair ->
val message = requireContext().getString(pair.first, *pair.second.toTypedArray())
val message = getString(pair.first, *pair.second.toTypedArray())
showSnackWithMessage(message, Snackbar.LENGTH_LONG)
}
sharedActionViewModel
@ -280,11 +280,12 @@ class RoomDetailFragment @Inject constructor(
}
roomDetailViewModel.downloadedFileEvent.observeEvent(this) { downloadFileState ->
val activity = requireActivity()
if (downloadFileState.throwable != null) {
requireActivity().toast(errorFormatter.toHumanReadable(downloadFileState.throwable))
activity.toast(errorFormatter.toHumanReadable(downloadFileState.throwable))
} else if (downloadFileState.file != null) {
requireActivity().toast(getString(R.string.downloaded_file, downloadFileState.file.path))
addEntryToDownloadManager(requireContext(), downloadFileState.file, downloadFileState.mimeType)
activity.toast(getString(R.string.downloaded_file, downloadFileState.file.path))
addEntryToDownloadManager(activity, downloadFileState.file, downloadFileState.mimeType)
}
}
@ -454,7 +455,7 @@ class RoomDetailFragment @Inject constructor(
updateComposerText(defaultContent)
composerLayout.composerRelatedMessageActionIcon.setImageDrawable(ContextCompat.getDrawable(requireContext(), iconRes))
composerLayout.sendButton.setContentDescription(getString(descriptionRes))
composerLayout.sendButton.contentDescription = getString(descriptionRes)
avatarRenderer.render(
MatrixItem.UserItem(event.root.senderId
@ -928,6 +929,7 @@ class RoomDetailFragment @Inject constructor(
val action = RoomDetailAction.DownloadFile(eventId, messageFileContent)
// We need WRITE_EXTERNAL permission
if (checkPermissions(PERMISSIONS_FOR_WRITING_FILES, this, PERMISSION_REQUEST_CODE_DOWNLOAD_FILE)) {
showSnackWithMessage(getString(R.string.downloading_file, messageFileContent.getFileName()), Snackbar.LENGTH_LONG)
roomDetailViewModel.handle(action)
} else {
roomDetailViewModel.pendingAction = action
@ -940,6 +942,12 @@ class RoomDetailFragment @Inject constructor(
PERMISSION_REQUEST_CODE_DOWNLOAD_FILE -> {
val action = roomDetailViewModel.pendingAction
if (action != null) {
(action as? RoomDetailAction.DownloadFile)
?.messageFileContent
?.getFileName()
?.let {
showSnackWithMessage(getString(R.string.downloading_file, it), Snackbar.LENGTH_LONG)
}
roomDetailViewModel.pendingAction = null
roomDetailViewModel.handle(action)
}
@ -1052,8 +1060,7 @@ class RoomDetailFragment @Inject constructor(
is EventSharedAction.Copy -> {
// I need info about the current selected message :/
copyToClipboard(requireContext(), action.content, false)
val msg = requireContext().getString(R.string.copied_to_clipboard)
showSnackWithMessage(msg, Snackbar.LENGTH_SHORT)
showSnackWithMessage(getString(R.string.copied_to_clipboard), Snackbar.LENGTH_SHORT)
}
is EventSharedAction.Delete -> {
roomDetailViewModel.handle(RoomDetailAction.RedactAction(action.eventId, context?.getString(R.string.event_redacted_by_user_reason)))
@ -1127,7 +1134,7 @@ class RoomDetailFragment @Inject constructor(
is EventSharedAction.CopyPermalink -> {
val permalink = PermalinkFactory.createPermalink(roomDetailArgs.roomId, action.eventId)
copyToClipboard(requireContext(), permalink, false)
showSnackWithMessage(requireContext().getString(R.string.copied_to_clipboard), Snackbar.LENGTH_SHORT)
showSnackWithMessage(getString(R.string.copied_to_clipboard), Snackbar.LENGTH_SHORT)
}
is EventSharedAction.Resend -> {
roomDetailViewModel.handle(RoomDetailAction.ResendMessage(action.eventId))