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 8b8ea14c32..b4f9afdbd4 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 @@ -28,6 +28,7 @@ import im.vector.matrix.android.api.session.call.CallSignalingService import im.vector.matrix.android.api.session.content.ContentUploadStateTracker import im.vector.matrix.android.api.session.content.ContentUrlResolver import im.vector.matrix.android.api.session.crypto.CryptoService +import im.vector.matrix.android.api.session.file.ContentDownloadStateTracker import im.vector.matrix.android.api.session.file.FileService import im.vector.matrix.android.api.session.group.GroupService import im.vector.matrix.android.api.session.homeserver.HomeServerCapabilitiesService @@ -46,7 +47,6 @@ import im.vector.matrix.android.api.session.terms.TermsService 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 /** * This interface defines interactions with a session. diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/download/ContentDownloadStateTracker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/file/ContentDownloadStateTracker.kt similarity index 95% rename from matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/download/ContentDownloadStateTracker.kt rename to matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/file/ContentDownloadStateTracker.kt index d40941d8df..ed098e7a42 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/download/ContentDownloadStateTracker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/file/ContentDownloadStateTracker.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package im.vector.matrix.android.internal.session.download +package im.vector.matrix.android.api.session.file interface ContentDownloadStateTracker { fun track(key: String, updateListener: UpdateListener) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/file/FileService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/file/FileService.kt index bafd4f36c6..c120c499c9 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/file/FileService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/session/file/FileService.kt @@ -32,10 +32,12 @@ interface FileService { * Download file in external storage */ TO_EXPORT, + /** * Download file in cache */ FOR_INTERNAL_USE, + /** * Download file in file provider path */ @@ -73,15 +75,15 @@ interface FileService { * Get information on the given file. * Mimetype should be the same one as passed to downloadFile (limitation for now) */ - fun fileState(mxcUrl: String, mimeType: String?) : FileState + fun fileState(mxcUrl: String, mimeType: String?): FileState /** - * Clears all the files downloaded by the service + * Clears all the files downloaded by the service */ fun clearCache() /** * Get size of cached files */ - fun getCacheSize() : Int + fun getCacheSize(): Int } diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/AuthQualifiers.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/AuthQualifiers.kt index 98af702184..8ef2710fc5 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/AuthQualifiers.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/di/AuthQualifiers.kt @@ -36,4 +36,4 @@ internal annotation class UnauthenticatedWithCertificate @Qualifier @Retention(AnnotationRetention.RUNTIME) -internal annotation class WithProgress +internal annotation class UnauthenticatedWithCertificateWithProgress diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultFileService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultFileService.kt index 0a4f4dbc39..6d0c9b7b96 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultFileService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/DefaultFileService.kt @@ -32,7 +32,8 @@ import im.vector.matrix.android.internal.crypto.attachments.MXEncryptedAttachmen import im.vector.matrix.android.internal.di.CacheDirectory import im.vector.matrix.android.internal.di.ExternalFilesDirectory import im.vector.matrix.android.internal.di.SessionDownloadsDirectory -import im.vector.matrix.android.internal.di.WithProgress +import im.vector.matrix.android.internal.di.UnauthenticatedWithCertificateWithProgress +import im.vector.matrix.android.internal.session.download.DownloadProgressInterceptor.Companion.DOWNLOAD_PROGRESS_INTERCEPTOR_HEADER import im.vector.matrix.android.internal.task.TaskExecutor import im.vector.matrix.android.internal.util.MatrixCoroutineDispatchers import im.vector.matrix.android.internal.util.toCancelable @@ -60,7 +61,7 @@ internal class DefaultFileService @Inject constructor( @SessionDownloadsDirectory private val sessionCacheDirectory: File, private val contentUrlResolver: ContentUrlResolver, - @WithProgress + @UnauthenticatedWithCertificateWithProgress private val okHttpClient: OkHttpClient, private val coroutineDispatchers: MatrixCoroutineDispatchers, private val taskExecutor: TaskExecutor @@ -122,7 +123,7 @@ internal class DefaultFileService @Inject constructor( val request = Request.Builder() .url(resolvedUrl) - .header("matrix-sdk:mxc_URL", url) + .header(DOWNLOAD_PROGRESS_INTERCEPTOR_HEADER, url) .build() val response = try { 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 f8931e9cf5..2172b4a05d 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 @@ -32,6 +32,7 @@ import im.vector.matrix.android.api.session.call.CallSignalingService import im.vector.matrix.android.api.session.content.ContentUploadStateTracker import im.vector.matrix.android.api.session.content.ContentUrlResolver import im.vector.matrix.android.api.session.crypto.CryptoService +import im.vector.matrix.android.api.session.file.ContentDownloadStateTracker import im.vector.matrix.android.api.session.file.FileService import im.vector.matrix.android.api.session.group.GroupService import im.vector.matrix.android.api.session.homeserver.HomeServerCapabilitiesService @@ -53,7 +54,6 @@ import im.vector.matrix.android.internal.auth.SessionParamsStore import im.vector.matrix.android.internal.crypto.DefaultCryptoService import im.vector.matrix.android.internal.di.SessionId import im.vector.matrix.android.internal.di.WorkManagerProvider -import im.vector.matrix.android.internal.session.download.ContentDownloadStateTracker import im.vector.matrix.android.internal.session.identity.DefaultIdentityService import im.vector.matrix.android.internal.session.room.timeline.TimelineEventDecryptor import im.vector.matrix.android.internal.session.sync.SyncTokenStore diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt index 1f974b0e2c..fb05bc68a2 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/SessionModule.kt @@ -49,9 +49,9 @@ import im.vector.matrix.android.internal.di.SessionFilesDirectory import im.vector.matrix.android.internal.di.SessionId import im.vector.matrix.android.internal.di.Unauthenticated import im.vector.matrix.android.internal.di.UnauthenticatedWithCertificate +import im.vector.matrix.android.internal.di.UnauthenticatedWithCertificateWithProgress import im.vector.matrix.android.internal.di.UserId import im.vector.matrix.android.internal.di.UserMd5 -import im.vector.matrix.android.internal.di.WithProgress import im.vector.matrix.android.internal.eventbus.EventBusTimberLogger import im.vector.matrix.android.internal.network.DefaultNetworkConnectivityChecker import im.vector.matrix.android.internal.network.FallbackNetworkCallbackStrategy @@ -222,7 +222,7 @@ internal abstract class SessionModule { @JvmStatic @Provides @SessionScope - @WithProgress + @UnauthenticatedWithCertificateWithProgress fun providesProgressOkHttpClient(@UnauthenticatedWithCertificate okHttpClient: OkHttpClient, downloadProgressInterceptor: DownloadProgressInterceptor): OkHttpClient { return okHttpClient.newBuilder() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/ContentModule.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/ContentModule.kt index eaddddb223..016a1252bc 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/ContentModule.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/content/ContentModule.kt @@ -20,7 +20,7 @@ import dagger.Binds import dagger.Module import im.vector.matrix.android.api.session.content.ContentUploadStateTracker import im.vector.matrix.android.api.session.content.ContentUrlResolver -import im.vector.matrix.android.internal.session.download.ContentDownloadStateTracker +import im.vector.matrix.android.api.session.file.ContentDownloadStateTracker import im.vector.matrix.android.internal.session.download.DefaultContentDownloadStateTracker @Module diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/download/DefaultContentDownloadStateTracker.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/download/DefaultContentDownloadStateTracker.kt index 9d322ccd84..bdae5b10ef 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/download/DefaultContentDownloadStateTracker.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/download/DefaultContentDownloadStateTracker.kt @@ -19,12 +19,13 @@ package im.vector.matrix.android.internal.session.download import android.os.Handler import android.os.Looper import im.vector.matrix.android.api.extensions.tryThis +import im.vector.matrix.android.api.session.file.ContentDownloadStateTracker import im.vector.matrix.android.internal.session.SessionScope import timber.log.Timber import javax.inject.Inject @SessionScope -class DefaultContentDownloadStateTracker @Inject constructor() : ProgressListener, ContentDownloadStateTracker { +internal class DefaultContentDownloadStateTracker @Inject constructor() : ProgressListener, ContentDownloadStateTracker { private val mainHandler = Handler(Looper.getMainLooper()) private val states = mutableMapOf() diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/download/DownloadProgressInterceptor.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/download/DownloadProgressInterceptor.kt index 9de8a06276..3fdc252cbc 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/download/DownloadProgressInterceptor.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/download/DownloadProgressInterceptor.kt @@ -20,16 +20,20 @@ import okhttp3.Interceptor import okhttp3.Response import javax.inject.Inject -class DownloadProgressInterceptor @Inject constructor( +internal class DownloadProgressInterceptor @Inject constructor( private val downloadStateTracker: DefaultContentDownloadStateTracker ) : Interceptor { + companion object { + const val DOWNLOAD_PROGRESS_INTERCEPTOR_HEADER = "matrix-sdk:mxc_URL" + } + override fun intercept(chain: Interceptor.Chain): Response { val url = chain.request().url.toUrl() - val mxcURl = chain.request().header("matrix-sdk:mxc_URL") + val mxcURl = chain.request().header(DOWNLOAD_PROGRESS_INTERCEPTOR_HEADER) val request = chain.request().newBuilder() - .removeHeader("matrix-sdk:mxc_URL") + .removeHeader(DOWNLOAD_PROGRESS_INTERCEPTOR_HEADER) .build() val originalResponse = chain.proceed(request) diff --git a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/ContentDownloadStateTrackerBinder.kt b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/ContentDownloadStateTrackerBinder.kt index 093ec8fb4b..5c63de3e8d 100644 --- a/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/ContentDownloadStateTrackerBinder.kt +++ b/vector/src/main/java/im/vector/riotx/features/home/room/detail/timeline/helper/ContentDownloadStateTrackerBinder.kt @@ -19,7 +19,7 @@ package im.vector.riotx.features.home.room.detail.timeline.helper import android.graphics.drawable.Drawable import androidx.vectordrawable.graphics.drawable.Animatable2Compat import androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat -import im.vector.matrix.android.internal.session.download.ContentDownloadStateTracker +import im.vector.matrix.android.api.session.file.ContentDownloadStateTracker import im.vector.riotx.R import im.vector.riotx.core.di.ActiveSessionHolder import im.vector.riotx.core.di.ScreenScope