mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-31 15:23:00 +00:00 
			
		
		
		
	Improved documentation
This commit is contained in:
		| @@ -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(); | ||||||
|  |     } | ||||||
|  | } | ||||||
| @@ -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(); |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -40,13 +40,13 @@ public class DebugSettingsFragment extends BasePreferenceFragment { | |||||||
|         assert showErrorSnackbarPreference != null; |         assert showErrorSnackbarPreference != null; | ||||||
|         assert createErrorNotificationPreference != null; |         assert createErrorNotificationPreference != null; | ||||||
|  |  | ||||||
|         final Optional<DebugSettingsBVLeakCanaryAPI> optBVLeakCanary = getBVLeakCanary(); |         final Optional<DebugSettingsBVDLeakCanaryAPI> optBVLeakCanary = getBVDLeakCanary(); | ||||||
|  |  | ||||||
|         allowHeapDumpingPreference.setEnabled(optBVLeakCanary.isPresent()); |         allowHeapDumpingPreference.setEnabled(optBVLeakCanary.isPresent()); | ||||||
|         showMemoryLeaksPreference.setEnabled(optBVLeakCanary.isPresent()); |         showMemoryLeaksPreference.setEnabled(optBVLeakCanary.isPresent()); | ||||||
|  |  | ||||||
|         if (optBVLeakCanary.isPresent()) { |         if (optBVLeakCanary.isPresent()) { | ||||||
|             final DebugSettingsBVLeakCanaryAPI pdLeakCanary = optBVLeakCanary.get(); |             final DebugSettingsBVDLeakCanaryAPI pdLeakCanary = optBVLeakCanary.get(); | ||||||
|  |  | ||||||
|             showMemoryLeaksPreference.setOnPreferenceClickListener(preference -> { |             showMemoryLeaksPreference.setOnPreferenceClickListener(preference -> { | ||||||
|                 startActivity(pdLeakCanary.getNewLeakDisplayActivityIntent()); |                 startActivity(pdLeakCanary.getNewLeakDisplayActivityIntent()); | ||||||
| @@ -79,11 +79,15 @@ public class DebugSettingsFragment extends BasePreferenceFragment { | |||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private Optional<DebugSettingsBVLeakCanaryAPI> 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<DebugSettingsBVDLeakCanaryAPI> getBVDLeakCanary() { | ||||||
|         try { |         try { | ||||||
|             // Try to find the implementation of the LeakCanary API |             // Try to find the implementation of the LeakCanary API | ||||||
|             return Optional.of((DebugSettingsBVLeakCanaryAPI) |             return Optional.of((DebugSettingsBVDLeakCanaryAPI) | ||||||
|                     Class.forName(DebugSettingsBVLeakCanaryAPI.IMPL_CLASS) |                     Class.forName(DebugSettingsBVDLeakCanaryAPI.IMPL_CLASS) | ||||||
|                             .getDeclaredConstructor() |                             .getDeclaredConstructor() | ||||||
|                             .newInstance()); |                             .newInstance()); | ||||||
|         } catch (final Exception e) { |         } 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 |      * Why is LeakCanary not used directly? Because it can't be assured | ||||||
|      */ |      */ | ||||||
|     public interface DebugSettingsBVLeakCanaryAPI { |     public interface DebugSettingsBVDLeakCanaryAPI { | ||||||
|         String IMPL_CLASS = |         String IMPL_CLASS = | ||||||
|                 "org.schabi.newpipe.settings.DebugSettingsBVLeakCanary"; |                 "org.schabi.newpipe.settings.DebugSettingsBVDLeakCanary"; | ||||||
|  |  | ||||||
|         Intent getNewLeakDisplayActivityIntent(); |         Intent getNewLeakDisplayActivityIntent(); | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 litetex
					litetex