Creating a ViewModel
This commit is contained in:
parent
374ac45505
commit
c6c46375d6
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* 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.app.features.media
|
||||||
|
|
||||||
|
import im.vector.app.core.platform.VectorViewModelAction
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
sealed class VectorAttachmentViewerAction : VectorViewModelAction {
|
||||||
|
data class DownloadMedia(val file: File) : VectorAttachmentViewerAction()
|
||||||
|
}
|
@ -273,9 +273,12 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt
|
|||||||
// check if it is already possible to save from menu with long press on video
|
// check if it is already possible to save from menu with long press on video
|
||||||
override fun onDownload() {
|
override fun onDownload() {
|
||||||
// TODO
|
// TODO
|
||||||
// create ViewModel with action downloadAction, events downloading, downloaded, error
|
// call usecase using viewModel into handle method
|
||||||
// call usecase using viewModel
|
|
||||||
// launch coroutine in Activity using repeatOnLifeCycle extension
|
// launch coroutine in Activity using repeatOnLifeCycle extension
|
||||||
|
// call ViewModel.handle inside this method
|
||||||
|
// show message on error event: see TimelineFragment
|
||||||
|
// check write file permissions: see TimelineFragment
|
||||||
|
// should we check if media is saveable?
|
||||||
// add unit tests for usecase?
|
// add unit tests for usecase?
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2020 New Vector Ltd
|
* Copyright (c) 2020 New Vector Ltd
|
||||||
* Copyright (C) 2018 stfalcon.com
|
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -15,8 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package im.vector.lib.attachmentviewer
|
package im.vector.app.features.media
|
||||||
|
|
||||||
class AttachmentViewerViewModel {
|
import im.vector.app.core.platform.VectorViewEvents
|
||||||
|
|
||||||
|
sealed class VectorAttachmentViewerViewEvents : VectorViewEvents {
|
||||||
|
object DownloadingMedia : VectorAttachmentViewerViewEvents()
|
||||||
|
object MediaDownloaded : VectorAttachmentViewerViewEvents()
|
||||||
|
object ErrorDownloadingMedia : VectorAttachmentViewerViewEvents()
|
||||||
}
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2020 New Vector Ltd
|
||||||
|
* Copyright (C) 2018 stfalcon.com
|
||||||
|
*
|
||||||
|
* 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.app.features.media
|
||||||
|
|
||||||
|
import dagger.assisted.Assisted
|
||||||
|
import dagger.assisted.AssistedFactory
|
||||||
|
import dagger.assisted.AssistedInject
|
||||||
|
import im.vector.app.core.di.MavericksAssistedViewModelFactory
|
||||||
|
import im.vector.app.core.platform.VectorDummyViewState
|
||||||
|
import im.vector.app.core.platform.VectorViewModel
|
||||||
|
|
||||||
|
class VectorAttachmentViewerViewModel @AssistedInject constructor(
|
||||||
|
@Assisted initialState: VectorDummyViewState
|
||||||
|
) : VectorViewModel<VectorDummyViewState, VectorAttachmentViewerAction, VectorAttachmentViewerViewEvents>(initialState) {
|
||||||
|
|
||||||
|
/* ==========================================================================================
|
||||||
|
* Factory
|
||||||
|
* ========================================================================================== */
|
||||||
|
|
||||||
|
@AssistedFactory
|
||||||
|
interface Factory : MavericksAssistedViewModelFactory<VectorAttachmentViewerViewModel, VectorDummyViewState> {
|
||||||
|
override fun create(initialState: VectorDummyViewState): VectorAttachmentViewerViewModel
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ==========================================================================================
|
||||||
|
* Specialization
|
||||||
|
* ========================================================================================== */
|
||||||
|
|
||||||
|
override fun handle(action: VectorAttachmentViewerAction) {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user