1
0
mirror of https://github.com/etesync/android synced 2025-01-23 22:21:23 +00:00

Add account setting: manage calendar colors

This commit is contained in:
Ricki Hirner 2016-03-31 20:07:36 +02:00
parent fa528a64e9
commit f0e45c71f5
8 changed files with 55 additions and 12 deletions

View File

@ -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"
}

View File

@ -67,6 +67,11 @@ public class AccountSettings {
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

View File

@ -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,15 +87,17 @@ 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));
if (withColor)
values.put(Calendars.CALENDAR_COLOR, info.color != null ? info.color : defaultColor);
if (info.readOnly)

View File

@ -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<String, CollectionInfo> 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);
}

View File

@ -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;
}
});
}
}

View File

@ -146,6 +146,9 @@
<item quantity="other">Termine, die mehr als %d Tage in der Vergangenheit liegen, werden ignoriert</item>
</plurals>
<string name="settings_sync_time_range_past_message">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.</string>
<string name="settings_manage_calendar_colors">Kalenderfarben verwalten</string>
<string name="settings_manage_calendar_colors_on">Kalenderfarben werden von DAVdroid verwaltet</string>
<string name="settings_manage_calendar_colors_off">DAVdroid setzt keine Kalenderfarben</string>
<string name="settings_version_update">Neue DAVdroid-Version</string>
<string name="settings_version_update_settings_updated">Interne Einstellungen wurden aktualisiert.</string>
<string name="settings_version_update_install_hint">Probleme? DAVdroid löschen und neu installieren.</string>

View File

@ -166,6 +166,9 @@
<item quantity="other">Events more than %d days in the past will be ignored</item>
</plurals>
<string name="settings_sync_time_range_past_message">Events which are more than this number of days in the past will be ignored (may be 0). Leave blank to synchronize all events.</string>
<string name="settings_manage_calendar_colors">Manage calendar colors</string>
<string name="settings_manage_calendar_colors_on">Calendar colors are managed by DAVdroid</string>
<string name="settings_manage_calendar_colors_off">Calendar colors are not set by DAVdroid</string>
<string name="settings_version_update">DAVdroid version update</string>
<string name="settings_version_update_settings_updated">Internal settings have been updated.</string>
<string name="settings_version_update_install_hint">Problems? Uninstall DAVdroid, then re-install.</string>

View File

@ -64,6 +64,13 @@
android:dialogMessage="@string/settings_sync_time_range_past_message"
android:inputType="number"/>
<SwitchPreferenceCompat
android:key="manage_calendar_colors"
android:persistent="false"
android:title="@string/settings_manage_calendar_colors"
android:summaryOn="@string/settings_manage_calendar_colors_on"
android:summaryOff="@string/settings_manage_calendar_colors_off"/>
</PreferenceCategory>
</PreferenceScreen>