From f0e45c71f5e69aa71fe2200e9d6faba3a47784fa Mon Sep 17 00:00:00 2001 From: Ricki Hirner Date: Thu, 31 Mar 2016 20:07:36 +0200 Subject: [PATCH] Add account setting: manage calendar colors --- app/build.gradle | 4 ++-- .../at/bitfire/davdroid/AccountSettings.java | 20 ++++++++++++++++--- .../davdroid/resource/LocalCalendar.java | 12 ++++++----- .../CalendarsSyncAdapterService.java | 8 ++++++-- .../davdroid/ui/AccountSettingsActivity.java | 10 ++++++++++ app/src/main/res/values-de/strings.xml | 3 +++ app/src/main/res/values/strings.xml | 3 +++ app/src/main/res/xml/settings_account.xml | 7 +++++++ 8 files changed, 55 insertions(+), 12 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index e2007252..cdb397eb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -17,8 +17,8 @@ android { minSdkVersion 14 targetSdkVersion 22 - versionCode 94 - versionName "1.0.4" + versionCode 95 + versionName "1.0.5" buildConfigField "long", "buildTime", System.currentTimeMillis() + "L" } diff --git a/app/src/main/java/at/bitfire/davdroid/AccountSettings.java b/app/src/main/java/at/bitfire/davdroid/AccountSettings.java index 04b23fe7..239c1a1a 100644 --- a/app/src/main/java/at/bitfire/davdroid/AccountSettings.java +++ b/app/src/main/java/at/bitfire/davdroid/AccountSettings.java @@ -60,13 +60,18 @@ public class AccountSettings { KEY_AUTH_PREEMPTIVE = "auth_preemptive"; /** Time range limitation to the past [in days] - value = null default value (DEFAULT_TIME_RANGE_PAST_DAYS) - < 0 (-1) no limit - >= 0 entries more than n days in the past won't be synchronized + value = null default value (DEFAULT_TIME_RANGE_PAST_DAYS) + < 0 (-1) no limit + >= 0 entries more than n days in the past won't be synchronized */ private final static String KEY_TIME_RANGE_PAST_DAYS = "time_range_past_days"; private final static int DEFAULT_TIME_RANGE_PAST_DAYS = 90; + /* Whether DAVdroid sets the local calendar color to the value from service DB at every sync + value = null (not existing) true (default) + "0" false */ + private final static String KEY_MANAGE_CALENDAR_COLORS = "manage_calendar_colors"; + public final static long SYNC_INTERVAL_MANUALLY = -1; final Context context; @@ -172,6 +177,15 @@ public class AccountSettings { accountManager.setUserData(account, KEY_TIME_RANGE_PAST_DAYS, String.valueOf(days == null ? -1 : days)); } + public boolean getManageCalendarColors() { + String manage = accountManager.getUserData(account, KEY_MANAGE_CALENDAR_COLORS); + return manage == null; + } + + public void setManageCalendarColors(boolean manage) { + accountManager.setUserData(account, KEY_MANAGE_CALENDAR_COLORS, manage ? null : "0"); + } + // update from previous account settings diff --git a/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java b/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java index eca6f597..5d99acfd 100644 --- a/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java +++ b/app/src/main/java/at/bitfire/davdroid/resource/LocalCalendar.java @@ -73,7 +73,7 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection { } public static Uri create(@NonNull Account account, @NonNull ContentProviderClient provider, @NonNull CollectionInfo info) throws CalendarStorageException { - ContentValues values = valuesFromCollectionInfo(info); + ContentValues values = valuesFromCollectionInfo(info, true); // ACCOUNT_NAME and ACCOUNT_TYPE are required (see docs)! If it's missing, other apps will crash. values.put(Calendars.ACCOUNT_NAME, account.name); @@ -87,16 +87,18 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection { return create(account, provider, values); } - public void update(CollectionInfo info) throws CalendarStorageException { - update(valuesFromCollectionInfo(info)); + public void update(CollectionInfo info, boolean updateColor) throws CalendarStorageException { + update(valuesFromCollectionInfo(info, updateColor)); } @TargetApi(15) - private static ContentValues valuesFromCollectionInfo(CollectionInfo info) { + private static ContentValues valuesFromCollectionInfo(CollectionInfo info, boolean withColor) { ContentValues values = new ContentValues(); values.put(Calendars.NAME, info.url); values.put(Calendars.CALENDAR_DISPLAY_NAME, !TextUtils.isEmpty(info.displayName) ? info.displayName : DavUtils.lastSegmentOfUrl(info.url)); - values.put(Calendars.CALENDAR_COLOR, info.color != null ? info.color : defaultColor); + + if (withColor) + values.put(Calendars.CALENDAR_COLOR, info.color != null ? info.color : defaultColor); if (info.readOnly) values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ); diff --git a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java index 5028ba1d..30df6bc6 100644 --- a/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java +++ b/app/src/main/java/at/bitfire/davdroid/syncadapter/CalendarsSyncAdapterService.java @@ -24,6 +24,7 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.logging.Level; +import at.bitfire.davdroid.AccountSettings; import at.bitfire.davdroid.App; import at.bitfire.davdroid.InvalidAccountException; import at.bitfire.davdroid.model.CollectionInfo; @@ -70,12 +71,15 @@ public class CalendarsSyncAdapterService extends SyncAdapterService { App.log.info("Calendar sync complete"); } - private void updateLocalCalendars(ContentProviderClient provider, Account account) throws CalendarStorageException { + private void updateLocalCalendars(ContentProviderClient provider, Account account) throws CalendarStorageException, InvalidAccountException { // enumerate remote and local calendars Long service = getService(account); Map remote = remoteCalendars(service); LocalCalendar[] local = (LocalCalendar[])LocalCalendar.find(account, provider, LocalCalendar.Factory.INSTANCE, null, null); + AccountSettings settings = new AccountSettings(getContext(), account); + boolean updateColors = settings.getManageCalendarColors(); + // delete obsolete local calendar for (LocalCalendar calendar : local) { String url = calendar.getName(); @@ -86,7 +90,7 @@ public class CalendarsSyncAdapterService extends SyncAdapterService { // remote CollectionInfo found for this local collection, update data CollectionInfo info = remote.get(url); App.log.fine("Updating local calendar " + url + " with " + info); - calendar.update(info); + calendar.update(info, updateColors); // we already have a local calendar for this remote collection, don't take into consideration anymore remote.remove(url); } diff --git a/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsActivity.java b/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsActivity.java index 1e013c27..6542e0da 100644 --- a/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsActivity.java +++ b/app/src/main/java/at/bitfire/davdroid/ui/AccountSettingsActivity.java @@ -206,6 +206,16 @@ public class AccountSettingsActivity extends AppCompatActivity { } }); + final SwitchPreferenceCompat prefManageColors = (SwitchPreferenceCompat)findPreference("manage_calendar_colors"); + prefManageColors.setChecked(settings.getManageCalendarColors()); + prefManageColors.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + settings.setManageCalendarColors((Boolean)newValue); + refresh(); return false; + } + }); + } } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 1f307fac..93cff420 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -146,6 +146,9 @@ Termine, die mehr als %d Tage in der Vergangenheit liegen, werden ignoriert Termine, die mehr als diese Anzahl von Tagen in der Vergangenheit liegen, werden ignoriert (kann 0 sein). Feld leer lassen, um alle Termine zu synchronisieren. + Kalenderfarben verwalten + Kalenderfarben werden von DAVdroid verwaltet + DAVdroid setzt keine Kalenderfarben Neue DAVdroid-Version Interne Einstellungen wurden aktualisiert. Probleme? DAVdroid löschen und neu installieren. diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a642c4cc..dbf6fe5b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -166,6 +166,9 @@ Events more than %d days in the past will be ignored Events which are more than this number of days in the past will be ignored (may be 0). Leave blank to synchronize all events. + Manage calendar colors + Calendar colors are managed by DAVdroid + Calendar colors are not set by DAVdroid DAVdroid version update Internal settings have been updated. Problems? Uninstall DAVdroid, then re-install. diff --git a/app/src/main/res/xml/settings_account.xml b/app/src/main/res/xml/settings_account.xml index 69928540..4cff8923 100644 --- a/app/src/main/res/xml/settings_account.xml +++ b/app/src/main/res/xml/settings_account.xml @@ -64,6 +64,13 @@ android:dialogMessage="@string/settings_sync_time_range_past_message" android:inputType="number"/> + +