mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2026-07-31 07:44:24 +02:00
Zepp OS: Respect sync calendar setting
This commit is contained in:
+1
@@ -82,6 +82,7 @@ public class DeviceSettingsPreferenceConst {
|
||||
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_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_TIME_SYNC = "time_sync";
|
||||
public static final String PREF_USE_CUSTOM_DEVICEICON = "use_custom_deviceicon";
|
||||
|
||||
+16
-2
@@ -30,6 +30,7 @@ import android.os.Handler;
|
||||
import android.provider.CalendarContract;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -105,6 +106,16 @@ public class CalendarReceiver extends ContentObserver {
|
||||
mForceSyncReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(final Context context, final Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (!ACTION_FORCE_SYNC.equals(action)) {
|
||||
LOG.warn("Got unknown action {}", action);
|
||||
return;
|
||||
}
|
||||
final GBDevice intentDevice = intent.getParcelableExtra(GBDevice.EXTRA_DEVICE);
|
||||
if (intentDevice != null && !intentDevice.equals(mGBDevice)) {
|
||||
// Force sync is not for this device - ignore
|
||||
return;
|
||||
}
|
||||
LOG.info("Got force sync: {}", intent.getAction());
|
||||
scheduleSync();
|
||||
}
|
||||
@@ -123,7 +134,7 @@ public class CalendarReceiver extends ContentObserver {
|
||||
}
|
||||
|
||||
public void scheduleSync() {
|
||||
LOG.debug("Scheduling calendar sync");
|
||||
LOG.debug("Scheduling calendar sync for {}", mGBDevice);
|
||||
mSyncHandler.removeCallbacksAndMessages(null);
|
||||
mSyncHandler.postDelayed(this::syncCalendar, 2500L);
|
||||
}
|
||||
@@ -273,9 +284,12 @@ public class CalendarReceiver extends ContentObserver {
|
||||
mSyncHandler.removeCallbacksAndMessages(null);
|
||||
}
|
||||
|
||||
public static void forceSync() {
|
||||
public static void forceSync(@Nullable final GBDevice device) {
|
||||
final Intent intent = new Intent(ACTION_FORCE_SYNC);
|
||||
intent.setPackage(BuildConfig.APPLICATION_ID);
|
||||
if (device != null) {
|
||||
intent.putExtra(GBDevice.EXTRA_DEVICE, device);
|
||||
}
|
||||
GBApplication.getContext().sendBroadcast(intent);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -92,6 +92,7 @@ import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceMusicUpdate;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.BatteryLevel;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.CalendarReceiver;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.NotificationListener;
|
||||
import nodomain.freeyourgadget.gadgetbridge.externalevents.opentracks.OpenTracksController;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
@@ -1242,7 +1243,12 @@ public abstract class AbstractDeviceSupport implements DeviceSupport {
|
||||
*/
|
||||
@Override
|
||||
public void onSendConfiguration(String config) {
|
||||
|
||||
switch (config) {
|
||||
case DeviceSettingsPreferenceConst.PREF_SYNC_CALENDAR:
|
||||
case DeviceSettingsPreferenceConst.PREF_SYNC_BIRTHDAYS:
|
||||
CalendarReceiver.forceSync(getDevice());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-1
@@ -105,7 +105,9 @@ public abstract class AbstractBTLEDeviceSupport extends AbstractDeviceSupport im
|
||||
|
||||
@Override
|
||||
public void onSendConfiguration(String config) {
|
||||
if(bleApi != null) {
|
||||
super.onSendConfiguration(config);
|
||||
|
||||
if (bleApi != null) {
|
||||
bleApi.onSendConfiguration(config);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1051,7 +1051,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
GB.toast("Database Error while forcefully syncing Calendar", Toast.LENGTH_SHORT, GB.ERROR, e1);
|
||||
}
|
||||
//force a syncCalendar now, send missing events
|
||||
CalendarReceiver.forceSync();
|
||||
CalendarReceiver.forceSync(getDevice());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
@@ -3020,6 +3020,8 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
|
||||
} catch (IOException e) {
|
||||
GB.toast("Error setting configuration", Toast.LENGTH_LONG, GB.ERROR, e);
|
||||
}
|
||||
|
||||
super.onSendConfiguration(config);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -388,7 +388,7 @@ public class ZeppOsSupport extends HuamiSupport implements ZeppOsFileTransferSer
|
||||
@Override
|
||||
protected ZeppOsSupport sendCalendarEvents(final TransactionBuilder builder) {
|
||||
// We have native calendar sync
|
||||
CalendarReceiver.forceSync();
|
||||
CalendarReceiver.forceSync(getDevice());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -193,7 +193,7 @@ public class SonyWena3DeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
requestActivityDataDownload(builder, false);
|
||||
|
||||
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
|
||||
CalendarReceiver.forceSync();
|
||||
CalendarReceiver.forceSync(getDevice());
|
||||
return builder;
|
||||
}
|
||||
|
||||
@@ -230,7 +230,7 @@ public class SonyWena3DeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
return true;
|
||||
}
|
||||
else if(request.requestType == StatusRequestType.GET_CALENDAR.value) {
|
||||
CalendarReceiver.forceSync();
|
||||
CalendarReceiver.forceSync(getDevice());
|
||||
sendAllCalendarEvents(null);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -151,7 +151,7 @@ public class Prefs {
|
||||
} catch (Exception ex) {
|
||||
try {
|
||||
String value = preferences.getString(key, String.valueOf(defaultValue));
|
||||
if ("".equals(value)) {
|
||||
if (value.isEmpty()) {
|
||||
return defaultValue;
|
||||
}
|
||||
return Boolean.parseBoolean(value);
|
||||
|
||||
+11
-6
@@ -45,6 +45,7 @@ import java.util.TimeZone;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.GBPrefs;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
@@ -93,18 +94,22 @@ public class CalendarManager {
|
||||
public List<CalendarEvent> getCalendarEventList() {
|
||||
loadCalendarsBlackList();
|
||||
|
||||
final SharedPreferences sharedPrefs = GBApplication.getDeviceSpecificSharedPrefs(deviceAddress);
|
||||
final Prefs prefs = new Prefs(sharedPrefs);
|
||||
int lookaheadDays = Math.max(1, prefs.getInt("calendar_lookahead_days", 7));
|
||||
final List<CalendarEvent> calendarEventList = getCalendarEvents(lookaheadDays);
|
||||
if (sharedPrefs.getBoolean("sync_birthdays", false)) {
|
||||
final Prefs prefs = new Prefs(GBApplication.getDeviceSpecificSharedPrefs(deviceAddress));
|
||||
|
||||
final List<CalendarEvent> calendarEventList = new ArrayList<>();
|
||||
final int lookaheadDays = Math.max(1, prefs.getInt("calendar_lookahead_days", 7));
|
||||
|
||||
if (prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_SYNC_CALENDAR, false)) {
|
||||
calendarEventList.addAll(getCalendarEvents(lookaheadDays));
|
||||
}
|
||||
if (prefs.getBoolean(DeviceSettingsPreferenceConst.PREF_SYNC_BIRTHDAYS, false)) {
|
||||
calendarEventList.addAll(getBirthdays(lookaheadDays));
|
||||
calendarEventList.sort(Comparator.comparingInt(CalendarEvent::getBeginSeconds));
|
||||
}
|
||||
return calendarEventList;
|
||||
}
|
||||
|
||||
public List<CalendarEvent> getCalendarEvents(final int lookaheadDays) {
|
||||
private List<CalendarEvent> getCalendarEvents(final int lookaheadDays) {
|
||||
final List<CalendarEvent> calendarEventList = new ArrayList<>();
|
||||
|
||||
Calendar cal = GregorianCalendar.getInstance();
|
||||
|
||||
Reference in New Issue
Block a user