Namespacing of file service

This commit is contained in:
Valere 2020-06-25 13:59:01 +02:00 committed by Benoit Marty
parent 04b6b3674d
commit ae1da6b9f5
10 changed files with 24 additions and 18 deletions

View File

@ -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.user.UserService
import im.vector.matrix.android.api.session.widgets.WidgetService import im.vector.matrix.android.api.session.widgets.WidgetService
import im.vector.matrix.android.internal.session.download.ContentDownloadStateTracker import im.vector.matrix.android.internal.session.download.ContentDownloadStateTracker
import java.io.File
/** /**
* This interface defines interactions with a session. * This interface defines interactions with a session.
@ -60,7 +61,6 @@ interface Session :
CacheService, CacheService,
SignOutService, SignOutService,
FilterService, FilterService,
FileService,
TermsService, TermsService,
ProfileService, ProfileService,
PushRuleService, PushRuleService,
@ -183,6 +183,11 @@ interface Session :
*/ */
fun callSignalingService(): CallSignalingService fun callSignalingService(): CallSignalingService
/**
* Returns the file download service associated with the session
*/
fun fileService(): FileService
/** /**
* Add a listener to the session. * Add a listener to the session.
* @param listener the listener to add. * @param listener the listener to add.

View File

@ -91,7 +91,7 @@ internal class DefaultSession @Inject constructor(
private val pushersService: Lazy<PushersService>, private val pushersService: Lazy<PushersService>,
private val termsService: Lazy<TermsService>, private val termsService: Lazy<TermsService>,
private val cryptoService: Lazy<DefaultCryptoService>, private val cryptoService: Lazy<DefaultCryptoService>,
private val fileService: Lazy<FileService>, private val defaultFileService: Lazy<FileService>,
private val secureStorageService: Lazy<SecureStorageService>, private val secureStorageService: Lazy<SecureStorageService>,
private val profileService: Lazy<ProfileService>, private val profileService: Lazy<ProfileService>,
private val widgetService: Lazy<WidgetService>, private val widgetService: Lazy<WidgetService>,
@ -122,7 +122,6 @@ internal class DefaultSession @Inject constructor(
FilterService by filterService.get(), FilterService by filterService.get(),
PushRuleService by pushRuleService.get(), PushRuleService by pushRuleService.get(),
PushersService by pushersService.get(), PushersService by pushersService.get(),
FileService by fileService.get(),
TermsService by termsService.get(), TermsService by termsService.get(),
InitialSyncProgressService by initialSyncProgressService.get(), InitialSyncProgressService by initialSyncProgressService.get(),
SecureStorageService by secureStorageService.get(), SecureStorageService by secureStorageService.get(),
@ -247,6 +246,8 @@ internal class DefaultSession @Inject constructor(
override fun identityService() = defaultIdentityService override fun identityService() = defaultIdentityService
override fun fileService(): FileService = defaultFileService.get()
override fun widgetService(): WidgetService = widgetService.get() override fun widgetService(): WidgetService = widgetService.get()
override fun integrationManagerService() = integrationManagerService override fun integrationManagerService() = integrationManagerService

View File

@ -1339,7 +1339,7 @@ class RoomDetailFragment @Inject constructor(
} }
private fun onShareActionClicked(action: EventSharedAction.Share) { private fun onShareActionClicked(action: EventSharedAction.Share) {
session.downloadFile( session.fileService().downloadFile(
FileService.DownloadMode.FOR_EXTERNAL_SHARE, FileService.DownloadMode.FOR_EXTERNAL_SHARE,
action.eventId, action.eventId,
action.messageContent.body, action.messageContent.body,
@ -1357,7 +1357,7 @@ class RoomDetailFragment @Inject constructor(
} }
private fun onSaveActionClicked(action: EventSharedAction.Save) { private fun onSaveActionClicked(action: EventSharedAction.Save) {
session.downloadFile( session.fileService().downloadFile(
downloadMode = FileService.DownloadMode.FOR_EXTERNAL_SHARE, downloadMode = FileService.DownloadMode.FOR_EXTERNAL_SHARE,
id = action.eventId, id = action.eventId,
fileName = action.messageContent.body, fileName = action.messageContent.body,

View File

@ -861,10 +861,10 @@ class RoomDetailViewModel @AssistedInject constructor(
private fun handleOpenOrDownloadFile(action: RoomDetailAction.DownloadOrOpen) { private fun handleOpenOrDownloadFile(action: RoomDetailAction.DownloadOrOpen) {
val mxcUrl = action.messageFileContent.getFileUrl() 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) { if (isDownloaded) {
// we can open it // 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( _viewEvents.post(RoomDetailViewEvents.OpenFile(
action.messageFileContent.mimeType, action.messageFileContent.mimeType,
uri, uri,
@ -872,7 +872,7 @@ class RoomDetailViewModel @AssistedInject constructor(
)) ))
} }
} else { } else {
session.downloadFile( session.fileService().downloadFile(
FileService.DownloadMode.FOR_INTERNAL_USE, FileService.DownloadMode.FOR_INTERNAL_USE,
action.eventId, action.eventId,
action.messageFileContent.getFileName(), action.messageFileContent.getFileName(),

View File

@ -245,7 +245,7 @@ class MessageItemFactory @Inject constructor(
.attributes(attributes) .attributes(attributes)
.leftGuideline(avatarSizeProvider.leftGuideline) .leftGuideline(avatarSizeProvider.leftGuideline)
.izLocalFile(messageContent.getFileUrl().isLocalFile()) .izLocalFile(messageContent.getFileUrl().isLocalFile())
.izDownloaded(session.isFileInCache(mxcUrl, messageContent.mimeType)) .izDownloaded(session.fileService().isFileInCache(mxcUrl, messageContent.mimeType))
.mxcUrl(mxcUrl) .mxcUrl(mxcUrl)
.contentUploadStateTrackerBinder(contentUploadStateTrackerBinder) .contentUploadStateTrackerBinder(contentUploadStateTrackerBinder)
.contentDownloadStateTrackerBinder(contentDownloadStateTrackerBinder) .contentDownloadStateTrackerBinder(contentDownloadStateTrackerBinder)

View File

@ -133,7 +133,7 @@ class ImageMediaViewerActivity : VectorBaseActivity() {
} }
private fun onShareActionClicked() { private fun onShareActionClicked() {
session.downloadFile( session.fileService().downloadFile(
FileService.DownloadMode.FOR_EXTERNAL_SHARE, FileService.DownloadMode.FOR_EXTERNAL_SHARE,
mediaData.eventId, mediaData.eventId,
mediaData.filename, mediaData.filename,

View File

@ -65,7 +65,7 @@ class VideoContentRenderer @Inject constructor(private val activeSessionHolder:
thumbnailView.isVisible = true thumbnailView.isVisible = true
loadingView.isVisible = true loadingView.isVisible = true
activeSessionHolder.getActiveSession() activeSessionHolder.getActiveSession().fileService()
.downloadFile( .downloadFile(
downloadMode = FileService.DownloadMode.FOR_INTERNAL_USE, downloadMode = FileService.DownloadMode.FOR_INTERNAL_USE,
id = data.eventId, id = data.eventId,
@ -104,7 +104,7 @@ class VideoContentRenderer @Inject constructor(private val activeSessionHolder:
thumbnailView.isVisible = true thumbnailView.isVisible = true
loadingView.isVisible = true loadingView.isVisible = true
activeSessionHolder.getActiveSession() activeSessionHolder.getActiveSession().fileService()
.downloadFile( .downloadFile(
downloadMode = FileService.DownloadMode.FOR_INTERNAL_USE, downloadMode = FileService.DownloadMode.FOR_INTERNAL_USE,
id = data.eventId, id = data.eventId,

View File

@ -78,7 +78,7 @@ class VideoMediaViewerActivity : VectorBaseActivity() {
} }
private fun onShareActionClicked() { private fun onShareActionClicked() {
session.downloadFile( session.fileService().downloadFile(
FileService.DownloadMode.FOR_EXTERNAL_SHARE, FileService.DownloadMode.FOR_EXTERNAL_SHARE,
mediaData.eventId, mediaData.eventId,
mediaData.filename, mediaData.filename,

View File

@ -136,7 +136,7 @@ class RoomUploadsViewModel @AssistedInject constructor(
viewModelScope.launch { viewModelScope.launch {
try { try {
val file = awaitCallback<File> { val file = awaitCallback<File> {
session.downloadFile( session.fileService().downloadFile(
downloadMode = FileService.DownloadMode.FOR_EXTERNAL_SHARE, downloadMode = FileService.DownloadMode.FOR_EXTERNAL_SHARE,
id = action.uploadEvent.eventId, id = action.uploadEvent.eventId,
fileName = action.uploadEvent.contentWithAttachmentContent.body, fileName = action.uploadEvent.contentWithAttachmentContent.body,
@ -157,7 +157,7 @@ class RoomUploadsViewModel @AssistedInject constructor(
viewModelScope.launch { viewModelScope.launch {
try { try {
val file = awaitCallback<File> { val file = awaitCallback<File> {
session.downloadFile( session.fileService().downloadFile(
FileService.DownloadMode.FOR_EXTERNAL_SHARE, FileService.DownloadMode.FOR_EXTERNAL_SHARE,
action.uploadEvent.eventId, action.uploadEvent.eventId,
action.uploadEvent.contentWithAttachmentContent.body, action.uploadEvent.contentWithAttachmentContent.body,

View File

@ -237,7 +237,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
// clear medias cache // clear medias cache
findPreference<VectorPreference>(VectorPreferences.SETTINGS_CLEAR_MEDIA_CACHE_PREFERENCE_KEY)!!.let { findPreference<VectorPreference>(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()) it.summary = TextUtils.formatFileSize(requireContext(), size.toLong())
@ -247,7 +247,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
displayLoadingView() displayLoadingView()
Glide.get(requireContext()).clearMemory() Glide.get(requireContext()).clearMemory()
session.clearCache() session.fileService().clearCache()
var newSize = 0 var newSize = 0
@ -256,7 +256,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
Glide.get(requireContext()).clearDiskCache() Glide.get(requireContext()).clearDiskCache()
newSize = getSizeOfFiles(File(requireContext().cacheDir, DiskCache.Factory.DEFAULT_DISK_CACHE_DIR)) 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()) it.summary = TextUtils.formatFileSize(requireContext(), newSize.toLong())