mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-27 20:36:51 +01:00
Make calendar lookahead configurable
This commit is contained in:
parent
69c2f12acb
commit
f6f196847b
@ -82,6 +82,7 @@ public class DeviceSettingsPreferenceConst {
|
|||||||
public static final String PREF_RESERVE_REMINDERS_CALENDAR = "reserve_reminders_calendar";
|
public static final String PREF_RESERVE_REMINDERS_CALENDAR = "reserve_reminders_calendar";
|
||||||
public static final String PREF_ALLOW_HIGH_MTU = "allow_high_mtu";
|
public static final String PREF_ALLOW_HIGH_MTU = "allow_high_mtu";
|
||||||
public static final String PREF_SYNC_CALENDAR = "sync_calendar";
|
public static final String PREF_SYNC_CALENDAR = "sync_calendar";
|
||||||
|
public static final String PREF_CALENDAR_LOOKAHEAD_DAYS = "calendar_lookahead_days";
|
||||||
public static final String PREF_TIME_SYNC = "time_sync";
|
public static final String PREF_TIME_SYNC = "time_sync";
|
||||||
public static final String PREF_USE_CUSTOM_DEVICEICON = "use_custom_deviceicon";
|
public static final String PREF_USE_CUSTOM_DEVICEICON = "use_custom_deviceicon";
|
||||||
public static final String PREF_BUTTON_1_FUNCTION_SHORT = "button_1_function_short";
|
public static final String PREF_BUTTON_1_FUNCTION_SHORT = "button_1_function_short";
|
||||||
|
@ -595,6 +595,7 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
|||||||
addPreferenceHandlerFor(PREF_CAMERA_REMOTE);
|
addPreferenceHandlerFor(PREF_CAMERA_REMOTE);
|
||||||
addPreferenceHandlerFor(PREF_SCREEN_LIFT_WRIST);
|
addPreferenceHandlerFor(PREF_SCREEN_LIFT_WRIST);
|
||||||
addPreferenceHandlerFor(PREF_SYNC_CALENDAR);
|
addPreferenceHandlerFor(PREF_SYNC_CALENDAR);
|
||||||
|
addPreferenceHandlerFor(PREF_CALENDAR_LOOKAHEAD_DAYS);
|
||||||
|
|
||||||
addPreferenceHandlerFor(PREF_BATTERY_POLLING_ENABLE);
|
addPreferenceHandlerFor(PREF_BATTERY_POLLING_ENABLE);
|
||||||
addPreferenceHandlerFor(PREF_BATTERY_POLLING_INTERVAL);
|
addPreferenceHandlerFor(PREF_BATTERY_POLLING_INTERVAL);
|
||||||
@ -1121,6 +1122,15 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final EditTextPreference calendarLookahead = findPreference(DeviceSettingsPreferenceConst.PREF_CALENDAR_LOOKAHEAD_DAYS);
|
||||||
|
if (calendarLookahead != null) {
|
||||||
|
setInputTypeFor(DeviceSettingsPreferenceConst.PREF_CALENDAR_LOOKAHEAD_DAYS, InputType.TYPE_CLASS_NUMBER);
|
||||||
|
calendarLookahead.setSummaryProvider(new GBSimpleSummaryProvider(
|
||||||
|
requireContext().getString(R.string.pref_summary_calendar_lookahead, "7"),
|
||||||
|
R.string.pref_summary_calendar_lookahead
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
setInputTypeFor(HuamiConst.PREF_BUTTON_ACTION_BROADCAST_DELAY, InputType.TYPE_CLASS_NUMBER);
|
setInputTypeFor(HuamiConst.PREF_BUTTON_ACTION_BROADCAST_DELAY, InputType.TYPE_CLASS_NUMBER);
|
||||||
setInputTypeFor(HuamiConst.PREF_BUTTON_ACTION_PRESS_MAX_INTERVAL, InputType.TYPE_CLASS_NUMBER);
|
setInputTypeFor(HuamiConst.PREF_BUTTON_ACTION_PRESS_MAX_INTERVAL, InputType.TYPE_CLASS_NUMBER);
|
||||||
setInputTypeFor(HuamiConst.PREF_BUTTON_ACTION_PRESS_COUNT, InputType.TYPE_CLASS_NUMBER);
|
setInputTypeFor(HuamiConst.PREF_BUTTON_ACTION_PRESS_COUNT, InputType.TYPE_CLASS_NUMBER);
|
||||||
|
@ -78,8 +78,6 @@ public class CalendarManager {
|
|||||||
Instances.RRULE
|
Instances.RRULE
|
||||||
};
|
};
|
||||||
|
|
||||||
private static final int lookahead_days = 7;
|
|
||||||
|
|
||||||
private final String deviceAddress;
|
private final String deviceAddress;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
@ -94,21 +92,22 @@ public class CalendarManager {
|
|||||||
loadCalendarsBlackList();
|
loadCalendarsBlackList();
|
||||||
|
|
||||||
final SharedPreferences sharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(deviceAddress);
|
final SharedPreferences sharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(deviceAddress);
|
||||||
|
final Prefs prefs = new Prefs(sharedPrefs);
|
||||||
final List<CalendarEvent> calendarEventList = getCalendarEvents();
|
int lookaheadDays = Math.max(1, prefs.getInt("calendar_lookahead_days", 7));
|
||||||
|
final List<CalendarEvent> calendarEventList = getCalendarEvents(lookaheadDays);
|
||||||
if (sharedPrefs.getBoolean("sync_birthdays", false)) {
|
if (sharedPrefs.getBoolean("sync_birthdays", false)) {
|
||||||
calendarEventList.addAll(getBirthdays());
|
calendarEventList.addAll(getBirthdays(lookaheadDays));
|
||||||
calendarEventList.sort(Comparator.comparingInt(CalendarEvent::getBeginSeconds));
|
calendarEventList.sort(Comparator.comparingInt(CalendarEvent::getBeginSeconds));
|
||||||
}
|
}
|
||||||
return calendarEventList;
|
return calendarEventList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CalendarEvent> getCalendarEvents() {
|
public List<CalendarEvent> getCalendarEvents(final int lookaheadDays) {
|
||||||
final List<CalendarEvent> calendarEventList = new ArrayList<>();
|
final List<CalendarEvent> calendarEventList = new ArrayList<>();
|
||||||
|
|
||||||
Calendar cal = GregorianCalendar.getInstance();
|
Calendar cal = GregorianCalendar.getInstance();
|
||||||
long dtStart = cal.getTimeInMillis();
|
long dtStart = cal.getTimeInMillis();
|
||||||
cal.add(Calendar.DATE, lookahead_days);
|
cal.add(Calendar.DATE, lookaheadDays);
|
||||||
long dtEnd = cal.getTimeInMillis();
|
long dtEnd = cal.getTimeInMillis();
|
||||||
|
|
||||||
Uri.Builder eventsUriBuilder = Instances.CONTENT_URI.buildUpon();
|
Uri.Builder eventsUriBuilder = Instances.CONTENT_URI.buildUpon();
|
||||||
@ -185,7 +184,7 @@ public class CalendarManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CalendarEvent> getBirthdays() {
|
public List<CalendarEvent> getBirthdays(final int lookaheadDays) {
|
||||||
final String[] projection = new String[]{
|
final String[] projection = new String[]{
|
||||||
ContactsContract.CommonDataKinds.Event.CONTACT_ID,
|
ContactsContract.CommonDataKinds.Event.CONTACT_ID,
|
||||||
ContactsContract.CommonDataKinds.Event.START_DATE,
|
ContactsContract.CommonDataKinds.Event.START_DATE,
|
||||||
@ -198,7 +197,7 @@ public class CalendarManager {
|
|||||||
String.valueOf(ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY)
|
String.valueOf(ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY)
|
||||||
};
|
};
|
||||||
final List<CalendarEvent> birthdays = new LinkedList<>();
|
final List<CalendarEvent> birthdays = new LinkedList<>();
|
||||||
final LocalDate maxDate = LocalDate.now().plusDays(30);
|
final LocalDate maxDate = LocalDate.now().plusDays(lookaheadDays);
|
||||||
|
|
||||||
try (Cursor birthdayCursor = mContext.getContentResolver().query(ContactsContract.Data.CONTENT_URI, projection, selection, selectionArgs, ContactsContract.CommonDataKinds.Event.START_DATE + " ASC")) {
|
try (Cursor birthdayCursor = mContext.getContentResolver().query(ContactsContract.Data.CONTENT_URI, projection, selection, selectionArgs, ContactsContract.CommonDataKinds.Event.START_DATE + " ASC")) {
|
||||||
if (birthdayCursor == null || birthdayCursor.getCount() == 0) {
|
if (birthdayCursor == null || birthdayCursor.getCount() == 0) {
|
||||||
|
@ -414,6 +414,8 @@
|
|||||||
<string name="pref_summary_use_custom_font">Enable this if your device has a custom font firmware for emoji support</string>
|
<string name="pref_summary_use_custom_font">Enable this if your device has a custom font firmware for emoji support</string>
|
||||||
<string name="pref_title_allow_high_mtu">Allow high MTU</string>
|
<string name="pref_title_allow_high_mtu">Allow high MTU</string>
|
||||||
<string name="pref_summary_allow_high_mtu">Increases transfer speed, but might not work on some Android devices.</string>
|
<string name="pref_summary_allow_high_mtu">Increases transfer speed, but might not work on some Android devices.</string>
|
||||||
|
<string name="pref_title_calendar_lookahead">Number of days ahead</string>
|
||||||
|
<string name="pref_summary_calendar_lookahead">Sync up to %1s days of calendar events</string>
|
||||||
<string name="pref_title_overwrite_settings_on_connection">Overwrite settings on connection</string>
|
<string name="pref_title_overwrite_settings_on_connection">Overwrite settings on connection</string>
|
||||||
<string name="pref_summary_overwrite_settings_on_connection">When connecting to the band, overwrite all the settings on it.</string>
|
<string name="pref_summary_overwrite_settings_on_connection">When connecting to the band, overwrite all the settings on it.</string>
|
||||||
<string name="pref_title_device_internet_access">Allow Internet Access</string>
|
<string name="pref_title_device_internet_access">Allow Internet Access</string>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:icon="@drawable/ic_calendar_sync"
|
android:icon="@drawable/ic_calendar_sync"
|
||||||
@ -7,6 +8,15 @@
|
|||||||
android:layout="@layout/preference_checkbox"
|
android:layout="@layout/preference_checkbox"
|
||||||
android:summary="@string/pref_summary_sync_calendar"
|
android:summary="@string/pref_summary_sync_calendar"
|
||||||
android:title="@string/pref_title_sync_caldendar" />
|
android:title="@string/pref_title_sync_caldendar" />
|
||||||
|
<EditTextPreference
|
||||||
|
android:defaultValue="7"
|
||||||
|
android:dependency="sync_calendar"
|
||||||
|
android:icon="@drawable/ic_calendar_to"
|
||||||
|
android:inputType="number"
|
||||||
|
android:key="calendar_lookahead_days"
|
||||||
|
android:maxLength="3"
|
||||||
|
android:title="@string/pref_title_calendar_lookahead"
|
||||||
|
app:useSimpleSummaryProvider="true" />
|
||||||
<SwitchPreferenceCompat
|
<SwitchPreferenceCompat
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:dependency="sync_calendar"
|
android:dependency="sync_calendar"
|
||||||
|
Loading…
Reference in New Issue
Block a user