Skip to content

Commit e6302cc

Browse files
Clean up Picasso leftovers
1 parent 844b4ed commit e6302cc

74 files changed

Lines changed: 108 additions & 386 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,6 @@ dependencies {
267267
implementation "com.github.lisawray.groupie:groupie-viewbinding:${groupieVersion}"
268268

269269
// Image loading
270-
//noinspection GradleDependency --> 2.8 is the last version, not 2.71828!
271-
implementation "com.squareup.picasso:picasso:2.8"
272270
implementation 'io.coil-kt:coil:2.6.0'
273271

274272
// Markdown library for Android

app/src/main/java/org/schabi/newpipe/App.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
import org.schabi.newpipe.util.ServiceHelper;
2424
import org.schabi.newpipe.util.StateSaver;
2525
import org.schabi.newpipe.util.image.ImageStrategy;
26-
import org.schabi.newpipe.util.image.PicassoHelper;
2726
import org.schabi.newpipe.util.image.PreferredImageQuality;
2827

28+
import java.io.File;
2929
import java.io.IOException;
3030
import java.io.InterruptedIOException;
3131
import java.net.SocketException;
@@ -113,12 +113,9 @@ public void onCreate() {
113113

114114
// Initialize image loader
115115
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
116-
PicassoHelper.init(this);
117116
ImageStrategy.setPreferredImageQuality(PreferredImageQuality.fromPreferenceKey(this,
118117
prefs.getString(getString(R.string.image_quality_key),
119118
getString(R.string.image_quality_default))));
120-
PicassoHelper.setIndicatorsEnabled(MainActivity.DEBUG
121-
&& prefs.getBoolean(getString(R.string.show_image_indicators_key), false));
122119

123120
configureRxJavaErrorHandler();
124121
}
@@ -131,13 +128,12 @@ public ImageLoader newImageLoader() {
131128
.maxSizeBytes(10 * 1024 * 1024)
132129
.build())
133130
.diskCache(() -> new DiskCache.Builder()
131+
.directory(new File(getExternalCacheDir(), "coil"))
134132
.maxSizeBytes(50 * 1024 * 1024)
135133
.build())
136134
.allowRgb565(true);
137135

138-
final var prefs = PreferenceManager.getDefaultSharedPreferences(this);
139-
if (MainActivity.DEBUG
140-
&& prefs.getBoolean(getString(R.string.show_image_indicators_key), false)) {
136+
if (MainActivity.DEBUG) {
141137
builder.logger(new DebugLogger());
142138
}
143139

app/src/main/java/org/schabi/newpipe/about/AboutActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ class AboutActivity : AppCompatActivity() {
167167
"https://square.github.io/okhttp/", StandardLicenses.APACHE2
168168
),
169169
SoftwareComponent(
170-
"Picasso", "2013", "Square, Inc.",
171-
"https://square.github.io/picasso/", StandardLicenses.APACHE2
170+
"Coil", "2023", "Coil Contributors",
171+
"https://coil-kt.github.io/coil/", StandardLicenses.APACHE2
172172
),
173173
SoftwareComponent(
174174
"PrettyTime", "2012 - 2020", "Lincoln Baxter, III",

app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,6 @@ public final class VideoDetailFragment
160160
private static final String DESCRIPTION_TAB_TAG = "DESCRIPTION TAB";
161161
private static final String EMPTY_TAB_TAG = "EMPTY TAB";
162162

163-
private static final String PICASSO_VIDEO_DETAILS_TAG = "PICASSO_VIDEO_DETAILS_TAG";
164-
165163
// tabs
166164
private boolean showComments;
167165
private boolean showRelatedItems;

app/src/main/java/org/schabi/newpipe/fragments/list/channel/ChannelFragment.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@
5454
import org.schabi.newpipe.util.external_communication.ShareUtils;
5555
import org.schabi.newpipe.util.image.CoilHelper;
5656
import org.schabi.newpipe.util.image.ImageStrategy;
57-
import org.schabi.newpipe.util.image.PicassoHelper;
5857

5958
import java.util.List;
6059
import java.util.Queue;
6160
import java.util.concurrent.TimeUnit;
6261

62+
import coil.util.CoilUtils;
6363
import icepick.State;
6464
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
6565
import io.reactivex.rxjava3.core.Observable;
@@ -74,7 +74,6 @@ public class ChannelFragment extends BaseStateFragment<ChannelInfo>
7474
implements StateSaver.WriteRead {
7575

7676
private static final int BUTTON_DEBOUNCE_INTERVAL = 100;
77-
private static final String PICASSO_CHANNEL_TAG = "PICASSO_CHANNEL_TAG";
7877

7978
@State
8079
protected int serviceId = Constants.NO_SERVICE_ID;
@@ -577,7 +576,9 @@ private void runWorker(final boolean forceLoad) {
577576
@Override
578577
public void showLoading() {
579578
super.showLoading();
580-
PicassoHelper.cancelTag(PICASSO_CHANNEL_TAG);
579+
CoilUtils.dispose(binding.channelAvatarView);
580+
CoilUtils.dispose(binding.channelBannerImage);
581+
CoilUtils.dispose(binding.subChannelAvatarView);
581582
animate(binding.channelSubscribeButton, false, 100);
582583
}
583584

app/src/main/java/org/schabi/newpipe/fragments/list/playlist/PlaylistFragment.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import org.schabi.newpipe.util.PlayButtonHelper;
5555
import org.schabi.newpipe.util.external_communication.ShareUtils;
5656
import org.schabi.newpipe.util.image.CoilHelper;
57-
import org.schabi.newpipe.util.image.PicassoHelper;
5857
import org.schabi.newpipe.util.text.TextEllipsizer;
5958

6059
import java.util.ArrayList;
@@ -63,6 +62,7 @@
6362
import java.util.function.Supplier;
6463
import java.util.stream.Collectors;
6564

65+
import coil.util.CoilUtils;
6666
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
6767
import io.reactivex.rxjava3.core.Flowable;
6868
import io.reactivex.rxjava3.core.Single;
@@ -72,8 +72,6 @@
7272
public class PlaylistFragment extends BaseListInfoFragment<StreamInfoItem, PlaylistInfo>
7373
implements PlaylistControlViewHolder {
7474

75-
private static final String PICASSO_PLAYLIST_TAG = "PICASSO_PLAYLIST_TAG";
76-
7775
private CompositeDisposable disposables;
7876
private Subscription bookmarkReactor;
7977
private AtomicBoolean isBookmarkButtonReady;
@@ -277,7 +275,7 @@ public void showLoading() {
277275
animate(headerBinding.getRoot(), false, 200);
278276
animateHideRecyclerViewAllowingScrolling(itemsList);
279277

280-
PicassoHelper.cancelTag(PICASSO_PLAYLIST_TAG);
278+
CoilUtils.dispose(headerBinding.uploaderAvatarView);
281279
animate(headerBinding.uploaderLayout, false, 200);
282280
}
283281

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package org.schabi.newpipe.ktx
2+
3+
import android.graphics.Bitmap
4+
import android.graphics.Rect
5+
import androidx.core.graphics.BitmapCompat
6+
7+
@Suppress("NOTHING_TO_INLINE")
8+
inline fun Bitmap.scale(
9+
width: Int,
10+
height: Int,
11+
srcRect: Rect? = null,
12+
scaleInLinearSpace: Boolean = true,
13+
) = BitmapCompat.createScaledBitmap(this, width, height, srcRect, scaleInLinearSpace)

app/src/main/java/org/schabi/newpipe/player/Player.java

Lines changed: 29 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060

6161
import androidx.annotation.NonNull;
6262
import androidx.annotation.Nullable;
63+
import androidx.core.graphics.drawable.DrawableKt;
6364
import androidx.core.math.MathUtils;
6465
import androidx.preference.PreferenceManager;
6566

@@ -77,8 +78,6 @@
7778
import com.google.android.exoplayer2.trackselection.MappingTrackSelector;
7879
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
7980
import com.google.android.exoplayer2.video.VideoSize;
80-
import com.squareup.picasso.Picasso;
81-
import com.squareup.picasso.Target;
8281

8382
import org.schabi.newpipe.MainActivity;
8483
import org.schabi.newpipe.R;
@@ -120,12 +119,13 @@
120119
import org.schabi.newpipe.util.NavigationHelper;
121120
import org.schabi.newpipe.util.SerializedCache;
122121
import org.schabi.newpipe.util.StreamTypeUtil;
123-
import org.schabi.newpipe.util.image.PicassoHelper;
122+
import org.schabi.newpipe.util.image.CoilHelper;
124123

125124
import java.util.List;
126125
import java.util.Optional;
127126
import java.util.stream.IntStream;
128127

128+
import coil.target.Target;
129129
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
130130
import io.reactivex.rxjava3.core.Observable;
131131
import io.reactivex.rxjava3.disposables.CompositeDisposable;
@@ -174,7 +174,6 @@ public final class Player implements PlaybackListener, Listener {
174174
//////////////////////////////////////////////////////////////////////////*/
175175

176176
public static final int RENDERER_UNAVAILABLE = -1;
177-
private static final String PICASSO_PLAYER_THUMBNAIL_TAG = "PICASSO_PLAYER_THUMBNAIL_TAG";
178177

179178
/*//////////////////////////////////////////////////////////////////////////
180179
// Playback
@@ -246,12 +245,6 @@ public final class Player implements PlaybackListener, Listener {
246245
@NonNull
247246
private final CompositeDisposable databaseUpdateDisposable = new CompositeDisposable();
248247

249-
// This is the only listener we need for thumbnail loading, since there is always at most only
250-
// one thumbnail being loaded at a time. This field is also here to maintain a strong reference,
251-
// which would otherwise be garbage collected since Picasso holds weak references to targets.
252-
@NonNull
253-
private final Target currentThumbnailTarget;
254-
255248
/*//////////////////////////////////////////////////////////////////////////
256249
// Utils
257250
//////////////////////////////////////////////////////////////////////////*/
@@ -295,8 +288,6 @@ public Player(@NonNull final PlayerService service) {
295288
videoResolver = new VideoPlaybackResolver(context, dataSource, getQualityResolver());
296289
audioResolver = new AudioPlaybackResolver(context, dataSource);
297290

298-
currentThumbnailTarget = getCurrentThumbnailTarget();
299-
300291
// The UIs added here should always be present. They will be initialized when the player
301292
// reaches the initialization step. Make sure the media session ui is before the
302293
// notification ui in the UIs list, since the notification depends on the media session in
@@ -602,7 +593,6 @@ public void destroy() {
602593

603594
databaseUpdateDisposable.clear();
604595
progressUpdateDisposable.set(null);
605-
cancelLoadingCurrentThumbnail();
606596

607597
UIs.destroyAll(Object.class); // destroy every UI: obviously every UI extends Object
608598
}
@@ -776,45 +766,12 @@ private void unregisterBroadcastReceiver() {
776766
//////////////////////////////////////////////////////////////////////////*/
777767
//region Thumbnail loading
778768

779-
private Target getCurrentThumbnailTarget() {
780-
// a Picasso target is just a listener for thumbnail loading events
781-
return new Target() {
782-
@Override
783-
public void onBitmapLoaded(final Bitmap bitmap, final Picasso.LoadedFrom from) {
784-
if (DEBUG) {
785-
Log.d(TAG, "Thumbnail - onBitmapLoaded() called with: bitmap = [" + bitmap
786-
+ " -> " + bitmap.getWidth() + "x" + bitmap.getHeight() + "], from = ["
787-
+ from + "]");
788-
}
789-
// there is a new thumbnail, so e.g. the end screen thumbnail needs to change, too.
790-
onThumbnailLoaded(bitmap);
791-
}
792-
793-
@Override
794-
public void onBitmapFailed(final Exception e, final Drawable errorDrawable) {
795-
Log.e(TAG, "Thumbnail - onBitmapFailed() called", e);
796-
// there is a new thumbnail, so e.g. the end screen thumbnail needs to change, too.
797-
onThumbnailLoaded(null);
798-
}
799-
800-
@Override
801-
public void onPrepareLoad(final Drawable placeHolderDrawable) {
802-
if (DEBUG) {
803-
Log.d(TAG, "Thumbnail - onPrepareLoad() called");
804-
}
805-
}
806-
};
807-
}
808-
809769
private void loadCurrentThumbnail(final List<Image> thumbnails) {
810770
if (DEBUG) {
811771
Log.d(TAG, "Thumbnail - loadCurrentThumbnail() called with thumbnails = ["
812772
+ thumbnails.size() + "]");
813773
}
814774

815-
// first cancel any previous loading
816-
cancelLoadingCurrentThumbnail();
817-
818775
// Unset currentThumbnail, since it is now outdated. This ensures it is not used in media
819776
// session metadata while the new thumbnail is being loaded by Coil.
820777
onThumbnailLoaded(null);
@@ -823,20 +780,38 @@ private void loadCurrentThumbnail(final List<Image> thumbnails) {
823780
}
824781

825782
// scale down the notification thumbnail for performance
826-
PicassoHelper.loadScaledDownThumbnail(context, thumbnails)
827-
.tag(PICASSO_PLAYER_THUMBNAIL_TAG)
828-
.into(currentThumbnailTarget);
829-
}
783+
final var target = new Target() {
784+
@Override
785+
public void onError(@Nullable final Drawable error) {
786+
Log.e(TAG, "Thumbnail - onError() called");
787+
// there is a new thumbnail, so e.g. the end screen thumbnail needs to change, too.
788+
onThumbnailLoaded(null);
789+
}
830790

831-
private void cancelLoadingCurrentThumbnail() {
832-
// cancel the Picasso job associated with the player thumbnail, if any
833-
PicassoHelper.cancelTag(PICASSO_PLAYER_THUMBNAIL_TAG);
791+
@Override
792+
public void onStart(@Nullable final Drawable placeholder) {
793+
if (DEBUG) {
794+
Log.d(TAG, "Thumbnail - onStart() called");
795+
}
796+
}
797+
798+
@Override
799+
public void onSuccess(@NonNull final Drawable result) {
800+
if (DEBUG) {
801+
Log.d(TAG, "Thumbnail - onSuccess() called with: drawable = [" + result + "]");
802+
}
803+
// there is a new thumbnail, so e.g. the end screen thumbnail needs to change, too.
804+
onThumbnailLoaded(DrawableKt.toBitmapOrNull(result, result.getIntrinsicWidth(),
805+
result.getIntrinsicHeight(), null));
806+
}
807+
};
808+
CoilHelper.INSTANCE.loadScaledDownThumbnail(context, thumbnails, target);
834809
}
835810

836811
private void onThumbnailLoaded(@Nullable final Bitmap bitmap) {
837812
// Avoid useless thumbnail updates, if the thumbnail has not actually changed. Based on the
838813
// thumbnail loading code, this if would be skipped only when both bitmaps are `null`, since
839-
// onThumbnailLoaded won't be called twice with the same nonnull bitmap by Picasso's target.
814+
// onThumbnailLoaded won't be called twice with the same nonnull bitmap by Coil's target.
840815
if (currentThumbnail != bitmap) {
841816
currentThumbnail = bitmap;
842817
UIs.call(playerUi -> playerUi.onThumbnailLoaded(bitmap));

app/src/main/java/org/schabi/newpipe/settings/ContentSettingsFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
4949
loader.getDiskCache().clear();
5050
}
5151
Toast.makeText(preference.getContext(),
52-
R.string.thumbnail_cache_wipe_complete_notice, Toast.LENGTH_SHORT)
52+
R.string.thumbnail_cache_wipe_complete_notice, Toast.LENGTH_SHORT)
5353
.show();
5454

5555
return true;

app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.schabi.newpipe.error.ErrorUtil;
1111
import org.schabi.newpipe.error.UserAction;
1212
import org.schabi.newpipe.local.feed.notifications.NotificationWorker;
13-
import org.schabi.newpipe.util.image.PicassoHelper;
1413

1514
import java.util.Optional;
1615

@@ -25,8 +24,6 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
2524
findPreference(getString(R.string.allow_heap_dumping_key));
2625
final Preference showMemoryLeaksPreference =
2726
findPreference(getString(R.string.show_memory_leaks_key));
28-
final Preference showImageIndicatorsPreference =
29-
findPreference(getString(R.string.show_image_indicators_key));
3027
final Preference checkNewStreamsPreference =
3128
findPreference(getString(R.string.check_new_streams_key));
3229
final Preference crashTheAppPreference =
@@ -38,7 +35,6 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
3835

3936
assert allowHeapDumpingPreference != null;
4037
assert showMemoryLeaksPreference != null;
41-
assert showImageIndicatorsPreference != null;
4238
assert checkNewStreamsPreference != null;
4339
assert crashTheAppPreference != null;
4440
assert showErrorSnackbarPreference != null;
@@ -61,11 +57,6 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
6157
showMemoryLeaksPreference.setSummary(R.string.leak_canary_not_available);
6258
}
6359

64-
showImageIndicatorsPreference.setOnPreferenceChangeListener((preference, newValue) -> {
65-
PicassoHelper.setIndicatorsEnabled((Boolean) newValue);
66-
return true;
67-
});
68-
6960
checkNewStreamsPreference.setOnPreferenceClickListener(preference -> {
7061
NotificationWorker.runNow(preference.getContext());
7162
return true;

0 commit comments

Comments
 (0)