From 8654788b60d4f3cb8287e01a7e0acd10a5d2ffb2 Mon Sep 17 00:00:00 2001 From: TobiGr Date: Tue, 29 Aug 2023 15:33:03 +0200 Subject: [PATCH] Fix memory leaks and add documentation --- .../main/java/org/schabi/newpipe/BaseFragment.java | 14 ++++++++++++++ .../newpipe/fragments/BaseStateFragment.java | 2 ++ .../org/schabi/newpipe/fragments/MainFragment.java | 6 ++++++ 3 files changed, 22 insertions(+) diff --git a/app/src/main/java/org/schabi/newpipe/BaseFragment.java b/app/src/main/java/org/schabi/newpipe/BaseFragment.java index 19a99009bd8..be9d63cc870 100644 --- a/app/src/main/java/org/schabi/newpipe/BaseFragment.java +++ b/app/src/main/java/org/schabi/newpipe/BaseFragment.java @@ -80,9 +80,23 @@ protected void onRestoreInstanceState(@NonNull final Bundle savedInstanceState) // Init //////////////////////////////////////////////////////////////////////////*/ + /** + * This method is called in {@link #onViewCreated(View, Bundle)} to initialize the views. + *
+ * {@link #initListeners()} is called after this method to initialize the corresponding + * listeners. + * @param rootView + * @param savedInstanceState + */ protected void initViews(final View rootView, final Bundle savedInstanceState) { } + /** + * Initialize the listeners for this fragment. + *
+ * This method is called after {@link #initViews(View, Bundle)} + * in {@link #onViewCreated(View, Bundle)}. + */ protected void initListeners() { } diff --git a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java index 85603d33705..a3d3d8b60f2 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/BaseStateFragment.java @@ -80,6 +80,8 @@ public void onDestroyView() { if (errorPanelHelper != null) { errorPanelHelper.dispose(); } + emptyStateView = null; + emptyStateMessageView = null; } protected void onRetryButtonClicked() { diff --git a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java index e1b61ea7c14..02364295500 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/MainFragment.java @@ -139,6 +139,12 @@ public void onDestroy() { } } + @Override + public void onDestroyView() { + super.onDestroyView(); + binding = null; + } + /*////////////////////////////////////////////////////////////////////////// // Menu //////////////////////////////////////////////////////////////////////////*/