From 9b2c86a37be7ce57f5a26dd222f854be0479a771 Mon Sep 17 00:00:00 2001 From: litetex <40789489+litetex@users.noreply.github.com> Date: Fri, 31 Dec 2021 16:14:01 +0100 Subject: [PATCH] Improved documentation --- .../settings/DebugSettingsBVDLeakCanary.java | 20 +++++++++++++++++++ .../settings/DebugSettingsBVLeakCanary.java | 15 -------------- .../settings/DebugSettingsFragment.java | 20 +++++++++++-------- 3 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsBVDLeakCanary.java delete mode 100644 app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsBVLeakCanary.java diff --git a/app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsBVDLeakCanary.java b/app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsBVDLeakCanary.java new file mode 100644 index 000000000..a2d65f6f4 --- /dev/null +++ b/app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsBVDLeakCanary.java @@ -0,0 +1,20 @@ +package org.schabi.newpipe.settings; + +import android.content.Intent; + +import leakcanary.LeakCanary; + +/** + * Build variant dependent (BVD) leak canary API implementation for the debug settings fragment. + * This class is loaded via reflection by + * {@link DebugSettingsFragment.DebugSettingsBVDLeakCanaryAPI}. + */ +@SuppressWarnings("unused") // Class is used but loaded via reflection +public class DebugSettingsBVDLeakCanary + implements DebugSettingsFragment.DebugSettingsBVDLeakCanaryAPI { + + @Override + public Intent getNewLeakDisplayActivityIntent() { + return LeakCanary.INSTANCE.newLeakDisplayActivityIntent(); + } +} diff --git a/app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsBVLeakCanary.java b/app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsBVLeakCanary.java deleted file mode 100644 index f8fd7f969..000000000 --- a/app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsBVLeakCanary.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.schabi.newpipe.settings; - -import android.content.Intent; - -import leakcanary.LeakCanary; - -@SuppressWarnings("unused") // Class is used but loaded via reflection -public class DebugSettingsBVLeakCanary - implements DebugSettingsFragment.DebugSettingsBVLeakCanaryAPI { - - @Override - public Intent getNewLeakDisplayActivityIntent() { - return LeakCanary.INSTANCE.newLeakDisplayActivityIntent(); - } -} diff --git a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java index 3e28a6065..395c7c0f0 100644 --- a/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java +++ b/app/src/main/java/org/schabi/newpipe/settings/DebugSettingsFragment.java @@ -40,13 +40,13 @@ public class DebugSettingsFragment extends BasePreferenceFragment { assert showErrorSnackbarPreference != null; assert createErrorNotificationPreference != null; - final Optional optBVLeakCanary = getBVLeakCanary(); + final Optional optBVLeakCanary = getBVDLeakCanary(); allowHeapDumpingPreference.setEnabled(optBVLeakCanary.isPresent()); showMemoryLeaksPreference.setEnabled(optBVLeakCanary.isPresent()); if (optBVLeakCanary.isPresent()) { - final DebugSettingsBVLeakCanaryAPI pdLeakCanary = optBVLeakCanary.get(); + final DebugSettingsBVDLeakCanaryAPI pdLeakCanary = optBVLeakCanary.get(); showMemoryLeaksPreference.setOnPreferenceClickListener(preference -> { startActivity(pdLeakCanary.getNewLeakDisplayActivityIntent()); @@ -79,11 +79,15 @@ public class DebugSettingsFragment extends BasePreferenceFragment { }); } - private Optional getBVLeakCanary() { + /** + * Tries to find the {@link DebugSettingsBVDLeakCanaryAPI#IMPL_CLASS} and loads it if available. + * @return An {@link Optional} which is empty if the implementation class couldn't be loaded. + */ + private Optional getBVDLeakCanary() { try { // Try to find the implementation of the LeakCanary API - return Optional.of((DebugSettingsBVLeakCanaryAPI) - Class.forName(DebugSettingsBVLeakCanaryAPI.IMPL_CLASS) + return Optional.of((DebugSettingsBVDLeakCanaryAPI) + Class.forName(DebugSettingsBVDLeakCanaryAPI.IMPL_CLASS) .getDeclaredConstructor() .newInstance()); } catch (final Exception e) { @@ -92,12 +96,12 @@ public class DebugSettingsFragment extends BasePreferenceFragment { } /** - * Build variant dependent leak canary API for this fragment. + * Build variant dependent (BVD) leak canary API for this fragment. * Why is LeakCanary not used directly? Because it can't be assured */ - public interface DebugSettingsBVLeakCanaryAPI { + public interface DebugSettingsBVDLeakCanaryAPI { String IMPL_CLASS = - "org.schabi.newpipe.settings.DebugSettingsBVLeakCanary"; + "org.schabi.newpipe.settings.DebugSettingsBVDLeakCanary"; Intent getNewLeakDisplayActivityIntent(); }