Skip to content

Commit

Permalink
Keep other category preferences enabled on disable
Browse files Browse the repository at this point in the history
See #29

The preferences under the "Other" PreferenceCategory will no longer be
disabled when Red Moon is disabled.
  • Loading branch information
raatmarien committed Apr 7, 2016
1 parent 3656bc8 commit 4483824
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public class ShadesFragment extends PreferenceFragment {
private FilterTimePreference automaticTurnOnPref;
private FilterTimePreference automaticTurnOffPref;
private LocationPreference locationPref;
private Preference otherPrefCategory;

private boolean searchingLocation;

Expand All @@ -105,6 +106,7 @@ public void onCreate(Bundle savedInstanceState) {
String automaticTurnOnPrefKey = getString(R.string.pref_key_custom_start_time);
String automaticTurnOffPrefKey = getString(R.string.pref_key_custom_end_time);
String locationPrefKey = getString(R.string.pref_key_location);
String otherCategoryPrefKey = getString(R.string.pref_key_other);

PreferenceScreen prefScreen = getPreferenceScreen();
darkThemePref = (SwitchPreference) prefScreen.findPreference(darkThemePrefKey);
Expand All @@ -113,6 +115,7 @@ public void onCreate(Bundle savedInstanceState) {
automaticTurnOnPref = (FilterTimePreference) prefScreen.findPreference(automaticTurnOnPrefKey);
automaticTurnOffPref = (FilterTimePreference) prefScreen.findPreference(automaticTurnOffPrefKey);
locationPref = (LocationPreference) prefScreen.findPreference(locationPrefKey);
otherPrefCategory = prefScreen.findPreference(otherCategoryPrefKey);

darkThemePref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
Expand Down Expand Up @@ -272,7 +275,7 @@ public void setSwitchOn(boolean powerState, boolean pauseState) {
updateFabIcon();

if (!powerState) {
disableAllPreferences();
disableFilterPreferences();
} else {
setPreferencesEnabled();
}
Expand All @@ -294,6 +297,11 @@ private void updateFabIcon() {
}
}

private void disableFilterPreferences() {
disableAllPreferences();
otherPrefCategory.setEnabled(true);
}

private void disableAllPreferences() {
PreferenceScreen root = getPreferenceScreen();
for (int i = 0; i < root.getPreferenceCount(); i++) {
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/donottranslate_prefkeys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,8 @@
<string name="pref_key_custom_start_time">pref_key_custom_start_time</string>
<string name="pref_key_custom_end_time">pref_key_custom_end_time</string>
<string name="pref_key_location">pref_key_location</string>
<string name="pref_key_github">pref_key_github</string>
<string name="pref_key_email">pref_key_email</string>
<string name="pref_key_other">pref_key_other</string>

</resources>
5 changes: 4 additions & 1 deletion app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,15 @@
android:defaultValue="not set" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/pref_title_other">
<PreferenceCategory android:title="@string/pref_title_other"
android:key="pref_key_other" >
<SwitchPreference
android:key="@string/pref_key_dark_theme"
android:title="@string/dark_theme"
android:defaultValue="false" />

<Preference
android:key="pref_key_github"
android:title="@string/project_page_title"
android:summary="@string/project_page_summary" >
<intent
Expand All @@ -98,6 +100,7 @@
</Preference>

<Preference
android:key="pref_key_email"
android:title="@string/email_me_title"
android:summary="@string/email_me_summary">
<intent
Expand Down

0 comments on commit 4483824

Please sign in to comment.