mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 18:35:40 +03:00
Convert to ViewEvents -> RoomDetailViewModel part 4
This commit is contained in:
parent
27e217fce5
commit
84e1169525
4 changed files with 16 additions and 37 deletions
|
@ -1,23 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright 2019 New Vector Ltd
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package im.vector.riotx.features.home.room.detail
|
|
||||||
|
|
||||||
data class FileTooBigError(
|
|
||||||
val filename: String,
|
|
||||||
val fileSizeInBytes: Long,
|
|
||||||
val homeServerLimitInBytes: Long
|
|
||||||
)
|
|
|
@ -261,10 +261,6 @@ class RoomDetailFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
.disposeOnDestroyView()
|
.disposeOnDestroyView()
|
||||||
|
|
||||||
roomDetailViewModel.fileTooBigEvent.observeEvent(this) {
|
|
||||||
displayFileTooBigWarning(it)
|
|
||||||
}
|
|
||||||
|
|
||||||
roomDetailViewModel.selectSubscribe(this, RoomDetailViewState::tombstoneEventHandling, uniqueOnly("tombstoneEventHandling")) {
|
roomDetailViewModel.selectSubscribe(this, RoomDetailViewState::tombstoneEventHandling, uniqueOnly("tombstoneEventHandling")) {
|
||||||
renderTombstoneEventHandling(it)
|
renderTombstoneEventHandling(it)
|
||||||
}
|
}
|
||||||
|
@ -300,6 +296,7 @@ class RoomDetailFragment @Inject constructor(
|
||||||
is RoomDetailViewEvents.ActionFailure -> displayRoomDetailActionFailure(it)
|
is RoomDetailViewEvents.ActionFailure -> displayRoomDetailActionFailure(it)
|
||||||
is RoomDetailViewEvents.ShowMessage -> showSnackWithMessage(it.message, Snackbar.LENGTH_LONG)
|
is RoomDetailViewEvents.ShowMessage -> showSnackWithMessage(it.message, Snackbar.LENGTH_LONG)
|
||||||
is RoomDetailViewEvents.NavigateToEvent -> navigateToEvent(it)
|
is RoomDetailViewEvents.NavigateToEvent -> navigateToEvent(it)
|
||||||
|
is RoomDetailViewEvents.FileTooBigError -> displayFileTooBigError(it)
|
||||||
is RoomDetailViewEvents.SendMessageResult -> renderSendMessageResult(it)
|
is RoomDetailViewEvents.SendMessageResult -> renderSendMessageResult(it)
|
||||||
}.exhaustive
|
}.exhaustive
|
||||||
}
|
}
|
||||||
|
@ -365,13 +362,13 @@ class RoomDetailFragment @Inject constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun displayFileTooBigWarning(error: FileTooBigError) {
|
private fun displayFileTooBigError(action: RoomDetailViewEvents.FileTooBigError) {
|
||||||
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,
|
action.filename,
|
||||||
TextUtils.formatFileSize(requireContext(), error.fileSizeInBytes),
|
TextUtils.formatFileSize(requireContext(), action.fileSizeInBytes),
|
||||||
TextUtils.formatFileSize(requireContext(), error.homeServerLimitInBytes)
|
TextUtils.formatFileSize(requireContext(), action.homeServerLimitInBytes)
|
||||||
))
|
))
|
||||||
.setPositiveButton(R.string.ok, null)
|
.setPositiveButton(R.string.ok, null)
|
||||||
.show()
|
.show()
|
||||||
|
|
|
@ -34,6 +34,12 @@ sealed class RoomDetailViewEvents : VectorViewEvents {
|
||||||
|
|
||||||
data class NavigateToEvent(val eventId: String) : RoomDetailViewEvents()
|
data class NavigateToEvent(val eventId: String) : RoomDetailViewEvents()
|
||||||
|
|
||||||
|
data class FileTooBigError(
|
||||||
|
val filename: String,
|
||||||
|
val fileSizeInBytes: Long,
|
||||||
|
val homeServerLimitInBytes: Long
|
||||||
|
) : RoomDetailViewEvents()
|
||||||
|
|
||||||
abstract class SendMessageResult : RoomDetailViewEvents()
|
abstract class SendMessageResult : RoomDetailViewEvents()
|
||||||
|
|
||||||
object MessageSent : SendMessageResult()
|
object MessageSent : SendMessageResult()
|
||||||
|
|
|
@ -314,10 +314,6 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Cleanup this and use ViewEvents
|
// TODO Cleanup this and use ViewEvents
|
||||||
private val _fileTooBigEvent = MutableLiveData<LiveEvent<FileTooBigError>>()
|
|
||||||
val fileTooBigEvent: LiveData<LiveEvent<FileTooBigError>>
|
|
||||||
get() = _fileTooBigEvent
|
|
||||||
|
|
||||||
private val _downloadedFileEvent = MutableLiveData<LiveEvent<DownloadFileState>>()
|
private val _downloadedFileEvent = MutableLiveData<LiveEvent<DownloadFileState>>()
|
||||||
val downloadedFileEvent: LiveData<LiveEvent<DownloadFileState>>
|
val downloadedFileEvent: LiveData<LiveEvent<DownloadFileState>>
|
||||||
get() = _downloadedFileEvent
|
get() = _downloadedFileEvent
|
||||||
|
@ -589,8 +585,11 @@ class RoomDetailViewModel @AssistedInject constructor(@Assisted initialState: Ro
|
||||||
} else {
|
} else {
|
||||||
when (val tooBigFile = attachments.find { it.size > maxUploadFileSize }) {
|
when (val tooBigFile = attachments.find { it.size > maxUploadFileSize }) {
|
||||||
null -> room.sendMedias(attachments)
|
null -> room.sendMedias(attachments)
|
||||||
else -> _fileTooBigEvent.postValue(LiveEvent(FileTooBigError(tooBigFile.name
|
else -> _viewEvents.post(RoomDetailViewEvents.FileTooBigError(
|
||||||
?: tooBigFile.path, tooBigFile.size, maxUploadFileSize)))
|
tooBigFile.name ?: tooBigFile.path,
|
||||||
|
tooBigFile.size,
|
||||||
|
maxUploadFileSize
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue