-Added listener unregistration to local item adapters to release dependency and avoid memory leak.

-Added listener unregistration on all listeners using contexts in local item related fragments.
This commit is contained in:
John Zhen Mo 2018-02-07 14:20:16 -08:00
parent c0a75f5b98
commit 7ab41e0c3a
6 changed files with 20 additions and 1 deletions

View file

@ -71,6 +71,10 @@ public class LocalItemListAdapter extends RecyclerView.Adapter<RecyclerView.View
localItemBuilder.setOnItemSelectedListener(listener);
}
public void unsetSelectedListener() {
localItemBuilder.setOnItemSelectedListener(null);
}
public void addItems(List<? extends LocalItem> data) {
if (data != null) {
if (DEBUG) {

View file

@ -230,6 +230,11 @@ public class LocalPlaylistFragment extends BaseLocalListFragment<List<PlaylistSt
public void onDestroyView() {
super.onDestroyView();
if (itemListAdapter != null) itemListAdapter.unsetSelectedListener();
if (headerBackgroundButton != null) headerBackgroundButton.setOnClickListener(null);
if (headerPlayAllButton != null) headerPlayAllButton.setOnClickListener(null);
if (headerPopupButton != null) headerPopupButton.setOnClickListener(null);
if (databaseSubscription != null) databaseSubscription.cancel();
if (debouncedSaver != null) debouncedSaver.dispose();

View file

@ -112,6 +112,7 @@ public final class PlaylistAppendDialog extends PlaylistDialog {
public void onDestroyView() {
super.onDestroyView();
if (playlistReactor != null) playlistReactor.dispose();
if (playlistAdapter != null) playlistAdapter.unsetSelectedListener();
playlistReactor = null;
playlistRecyclerView = null;

View file

@ -178,6 +178,9 @@ public final class BookmarkFragment
@Override
public void onDestroyView() {
super.onDestroyView();
if (mostWatchedButton != null) mostWatchedButton.setOnClickListener(null);
if (watchHistoryButton != null) watchHistoryButton.setOnClickListener(null);
if (disposables != null) disposables.clear();
if (databaseSubscription != null) databaseSubscription.cancel();

View file

@ -140,6 +140,12 @@ public abstract class StatisticsPlaylistFragment
@Override
public void onDestroyView() {
super.onDestroyView();
if (itemListAdapter != null) itemListAdapter.unsetSelectedListener();
if (headerBackgroundButton != null) headerBackgroundButton.setOnClickListener(null);
if (headerPlayAllButton != null) headerPlayAllButton.setOnClickListener(null);
if (headerPopupButton != null) headerPopupButton.setOnClickListener(null);
if (databaseSubscription != null) databaseSubscription.cancel();
databaseSubscription = null;
}

View file

@ -84,7 +84,7 @@ public class LocalPlaylistStreamItemHolder extends LocalItemHolder {
private View.OnTouchListener getOnTouchListener(final PlaylistStreamEntry item) {
return (view, motionEvent) -> {
view.performClick();
if (itemBuilder != null &&
if (itemBuilder != null && itemBuilder.getOnItemSelectedListener() != null &&
motionEvent.getActionMasked() == MotionEvent.ACTION_DOWN) {
itemBuilder.getOnItemSelectedListener().drag(item,
LocalPlaylistStreamItemHolder.this);