mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-12-23 08:30:44 +00:00
Made debug settings searchable (debug only)
* Consolidated main-setttings into a single file * Debug settings are only enabled in the DEBUG build * Moved LeakCanary (debug) specific stuff into a small class that's only shipped with the debug build * Other minor fixes
This commit is contained in:
parent
d59314801c
commit
6b23df0659
@ -1,5 +1,6 @@
|
||||
package org.schabi.newpipe.settings;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
@ -10,13 +11,15 @@ import org.schabi.newpipe.error.ErrorUtil;
|
||||
import org.schabi.newpipe.error.UserAction;
|
||||
import org.schabi.newpipe.util.PicassoHelper;
|
||||
|
||||
import leakcanary.LeakCanary;
|
||||
import java.util.Optional;
|
||||
|
||||
public class DebugSettingsFragment extends BasePreferenceFragment {
|
||||
@Override
|
||||
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
|
||||
addPreferencesFromResource(R.xml.debug_settings);
|
||||
addPreferencesFromResourceRegistry();
|
||||
|
||||
final Preference allowHeapDumpingPreference
|
||||
= findPreference(getString(R.string.allow_heap_dumping_key));
|
||||
final Preference showMemoryLeaksPreference
|
||||
= findPreference(getString(R.string.show_memory_leaks_key));
|
||||
final Preference showImageIndicatorsPreference
|
||||
@ -28,16 +31,29 @@ public class DebugSettingsFragment extends BasePreferenceFragment {
|
||||
final Preference createErrorNotificationPreference
|
||||
= findPreference(getString(R.string.create_error_notification_key));
|
||||
|
||||
assert allowHeapDumpingPreference != null;
|
||||
assert showMemoryLeaksPreference != null;
|
||||
assert showImageIndicatorsPreference != null;
|
||||
assert crashTheAppPreference != null;
|
||||
assert showErrorSnackbarPreference != null;
|
||||
assert createErrorNotificationPreference != null;
|
||||
|
||||
showMemoryLeaksPreference.setOnPreferenceClickListener(preference -> {
|
||||
startActivity(LeakCanary.INSTANCE.newLeakDisplayActivityIntent());
|
||||
return true;
|
||||
});
|
||||
final Optional<DebugSettingsBVLeakCanaryAPI> optPDLeakCanary = getBVLeakCanary();
|
||||
|
||||
allowHeapDumpingPreference.setEnabled(optPDLeakCanary.isPresent());
|
||||
showMemoryLeaksPreference.setEnabled(optPDLeakCanary.isPresent());
|
||||
|
||||
if (optPDLeakCanary.isPresent()) {
|
||||
final DebugSettingsBVLeakCanaryAPI pdLeakCanary = optPDLeakCanary.get();
|
||||
|
||||
showMemoryLeaksPreference.setOnPreferenceClickListener(preference -> {
|
||||
startActivity(pdLeakCanary.getNewLeakDisplayActivityIntent());
|
||||
return true;
|
||||
});
|
||||
} else {
|
||||
allowHeapDumpingPreference.setSummary(R.string.leak_canary_not_available);
|
||||
showMemoryLeaksPreference.setSummary(R.string.leak_canary_not_available);
|
||||
}
|
||||
|
||||
showImageIndicatorsPreference.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
PicassoHelper.setIndicatorsEnabled((Boolean) newValue);
|
||||
@ -60,4 +76,26 @@ public class DebugSettingsFragment extends BasePreferenceFragment {
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
private Optional<DebugSettingsBVLeakCanaryAPI> getBVLeakCanary() {
|
||||
try {
|
||||
// Try to find the implementation of the LeakCanary API
|
||||
return Optional.of((DebugSettingsBVLeakCanaryAPI)
|
||||
Class.forName(DebugSettingsBVLeakCanaryAPI.IMPL_CLASS).newInstance());
|
||||
} catch (final ClassNotFoundException
|
||||
| IllegalAccessException | java.lang.InstantiationException e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build variant dependent leak canary API for this fragment.
|
||||
* Why is LeakCanary not used directly? Because it can't be assured
|
||||
*/
|
||||
public interface DebugSettingsBVLeakCanaryAPI {
|
||||
String IMPL_CLASS =
|
||||
"org.schabi.newpipe.settings.DebugSettingsBVLeakCanary";
|
||||
|
||||
Intent getNewLeakDisplayActivityIntent();
|
||||
}
|
||||
}
|
@ -6,7 +6,6 @@ import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import org.schabi.newpipe.App;
|
||||
import org.schabi.newpipe.CheckForNewAppVersion;
|
||||
@ -26,12 +25,17 @@ public class MainSettingsFragment extends BasePreferenceFragment {
|
||||
|
||||
// Check if the app is updatable
|
||||
if (!CheckForNewAppVersion.isReleaseApk(App.getApp())) {
|
||||
final Preference update
|
||||
= findPreference(getString(R.string.update_pref_screen_key));
|
||||
getPreferenceScreen().removePreference(update);
|
||||
getPreferenceScreen().removePreference(
|
||||
findPreference(getString(R.string.update_pref_screen_key)));
|
||||
|
||||
defaultPreferences.edit().putBoolean(getString(R.string.update_app_key), false).apply();
|
||||
}
|
||||
|
||||
// Hide debug preferences in RELEASE build variant
|
||||
if (!DEBUG) {
|
||||
getPreferenceScreen().removePreference(
|
||||
findPreference(getString(R.string.debug_pref_screen_key)));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -217,6 +217,13 @@ public class SettingsActivity extends AppCompatActivity implements
|
||||
.getEntryByPreferencesResId(R.xml.update_settings)
|
||||
.setSearchable(false);
|
||||
}
|
||||
|
||||
// Hide debug preferences in RELEASE build variant
|
||||
if (DEBUG) {
|
||||
SettingsResourceRegistry.getInstance()
|
||||
.getEntryByPreferencesResId(R.xml.debug_settings)
|
||||
.setSearchable(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void setMenuSearchItem(final MenuItem menuSearchItem) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.schabi.newpipe.settings;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.XmlRes;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
@ -34,6 +33,7 @@ public final class SettingsResourceRegistry {
|
||||
|
||||
add(AppearanceSettingsFragment.class, R.xml.appearance_settings);
|
||||
add(ContentSettingsFragment.class, R.xml.content_settings);
|
||||
add(DebugSettingsFragment.class, R.xml.debug_settings).setSearchable(false);
|
||||
add(DownloadSettingsFragment.class, R.xml.download_settings);
|
||||
add(HistorySettingsFragment.class, R.xml.history_settings);
|
||||
add(NotificationSettingsFragment.class, R.xml.notification_settings);
|
||||
@ -51,7 +51,6 @@ public final class SettingsResourceRegistry {
|
||||
return entry;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public SettingRegistryEntry getEntryByFragmentClass(
|
||||
final Class<? extends Fragment> fragmentClass
|
||||
) {
|
||||
@ -62,7 +61,6 @@ public final class SettingsResourceRegistry {
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public SettingRegistryEntry getEntryByPreferencesResId(@XmlRes final int preferencesResId) {
|
||||
return registeredEntries.stream()
|
||||
.filter(e -> Objects.equals(e.getPreferencesResId(), preferencesResId))
|
||||
@ -78,7 +76,6 @@ public final class SettingsResourceRegistry {
|
||||
return entry.getPreferencesResId();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public Class<? extends Fragment> getFragmentClass(@XmlRes final int preferencesResId) {
|
||||
final SettingRegistryEntry entry = getEntryByPreferencesResId(preferencesResId);
|
||||
if (entry == null) {
|
||||
|
@ -441,6 +441,7 @@
|
||||
<string name="caption_setting_title">Captions</string>
|
||||
<string name="caption_setting_description">Modify player caption text scale and background styles. Requires app restart to take effect</string>
|
||||
<!-- Debug Settings -->
|
||||
<string name="leak_canary_not_available">LeakCanary is not available</string>
|
||||
<string name="enable_leak_canary_summary">Memory leak monitoring may cause the app to become unresponsive when heap dumping</string>
|
||||
<string name="show_memory_leaks">Show memory leaks</string>
|
||||
<string name="enable_disposed_exceptions_title">Report out-of-lifecycle errors</string>
|
||||
|
@ -1,49 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:key="general_preferences"
|
||||
android:title="@string/settings">
|
||||
|
||||
<PreferenceScreen
|
||||
android:fragment="org.schabi.newpipe.settings.VideoAudioSettingsFragment"
|
||||
android:icon="@drawable/ic_headset"
|
||||
android:title="@string/settings_category_video_audio_title"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:fragment="org.schabi.newpipe.settings.DownloadSettingsFragment"
|
||||
android:icon="@drawable/ic_file_download"
|
||||
android:title="@string/settings_category_downloads_title"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:fragment="org.schabi.newpipe.settings.AppearanceSettingsFragment"
|
||||
android:icon="@drawable/ic_palette"
|
||||
android:title="@string/settings_category_appearance_title"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:fragment="org.schabi.newpipe.settings.HistorySettingsFragment"
|
||||
android:icon="@drawable/ic_history"
|
||||
android:title="@string/settings_category_history_title"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:fragment="org.schabi.newpipe.settings.ContentSettingsFragment"
|
||||
android:icon="@drawable/ic_language"
|
||||
android:title="@string/content"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:fragment="org.schabi.newpipe.settings.NotificationSettingsFragment"
|
||||
android:icon="@drawable/ic_play_arrow"
|
||||
android:title="@string/settings_category_notification_title"
|
||||
app:iconSpaceReserved="false" />
|
||||
|
||||
<PreferenceScreen
|
||||
android:fragment="org.schabi.newpipe.settings.UpdateSettingsFragment"
|
||||
android:icon="@drawable/ic_cloud_download"
|
||||
android:key="update_pref_screen_key"
|
||||
android:title="@string/settings_category_updates_title"
|
||||
app:iconSpaceReserved="false" />
|
||||
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user