Skip to content

Commit

Permalink
plusonelabs#325 Hide Color preferences that are unused (day headers d…
Browse files Browse the repository at this point in the history
…isabled or no past events/tasks shown)
  • Loading branch information
yvolk committed Sep 16, 2019
1 parent 29bbff3 commit 47af3c5
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private static void configureNoEvents(InstanceSettings settings, RemoteViews rv)
}
setTextSize(settings, rv, viewId, R.dimen.event_entry_details);
setBackgroundColor(rv, viewId, settings.getEventsBackgroundColor());
setTextColorFromAttr(settings.getShadingContext(TextShadingPref.ENTRY), rv, viewId, R.attr.eventEntryTitle);
setTextColorFromAttr(settings.getShadingContext(TextShadingPref.ENTRY_TODAY), rv, viewId, R.attr.eventEntryTitle);
}

private static List<Integer> asList(final int[] is) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ public static void setWidgetId(Context context, int value) {
setInt(context, PREF_WIDGET_ID, value);
}

public static boolean noTaskSources(Context context) {
List<EventSource> sources = getActiveEventSources(context);
for(EventSource source: sources) {
if (!source.providerType.isCalendar) return false;
}
return true;
}

public static List<EventSource> getActiveEventSources(Context context) {
return EventSource.fromStringSet(PreferenceManager.getDefaultSharedPreferences(context)
.getStringSet(PREF_ACTIVE_SOURCES, null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;

import org.andstatus.todoagenda.EndedSomeTimeAgo;
import org.andstatus.todoagenda.R;
import org.andstatus.todoagenda.TextShading;
import org.andstatus.todoagenda.widget.TimeSection;

public class ColorsPreferencesFragment extends PreferenceFragment
implements SharedPreferences.OnSharedPreferenceChangeListener {

private boolean hideDayHeader;
private boolean hidePast;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -21,10 +29,21 @@ public void onCreate(Bundle savedInstanceState) {
public void onResume() {
super.onResume();
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
hideDayHeader = !ApplicationPreferences.getShowDayHeaders(getActivity());
hidePast = !ApplicationPreferences.getShowPastEventsWithDefaultColor(getActivity()) &&
ApplicationPreferences.getEventsEnded(getActivity()) == EndedSomeTimeAgo.NONE &&
ApplicationPreferences.noTaskSources(getActivity());
showShadings();
}

private void showShadings() {
if (hidePast) {
PreferenceScreen screen = getPreferenceScreen();
Preference preference = findPreference(TimeSection.PAST.preferenceCategoryKey);
if (screen != null && preference != null) {
screen.removePreference(preference);
}
}
for (TextShadingPref shadingPref : TextShadingPref.values()) {
showShading(shadingPref);
}
Expand All @@ -45,7 +64,14 @@ private void showShading(TextShadingPref prefs) {
ListPreference preference = (ListPreference) findPreference(prefs.preferenceName);
if (preference != null) {
TextShading shading = TextShading.fromName(preference.getValue(), prefs.defaultShading);
preference.setSummary(getActivity().getString(shading.titleResId));
if (hideDayHeader && prefs.dependsOnDayHeader) {
PreferenceCategory category = (PreferenceCategory) findPreference(prefs.timeSection.preferenceCategoryKey);
if (category != null) {
category.removePreference(preference);
}
} else {
preference.setSummary(getActivity().getString(shading.titleResId));
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,50 @@

import org.andstatus.todoagenda.R;
import org.andstatus.todoagenda.TextShading;
import org.andstatus.todoagenda.widget.TimeSection;
import org.andstatus.todoagenda.widget.WidgetEntry;

import androidx.annotation.StringRes;

public enum TextShadingPref {

WIDGET_HEADER("headerTheme", TextShading.DARK, R.string.appearance_header_theme_title),
DAY_HEADER_PAST("dayHeaderThemePast", TextShading.DARK, R.string.day_header_theme_title),
DAY_HEADER("dayHeaderTheme", TextShading.DARK, R.string.day_header_theme_title),
DAY_HEADER_FUTURE("dayHeaderThemeFuture", TextShading.DARK, R.string.day_header_theme_title),
ENTRY_PAST("entryThemePast", TextShading.BLACK, R.string.appearance_entries_theme_title),
ENTRY("entryTheme", TextShading.BLACK, R.string.appearance_entries_theme_title),
ENTRY_FUTURE("entryThemeFuture", TextShading.BLACK, R.string.appearance_entries_theme_title);
WIDGET_HEADER("headerTheme", TextShading.DARK, R.string.appearance_header_theme_title,
false, TimeSection.ALL),
DAY_HEADER_PAST("dayHeaderThemePast", TextShading.DARK, R.string.day_header_theme_title,
true, TimeSection.PAST),
DAY_HEADER_TODAY("dayHeaderTheme", TextShading.DARK, R.string.day_header_theme_title,
true, TimeSection.TODAY),
DAY_HEADER_FUTURE("dayHeaderThemeFuture", TextShading.DARK, R.string.day_header_theme_title,
true, TimeSection.FUTURE),
ENTRY_PAST("entryThemePast", TextShading.BLACK, R.string.appearance_entries_theme_title,
false, TimeSection.PAST),
ENTRY_TODAY("entryTheme", TextShading.BLACK, R.string.appearance_entries_theme_title,
false, TimeSection.TODAY),
ENTRY_FUTURE("entryThemeFuture", TextShading.BLACK, R.string.appearance_entries_theme_title,
false, TimeSection.FUTURE);

public final String preferenceName;
public final TextShading defaultShading;
@StringRes
public final int titleResId;
public final boolean dependsOnDayHeader;
public final TimeSection timeSection;

TextShadingPref(String preferenceName, TextShading defaultShading, int titleResId) {
TextShadingPref(String preferenceName, TextShading defaultShading, int titleResId,
boolean dependsOnDayHeader, TimeSection timeSection) {
this.preferenceName = preferenceName;
this.defaultShading = defaultShading;
this.titleResId = titleResId;
this.dependsOnDayHeader = dependsOnDayHeader;
this.timeSection = timeSection;
}

public static TextShadingPref getDayHeader(WidgetEntry<?> entry) {
return entry.getTimeSection().select(DAY_HEADER_PAST, DAY_HEADER, DAY_HEADER_FUTURE);
return entry.getTimeSection().select(DAY_HEADER_PAST, DAY_HEADER_TODAY, DAY_HEADER_FUTURE);
}

public static TextShadingPref getEntry(WidgetEntry<?> entry) {
return entry.getTimeSection().select(ENTRY_PAST, ENTRY, ENTRY_FUTURE);
return entry.getTimeSection().select(ENTRY_PAST, ENTRY_TODAY, ENTRY_FUTURE);
}

}
13 changes: 10 additions & 3 deletions app/src/main/java/org/andstatus/todoagenda/widget/TimeSection.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package org.andstatus.todoagenda.widget;

public enum TimeSection {
PAST,
TODAY,
FUTURE;
PAST("PastTime"),
TODAY("TodayTime"),
FUTURE("FutureTime"),
ALL("AllTime");

public final String preferenceCategoryKey;

TimeSection(String preferenceCategoryKey) {
this.preferenceCategoryKey = preferenceCategoryKey;
}

public <T> T select(T past, T today, T future) {
switch (this) {
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/xml/preferences_colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
app:colorpicker_selectNoneButtonText="@string/default_value" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/past_events">
<PreferenceCategory android:title="@string/past_events" android:key="PastTime">
<ListPreference
android:key="dayHeaderThemePast"
android:defaultValue="DARK"
Expand All @@ -43,7 +43,7 @@
app:colorpicker_selectNoneButtonText="@string/default_value" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/todays_events">
<PreferenceCategory android:title="@string/todays_events" android:key="TodayTime">
<ListPreference
android:key="dayHeaderTheme"
android:defaultValue="DARK"
Expand All @@ -68,7 +68,7 @@
app:colorpicker_selectNoneButtonText="@string/default_value" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/future_events">
<PreferenceCategory android:title="@string/future_events" android:key="FutureTime">
<ListPreference
android:key="dayHeaderThemeFuture"
android:defaultValue="DARK"
Expand Down

0 comments on commit 47af3c5

Please sign in to comment.