Skip to content

Commit 9b2c86a

Browse files
committed
Improved documentation
1 parent ce4dd33 commit 9b2c86a

3 files changed

Lines changed: 32 additions & 23 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.schabi.newpipe.settings;
2+
3+
import android.content.Intent;
4+
5+
import leakcanary.LeakCanary;
6+
7+
/**
8+
* Build variant dependent (BVD) leak canary API implementation for the debug settings fragment.
9+
* This class is loaded via reflection by
10+
* {@link DebugSettingsFragment.DebugSettingsBVDLeakCanaryAPI}.
11+
*/
12+
@SuppressWarnings("unused") // Class is used but loaded via reflection
13+
public class DebugSettingsBVDLeakCanary
14+
implements DebugSettingsFragment.DebugSettingsBVDLeakCanaryAPI {
15+
16+
@Override
17+
public Intent getNewLeakDisplayActivityIntent() {
18+
return LeakCanary.INSTANCE.newLeakDisplayActivityIntent();
19+
}
20+
}

app/src/debug/java/org/schabi/newpipe/settings/DebugSettingsBVLeakCanary.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

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

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
4040
assert showErrorSnackbarPreference != null;
4141
assert createErrorNotificationPreference != null;
4242

43-
final Optional<DebugSettingsBVLeakCanaryAPI> optBVLeakCanary = getBVLeakCanary();
43+
final Optional<DebugSettingsBVDLeakCanaryAPI> optBVLeakCanary = getBVDLeakCanary();
4444

4545
allowHeapDumpingPreference.setEnabled(optBVLeakCanary.isPresent());
4646
showMemoryLeaksPreference.setEnabled(optBVLeakCanary.isPresent());
4747

4848
if (optBVLeakCanary.isPresent()) {
49-
final DebugSettingsBVLeakCanaryAPI pdLeakCanary = optBVLeakCanary.get();
49+
final DebugSettingsBVDLeakCanaryAPI pdLeakCanary = optBVLeakCanary.get();
5050

5151
showMemoryLeaksPreference.setOnPreferenceClickListener(preference -> {
5252
startActivity(pdLeakCanary.getNewLeakDisplayActivityIntent());
@@ -79,11 +79,15 @@ public void onCreatePreferences(final Bundle savedInstanceState, final String ro
7979
});
8080
}
8181

82-
private Optional<DebugSettingsBVLeakCanaryAPI> getBVLeakCanary() {
82+
/**
83+
* Tries to find the {@link DebugSettingsBVDLeakCanaryAPI#IMPL_CLASS} and loads it if available.
84+
* @return An {@link Optional} which is empty if the implementation class couldn't be loaded.
85+
*/
86+
private Optional<DebugSettingsBVDLeakCanaryAPI> getBVDLeakCanary() {
8387
try {
8488
// Try to find the implementation of the LeakCanary API
85-
return Optional.of((DebugSettingsBVLeakCanaryAPI)
86-
Class.forName(DebugSettingsBVLeakCanaryAPI.IMPL_CLASS)
89+
return Optional.of((DebugSettingsBVDLeakCanaryAPI)
90+
Class.forName(DebugSettingsBVDLeakCanaryAPI.IMPL_CLASS)
8791
.getDeclaredConstructor()
8892
.newInstance());
8993
} catch (final Exception e) {
@@ -92,12 +96,12 @@ private Optional<DebugSettingsBVLeakCanaryAPI> getBVLeakCanary() {
9296
}
9397

9498
/**
95-
* Build variant dependent leak canary API for this fragment.
99+
* Build variant dependent (BVD) leak canary API for this fragment.
96100
* Why is LeakCanary not used directly? Because it can't be assured
97101
*/
98-
public interface DebugSettingsBVLeakCanaryAPI {
102+
public interface DebugSettingsBVDLeakCanaryAPI {
99103
String IMPL_CLASS =
100-
"org.schabi.newpipe.settings.DebugSettingsBVLeakCanary";
104+
"org.schabi.newpipe.settings.DebugSettingsBVDLeakCanary";
101105

102106
Intent getNewLeakDisplayActivityIntent();
103107
}

0 commit comments

Comments
 (0)