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.sendMessageResultLiveData.observeEvent(viewLifecycleOwner) { renderSendMessageResult(it) }
roomDetailViewModel.nonBlockingPopAlert.observeEvent(this) { pair -> 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) showSnackWithMessage(message, Snackbar.LENGTH_LONG)
} }
sharedActionViewModel sharedActionViewModel
@ -280,11 +280,12 @@ class RoomDetailFragment @Inject constructor(
} }
roomDetailViewModel.downloadedFileEvent.observeEvent(this) { downloadFileState -> roomDetailViewModel.downloadedFileEvent.observeEvent(this) { downloadFileState ->
val activity = requireActivity()
if (downloadFileState.throwable != null) { if (downloadFileState.throwable != null) {
requireActivity().toast(errorFormatter.toHumanReadable(downloadFileState.throwable)) activity.toast(errorFormatter.toHumanReadable(downloadFileState.throwable))
} else if (downloadFileState.file != null) { } else if (downloadFileState.file != null) {
requireActivity().toast(getString(R.string.downloaded_file, downloadFileState.file.path)) activity.toast(getString(R.string.downloaded_file, downloadFileState.file.path))
addEntryToDownloadManager(requireContext(), downloadFileState.file, downloadFileState.mimeType) addEntryToDownloadManager(activity, downloadFileState.file, downloadFileState.mimeType)
} }
} }
@ -369,9 +370,9 @@ class RoomDetailFragment @Inject constructor(
AlertDialog.Builder(requireActivity()) AlertDialog.Builder(requireActivity())
.setTitle(R.string.dialog_title_error) .setTitle(R.string.dialog_title_error)
.setMessage(getString(R.string.error_file_too_big, .setMessage(getString(R.string.error_file_too_big,
error.filename, error.filename,
TextUtils.formatFileSize(requireContext(), error.fileSizeInBytes), TextUtils.formatFileSize(requireContext(), error.fileSizeInBytes),
TextUtils.formatFileSize(requireContext(), error.homeServerLimitInBytes) TextUtils.formatFileSize(requireContext(), error.homeServerLimitInBytes)
)) ))
.setPositiveButton(R.string.ok, null) .setPositiveButton(R.string.ok, null)
.show() .show()
@ -454,11 +455,11 @@ class RoomDetailFragment @Inject constructor(
updateComposerText(defaultContent) updateComposerText(defaultContent)
composerLayout.composerRelatedMessageActionIcon.setImageDrawable(ContextCompat.getDrawable(requireContext(), iconRes)) composerLayout.composerRelatedMessageActionIcon.setImageDrawable(ContextCompat.getDrawable(requireContext(), iconRes))
composerLayout.sendButton.setContentDescription(getString(descriptionRes)) composerLayout.sendButton.contentDescription = getString(descriptionRes)
avatarRenderer.render( avatarRenderer.render(
MatrixItem.UserItem(event.root.senderId MatrixItem.UserItem(event.root.senderId
?: "", event.getDisambiguatedDisplayName(), event.senderAvatar), ?: "", event.getDisambiguatedDisplayName(), event.senderAvatar),
composerLayout.composerRelatedMessageAvatar composerLayout.composerRelatedMessageAvatar
) )
@ -477,7 +478,7 @@ class RoomDetailFragment @Inject constructor(
// Ignore update to avoid saving a draft // Ignore update to avoid saving a draft
composerLayout.composerEditText.setText(text) composerLayout.composerEditText.setText(text)
composerLayout.composerEditText.setSelection(composerLayout.composerEditText.text?.length composerLayout.composerEditText.setSelection(composerLayout.composerEditText.text?.length
?: 0) ?: 0)
} }
} }
@ -928,6 +929,7 @@ class RoomDetailFragment @Inject constructor(
val action = RoomDetailAction.DownloadFile(eventId, messageFileContent) val action = RoomDetailAction.DownloadFile(eventId, messageFileContent)
// We need WRITE_EXTERNAL permission // We need WRITE_EXTERNAL permission
if (checkPermissions(PERMISSIONS_FOR_WRITING_FILES, this, PERMISSION_REQUEST_CODE_DOWNLOAD_FILE)) { 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) roomDetailViewModel.handle(action)
} else { } else {
roomDetailViewModel.pendingAction = action roomDetailViewModel.pendingAction = action
@ -940,6 +942,12 @@ class RoomDetailFragment @Inject constructor(
PERMISSION_REQUEST_CODE_DOWNLOAD_FILE -> { PERMISSION_REQUEST_CODE_DOWNLOAD_FILE -> {
val action = roomDetailViewModel.pendingAction val action = roomDetailViewModel.pendingAction
if (action != null) { if (action != null) {
(action as? RoomDetailAction.DownloadFile)
?.messageFileContent
?.getFileName()
?.let {
showSnackWithMessage(getString(R.string.downloading_file, it), Snackbar.LENGTH_LONG)
}
roomDetailViewModel.pendingAction = null roomDetailViewModel.pendingAction = null
roomDetailViewModel.handle(action) roomDetailViewModel.handle(action)
} }
@ -1052,8 +1060,7 @@ class RoomDetailFragment @Inject constructor(
is EventSharedAction.Copy -> { is EventSharedAction.Copy -> {
// I need info about the current selected message :/ // I need info about the current selected message :/
copyToClipboard(requireContext(), action.content, false) copyToClipboard(requireContext(), action.content, false)
val msg = requireContext().getString(R.string.copied_to_clipboard) showSnackWithMessage(getString(R.string.copied_to_clipboard), Snackbar.LENGTH_SHORT)
showSnackWithMessage(msg, Snackbar.LENGTH_SHORT)
} }
is EventSharedAction.Delete -> { is EventSharedAction.Delete -> {
roomDetailViewModel.handle(RoomDetailAction.RedactAction(action.eventId, context?.getString(R.string.event_redacted_by_user_reason))) 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 -> { is EventSharedAction.CopyPermalink -> {
val permalink = PermalinkFactory.createPermalink(roomDetailArgs.roomId, action.eventId) val permalink = PermalinkFactory.createPermalink(roomDetailArgs.roomId, action.eventId)
copyToClipboard(requireContext(), permalink, false) 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 -> { is EventSharedAction.Resend -> {
roomDetailViewModel.handle(RoomDetailAction.ResendMessage(action.eventId)) roomDetailViewModel.handle(RoomDetailAction.ResendMessage(action.eventId))
@ -1171,7 +1178,7 @@ class RoomDetailFragment @Inject constructor(
val startToCompose = composerLayout.composerEditText.text.isNullOrBlank() val startToCompose = composerLayout.composerEditText.text.isNullOrBlank()
if (startToCompose if (startToCompose
&& userId == session.myUserId) { && userId == session.myUserId) {
// Empty composer, current user: start an emote // Empty composer, current user: start an emote
composerLayout.composerEditText.setText(Command.EMOTE.command + " ") composerLayout.composerEditText.setText(Command.EMOTE.command + " ")
composerLayout.composerEditText.setSelection(Command.EMOTE.length) composerLayout.composerEditText.setSelection(Command.EMOTE.length)