From ae1da6b9f5381b87086b80fa3cbbf46095032e70 Mon Sep 17 00:00:00 2001 From: Valere Date: Thu, 25 Jun 2020 13:59:01 +0200 Subject: [PATCH] Namespacing of file service --- .../java/im/vector/matrix/android/api/session/Session.kt | 7 ++++++- .../matrix/android/internal/session/DefaultSession.kt | 5 +++-- .../riotx/features/home/room/detail/RoomDetailFragment.kt | 4 ++-- .../riotx/features/home/room/detail/RoomDetailViewModel.kt | 6 +++--- .../room/detail/timeline/factory/MessageItemFactory.kt | 2 +- .../riotx/features/media/ImageMediaViewerActivity.kt | 2 +- .../im/vector/riotx/features/media/VideoContentRenderer.kt | 4 ++-- .../riotx/features/media/VideoMediaViewerActivity.kt | 2 +- .../features/roomprofile/uploads/RoomUploadsViewModel.kt | 4 ++-- .../features/settings/VectorSettingsGeneralFragment.kt | 6 +++--- 10 files changed, 24 insertions(+), 18 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt index b5418b66ca..98b973bab5 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/Session.kt @@ -47,6 +47,7 @@ import im.vector.matrix.android.api.session.typing.TypingUsersTracker import im.vector.matrix.android.api.session.user.UserService import im.vector.matrix.android.api.session.widgets.WidgetService import im.vector.matrix.android.internal.session.download.ContentDownloadStateTracker +import java.io.File /** * This interface defines interactions with a session. @@ -60,7 +61,6 @@ interface Session : CacheService, SignOutService, FilterService, - FileService, TermsService, ProfileService, PushRuleService, @@ -183,6 +183,11 @@ interface Session : */ fun callSignalingService(): CallSignalingService + /** + * Returns the file download service associated with the session + */ + fun fileService(): FileService + /** * Add a listener to the session. * @param listener the listener to add. diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt index 02c9921de7..f8931e9cf5 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultSession.kt @@ -91,7 +91,7 @@ internal class DefaultSession @Inject constructor( private val pushersService: Lazy, private val termsService: Lazy, private val cryptoService: Lazy, - private val fileService: Lazy, + private val defaultFileService: Lazy, private val secureStorageService: Lazy, private val profileService: Lazy, private val widgetService: Lazy, @@ -122,7 +122,6 @@ internal class DefaultSession @Inject constructor( FilterService by filterService.get(), PushRuleService by pushRuleService.get(), PushersService by pushersService.get(), - FileService by fileService.get(), TermsService by termsService.get(), InitialSyncProgressService by initialSyncProgressService.get(), SecureStorageService by secureStorageService.get(), @@ -247,6 +246,8 @@ internal class DefaultSession @Inject constructor( override fun identityService() = defaultIdentityService + override fun fileService(): FileService = defaultFileService.get() + override fun widgetService(): WidgetService = widgetService.get() override fun integrationManagerService() = integrationManagerService diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt index 9d1cf2a66c..2d7a26efb7 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailFragment.kt @@ -1339,7 +1339,7 @@ class RoomDetailFragment @Inject constructor( } private fun onShareActionClicked(action: EventSharedAction.Share) { - session.downloadFile( + session.fileService().downloadFile( FileService.DownloadMode.FOR_EXTERNAL_SHARE, action.eventId, action.messageContent.body, @@ -1357,7 +1357,7 @@ class RoomDetailFragment @Inject constructor( } private fun onSaveActionClicked(action: EventSharedAction.Save) { - session.downloadFile( + session.fileService().downloadFile( downloadMode = FileService.DownloadMode.FOR_EXTERNAL_SHARE, id = action.eventId, fileName = action.messageContent.body, diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt index b6a5009908..62830a1c63 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/RoomDetailViewModel.kt @@ -861,10 +861,10 @@ class RoomDetailViewModel @AssistedInject constructor( private fun handleOpenOrDownloadFile(action: RoomDetailAction.DownloadOrOpen) { val mxcUrl = action.messageFileContent.getFileUrl() - val isDownloaded = mxcUrl?.let { session.isFileInCache(it, action.messageFileContent.mimeType) } ?: false + val isDownloaded = mxcUrl?.let { session.fileService().isFileInCache(it, action.messageFileContent.mimeType) } ?: false if (isDownloaded) { // we can open it - session.getTemporarySharableURI(mxcUrl!!, action.messageFileContent.mimeType)?.let { uri -> + session.fileService().getTemporarySharableURI(mxcUrl!!, action.messageFileContent.mimeType)?.let { uri -> _viewEvents.post(RoomDetailViewEvents.OpenFile( action.messageFileContent.mimeType, uri, @@ -872,7 +872,7 @@ class RoomDetailViewModel @AssistedInject constructor( )) } } else { - session.downloadFile( + session.fileService().downloadFile( FileService.DownloadMode.FOR_INTERNAL_USE, action.eventId, action.messageFileContent.getFileName(), diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt index 16c8ed93ad..2174556098 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -245,7 +245,7 @@ class MessageItemFactory @Inject constructor( .attributes(attributes) .leftGuideline(avatarSizeProvider.leftGuideline) .izLocalFile(messageContent.getFileUrl().isLocalFile()) - .izDownloaded(session.isFileInCache(mxcUrl, messageContent.mimeType)) + .izDownloaded(session.fileService().isFileInCache(mxcUrl, messageContent.mimeType)) .mxcUrl(mxcUrl) .contentUploadStateTrackerBinder(contentUploadStateTrackerBinder) .contentDownloadStateTrackerBinder(contentDownloadStateTrackerBinder) diff --git a/vector/src/main/java/im/vector/riotx/features/media/ImageMediaViewerActivity.kt b/vector/src/main/java/im/vector/riotx/features/media/ImageMediaViewerActivity.kt index 00f47b6a28..2be940d0c1 100644 --- a/vector/src/main/java/im/vector/riotx/features/media/ImageMediaViewerActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/media/ImageMediaViewerActivity.kt @@ -133,7 +133,7 @@ class ImageMediaViewerActivity : VectorBaseActivity() { } private fun onShareActionClicked() { - session.downloadFile( + session.fileService().downloadFile( FileService.DownloadMode.FOR_EXTERNAL_SHARE, mediaData.eventId, mediaData.filename, diff --git a/vector/src/main/java/im/vector/riotx/features/media/VideoContentRenderer.kt b/vector/src/main/java/im/vector/riotx/features/media/VideoContentRenderer.kt index 0d6ac176c1..eb9105f792 100644 --- a/vector/src/main/java/im/vector/riotx/features/media/VideoContentRenderer.kt +++ b/vector/src/main/java/im/vector/riotx/features/media/VideoContentRenderer.kt @@ -65,7 +65,7 @@ class VideoContentRenderer @Inject constructor(private val activeSessionHolder: thumbnailView.isVisible = true loadingView.isVisible = true - activeSessionHolder.getActiveSession() + activeSessionHolder.getActiveSession().fileService() .downloadFile( downloadMode = FileService.DownloadMode.FOR_INTERNAL_USE, id = data.eventId, @@ -104,7 +104,7 @@ class VideoContentRenderer @Inject constructor(private val activeSessionHolder: thumbnailView.isVisible = true loadingView.isVisible = true - activeSessionHolder.getActiveSession() + activeSessionHolder.getActiveSession().fileService() .downloadFile( downloadMode = FileService.DownloadMode.FOR_INTERNAL_USE, id = data.eventId, diff --git a/vector/src/main/java/im/vector/riotx/features/media/VideoMediaViewerActivity.kt b/vector/src/main/java/im/vector/riotx/features/media/VideoMediaViewerActivity.kt index 1e8a2d8a72..6ef8927f00 100644 --- a/vector/src/main/java/im/vector/riotx/features/media/VideoMediaViewerActivity.kt +++ b/vector/src/main/java/im/vector/riotx/features/media/VideoMediaViewerActivity.kt @@ -78,7 +78,7 @@ class VideoMediaViewerActivity : VectorBaseActivity() { } private fun onShareActionClicked() { - session.downloadFile( + session.fileService().downloadFile( FileService.DownloadMode.FOR_EXTERNAL_SHARE, mediaData.eventId, mediaData.filename, diff --git a/vector/src/main/java/im/vector/riotx/features/roomprofile/uploads/RoomUploadsViewModel.kt b/vector/src/main/java/im/vector/riotx/features/roomprofile/uploads/RoomUploadsViewModel.kt index 6037d17a84..10f0a5051e 100644 --- a/vector/src/main/java/im/vector/riotx/features/roomprofile/uploads/RoomUploadsViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/roomprofile/uploads/RoomUploadsViewModel.kt @@ -136,7 +136,7 @@ class RoomUploadsViewModel @AssistedInject constructor( viewModelScope.launch { try { val file = awaitCallback { - session.downloadFile( + session.fileService().downloadFile( downloadMode = FileService.DownloadMode.FOR_EXTERNAL_SHARE, id = action.uploadEvent.eventId, fileName = action.uploadEvent.contentWithAttachmentContent.body, @@ -157,7 +157,7 @@ class RoomUploadsViewModel @AssistedInject constructor( viewModelScope.launch { try { val file = awaitCallback { - session.downloadFile( + session.fileService().downloadFile( FileService.DownloadMode.FOR_EXTERNAL_SHARE, action.uploadEvent.eventId, action.uploadEvent.contentWithAttachmentContent.body, diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt index 928d795eac..18fa9d95ed 100644 --- a/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt +++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorSettingsGeneralFragment.kt @@ -237,7 +237,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() { // clear medias cache findPreference(VectorPreferences.SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY)!!.let { - val size = getSizeOfFiles(File(requireContext().cacheDir, DiskCache.Factory.DEFAULT_DISK_CACHE_DIR)) + session.getCacheSize() + val size = getSizeOfFiles(File(requireContext().cacheDir, DiskCache.Factory.DEFAULT_DISK_CACHE_DIR)) + session.fileService().getCacheSize() it.summary = TextUtils.formatFileSize(requireContext(), size.toLong()) @@ -247,7 +247,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() { displayLoadingView() Glide.get(requireContext()).clearMemory() - session.clearCache() + session.fileService().clearCache() var newSize = 0 @@ -256,7 +256,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() { Glide.get(requireContext()).clearDiskCache() newSize = getSizeOfFiles(File(requireContext().cacheDir, DiskCache.Factory.DEFAULT_DISK_CACHE_DIR)) - newSize += session.getCacheSize() + newSize += session.fileService().getCacheSize() } it.summary = TextUtils.formatFileSize(requireContext(), newSize.toLong())