mirror of
https://github.com/etesync/android
synced 2025-06-22 07:58:57 +00:00
Add account setting: manage calendar colors
This commit is contained in:
parent
fa528a64e9
commit
f0e45c71f5
@ -17,8 +17,8 @@ android {
|
|||||||
minSdkVersion 14
|
minSdkVersion 14
|
||||||
targetSdkVersion 22
|
targetSdkVersion 22
|
||||||
|
|
||||||
versionCode 94
|
versionCode 95
|
||||||
versionName "1.0.4"
|
versionName "1.0.5"
|
||||||
|
|
||||||
buildConfigField "long", "buildTime", System.currentTimeMillis() + "L"
|
buildConfigField "long", "buildTime", System.currentTimeMillis() + "L"
|
||||||
}
|
}
|
||||||
|
@ -60,13 +60,18 @@ public class AccountSettings {
|
|||||||
KEY_AUTH_PREEMPTIVE = "auth_preemptive";
|
KEY_AUTH_PREEMPTIVE = "auth_preemptive";
|
||||||
|
|
||||||
/** Time range limitation to the past [in days]
|
/** Time range limitation to the past [in days]
|
||||||
value = null default value (DEFAULT_TIME_RANGE_PAST_DAYS)
|
value = null default value (DEFAULT_TIME_RANGE_PAST_DAYS)
|
||||||
< 0 (-1) no limit
|
< 0 (-1) no limit
|
||||||
>= 0 entries more than n days in the past won't be synchronized
|
>= 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 String KEY_TIME_RANGE_PAST_DAYS = "time_range_past_days";
|
||||||
private final static int DEFAULT_TIME_RANGE_PAST_DAYS = 90;
|
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;
|
public final static long SYNC_INTERVAL_MANUALLY = -1;
|
||||||
|
|
||||||
final Context context;
|
final Context context;
|
||||||
@ -172,6 +177,15 @@ public class AccountSettings {
|
|||||||
accountManager.setUserData(account, KEY_TIME_RANGE_PAST_DAYS, String.valueOf(days == null ? -1 : days));
|
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
|
// update from previous account settings
|
||||||
|
|
||||||
|
@ -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 {
|
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.
|
// ACCOUNT_NAME and ACCOUNT_TYPE are required (see docs)! If it's missing, other apps will crash.
|
||||||
values.put(Calendars.ACCOUNT_NAME, account.name);
|
values.put(Calendars.ACCOUNT_NAME, account.name);
|
||||||
@ -87,16 +87,18 @@ public class LocalCalendar extends AndroidCalendar implements LocalCollection {
|
|||||||
return create(account, provider, values);
|
return create(account, provider, values);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(CollectionInfo info) throws CalendarStorageException {
|
public void update(CollectionInfo info, boolean updateColor) throws CalendarStorageException {
|
||||||
update(valuesFromCollectionInfo(info));
|
update(valuesFromCollectionInfo(info, updateColor));
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(15)
|
@TargetApi(15)
|
||||||
private static ContentValues valuesFromCollectionInfo(CollectionInfo info) {
|
private static ContentValues valuesFromCollectionInfo(CollectionInfo info, boolean withColor) {
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(Calendars.NAME, info.url);
|
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_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)
|
if (info.readOnly)
|
||||||
values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ);
|
values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ);
|
||||||
|
@ -24,6 +24,7 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
import at.bitfire.davdroid.AccountSettings;
|
||||||
import at.bitfire.davdroid.App;
|
import at.bitfire.davdroid.App;
|
||||||
import at.bitfire.davdroid.InvalidAccountException;
|
import at.bitfire.davdroid.InvalidAccountException;
|
||||||
import at.bitfire.davdroid.model.CollectionInfo;
|
import at.bitfire.davdroid.model.CollectionInfo;
|
||||||
@ -70,12 +71,15 @@ public class CalendarsSyncAdapterService extends SyncAdapterService {
|
|||||||
App.log.info("Calendar sync complete");
|
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
|
// enumerate remote and local calendars
|
||||||
Long service = getService(account);
|
Long service = getService(account);
|
||||||
Map<String, CollectionInfo> remote = remoteCalendars(service);
|
Map<String, CollectionInfo> remote = remoteCalendars(service);
|
||||||
LocalCalendar[] local = (LocalCalendar[])LocalCalendar.find(account, provider, LocalCalendar.Factory.INSTANCE, null, null);
|
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
|
// delete obsolete local calendar
|
||||||
for (LocalCalendar calendar : local) {
|
for (LocalCalendar calendar : local) {
|
||||||
String url = calendar.getName();
|
String url = calendar.getName();
|
||||||
@ -86,7 +90,7 @@ public class CalendarsSyncAdapterService extends SyncAdapterService {
|
|||||||
// remote CollectionInfo found for this local collection, update data
|
// remote CollectionInfo found for this local collection, update data
|
||||||
CollectionInfo info = remote.get(url);
|
CollectionInfo info = remote.get(url);
|
||||||
App.log.fine("Updating local calendar " + url + " with " + info);
|
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
|
// we already have a local calendar for this remote collection, don't take into consideration anymore
|
||||||
remote.remove(url);
|
remote.remove(url);
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -146,6 +146,9 @@
|
|||||||
<item quantity="other">Termine, die mehr als %d Tage in der Vergangenheit liegen, werden ignoriert</item>
|
<item quantity="other">Termine, die mehr als %d Tage in der Vergangenheit liegen, werden ignoriert</item>
|
||||||
</plurals>
|
</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_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">Neue DAVdroid-Version</string>
|
||||||
<string name="settings_version_update_settings_updated">Interne Einstellungen wurden aktualisiert.</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>
|
<string name="settings_version_update_install_hint">Probleme? DAVdroid löschen und neu installieren.</string>
|
||||||
|
@ -166,6 +166,9 @@
|
|||||||
<item quantity="other">Events more than %d days in the past will be ignored</item>
|
<item quantity="other">Events more than %d days in the past will be ignored</item>
|
||||||
</plurals>
|
</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_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">DAVdroid version update</string>
|
||||||
<string name="settings_version_update_settings_updated">Internal settings have been updated.</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>
|
<string name="settings_version_update_install_hint">Problems? Uninstall DAVdroid, then re-install.</string>
|
||||||
|
@ -64,6 +64,13 @@
|
|||||||
android:dialogMessage="@string/settings_sync_time_range_past_message"
|
android:dialogMessage="@string/settings_sync_time_range_past_message"
|
||||||
android:inputType="number"/>
|
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>
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
||||||
|
Loading…
Reference in New Issue
Block a user