mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Fossil/Skagen Hybrids: Add calendar sending preferences
This commit is contained in:
+4
@@ -85,6 +85,10 @@ public class DeviceSettingsPreferenceConst {
|
||||
public static final String PREF_SYNC_CALENDAR = "sync_calendar";
|
||||
public static final String PREF_SYNC_BIRTHDAYS = "sync_birthdays";
|
||||
public static final String PREF_CALENDAR_LOOKAHEAD_DAYS = "calendar_lookahead_days";
|
||||
public static final String PREF_CALENDAR_SYNC_EVENTS_AMOUNT = "calendar_sync_events_amount";
|
||||
public static final String PREF_CALENDAR_MAX_TITLE_LENGTH = "calendar_sync_event_title_length";
|
||||
public static final String PREF_CALENDAR_MAX_DESC_LENGTH = "calendar_sync_event_desc_length";
|
||||
public static final String PREF_CALENDAR_TARGET_APP = "calendar_sync_target_app";
|
||||
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_BUTTON_1_FUNCTION_SHORT = "button_1_function_short";
|
||||
|
||||
+8
@@ -961,6 +961,11 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
||||
addPreferenceHandlerFor(PREF_DISPLAY_ON_START);
|
||||
addPreferenceHandlerFor(PREF_DISPLAY_ON_END);
|
||||
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_SYNC_EVENTS_AMOUNT);
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_MAX_TITLE_LENGTH);
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_MAX_DESC_LENGTH);
|
||||
addPreferenceHandlerFor(PREF_CALENDAR_TARGET_APP);
|
||||
|
||||
final Preference dischargeIntervalsSet = findPreference(PREF_BATTERY_DISCHARGE_INTERVALS_SET);
|
||||
if (dischargeIntervalsSet != null) {
|
||||
dischargeIntervalsSet.setOnPreferenceClickListener(preference -> {
|
||||
@@ -1303,6 +1308,9 @@ public class DeviceSpecificSettingsFragment extends AbstractPreferenceFragment i
|
||||
setInputTypeFor(DeviceSettingsPreferenceConst.PREF_BANGLEJS_TEXT_BITMAP_SIZE, InputType.TYPE_CLASS_NUMBER);
|
||||
setInputTypeFor(DeviceSettingsPreferenceConst.PREF_AUTO_REPLY_INCOMING_CALL_DELAY, InputType.TYPE_CLASS_NUMBER);
|
||||
setInputTypeFor("hplus_screentime", InputType.TYPE_CLASS_NUMBER);
|
||||
setInputTypeFor(PREF_CALENDAR_SYNC_EVENTS_AMOUNT, InputType.TYPE_CLASS_NUMBER);
|
||||
setInputTypeFor(PREF_CALENDAR_MAX_TITLE_LENGTH, InputType.TYPE_CLASS_NUMBER);
|
||||
setInputTypeFor(PREF_CALENDAR_MAX_DESC_LENGTH, InputType.TYPE_CLASS_NUMBER);
|
||||
setNumericInputTypeWithRangeFor(DeviceSettingsPreferenceConst.PREF_BATTERY_DISCHARGE_INTERVAL1_WATT, 80, 800, false);
|
||||
setNumericInputTypeWithRangeFor(DeviceSettingsPreferenceConst.PREF_BATTERY_DISCHARGE_INTERVAL2_WATT, 80, 800, false);
|
||||
setNumericInputTypeWithRangeFor(DeviceSettingsPreferenceConst.PREF_BATTERY_DISCHARGE_INTERVAL3_WATT, 80, 800, false);
|
||||
|
||||
+21
-7
@@ -18,6 +18,10 @@
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
package nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.adapter.fossil_hr;
|
||||
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_CALENDAR_MAX_DESC_LENGTH;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_CALENDAR_MAX_TITLE_LENGTH;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_CALENDAR_SYNC_EVENTS_AMOUNT;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst.PREF_CALENDAR_TARGET_APP;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationPutRequest.FitnessConfigItem;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationPutRequest.InactivityWarningItem;
|
||||
import static nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.configuration.ConfigurationPutRequest.UnitsConfigItem;
|
||||
@@ -189,7 +193,6 @@ import nodomain.freeyourgadget.gadgetbridge.util.calendar.CalendarManager;
|
||||
|
||||
public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
public static final int MESSAGE_WHAT_VOICE_DATA_RECEIVED = 0;
|
||||
private static final int MAX_CALENDAR_ITEMS = 10;
|
||||
|
||||
private byte[] phoneRandomNumber;
|
||||
private byte[] watchRandomNumber;
|
||||
@@ -1624,6 +1627,11 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
int maxItems = Integer.parseInt(getDeviceSpecificPreferences().getString(PREF_CALENDAR_SYNC_EVENTS_AMOUNT, "5"));
|
||||
int titleLength = Integer.parseInt(getDeviceSpecificPreferences().getString(PREF_CALENDAR_MAX_TITLE_LENGTH, "40"));
|
||||
int descLength = Integer.parseInt(getDeviceSpecificPreferences().getString(PREF_CALENDAR_MAX_DESC_LENGTH, "40"));
|
||||
String targetApp = getDeviceSpecificPreferences().getString(PREF_CALENDAR_TARGET_APP, "customWatchFace");
|
||||
|
||||
final CalendarManager upcomingEvents = new CalendarManager(getContext(), getDeviceSupport().getDevice().getAddress());
|
||||
final List<CalendarEvent> calendarEvents = upcomingEvents.getCalendarEventList();
|
||||
|
||||
@@ -1631,8 +1639,8 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
int nEvents = 0;
|
||||
|
||||
for (final CalendarEvent calendarEvent : calendarEvents) {
|
||||
if (++nEvents > MAX_CALENDAR_ITEMS) {
|
||||
LOG.warn("Syncing only first {} events of {}", MAX_CALENDAR_ITEMS, calendarEvents.size());
|
||||
if (++nEvents > maxItems) {
|
||||
LOG.warn("Syncing only first {} events of {}", maxItems, calendarEvents.size());
|
||||
break;
|
||||
}
|
||||
thisSync.add(calendarEvent);
|
||||
@@ -1658,10 +1666,16 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
for (long reminder : event.getRemindersAbsoluteTs()) {
|
||||
reminders.put(reminder / 1000);
|
||||
}
|
||||
String title = event.getTitle();
|
||||
if (title != null && title.length() > titleLength)
|
||||
title = event.getTitle().substring(0, titleLength);
|
||||
String desc = event.getDescription();
|
||||
if (desc != null && desc.length() > descLength)
|
||||
desc = event.getDescription().substring(0, descLength);
|
||||
items.put(new JSONObject()
|
||||
.put("id", event.getId())
|
||||
.put("title", event.getTitle())
|
||||
.put("desc", event.getDescription())
|
||||
.put("title", title)
|
||||
.put("desc", desc)
|
||||
.put("start", event.getBeginSeconds())
|
||||
.put("end", event.getEndSeconds())
|
||||
.put("reminders", reminders)
|
||||
@@ -1670,7 +1684,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
JSONObject calendarObj = new JSONObject()
|
||||
.put("res", new JSONObject()
|
||||
.put("set", new JSONObject()
|
||||
.put("calendarApp._.config.events", items)
|
||||
.put(targetApp + "._.config.events", items)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -1687,7 +1701,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
|
||||
|
||||
@Override
|
||||
public void onTestNewFunction() {
|
||||
setVibrationStrengthFromConfig();
|
||||
onSendCalendar();
|
||||
}
|
||||
|
||||
public byte[] getSecretKey() throws IllegalAccessException {
|
||||
|
||||
@@ -4063,4 +4063,8 @@
|
||||
<string name="wifi_frequency_2_4_ghz">2.4 GHz</string>
|
||||
<string name="wifi_frequency_5_ghz">5 GHz</string>
|
||||
<string name="wifi_frequency">Wi-Fi Frequency</string>
|
||||
<string name="pref_calendar_amount_events_to_sync_title">Amount of calendar events to synchronize</string>
|
||||
<string name="pref_calendar_maximum_title_characters_title">Maximum characters in event title</string>
|
||||
<string name="pref_calendar_maximum_description_characters_title">Maximum characters in event description</string>
|
||||
<string name="pref_calendar_target_app_title">Target app on watch for calendar events</string>
|
||||
</resources>
|
||||
|
||||
@@ -48,4 +48,31 @@
|
||||
android:icon="@drawable/ic_voice"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="calendar_sync_events_amount"
|
||||
android:title="@string/pref_calendar_amount_events_to_sync_title"
|
||||
android:icon="@drawable/ic_calendar_sync"
|
||||
android:defaultValue="5"
|
||||
android:inputType="number"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<EditTextPreference
|
||||
android:key="calendar_sync_event_title_length"
|
||||
android:title="@string/pref_calendar_maximum_title_characters_title"
|
||||
android:icon="@drawable/ic_calendar_sync"
|
||||
android:defaultValue="40"
|
||||
android:inputType="number"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<EditTextPreference
|
||||
android:key="calendar_sync_event_desc_length"
|
||||
android:title="@string/pref_calendar_maximum_description_characters_title"
|
||||
android:icon="@drawable/ic_calendar_sync"
|
||||
android:defaultValue="40"
|
||||
android:inputType="number"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<EditTextPreference
|
||||
android:key="calendar_sync_target_app"
|
||||
android:title="@string/pref_calendar_target_app_title"
|
||||
android:icon="@drawable/ic_calendar_sync"
|
||||
android:defaultValue="calendarApp"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
</androidx.preference.PreferenceScreen>
|
||||
|
||||
Reference in New Issue
Block a user