From 4bb904f8cbe6c77e87fbacf07ad3c3435473da04 Mon Sep 17 00:00:00 2001 From: Isabel Martin Date: Tue, 16 Apr 2024 11:29:08 -0700 Subject: [PATCH] MBL-1318: - Removed Picasso dependency (#2018) Co-authored-by: leighdouglas --- app/build.gradle | 10 ++- .../kickstarter/libs/PushNotifications.java | 34 +++++---- .../transformations/CircleTransformation.java | 69 ------------------- .../CropSquareTransformation.java | 44 ------------ .../kickstarter/ui/extensions/ImageViewExt.kt | 8 +-- 5 files changed, 30 insertions(+), 135 deletions(-) delete mode 100644 app/src/main/java/com/kickstarter/libs/transformations/CircleTransformation.java delete mode 100644 app/src/main/java/com/kickstarter/libs/transformations/CropSquareTransformation.java diff --git a/app/build.gradle b/app/build.gradle index eed7db4fb4..3adf8ac617 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -255,13 +255,11 @@ dependencies { // Dependencies for HTML Parser implementation 'org.jsoup:jsoup:1.16.1' - // Picasso - implementation 'com.squareup.picasso:picasso:2.71828' - // GLIDE - implementation 'com.github.bumptech.glide:glide:4.14.2' - annotationProcessor 'com.github.bumptech.glide:compiler:4.14.2' - kapt 'com.github.bumptech.glide:compiler:4.14.2' + final glide_version = "4.16.0" + implementation "com.github.bumptech.glide:glide:$glide_version" + annotationProcessor "com.github.bumptech.glide:compiler:$glide_version" + kapt "com.github.bumptech.glide:compiler:$glide_version" //Compose Coil implementation("io.coil-kt:coil-compose:2.4.0") diff --git a/app/src/main/java/com/kickstarter/libs/PushNotifications.java b/app/src/main/java/com/kickstarter/libs/PushNotifications.java index d3fc68a609..b3a5eda6fa 100644 --- a/app/src/main/java/com/kickstarter/libs/PushNotifications.java +++ b/app/src/main/java/com/kickstarter/libs/PushNotifications.java @@ -18,10 +18,12 @@ import androidx.core.app.TaskStackBuilder; import androidx.core.content.ContextCompat; +import com.bumptech.glide.Glide; +import com.bumptech.glide.load.MultiTransformation; +import com.bumptech.glide.request.FutureTarget; +import com.bumptech.glide.request.RequestOptions; import com.kickstarter.R; import com.kickstarter.libs.qualifiers.ApplicationContext; -import com.kickstarter.libs.transformations.CircleTransformation; -import com.kickstarter.libs.transformations.CropSquareTransformation; import com.kickstarter.libs.utils.extensions.AnyExtKt; import com.kickstarter.libs.utils.extensions.IntentExtKt; import com.kickstarter.models.MessageThread; @@ -38,18 +40,17 @@ import com.kickstarter.ui.activities.ProjectPageActivity; import com.kickstarter.ui.activities.SurveyResponseActivity; import com.kickstarter.ui.activities.UpdateActivity; -import com.squareup.picasso.Picasso; -import com.squareup.picasso.RequestCreator; +import com.bumptech.glide.load.resource.bitmap.CenterCrop; +import com.bumptech.glide.load.resource.bitmap.RoundedCorners; -import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ExecutionException; import rx.Observable; import rx.schedulers.Schedulers; import rx.subjects.PublishSubject; import rx.subscriptions.CompositeSubscription; -import timber.log.Timber; import static com.kickstarter.libs.rx.transformers.Transformers.combineLatestPair; import static com.kickstarter.libs.rx.transformers.Transformers.neverError; @@ -415,14 +416,23 @@ private void displayNotificationFromUpdateActivity(final @NonNull PushNotificati } try { - RequestCreator requestCreator = Picasso.get().load(url).transform(new CropSquareTransformation()); if (transformIntoCircle) { - requestCreator = requestCreator.transform(new CircleTransformation()); + final FutureTarget circleCrop = Glide.with(this.context) + .asBitmap() + .load(url) + .apply(RequestOptions.circleCropTransform()) + .submit(); + return circleCrop.get(); + } else { + final FutureTarget SquareRoundCorners = Glide.with(this.context) + .asBitmap() + .load(url) + .transform(new MultiTransformation<>(new CenterCrop(), new RoundedCorners(10))) + .submit(); + return SquareRoundCorners.get(); } - return requestCreator.get(); - } catch (IOException e) { - Timber.e(e.getMessage(), "Failed to load large icon: %s"); - return null; + } catch (ExecutionException | InterruptedException e) { + throw new RuntimeException(e); } } diff --git a/app/src/main/java/com/kickstarter/libs/transformations/CircleTransformation.java b/app/src/main/java/com/kickstarter/libs/transformations/CircleTransformation.java deleted file mode 100644 index d2dec8db15..0000000000 --- a/app/src/main/java/com/kickstarter/libs/transformations/CircleTransformation.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.kickstarter.libs.transformations; - -/* - * Copyright 2014 Julian Shen - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * *** - * - * Original: https://gist.github.com/julianshen/5829333 - * Modifications: Some modifiers and annotations have been added by Kickstarter. - */ - -import android.graphics.Bitmap; -import android.graphics.BitmapShader; -import android.graphics.Canvas; -import android.graphics.Paint; - -import com.squareup.picasso.Transformation; - -import androidx.annotation.NonNull; - -public class CircleTransformation implements Transformation { - private int x; - private int y; - - @Override - public Bitmap transform(final @NonNull Bitmap source) { - final int size = Math.min(source.getWidth(), source.getHeight()); - - this.x = (source.getWidth() - size) / 2; - this.y = (source.getHeight() - size) / 2; - - final Bitmap squaredBitmap = Bitmap.createBitmap(source, this.x, this.y, size, size); - if (squaredBitmap != source) { - source.recycle(); - } - - final Bitmap.Config config = source.getConfig() != null ? source.getConfig() : Bitmap.Config.ARGB_8888; - final Bitmap bitmap = Bitmap.createBitmap(size, size, config); - - final Canvas canvas = new Canvas(bitmap); - final Paint paint = new Paint(); - final BitmapShader shader = new BitmapShader(squaredBitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP); - paint.setShader(shader); - paint.setAntiAlias(true); - - final float r = size/2f; - canvas.drawCircle(r, r, r, paint); - - squaredBitmap.recycle(); - return bitmap; - } - - @Override - public String key() { - return "circle(x=" + this.x + ",y=" + this.y + ")"; - } -} diff --git a/app/src/main/java/com/kickstarter/libs/transformations/CropSquareTransformation.java b/app/src/main/java/com/kickstarter/libs/transformations/CropSquareTransformation.java deleted file mode 100644 index c3f9a6e76c..0000000000 --- a/app/src/main/java/com/kickstarter/libs/transformations/CropSquareTransformation.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Copyright 2013 Square, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * *** - * - * Original: https://github.com/square/picasso/blob/000a72859ca82f28975d0ef5099b01ec110e73ea/website/index.html#L78-L91 - * Modifications: Some modifiers and annotations have been added by Kickstarter. - */ -package com.kickstarter.libs.transformations; - -import android.graphics.Bitmap; - -import com.squareup.picasso.Transformation; - -import androidx.annotation.NonNull; - -public class CropSquareTransformation implements Transformation { - @Override public @NonNull Bitmap transform(final @NonNull Bitmap source) { - final int size = Math.min(source.getWidth(), source.getHeight()); - final int x = (source.getWidth() - size) / 2; - final int y = (source.getHeight() - size) / 2; - final Bitmap result = Bitmap.createBitmap(source, x, y, size, size); - if (result != source) { - source.recycle(); - } - return result; - } - - @Override public String key() { - return "square()"; - } -} diff --git a/app/src/main/java/com/kickstarter/ui/extensions/ImageViewExt.kt b/app/src/main/java/com/kickstarter/ui/extensions/ImageViewExt.kt index be33ea9203..f230090273 100644 --- a/app/src/main/java/com/kickstarter/ui/extensions/ImageViewExt.kt +++ b/app/src/main/java/com/kickstarter/ui/extensions/ImageViewExt.kt @@ -89,10 +89,10 @@ fun ImageView.loadImage(url: String?, context: Context, imageViewPlaceholder: Ap .load(url) .listener(object : RequestListener { override fun onResourceReady( - resource: Drawable?, - model: Any?, + resource: Drawable, + model: Any, target: Target?, - dataSource: com.bumptech.glide.load.DataSource?, + dataSource: com.bumptech.glide.load.DataSource, isFirstResource: Boolean ): Boolean { imageViewPlaceholder?.setImageDrawable(resource) @@ -102,7 +102,7 @@ fun ImageView.loadImage(url: String?, context: Context, imageViewPlaceholder: Ap override fun onLoadFailed( e: GlideException?, model: Any?, - target: Target?, + target: Target, isFirstResource: Boolean ): Boolean { targetView.setImageDrawable(null)