mirror of
				https://github.com/TeamNewPipe/NewPipe
				synced 2025-10-30 23:03:00 +00:00 
			
		
		
		
	solve merge conflict
This commit is contained in:
		| @@ -89,4 +89,8 @@ dependencies { | |||||||
|  |  | ||||||
|     implementation 'frankiesardo:icepick:3.2.0' |     implementation 'frankiesardo:icepick:3.2.0' | ||||||
|     annotationProcessor 'frankiesardo:icepick-processor:3.2.0' |     annotationProcessor 'frankiesardo:icepick-processor:3.2.0' | ||||||
|  |  | ||||||
|  |     debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4' | ||||||
|  |     betaImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4' | ||||||
|  |     releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4' | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,9 +1,21 @@ | |||||||
| package org.schabi.newpipe; | package org.schabi.newpipe; | ||||||
|  |  | ||||||
| import android.content.Context; | import android.content.Context; | ||||||
|  | import android.content.SharedPreferences; | ||||||
|  | import android.preference.PreferenceManager; | ||||||
|  | import android.support.annotation.NonNull; | ||||||
| import android.support.multidex.MultiDex; | import android.support.multidex.MultiDex; | ||||||
|  |  | ||||||
| import com.facebook.stetho.Stetho; | import com.facebook.stetho.Stetho; | ||||||
|  | import com.squareup.leakcanary.AndroidHeapDumper; | ||||||
|  | import com.squareup.leakcanary.DefaultLeakDirectoryProvider; | ||||||
|  | import com.squareup.leakcanary.HeapDumper; | ||||||
|  | import com.squareup.leakcanary.LeakCanary; | ||||||
|  | import com.squareup.leakcanary.LeakDirectoryProvider; | ||||||
|  | import com.squareup.leakcanary.RefWatcher; | ||||||
|  |  | ||||||
|  | import java.io.File; | ||||||
|  | import java.util.concurrent.TimeUnit; | ||||||
|  |  | ||||||
| public class DebugApp extends App { | public class DebugApp extends App { | ||||||
|     private static final String TAG = DebugApp.class.toString(); |     private static final String TAG = DebugApp.class.toString(); | ||||||
| @@ -41,4 +53,35 @@ public class DebugApp extends App { | |||||||
|         // Initialize Stetho with the Initializer |         // Initialize Stetho with the Initializer | ||||||
|         Stetho.initialize(initializer); |         Stetho.initialize(initializer); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     protected RefWatcher installLeakCanary() { | ||||||
|  |         return LeakCanary.refWatcher(this) | ||||||
|  |                 .heapDumper(new ToggleableHeapDumper(this)) | ||||||
|  |                 // give each object 10 seconds to be gc'ed, before leak canary gets nosy on it | ||||||
|  |                 .watchDelay(10, TimeUnit.SECONDS) | ||||||
|  |                 .buildAndInstall(); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public static class ToggleableHeapDumper implements HeapDumper { | ||||||
|  |         private final HeapDumper dumper; | ||||||
|  |         private final SharedPreferences preferences; | ||||||
|  |         private final String dumpingAllowanceKey; | ||||||
|  |  | ||||||
|  |         ToggleableHeapDumper(@NonNull final Context context) { | ||||||
|  |             LeakDirectoryProvider leakDirectoryProvider = new DefaultLeakDirectoryProvider(context); | ||||||
|  |             this.dumper = new AndroidHeapDumper(context, leakDirectoryProvider); | ||||||
|  |             this.preferences = PreferenceManager.getDefaultSharedPreferences(context); | ||||||
|  |             this.dumpingAllowanceKey = context.getString(R.string.allow_heap_dumping_key); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         private boolean isDumpingAllowed() { | ||||||
|  |             return preferences.getBoolean(dumpingAllowanceKey, false); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         @Override | ||||||
|  |         public File dumpHeap() { | ||||||
|  |             return isDumpingAllowed() ? dumper.dumpHeap() : HeapDumper.RETRY_LATER; | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -5,11 +5,14 @@ import android.app.NotificationChannel; | |||||||
| import android.app.NotificationManager; | import android.app.NotificationManager; | ||||||
| import android.content.Context; | import android.content.Context; | ||||||
| import android.os.Build; | import android.os.Build; | ||||||
|  | import android.support.annotation.Nullable; | ||||||
| import android.util.Log; | import android.util.Log; | ||||||
|  |  | ||||||
| import com.nostra13.universalimageloader.cache.memory.impl.LRULimitedMemoryCache; | import com.nostra13.universalimageloader.cache.memory.impl.LRULimitedMemoryCache; | ||||||
| import com.nostra13.universalimageloader.core.ImageLoader; | import com.nostra13.universalimageloader.core.ImageLoader; | ||||||
| import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; | import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; | ||||||
|  | import com.squareup.leakcanary.LeakCanary; | ||||||
|  | import com.squareup.leakcanary.RefWatcher; | ||||||
|  |  | ||||||
| import org.acra.ACRA; | import org.acra.ACRA; | ||||||
| import org.acra.config.ACRAConfiguration; | import org.acra.config.ACRAConfiguration; | ||||||
| @@ -54,6 +57,7 @@ import io.reactivex.plugins.RxJavaPlugins; | |||||||
|  |  | ||||||
| public class App extends Application { | public class App extends Application { | ||||||
|     protected static final String TAG = App.class.toString(); |     protected static final String TAG = App.class.toString(); | ||||||
|  |     private RefWatcher refWatcher; | ||||||
|  |  | ||||||
|     @SuppressWarnings("unchecked") |     @SuppressWarnings("unchecked") | ||||||
|     private static final Class<? extends ReportSenderFactory>[] reportSenderFactoryClasses = new Class[]{AcraReportSenderFactory.class}; |     private static final Class<? extends ReportSenderFactory>[] reportSenderFactoryClasses = new Class[]{AcraReportSenderFactory.class}; | ||||||
| @@ -69,6 +73,13 @@ public class App extends Application { | |||||||
|     public void onCreate() { |     public void onCreate() { | ||||||
|         super.onCreate(); |         super.onCreate(); | ||||||
|  |  | ||||||
|  |         if (LeakCanary.isInAnalyzerProcess(this)) { | ||||||
|  |             // This process is dedicated to LeakCanary for heap analysis. | ||||||
|  |             // You should not init your app in this process. | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         refWatcher = installLeakCanary(); | ||||||
|  |  | ||||||
|         // Initialize settings first because others inits can use its values |         // Initialize settings first because others inits can use its values | ||||||
|         SettingsActivity.initSettings(this); |         SettingsActivity.initSettings(this); | ||||||
|  |  | ||||||
| @@ -157,4 +168,13 @@ public class App extends Application { | |||||||
|         mNotificationManager.createNotificationChannel(mChannel); |         mNotificationManager.createNotificationChannel(mChannel); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Nullable | ||||||
|  |     public static RefWatcher getRefWatcher(Context context) { | ||||||
|  |         final App application = (App) context.getApplicationContext(); | ||||||
|  |         return application.refWatcher; | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     protected RefWatcher installLeakCanary() { | ||||||
|  |         return RefWatcher.DISABLED; | ||||||
|  |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -13,6 +13,7 @@ import android.view.View; | |||||||
| import com.nostra13.universalimageloader.core.DisplayImageOptions; | import com.nostra13.universalimageloader.core.DisplayImageOptions; | ||||||
| import com.nostra13.universalimageloader.core.ImageLoader; | import com.nostra13.universalimageloader.core.ImageLoader; | ||||||
| import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer; | import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer; | ||||||
|  | import com.squareup.leakcanary.RefWatcher; | ||||||
|  |  | ||||||
| import icepick.Icepick; | import icepick.Icepick; | ||||||
|  |  | ||||||
| @@ -67,6 +68,14 @@ public abstract class BaseFragment extends Fragment { | |||||||
|     protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { |     protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public void onDestroy() { | ||||||
|  |         super.onDestroy(); | ||||||
|  |  | ||||||
|  |         RefWatcher refWatcher = App.getRefWatcher(getActivity()); | ||||||
|  |         if (refWatcher != null) refWatcher.watch(this); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /*////////////////////////////////////////////////////////////////////////// |     /*////////////////////////////////////////////////////////////////////////// | ||||||
|     // Init |     // Init | ||||||
|     //////////////////////////////////////////////////////////////////////////*/ |     //////////////////////////////////////////////////////////////////////////*/ | ||||||
|   | |||||||
| @@ -20,12 +20,14 @@ | |||||||
|  |  | ||||||
| package org.schabi.newpipe; | package org.schabi.newpipe; | ||||||
|  |  | ||||||
|  | import android.annotation.SuppressLint; | ||||||
| import android.content.Intent; | import android.content.Intent; | ||||||
| import android.content.SharedPreferences; | import android.content.SharedPreferences; | ||||||
| import android.os.Bundle; | import android.os.Bundle; | ||||||
| import android.os.Handler; | import android.os.Handler; | ||||||
| import android.os.Looper; | import android.os.Looper; | ||||||
| import android.preference.PreferenceManager; | import android.preference.PreferenceManager; | ||||||
|  | import android.support.annotation.NonNull; | ||||||
| import android.support.design.widget.NavigationView; | import android.support.design.widget.NavigationView; | ||||||
| import android.support.v4.app.Fragment; | import android.support.v4.app.Fragment; | ||||||
| import android.support.v4.view.GravityCompat; | import android.support.v4.view.GravityCompat; | ||||||
| @@ -39,6 +41,7 @@ import android.view.Menu; | |||||||
| import android.view.MenuInflater; | import android.view.MenuInflater; | ||||||
| import android.view.MenuItem; | import android.view.MenuItem; | ||||||
| import android.view.View; | import android.view.View; | ||||||
|  | import android.widget.Toast; | ||||||
|  |  | ||||||
| import org.schabi.newpipe.extractor.StreamingService; | import org.schabi.newpipe.extractor.StreamingService; | ||||||
| import org.schabi.newpipe.fragments.BackPressable; | import org.schabi.newpipe.fragments.BackPressable; | ||||||
| @@ -211,6 +214,22 @@ public class MainActivity extends AppCompatActivity { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @SuppressLint("ShowToast") | ||||||
|  |     private void onHeapDumpToggled(@NonNull MenuItem item) { | ||||||
|  |         final boolean isHeapDumpEnabled = !item.isChecked(); | ||||||
|  |  | ||||||
|  |         PreferenceManager.getDefaultSharedPreferences(this).edit() | ||||||
|  |                 .putBoolean(getString(R.string.allow_heap_dumping_key), isHeapDumpEnabled).apply(); | ||||||
|  |         item.setChecked(isHeapDumpEnabled); | ||||||
|  |  | ||||||
|  |         final String heapDumpNotice; | ||||||
|  |         if (isHeapDumpEnabled) { | ||||||
|  |             heapDumpNotice = getString(R.string.enable_leak_canary_notice); | ||||||
|  |         } else { | ||||||
|  |             heapDumpNotice = getString(R.string.disable_leak_canary_notice); | ||||||
|  |         } | ||||||
|  |         Toast.makeText(getApplicationContext(), heapDumpNotice, Toast.LENGTH_SHORT).show(); | ||||||
|  |     } | ||||||
|     /*////////////////////////////////////////////////////////////////////////// |     /*////////////////////////////////////////////////////////////////////////// | ||||||
|     // Menu |     // Menu | ||||||
|     //////////////////////////////////////////////////////////////////////////*/ |     //////////////////////////////////////////////////////////////////////////*/ | ||||||
| @@ -232,6 +251,10 @@ public class MainActivity extends AppCompatActivity { | |||||||
|             inflater.inflate(R.menu.main_menu, menu); |             inflater.inflate(R.menu.main_menu, menu); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  |         if (DEBUG) { | ||||||
|  |             getMenuInflater().inflate(R.menu.debug_menu, menu); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         ActionBar actionBar = getSupportActionBar(); |         ActionBar actionBar = getSupportActionBar(); | ||||||
|         if (actionBar != null) { |         if (actionBar != null) { | ||||||
|             actionBar.setDisplayHomeAsUpEnabled(false); |             actionBar.setDisplayHomeAsUpEnabled(false); | ||||||
| @@ -242,6 +265,17 @@ public class MainActivity extends AppCompatActivity { | |||||||
|         return true; |         return true; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     @Override | ||||||
|  |     public boolean onPrepareOptionsMenu(Menu menu) { | ||||||
|  |         MenuItem heapDumpToggle = menu.findItem(R.id.action_toggle_heap_dump); | ||||||
|  |         if (heapDumpToggle != null) { | ||||||
|  |             final boolean isToggled = PreferenceManager.getDefaultSharedPreferences(this) | ||||||
|  |                     .getBoolean(getString(R.string.allow_heap_dumping_key), false); | ||||||
|  |             heapDumpToggle.setChecked(isToggled); | ||||||
|  |         } | ||||||
|  |         return super.onPrepareOptionsMenu(menu); | ||||||
|  |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public boolean onOptionsItemSelected(MenuItem item) { |     public boolean onOptionsItemSelected(MenuItem item) { | ||||||
|         if (DEBUG) Log.d(TAG, "onOptionsItemSelected() called with: item = [" + item + "]"); |         if (DEBUG) Log.d(TAG, "onOptionsItemSelected() called with: item = [" + item + "]"); | ||||||
| @@ -262,6 +296,9 @@ public class MainActivity extends AppCompatActivity { | |||||||
|             case R.id.action_history: |             case R.id.action_history: | ||||||
|                 NavigationHelper.openHistory(this); |                 NavigationHelper.openHistory(this); | ||||||
|                 return true; |                 return true; | ||||||
|  |             case R.id.action_toggle_heap_dump: | ||||||
|  |                 onHeapDumpToggled(item); | ||||||
|  |                 return true; | ||||||
|             default: |             default: | ||||||
|                 return super.onOptionsItemSelected(item); |                 return super.onOptionsItemSelected(item); | ||||||
|         } |         } | ||||||
|   | |||||||
							
								
								
									
										12
									
								
								app/src/main/res/menu/debug_menu.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								app/src/main/res/menu/debug_menu.xml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <menu xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     xmlns:app="http://schemas.android.com/apk/res-auto"> | ||||||
|  |  | ||||||
|  |     <item android:id="@+id/action_toggle_heap_dump" | ||||||
|  |         android:orderInCategory="9999" | ||||||
|  |         android:checkable="true" | ||||||
|  |         android:title="@string/toggle_leak_canary" | ||||||
|  |         android:visible="true" | ||||||
|  |         app:showAsAction="never"/> | ||||||
|  |  | ||||||
|  | </menu> | ||||||
| @@ -83,6 +83,9 @@ | |||||||
|  |  | ||||||
|     <string name="last_orientation_landscape_key" translatable="false">last_orientation_landscape_key</string> |     <string name="last_orientation_landscape_key" translatable="false">last_orientation_landscape_key</string> | ||||||
|  |  | ||||||
|  |     <!-- DEBUG ONLY --> | ||||||
|  |     <string name="allow_heap_dumping_key" translatable="false">allow_heap_dumping_key</string> | ||||||
|  |  | ||||||
|     <!-- THEMES --> |     <!-- THEMES --> | ||||||
|     <string name="theme_key" translatable="false">theme</string> |     <string name="theme_key" translatable="false">theme</string> | ||||||
|     <string name="light_theme_key" translatable="false">light_theme</string> |     <string name="light_theme_key" translatable="false">light_theme</string> | ||||||
|   | |||||||
| @@ -410,4 +410,8 @@ | |||||||
|     <string name="normal_caption_font_size">Normal Font</string> |     <string name="normal_caption_font_size">Normal Font</string> | ||||||
|     <string name="larger_caption_font_size">Larger Font</string> |     <string name="larger_caption_font_size">Larger Font</string> | ||||||
|  |  | ||||||
|  |     <!-- Debug Only --> | ||||||
|  |     <string name="toggle_leak_canary">Monitor Leaks</string> | ||||||
|  |     <string name="enable_leak_canary_notice">Memory leak monitoring enabled, app may become unresponsive when heap dumping</string> | ||||||
|  |     <string name="disable_leak_canary_notice">Memory leak monitoring disabled</string> | ||||||
| </resources> | </resources> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Christian Schabesberger
					Christian Schabesberger