mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-30 23:03:00 +00:00 
			
		
		
		
	-Fixed memory leak in playlist append dialog due to rogue flowables.
-Changed image loader memory cache to use limited LRU.
This commit is contained in:
		| @@ -10,6 +10,8 @@ import android.content.Intent; | ||||
| import android.os.Build; | ||||
| import android.util.Log; | ||||
|  | ||||
| import com.nostra13.universalimageloader.cache.memory.impl.LRULimitedMemoryCache; | ||||
| import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache; | ||||
| import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache; | ||||
| import com.nostra13.universalimageloader.core.ImageLoader; | ||||
| import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; | ||||
| @@ -81,10 +83,7 @@ public class App extends Application { | ||||
|         initNotificationChannel(); | ||||
|  | ||||
|         // Initialize image loader | ||||
|         ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this) | ||||
|                 .memoryCache(new WeakMemoryCache()) | ||||
|                 .build(); | ||||
|         ImageLoader.getInstance().init(config); | ||||
|         ImageLoader.getInstance().init(getImageLoaderConfigurations(10)); | ||||
|  | ||||
|         configureRxJavaErrorHandler(); | ||||
|     } | ||||
| @@ -122,6 +121,12 @@ public class App extends Application { | ||||
|         }); | ||||
|     } | ||||
|  | ||||
|     private ImageLoaderConfiguration getImageLoaderConfigurations(final int memoryCacheSizeMb) { | ||||
|         return new ImageLoaderConfiguration.Builder(this) | ||||
|                 .memoryCache(new LRULimitedMemoryCache(memoryCacheSizeMb * 1024 * 1024)) | ||||
|                 .build(); | ||||
|     } | ||||
|  | ||||
|     private void initACRA() { | ||||
|         try { | ||||
|             final ACRAConfiguration acraConfig = new ConfigurationBuilder(this) | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| package org.schabi.newpipe.fragments.local; | ||||
|  | ||||
| import android.annotation.SuppressLint; | ||||
| import android.content.Context; | ||||
| import android.os.Bundle; | ||||
| import android.support.annotation.NonNull; | ||||
| @@ -25,6 +26,7 @@ import java.util.Collections; | ||||
| import java.util.List; | ||||
|  | ||||
| import io.reactivex.android.schedulers.AndroidSchedulers; | ||||
| import io.reactivex.disposables.Disposable; | ||||
|  | ||||
| public final class PlaylistAppendDialog extends PlaylistDialog { | ||||
|     private static final String TAG = PlaylistAppendDialog.class.getCanonicalName(); | ||||
| @@ -32,6 +34,8 @@ public final class PlaylistAppendDialog extends PlaylistDialog { | ||||
|     private RecyclerView playlistRecyclerView; | ||||
|     private LocalItemListAdapter playlistAdapter; | ||||
|  | ||||
|     private Disposable playlistReactor; | ||||
|  | ||||
|     public static PlaylistAppendDialog fromStreamInfo(final StreamInfo info) { | ||||
|         PlaylistAppendDialog dialog = new PlaylistAppendDialog(); | ||||
|         dialog.setInfo(Collections.singletonList(new StreamEntity(info))); | ||||
| @@ -68,6 +72,15 @@ public final class PlaylistAppendDialog extends PlaylistDialog { | ||||
|         playlistAdapter = new LocalItemListAdapter(getActivity()); | ||||
|     } | ||||
|  | ||||
|     @Override | ||||
|     public void onDestroy() { | ||||
|         super.onDestroy(); | ||||
|         if (playlistReactor != null) playlistReactor.dispose(); | ||||
|         playlistReactor = null; | ||||
|         playlistRecyclerView = null; | ||||
|         playlistAdapter = null; | ||||
|     } | ||||
|  | ||||
|     /*////////////////////////////////////////////////////////////////////////// | ||||
|     // Views | ||||
|     //////////////////////////////////////////////////////////////////////////*/ | ||||
| @@ -99,18 +112,20 @@ public final class PlaylistAppendDialog extends PlaylistDialog { | ||||
|                     return; | ||||
|  | ||||
|                 final long playlistId = ((PlaylistMetadataEntry) selectedItem).uid; | ||||
|                 final Toast successToast = Toast.makeText(getContext(), | ||||
|                         R.string.playlist_add_stream_success, Toast.LENGTH_SHORT); | ||||
|                 @SuppressLint("ShowToast") | ||||
|                 final Toast successToast = Toast.makeText(getContext(), R.string.playlist_add_stream_success, | ||||
|                         Toast.LENGTH_SHORT); | ||||
|  | ||||
|                 playlistManager.appendToPlaylist(playlistId, getStreams()) | ||||
|                         .observeOn(AndroidSchedulers.mainThread()) | ||||
|                         .subscribe(ignored -> successToast.show()); | ||||
|                         .doOnDispose(successToast::show) | ||||
|                         .subscribe(ignored -> {}); | ||||
|  | ||||
|                 getDialog().dismiss(); | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|         playlistManager.getPlaylists() | ||||
|         playlistReactor = playlistManager.getPlaylists() | ||||
|                 .observeOn(AndroidSchedulers.mainThread()) | ||||
|                 .subscribe(metadataEntries -> { | ||||
|                     if (metadataEntries.isEmpty()) { | ||||
| @@ -118,9 +133,13 @@ public final class PlaylistAppendDialog extends PlaylistDialog { | ||||
|                         return; | ||||
|                     } | ||||
|  | ||||
|                     if (playlistAdapter != null) { | ||||
|                         playlistAdapter.clearStreamItemList(); | ||||
|                         playlistAdapter.addItems(metadataEntries); | ||||
|                     } | ||||
|                     if (playlistRecyclerView != null) { | ||||
|                         playlistRecyclerView.setVisibility(View.VISIBLE); | ||||
|                     } | ||||
|                 }); | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 John Zhen Mo
					John Zhen Mo