-Changed leak canary toggle text to "monitor leaks".

-Added toast when enabling/disabling heap dumping.
This commit is contained in:
John Zhen Mo 2018-02-10 12:24:23 -08:00
parent 829059ea01
commit e7d148336b
2 changed files with 18 additions and 5 deletions

View file

@ -20,6 +20,7 @@
package org.schabi.newpipe;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
@ -39,6 +40,7 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.fragments.BackPressable;
@ -211,11 +213,20 @@ public class MainActivity extends AppCompatActivity {
}
}
@SuppressLint("ShowToast")
private void onHeapDumpToggled(@NonNull MenuItem item) {
final boolean newToggleState = !item.isChecked();
sharedPreferences.edit().putBoolean(getString(R.string.allow_heap_dumping_key),
newToggleState).apply();
item.setChecked(newToggleState);
final boolean isHeapDumpEnabled = !item.isChecked();
sharedPreferences.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

View file

@ -397,5 +397,7 @@
<string name="playlist_delete_failure">Failed to delete playlist</string>
<!-- Debug Only -->
<string name="toggle_leak_canary">Leak Canary</string>
<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>