-Added debug preference settings for debug and beta builds.

-Removed leak canary toggle on app menu.
-Added leak canary settings to debug preference.
-Removed/renamed leak canary related strings.
This commit is contained in:
John Zhen Mo 2018-02-20 05:45:12 -08:00
parent c1a302834c
commit e8402008bc
14 changed files with 48 additions and 76 deletions

View File

@ -20,7 +20,6 @@
package org.schabi.newpipe;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
@ -28,7 +27,6 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment;
import android.support.v4.view.GravityCompat;
@ -264,22 +262,6 @@ 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
//////////////////////////////////////////////////////////////////////////*/
@ -301,10 +283,6 @@ public class MainActivity extends AppCompatActivity {
inflater.inflate(R.menu.main_menu, menu);
}
if (DEBUG) {
getMenuInflater().inflate(R.menu.debug_menu, menu);
}
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(false);
@ -315,17 +293,6 @@ public class MainActivity extends AppCompatActivity {
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
public boolean onOptionsItemSelected(MenuItem item) {
if (DEBUG) Log.d(TAG, "onOptionsItemSelected() called with: item = [" + item + "]");
@ -346,9 +313,6 @@ public class MainActivity extends AppCompatActivity {
case R.id.action_history:
NavigationHelper.openHistory(this);
return true;
case R.id.action_toggle_heap_dump:
onHeapDumpToggled(item);
return true;
default:
return super.onOptionsItemSelected(item);
}

View File

@ -0,0 +1,12 @@
package org.schabi.newpipe.settings;
import android.os.Bundle;
import org.schabi.newpipe.R;
public class DebugSettingsFragment extends BasePreferenceFragment {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.debug_settings);
}
}

View File

@ -3,11 +3,19 @@ package org.schabi.newpipe.settings;
import android.os.Bundle;
import android.support.v7.preference.Preference;
import org.schabi.newpipe.BuildConfig;
import org.schabi.newpipe.R;
public class MainSettingsFragment extends BasePreferenceFragment {
public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release");
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.main_settings);
if (!DEBUG) {
final Preference debug = findPreference(getString(R.string.debug_pref_screen_key));
getPreferenceScreen().removePreference(debug);
}
}
}

View File

@ -1,12 +0,0 @@
<?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>

View File

@ -395,9 +395,6 @@
<string name="normal_caption_font_size">Carattere normale</string>
<string name="larger_caption_font_size">Carattere più grande</string>
<string name="enable_leak_canary_notice">Controllo delle perdite di memoria abilitato, l\'applicazione può non rispondere mentre effettua il dumping dell\'heap</string>
<string name="disable_leak_canary_notice">Controllo delle perdite di memoria disabilitato</string>
<string name="drawer_header_action_paceholder_text">A breve qualcosa si troverà qui ;D</string>
<string name="drawer_header_action_paceholder_text">A breve qualcosa si troverà qui ;D</string>
</resources>
</resources>

View File

@ -382,7 +382,4 @@
<string name="smaller_caption_font_size">Mindre skrift</string>
<string name="normal_caption_font_size">Normal skrift</string>
<string name="larger_caption_font_size">Større skrift</string>
<string name="enable_leak_canary_notice">Oppsyn med minnelekasjer påslått, programmet kan slutte å svare under haug-dumping</string>
<string name="disable_leak_canary_notice">Oppsyn med minnelekasjer slått av</string>
</resources>

View File

@ -391,9 +391,5 @@ te openen in pop-upmodus</string>
<string name="normal_caption_font_size">Normaal lettertype</string>
<string name="larger_caption_font_size">Groter lettertype</string>
<string name="enable_leak_canary_notice">Controleren op geheugenlekken ingeschakeld, tijdens heapdumping kan de app tijdelijk niet reageren</string>
<string name="disable_leak_canary_notice">Controleren op geheugenlekken uitgeschakeld</string>
<string name="drawer_header_action_paceholder_text">Hier zal binnenkort iets verschijnen ;D</string>
</resources>
<string name="drawer_header_action_paceholder_text">Hier zal binnenkort iets verschijnen ;D</string>
</resources>

View File

@ -368,7 +368,4 @@ abrir em modo popup</string>
<string name="smaller_caption_font_size">Fonte menor</string>
<string name="normal_caption_font_size">Fonte normal</string>
<string name="larger_caption_font_size">Maior fonte</string>
<string name="enable_leak_canary_notice">Monitoramento de vazamentos de memória habilitado, o aplicativo pode ficar sem responder quando estiver descarregando pilha de memória</string>
<string name="disable_leak_canary_notice">Monitoramento de vazamentos de memória desabilitado</string>
</resources>

View File

@ -391,8 +391,4 @@ otvorenie okna na popredí</string>
<string name="smaller_caption_font_size">Menšie Písmo</string>
<string name="normal_caption_font_size">Normálne Písmo</string>
<string name="larger_caption_font_size">Väčšie Písmo</string>
<string name="toggle_leak_canary">Monitorovanie pretečenia</string>
<string name="enable_leak_canary_notice">Monitorovanie pretečenia pamäte je povolené, pri hromadnom zbere môže aplikácia prestať reagovať</string>
<string name="disable_leak_canary_notice">Monitorovanie pretečenia pamäte je vypnuté</string>
</resources>

View File

@ -384,7 +384,4 @@
<string name="smaller_caption_font_size">Küçük Yazı Tipi</string>
<string name="normal_caption_font_size">Olağan Yazı Tipi</string>
<string name="larger_caption_font_size">Büyük Yazı Tipi</string>
<string name="enable_leak_canary_notice">Bellek sızıntısı gözlemleme etkinleştirildi, uygulama yığın atımı sırasında yanıtsız kalabilir</string>
<string name="disable_leak_canary_notice">Bellek sızıntısı gözlemleme devre dışı</string>
</resources>

View File

@ -84,6 +84,7 @@
<string name="last_orientation_landscape_key" translatable="false">last_orientation_landscape_key</string>
<!-- DEBUG ONLY -->
<string name="debug_pref_screen_key" translatable="false">debug_pref_screen_key</string>
<string name="allow_heap_dumping_key" translatable="false">allow_heap_dumping_key</string>
<!-- THEMES -->

View File

@ -98,6 +98,7 @@
<string name="settings_category_popup_title">Popup</string>
<string name="settings_category_appearance_title">Appearance</string>
<string name="settings_category_other_title">Other</string>
<string name="settings_category_debug_title">Debug</string>
<string name="background_player_playing_toast">Playing in background</string>
<string name="popup_playing_toast">Playing in popup mode</string>
<string name="background_player_append">Queued on background player</string>
@ -412,8 +413,7 @@
<string name="normal_caption_font_size">Normal Font</string>
<string name="larger_caption_font_size">Larger Font</string>
<!-- Debug Only -->
<string name="toggle_leak_canary" translatable="false">LeakCanary</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>
<!-- Debug Settings -->
<string name="enable_leak_canary_title">Enable LeakCanary</string>
<string name="enable_leak_canary_summary">Memory leak monitoring may cause app to become unresponsive when heap dumping</string>
</resources>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="general_preferences"
android:title="@string/settings_category_debug_title">
<SwitchPreference
android:defaultValue="false"
android:key="@string/allow_heap_dumping_key"
android:title="@string/enable_leak_canary_title"
android:summary="@string/enable_leak_canary_summary"/>
</PreferenceScreen>

View File

@ -28,4 +28,10 @@
android:fragment="org.schabi.newpipe.settings.ContentSettingsFragment"
android:icon="?attr/language"
android:title="@string/content"/>
<PreferenceScreen
android:fragment="org.schabi.newpipe.settings.DebugSettingsFragment"
android:icon="?attr/info"
android:title="@string/settings_category_debug_title"
android:key="@string/debug_pref_screen_key"/>
</PreferenceScreen>