Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ object ThumbnailsRequester : KoinComponent {

private val thumbnailImageLoaders = ConcurrentHashMap<String, ImageLoader>()
private val avatarImageLoaders = ConcurrentHashMap<String, ImageLoader>()
private val accountBaseUrls = ConcurrentHashMap<String, String>()

private val sharedDiskCache: DiskCache by lazy {
DiskCache.Builder()
Expand All @@ -86,11 +87,12 @@ object ThumbnailsRequester : KoinComponent {
}

fun getAvatarUri(account: Account): String {
val accountManager = AccountManager.get(appContext)
val baseUrl =
val baseUrl = accountBaseUrls.getOrPut(account.name) {
val accountManager = AccountManager.get(appContext)
accountManager.getUserData(account, eu.opencloud.android.lib.common.accounts.AccountUtils.Constants.KEY_OC_BASE_URL)
?.trimEnd('/')
.orEmpty()
}
// ?u= disambiguates the Coil cache key per account; without it two accounts
// on the same server share the same URL and collide in the shared disk/memory cache.
return "$baseUrl/graph/v1.0/me/photo/\$value?u=${account.name.hashCode().toString(16)}"
Expand All @@ -106,10 +108,12 @@ object ThumbnailsRequester : KoinComponent {
String.format(Locale.US, SPACE_SPECIAL_PREVIEW_URI, spaceSpecial.webDavUrl, 1024, 1024, spaceSpecial.eTag)

private fun getPreviewUri(remotePath: String?, etag: String?, account: Account, width: Int, height: Int): String {
val accountManager = AccountManager.get(appContext)
val baseUrl = accountManager.getUserData(account, eu.opencloud.android.lib.common.accounts.AccountUtils.Constants.KEY_OC_BASE_URL)
?.trimEnd('/')
.orEmpty()
val baseUrl = accountBaseUrls.getOrPut(account.name) {
val accountManager = AccountManager.get(appContext)
accountManager.getUserData(account, eu.opencloud.android.lib.common.accounts.AccountUtils.Constants.KEY_OC_BASE_URL)
?.trimEnd('/')
.orEmpty()
}
val path = if (remotePath?.startsWith("/") == true) remotePath else "/$remotePath"
val encodedPath = Uri.encode(path, "/")

Expand Down Expand Up @@ -156,7 +160,9 @@ object ThumbnailsRequester : KoinComponent {
// must not run on the main thread.
clientManager.getClientForCoilThumbnails(account.name)
.okHttpClient.newBuilder()
.addInterceptor(interceptor).build()
.addInterceptor(interceptor)
.addNetworkInterceptor(CoilCacheResponseInterceptor())
.build()
}
.apply { if (preferencesProvider.getBoolean("enable_logging", false)) logger(DebugLogger()) }
.memoryCache { sharedMemoryCache }
Expand All @@ -172,6 +178,7 @@ object ThumbnailsRequester : KoinComponent {
clientManager.getClientForCoilThumbnails(account.name)
.okHttpClient.newBuilder()
.addInterceptor(interceptor)
.addNetworkInterceptor(CoilCacheResponseInterceptor())
.cache(avatarHttpCache)
.build()
}
Expand Down Expand Up @@ -221,7 +228,13 @@ object ThumbnailsRequester : KoinComponent {
requestHeaders.toHeaders().forEach { requestBuilder.addHeader(it.first, it.second) }
val requestWithHeaders = requestBuilder.build()

var response = chain.proceed(requestWithHeaders)
return chain.proceed(requestWithHeaders)
}
}

private class CoilCacheResponseInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val response = chain.proceed(chain.request())

var builder = response.newBuilder()
var changed = false
Expand Down Expand Up @@ -252,6 +265,5 @@ object ThumbnailsRequester : KoinComponent {
}
return response
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ class OCRemoteFileDataSource(
OCFile(
owner = owner,
remoteId = remoteId,
remotePath = remotePath,
remotePath = if (isFolder && !remotePath.endsWith(OCFile.PATH_SEPARATOR)) {
"$remotePath${OCFile.PATH_SEPARATOR}"
} else {
remotePath
},
length = if (isFolder) {
size
} else {
Expand Down
Loading