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.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.

View file

@ -91,7 +91,7 @@ internal class DefaultSession @Inject constructor(
private val pushersService: Lazy<PushersService>,
private val termsService: Lazy<TermsService>,
private val cryptoService: Lazy<DefaultCryptoService>,
private val fileService: Lazy<FileService>,
private val defaultFileService: Lazy<FileService>,
private val secureStorageService: Lazy<SecureStorageService>,
private val profileService: Lazy<ProfileService>,
private val widgetService: Lazy<WidgetService>,
@ -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

View file

@ -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,

View file

@ -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(),

View file

@ -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)

View file

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

View file

@ -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,

View file

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

View file

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

View file

@ -237,7 +237,7 @@ class VectorSettingsGeneralFragment : VectorSettingsBaseFragment() {
// clear medias cache
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())
@ -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())