diff --git a/app/build.gradle b/app/build.gradle index 591eb6ea5a..0e6f27f11a 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -126,15 +126,10 @@ dependencies { implementation 'com.wdullaer:materialdatetimepicker:4.2.3' implementation 'com.github.rubensousa:gravitysnaphelper:2.2.2' - def coil_version = '1.4.0' + def coil_version = '2.0.0-rc01' implementation "io.coil-kt:coil:$coil_version" implementation "io.coil-kt:coil-gif:$coil_version" - def glide_version = '4.12.0' - implementation("com.github.bumptech.glide:glide:$glide_version") { exclude group: 'com.android.support' } - implementation "com.github.bumptech.glide:okhttp3-integration:$glide_version" - kapt "com.github.bumptech.glide:compiler:$glide_version" - implementation 'io.realm:android-adapters:4.0.0' standardImplementation 'com.google.android.play:core:1.10.3' diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index e8f66c5cc5..481bb43481 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -18,8 +18,4 @@ # If you keep the line number information, uncomment this to # hide the original source file name. -#-renamesourcefileattribute SourceFile - -## Glider --keep public class * extends com.bumptech.glide.module.AppGlideModule --keep class com.bumptech.glide.GeneratedAppGlideModuleImpl \ No newline at end of file +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/main/java/com/infomaniak/drive/ApplicationMain.kt b/app/src/main/java/com/infomaniak/drive/ApplicationMain.kt index 02f4562962..1b9c391b03 100644 --- a/app/src/main/java/com/infomaniak/drive/ApplicationMain.kt +++ b/app/src/main/java/com/infomaniak/drive/ApplicationMain.kt @@ -27,9 +27,11 @@ import androidx.appcompat.app.AppCompatDelegate import androidx.core.app.NotificationManagerCompat import coil.ImageLoader import coil.ImageLoaderFactory +import coil.annotation.ExperimentalCoilApi import coil.decode.GifDecoder import coil.decode.ImageDecoderDecoder -import coil.util.CoilUtils +import coil.disk.DiskCache +import coil.memory.MemoryCache import com.facebook.stetho.Stetho import com.facebook.stetho.okhttp3.StethoInterceptor import com.infomaniak.drive.BuildConfig.DRIVE_API @@ -66,6 +68,7 @@ import okhttp3.OkHttpClient import org.matomo.sdk.Tracker import java.util.* +@ExperimentalCoilApi class ApplicationMain : Application(), ImageLoaderFactory { val matomoTracker: Tracker by lazy { buildTracker() } @@ -122,8 +125,8 @@ class ApplicationMain : Application(), ImageLoaderFactory { override fun newImageLoader(): ImageLoader { return ImageLoader.Builder(applicationContext) .crossfade(true) - .componentRegistry { - add(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) ImageDecoderDecoder(applicationContext) else GifDecoder()) + .components { + add(if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) ImageDecoderDecoder.Factory() else GifDecoder.Factory()) } .okHttpClient { OkHttpClient.Builder().apply { @@ -139,9 +142,14 @@ class ApplicationMain : Application(), ImageLoaderFactory { if (com.infomaniak.lib.core.BuildConfig.DEBUG) { addNetworkInterceptor(StethoInterceptor()) } - cache(CoilUtils.createDefaultCache(applicationContext)) }.build() } + .memoryCache { + MemoryCache.Builder(applicationContext).build() + } + .diskCache { + DiskCache.Builder().directory(applicationContext.cacheDir.resolve(COIL_CACHE_DIR)).build() + } .build() } @@ -172,4 +180,8 @@ class ApplicationMain : Application(), ImageLoaderFactory { return AccountUtils.currentUser!!.apiToken } } + + private companion object { + const val COIL_CACHE_DIR = "coil_cache" + } } diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileActivitiesAdapter.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileActivitiesAdapter.kt index d64da27975..e7a50af21c 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileActivitiesAdapter.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileActivitiesAdapter.kt @@ -23,10 +23,10 @@ import android.view.ViewGroup import androidx.core.view.isGone import androidx.core.view.isInvisible import androidx.core.view.isVisible +import coil.load import com.infomaniak.drive.R import com.infomaniak.drive.data.models.FileActivity import com.infomaniak.drive.utils.loadAvatar -import com.infomaniak.drive.utils.loadGlide import com.infomaniak.lib.core.views.LoaderAdapter import com.infomaniak.lib.core.views.ViewHolder import kotlinx.android.synthetic.main.item_file_activity.view.* @@ -58,7 +58,7 @@ class FileActivitiesAdapter(val isFolder: Boolean) : LoaderAdapter activityUserAvatar.loadAvatar(driveUser) } ?: run { activityUserName.setText(R.string.allUserAnonymous) - activityUserAvatar.loadGlide(R.drawable.ic_account) + activityUserAvatar.load(R.drawable.ic_account) } if (position == 0 || !isSameDay(currentFileActivity.createdAt, itemList[position - 1].createdAt)) { diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsFragment.kt index ee0b62f492..b446277daf 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileDetails/FileDetailsFragment.kt @@ -127,7 +127,7 @@ class FileDetailsFragment : FileDetailsSubFragment() { private fun setBannerThumbnail(file: File) { if (file.hasThumbnail) { - collapsingBackground.loadGlideUrl(file.thumbnail()) + collapsingBackground.loadAny(file.thumbnail()) } else { appBar.setBackgroundColor(ContextCompat.getColor(requireContext(), R.color.background)) val params = subtitleToolbar.layoutParams as CoordinatorLayout.LayoutParams diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/AvailableShareableItemsAdapter.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/AvailableShareableItemsAdapter.kt index d92ae3eaca..c49e8c9284 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/AvailableShareableItemsAdapter.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/AvailableShareableItemsAdapter.kt @@ -25,6 +25,7 @@ import android.widget.ArrayAdapter import android.widget.Filter import android.widget.Filterable import androidx.core.view.isGone +import coil.load import com.infomaniak.drive.R import com.infomaniak.drive.data.models.DriveUser import com.infomaniak.drive.data.models.Invitation @@ -33,7 +34,6 @@ import com.infomaniak.drive.data.models.Team import com.infomaniak.drive.utils.AccountUtils import com.infomaniak.drive.utils.isEmail import com.infomaniak.drive.utils.loadAvatar -import com.infomaniak.drive.utils.loadGlide import kotlinx.android.synthetic.main.item_user.view.* /** @@ -104,14 +104,14 @@ class AvailableShareableItemsAdapter( chevron.isGone = true } is Invitation -> { - userAvatar.loadGlide(R.drawable.ic_account) + userAvatar.load(R.drawable.ic_account) userName.text = item.email userEmail.text = context.getString(R.string.userInviteByEmail) chevron.isGone = true } is Team -> { val teamUsersCount = item.usersCount(AccountUtils.getCurrentDrive()!!) - userAvatar.loadGlide(R.drawable.ic_circle_team) + userAvatar.load(R.drawable.ic_circle_team) userAvatar.setBackgroundColor(item.getParsedColor()) userName.text = item.name userEmail.text = diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/PermissionsAdapter.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/PermissionsAdapter.kt index e04eb01638..d2e3b62845 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/PermissionsAdapter.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/PermissionsAdapter.kt @@ -23,6 +23,7 @@ import android.view.ViewGroup import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView +import coil.load import com.google.android.material.card.MaterialCardView import com.google.android.material.shape.RelativeCornerSize import com.google.android.material.shape.ShapeAppearanceModel @@ -33,7 +34,6 @@ import com.infomaniak.drive.data.models.Permission import com.infomaniak.drive.data.models.Shareable.ShareablePermission import com.infomaniak.drive.utils.AccountUtils import com.infomaniak.drive.utils.loadAvatar -import com.infomaniak.drive.utils.loadGlide import com.infomaniak.lib.core.models.User import com.infomaniak.lib.core.utils.toPx import com.infomaniak.lib.core.views.ViewHolder @@ -134,7 +134,7 @@ class PermissionsAdapter( } private fun View.setupOthersPermissionUi(permission: Permission) { - mainIcon.loadGlide(permission.icon) + mainIcon.load(permission.icon) mainIcon.shapeAppearanceModel = ShapeAppearanceModel() when { diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/SharedItemsAdapter.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/SharedItemsAdapter.kt index 1ddd74ef68..4a3eedfc8a 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/SharedItemsAdapter.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/fileShare/SharedItemsAdapter.kt @@ -25,10 +25,11 @@ import androidx.core.view.isGone import androidx.core.view.isInvisible import androidx.core.view.isVisible import androidx.recyclerview.widget.RecyclerView +import coil.load import com.infomaniak.drive.R import com.infomaniak.drive.data.models.* +import com.infomaniak.drive.utils.loadAny import com.infomaniak.drive.utils.loadAvatar -import com.infomaniak.drive.utils.loadGlide import com.infomaniak.lib.core.views.ViewHolder import kotlinx.android.synthetic.main.item_shareable_item.view.* @@ -92,9 +93,7 @@ class SharedItemsAdapter( infos.isVisible = true } - avatar.apply { - loadGlide(null, errorRes = R.drawable.ic_circle_send) - } + avatar.loadAny(null, errorRes = R.drawable.ic_circle_send) rightsValue.setText(invitation.getFilePermission().translation) externalUserLabel.apply { @@ -110,10 +109,10 @@ class SharedItemsAdapter( private fun View.bindTeam(team: Team) { if (team.isAllUsers()) { name.setText(R.string.allAllDriveUsers) - avatar.loadGlide(R.drawable.ic_circle_drive) + avatar.load(R.drawable.ic_circle_drive) } else { name.text = team.name - avatar.loadGlide(R.drawable.ic_circle_team) + avatar.load(R.drawable.ic_circle_team) } avatar.setBackgroundColor(team.getParsedColor()) diff --git a/app/src/main/java/com/infomaniak/drive/ui/fileList/preview/PreviewPictureFragment.kt b/app/src/main/java/com/infomaniak/drive/ui/fileList/preview/PreviewPictureFragment.kt index c44132fd07..94bc9bf9b4 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/fileList/preview/PreviewPictureFragment.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/fileList/preview/PreviewPictureFragment.kt @@ -79,10 +79,10 @@ class PreviewPictureFragment : PreviewFragment() { private fun buildPreviewRequest(): ImageRequest { val timer = createRefreshTimer(milliseconds = 400) { noThumbnailLayout?.isVisible = true }.start() - val offlineFile = if (file.isOffline) getOfflineFile() else null +// val offlineFile = if (file.isOffline) getOfflineFile() else null // TODO issue https://github.com/coil-kt/coil/issues/1201 return ImageRequest.Builder(requireContext()) - .data(offlineFile ?: file.imagePreview()) + .data(file.imagePreview()) // load only remote file because load a large image from local issue https://github.com/coil-kt/coil/issues/1201 .listener( onError = { _, _ -> fileName?.text = file.name @@ -98,6 +98,9 @@ class PreviewPictureFragment : PreviewFragment() { .build() } + /** + * TODO waiting for issue https://github.com/coil-kt/coil/issues/1201 + */ private fun getOfflineFile(): File? { return file.getOfflineFile(requireContext(), previewSliderViewModel.userDrive.userId)?.let { if (file.isOfflineAndIntact(it)) it else null diff --git a/app/src/main/java/com/infomaniak/drive/ui/home/LastActivitiesAdapter.kt b/app/src/main/java/com/infomaniak/drive/ui/home/LastActivitiesAdapter.kt index 2242159630..5845fc179e 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/home/LastActivitiesAdapter.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/home/LastActivitiesAdapter.kt @@ -25,14 +25,14 @@ import android.widget.ImageView import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.view.isGone import androidx.core.view.isVisible +import coil.load import com.infomaniak.drive.R import com.infomaniak.drive.data.models.ConvertedType import com.infomaniak.drive.data.models.DriveUser import com.infomaniak.drive.data.models.File import com.infomaniak.drive.data.models.FileActivity +import com.infomaniak.drive.utils.loadAny import com.infomaniak.drive.utils.loadAvatar -import com.infomaniak.drive.utils.loadGlide -import com.infomaniak.drive.utils.loadGlideUrl import com.infomaniak.lib.core.views.LoaderAdapter import com.infomaniak.lib.core.views.LoaderCardView import com.infomaniak.lib.core.views.ViewHolder @@ -76,7 +76,7 @@ class LastActivitiesAdapter : LoaderAdapter() { 2 * DAY_IN_MILLIS, FORMAT_ABBREV_ALL ) - fileIcon.loadGlide(getFileTypeIcon(fileActivity.file)) + fileIcon.load(getFileTypeIcon(fileActivity.file)) fileName1.text = fileActivityName if (sizeMergedFile >= 1) { @@ -87,7 +87,7 @@ class LastActivitiesAdapter : LoaderAdapter() { fileActivity.file.loadPreview(filePreview1, filePreviewIcon1 as ConstraintLayout) val file2 = fileActivity.mergedFileActivities[0].file file2.loadPreview(filePreview2, filePreviewIcon2 as ConstraintLayout) - fileIcon2.loadGlide(getFileTypeIcon(file2)) + fileIcon2.load(getFileTypeIcon(file2)) fileName2.text = file2?.name ?: fileActivity.mergedFileActivities[0].path.substringAfterLast("/") if (sizeMergedFile == 1) { @@ -107,12 +107,12 @@ class LastActivitiesAdapter : LoaderAdapter() { (cardFilePreview2.layoutParams as ConstraintLayout.LayoutParams).dimensionRatio = "1:1" if (sizeMergedFile > 2) { - fileIcon3.loadGlide(R.drawable.ic_copy) + fileIcon3.load(R.drawable.ic_copy) fileName3.text = fileName3.context.getString(R.string.fileActivityOtherFiles, sizeMergedFile - 1) moreFile.text = "+${sizeMergedFile - 1}" moreFile.isVisible = true } else { - fileIcon3.loadGlide(getFileTypeIcon(file3)) + fileIcon3.load(getFileTypeIcon(file3)) fileName3.text = file3?.name ?: fileActivity.mergedFileActivities[1].path.substringAfterLast("/") moreFile.isGone = true } @@ -169,11 +169,11 @@ class LastActivitiesAdapter : LoaderAdapter() { if (this?.hasThumbnail == true && getFileType() == ConvertedType.IMAGE || this?.getFileType() == ConvertedType.VIDEO) { iconView.isGone = true imageView.isVisible = true - imageView.loadGlideUrl(thumbnail(), getFileType().icon) + imageView.loadAny(thumbnail(), getFileType().icon) } else { imageView.isGone = true iconView.isVisible = true - iconView.icon.loadGlide(getFileTypeIcon(this)) + iconView.icon.load(getFileTypeIcon(this)) } } diff --git a/app/src/main/java/com/infomaniak/drive/ui/menu/PicturesAdapter.kt b/app/src/main/java/com/infomaniak/drive/ui/menu/PicturesAdapter.kt index 16bb3f5a12..2b08aa3872 100644 --- a/app/src/main/java/com/infomaniak/drive/ui/menu/PicturesAdapter.kt +++ b/app/src/main/java/com/infomaniak/drive/ui/menu/PicturesAdapter.kt @@ -26,7 +26,7 @@ import com.google.android.material.checkbox.MaterialCheckBox import com.infomaniak.drive.R import com.infomaniak.drive.data.models.File import com.infomaniak.drive.ui.fileList.multiSelect.MultiSelectManager -import com.infomaniak.drive.utils.loadGlideUrl +import com.infomaniak.drive.utils.loadAny import com.infomaniak.lib.core.utils.format import com.infomaniak.lib.core.views.LoaderAdapter import com.infomaniak.lib.core.views.LoaderCardView @@ -78,7 +78,7 @@ class PicturesAdapter( private fun LoaderCardView.displayThumbnail(file: File) { stop() picture.apply { - loadGlideUrl(file.thumbnail()) + loadAny(file.thumbnail()) contentDescription = file.name } } diff --git a/app/src/main/java/com/infomaniak/drive/utils/Extensions.kt b/app/src/main/java/com/infomaniak/drive/utils/Extensions.kt index 932743d1d4..0712964bdf 100644 --- a/app/src/main/java/com/infomaniak/drive/utils/Extensions.kt +++ b/app/src/main/java/com/infomaniak/drive/utils/Extensions.kt @@ -28,10 +28,8 @@ import android.content.Intent import android.content.res.Configuration import android.content.res.Resources import android.database.Cursor -import android.graphics.Bitmap import android.graphics.Color import android.graphics.Point -import android.graphics.drawable.Drawable import android.net.Uri import android.os.Build import android.os.Bundle @@ -70,7 +68,6 @@ import androidx.navigation.fragment.findNavController import coil.ImageLoader import coil.load import coil.request.Disposable -import com.bumptech.glide.Glide import com.google.android.material.card.MaterialCardView import com.google.android.material.shape.CornerFamily import com.google.android.material.textfield.MaterialAutoCompleteTextView @@ -118,36 +115,12 @@ fun Context.isKeyguardSecure(): Boolean { return (getSystemService(Context.KEYGUARD_SERVICE) as? KeyguardManager)?.isKeyguardSecure ?: false } -fun ImageView.loadGlide(@DrawableRes drawable: Int) { - Glide.with(this).load(drawable).into(this) -} - -fun ImageView.loadGlide(drawable: Drawable?) { - Glide.with(this).load(drawable).into(this) -} - -fun ImageView.loadGlide(bitmap: Bitmap?, @DrawableRes errorRes: Int) { - Glide.with(this) - .load(bitmap) - .transition(Utils.CROSS_FADE_TRANSITION) - .placeholder(R.drawable.placeholder) - .error(errorRes) - .centerCrop() - .into(this) -} - -fun ImageView.loadGlideUrl( - url: String?, - @DrawableRes errorRes: Int = R.drawable.fallback_image, - errorDrawable: Drawable? = null, -) { - Glide.with(this) - .load(OkHttpLibraryGlideModule.GlideAuthUrl(url)) - .transition(Utils.CROSS_FADE_TRANSITION) - .placeholder(R.drawable.placeholder) - .let { if (errorDrawable == null) it.error(errorRes) else it.error(errorDrawable) } - .centerCrop() - .into(this) +fun ImageView.loadAny(data: Any?, @DrawableRes errorRes: Int = R.drawable.fallback_image): Disposable { + return load(data) { + error(errorRes) + fallback(errorRes) + placeholder(R.drawable.placeholder) + } } fun ImageView.loadAvatar(driveUser: DriveUser): Disposable { diff --git a/app/src/main/java/com/infomaniak/drive/utils/FileItemUtils.kt b/app/src/main/java/com/infomaniak/drive/utils/FileItemUtils.kt index f80263a4f4..d2e99b3637 100644 --- a/app/src/main/java/com/infomaniak/drive/utils/FileItemUtils.kt +++ b/app/src/main/java/com/infomaniak/drive/utils/FileItemUtils.kt @@ -38,6 +38,7 @@ import androidx.core.net.toUri import androidx.core.view.forEachIndexed import androidx.core.view.isGone import androidx.core.view.isVisible +import coil.load import com.infomaniak.drive.R import com.infomaniak.drive.data.cache.DriveInfosController import com.infomaniak.drive.data.models.ConvertedType @@ -104,11 +105,11 @@ private fun View.displayIcon(file: File, isGrid: Boolean, viewHolder: FileViewHo private fun View.displayFolderIcon(file: File, viewHolder: FileViewHolder?) { val (icon, tint) = file.getFolderIcon() - if (tint == null) filePreview.loadGlide(icon) else filePreview.loadGlide(context.getTintedDrawable(viewHolder, icon, tint)) + if (tint == null) filePreview.load(icon) else filePreview.load(context.getTintedDrawable(viewHolder, icon, tint)) } private fun View.displayDriveIcon(file: File, viewHolder: FileViewHolder?) { - filePreview.loadGlide(context.getTintedDrawable(viewHolder, R.drawable.ic_drive, file.driveColor)) + filePreview.load(context.getTintedDrawable(viewHolder, R.drawable.ic_drive, file.driveColor)) } private fun View.displayFileIcon(file: File, isGrid: Boolean) { @@ -116,19 +117,19 @@ private fun View.displayFileIcon(file: File, isGrid: Boolean) { val isGraphic = fileType == ConvertedType.IMAGE || fileType == ConvertedType.VIDEO when { - file.hasThumbnail && (isGrid || isGraphic) -> filePreview.loadGlideUrl(file.thumbnail(), fileType.icon) + file.hasThumbnail && (isGrid || isGraphic) -> filePreview.loadAny(file.thumbnail(), fileType.icon) file.isFromUploads && isGraphic -> { CoroutineScope(Dispatchers.IO).launch { val bitmap = context.getLocalThumbnail(file) withContext(Dispatchers.Main) { - if (filePreview?.isVisible == true && context != null) filePreview.loadGlide(bitmap, fileType.icon) + if (filePreview?.isVisible == true && context != null) filePreview.loadAny(bitmap, fileType.icon) } } } - else -> filePreview.loadGlide(fileType.icon) + else -> filePreview.load(fileType.icon) } - filePreview2?.loadGlide(fileType.icon) + filePreview2?.load(fileType.icon) setupFileProgress(file) } diff --git a/app/src/main/java/com/infomaniak/drive/utils/OkHttpLibraryGlideModule.kt b/app/src/main/java/com/infomaniak/drive/utils/OkHttpLibraryGlideModule.kt deleted file mode 100644 index 2a037be472..0000000000 --- a/app/src/main/java/com/infomaniak/drive/utils/OkHttpLibraryGlideModule.kt +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Infomaniak kDrive - Android - * Copyright (C) 2022 Infomaniak Network SA - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.infomaniak.drive.utils - -import android.content.Context -import com.bumptech.glide.Glide -import com.bumptech.glide.Registry -import com.bumptech.glide.annotation.GlideModule -import com.bumptech.glide.integration.okhttp3.OkHttpStreamFetcher -import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader -import com.bumptech.glide.load.Options -import com.bumptech.glide.load.model.* -import com.bumptech.glide.module.AppGlideModule -import com.infomaniak.lib.core.networking.HttpClient -import com.infomaniak.lib.core.networking.HttpUtils -import okhttp3.Call -import java.io.InputStream - -@GlideModule -class OkHttpLibraryGlideModule : AppGlideModule() { - - override fun registerComponents(context: Context, glide: Glide, registry: Registry) { - val factory = OkHttpUrlLoader.Factory(HttpClient.okHttpClient) - registry.replace(GlideUrl::class.java, InputStream::class.java, factory) - } - - //TODO Only auth url - private class GlideAuthLoader(private val client: Call.Factory) : ModelLoader { - - override fun buildLoadData( - model: GlideAuthUrl, - width: Int, - height: Int, - options: Options - ): ModelLoader.LoadData { - return ModelLoader.LoadData(model, OkHttpStreamFetcher(client, model)) - } - - override fun handles(model: GlideAuthUrl) = true - - //TODO - class Factory(private val client: Call.Factory) : ModelLoaderFactory { - - override fun build(multiFactory: MultiModelLoaderFactory): ModelLoader { - return GlideAuthLoader(client) - } - - override fun teardown() = Unit - - } - } - - //TODO Temp GlideUrl: you should have a custom glideUrl just for the links with authentication - class GlideAuthUrl(url: String?) : GlideUrl( - url, - LazyHeaders.Builder() - .apply { HttpUtils.getHeaders().toMap().filter { it.key != "Cache-Control" } } - .build() - ) -} diff --git a/app/src/main/java/com/infomaniak/drive/utils/Utils.kt b/app/src/main/java/com/infomaniak/drive/utils/Utils.kt index 3c47567ce1..a454e0f6ce 100644 --- a/app/src/main/java/com/infomaniak/drive/utils/Utils.kt +++ b/app/src/main/java/com/infomaniak/drive/utils/Utils.kt @@ -39,8 +39,6 @@ import androidx.core.widget.doOnTextChanged import androidx.navigation.NavController import androidx.navigation.NavOptions import androidx.work.* -import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade -import com.bumptech.glide.request.transition.DrawableCrossFadeFactory import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.snackbar.Snackbar import com.infomaniak.drive.R @@ -68,8 +66,6 @@ object Utils { const val INDETERMINATE_PROGRESS = -1 - val CROSS_FADE_TRANSITION = withCrossFade(DrawableCrossFadeFactory.Builder().setCrossFadeEnabled(true).build()) - fun createConfirmation( context: Context, title: String,