Java Code Examples for com.eveningoutpost.dexdrip.Services.SyncService#startSyncService()

The following examples show how to use com.eveningoutpost.dexdrip.Services.SyncService#startSyncService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Treatments.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private static void pushTreatmentSync(Treatments treatment, boolean is_new, String suggested_uuid) {

        if (Home.get_master_or_follower()) GcmActivity.pushTreatmentAsync(treatment);

        if (!(Pref.getBoolean("cloud_storage_api_enable", false) || Pref.getBoolean("cloud_storage_mongodb_enable", false))) {
            NSClientChat.pushTreatmentAsync(treatment);
        } else {
            Log.d(TAG, "Skipping NSClient treatment broadcast as nightscout direct sync is enabled");
        }

        if (suggested_uuid == null) {
            // only sync to nightscout if source of change was not from nightscout
            if (UploaderQueue.newEntry(is_new ? "insert" : "update", treatment) != null) {
                SyncService.startSyncService(3000); // sync in 3 seconds
            }
        }
    }
 
Example 2
Source File: Treatments.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private static void pushTreatmentSync(Treatments treatment, boolean is_new, String suggested_uuid) {

        if (Home.get_master_or_follower()) GcmActivity.pushTreatmentAsync(treatment);

        if (!(Pref.getBoolean("cloud_storage_api_enable", false) || Pref.getBoolean("cloud_storage_mongodb_enable", false))) {
            NSClientChat.pushTreatmentAsync(treatment);
        } else {
            Log.d(TAG, "Skipping NSClient treatment broadcast as nightscout direct sync is enabled");
        }

        if (suggested_uuid == null) {
            // only sync to nightscout if source of change was not from nightscout
            if (UploaderQueue.newEntry(is_new ? "insert" : "update", treatment) != null) {
                SyncService.startSyncService(3000); // sync in 3 seconds
            }
        }
    }
 
Example 3
Source File: BgReading.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void pushBgReadingSyncToWatch(BgReading bgReading, boolean is_new) {
    Log.d(TAG, "pushTreatmentSyncToWatch Add treatment to UploaderQueue.");
    if (Pref.getBooleanDefaultFalse("wear_sync")) {
        if (UploaderQueue.newEntryForWatch(is_new ? "insert" : "update", bgReading) != null) {
            SyncService.startSyncService(3000); // sync in 3 seconds
        }
    }
}
 
Example 4
Source File: BloodTest.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void pushBloodTestSyncToWatch(BloodTest bt, boolean is_new) {
    Log.d(TAG, "pushTreatmentSyncToWatch Add treatment to UploaderQueue.");
    if (Pref.getBooleanDefaultFalse("wear_sync")) {
        if (UploaderQueue.newEntryForWatch(is_new ? "insert" : "update", bt) != null) {
            SyncService.startSyncService(3000); // sync in 3 seconds
        }
    }
}
 
Example 5
Source File: BloodTest.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private static void processFromMessage(BloodTestMessage btm) {
    if ((btm != null) && (btm.uuid != null) && (btm.uuid.length() == 36)) {
        boolean is_new = false;
        BloodTest bt = byUUID(btm.uuid);
        if (bt == null) {
            bt = getForPreciseTimestamp(Wire.get(btm.timestamp, BloodTestMessage.DEFAULT_TIMESTAMP), CLOSEST_READING_MS);
            if (bt != null) {
                UserError.Log.wtf(TAG, "Error matches a different uuid with the same timestamp: " + bt.uuid + " vs " + btm.uuid + " skipping!");
                return;
            }
            bt = new BloodTest();
            is_new = true;
        } else {
            if (bt.state != Wire.get(btm.state, BloodTestMessage.DEFAULT_STATE)) {
                is_new = true;
            }
        }
        bt.timestamp = Wire.get(btm.timestamp, BloodTestMessage.DEFAULT_TIMESTAMP);
        bt.mgdl = Wire.get(btm.mgdl, BloodTestMessage.DEFAULT_MGDL);
        bt.created_timestamp = Wire.get(btm.created_timestamp, BloodTestMessage.DEFAULT_CREATED_TIMESTAMP);
        bt.state = Wire.get(btm.state, BloodTestMessage.DEFAULT_STATE);
        bt.source = Wire.get(btm.source, BloodTestMessage.DEFAULT_SOURCE);
        bt.uuid = btm.uuid;
        bt.saveit(); // de-dupe by uuid
        if (is_new) { // cannot handle updates yet
            if (UploaderQueue.newEntry(is_new ? "insert" : "update", bt) != null) {
                if (JoH.quietratelimit("start-sync-service", 5)) {
                    SyncService.startSyncService(3000); // sync in 3 seconds
                }
            }
        }
    } else {
        UserError.Log.wtf(TAG, "processFromMessage uuid is null or invalid");
    }
}
 
Example 6
Source File: Treatments.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void pushTreatmentSyncToWatch(Treatments treatment, boolean is_new) {
    Log.d(TAG, "pushTreatmentSyncToWatch Add treatment to UploaderQueue.");
    if (Pref.getBooleanDefaultFalse("wear_sync")) {
        if (UploaderQueue.newEntryForWatch(is_new ? "insert" : "update", treatment) != null) {
            SyncService.startSyncService(3000); // sync in 3 seconds
        }
    }
}
 
Example 7
Source File: Treatments.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void delete_by_uuid(String uuid, boolean from_interactive) {
    Treatments thistreat = byuuid(uuid);
    if (thistreat != null) {

        UploaderQueue.newEntry("delete", thistreat);
        if (from_interactive) {
            GcmActivity.push_delete_treatment(thistreat);
            SyncService.startSyncService(3000); // sync in 3 seconds
        }

        thistreat.delete();
        Home.staticRefreshBGCharts();
    }
}
 
Example 8
Source File: BgReading.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public static void pushBgReadingSyncToWatch(BgReading bgReading, boolean is_new) {
    Log.d(TAG, "pushTreatmentSyncToWatch Add treatment to UploaderQueue.");
    if (Pref.getBooleanDefaultFalse("wear_sync")) {
        if (UploaderQueue.newEntryForWatch(is_new ? "insert" : "update", bgReading) != null) {
            SyncService.startSyncService(3000); // sync in 3 seconds
        }
    }
}
 
Example 9
Source File: BgReading.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void pushBgReadingSyncToWatch(BgReading bgReading, boolean is_new) {
    Log.d(TAG, "pushTreatmentSyncToWatch Add treatment to UploaderQueue.");
    if (Pref.getBooleanDefaultFalse("wear_sync")) {
        if (UploaderQueue.newEntryForWatch(is_new ? "insert" : "update", bgReading) != null) {
            SyncService.startSyncService(3000); // sync in 3 seconds
        }
    }
}
 
Example 10
Source File: BloodTest.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void pushBloodTestSyncToWatch(BloodTest bt, boolean is_new) {
    Log.d(TAG, "pushTreatmentSyncToWatch Add treatment to UploaderQueue.");
    if (Pref.getBooleanDefaultFalse("wear_sync")) {
        if (UploaderQueue.newEntryForWatch(is_new ? "insert" : "update", bt) != null) {
            SyncService.startSyncService(3000); // sync in 3 seconds
        }
    }
}
 
Example 11
Source File: BloodTest.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private static void processFromMessage(BloodTestMessage btm) {
    if ((btm != null) && (btm.uuid != null) && (btm.uuid.length() == 36)) {
        boolean is_new = false;
        BloodTest bt = byUUID(btm.uuid);
        if (bt == null) {
            bt = getForPreciseTimestamp(Wire.get(btm.timestamp, BloodTestMessage.DEFAULT_TIMESTAMP), CLOSEST_READING_MS);
            if (bt != null) {
                UserError.Log.wtf(TAG, "Error matches a different uuid with the same timestamp: " + bt.uuid + " vs " + btm.uuid + " skipping!");
                return;
            }
            bt = new BloodTest();
            is_new = true;
        } else {
            if (bt.state != Wire.get(btm.state, BloodTestMessage.DEFAULT_STATE)) {
                is_new = true;
            }
        }
        bt.timestamp = Wire.get(btm.timestamp, BloodTestMessage.DEFAULT_TIMESTAMP);
        bt.mgdl = Wire.get(btm.mgdl, BloodTestMessage.DEFAULT_MGDL);
        bt.created_timestamp = Wire.get(btm.created_timestamp, BloodTestMessage.DEFAULT_CREATED_TIMESTAMP);
        bt.state = Wire.get(btm.state, BloodTestMessage.DEFAULT_STATE);
        bt.source = Wire.get(btm.source, BloodTestMessage.DEFAULT_SOURCE);
        bt.uuid = btm.uuid;
        bt.saveit(); // de-dupe by uuid
        if (is_new) { // cannot handle updates yet
            if (UploaderQueue.newEntry(is_new ? "insert" : "update", bt) != null) {
                if (JoH.quietratelimit("start-sync-service", 5)) {
                    SyncService.startSyncService(3000); // sync in 3 seconds
                }
            }
        }
    } else {
        UserError.Log.wtf(TAG, "processFromMessage uuid is null or invalid");
    }
}
 
Example 12
Source File: Treatments.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void pushTreatmentSyncToWatch(Treatments treatment, boolean is_new) {
    Log.d(TAG, "pushTreatmentSyncToWatch Add treatment to UploaderQueue.");
    if (Pref.getBooleanDefaultFalse("wear_sync")) {
        if (UploaderQueue.newEntryForWatch(is_new ? "insert" : "update", treatment) != null) {
            SyncService.startSyncService(3000); // sync in 3 seconds
        }
    }
}
 
Example 13
Source File: Treatments.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void delete_by_uuid(String uuid, boolean from_interactive) {
    Treatments thistreat = byuuid(uuid);
    if (thistreat != null) {

        UploaderQueue.newEntry("delete", thistreat);
        if (from_interactive) {
            GcmActivity.push_delete_treatment(thistreat);
            SyncService.startSyncService(3000); // sync in 3 seconds
        }

        thistreat.delete();
        Home.staticRefreshBGCharts();
    }
}
 
Example 14
Source File: BgReading.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static void pushBgReadingSyncToWatch(BgReading bgReading, boolean is_new) {
    Log.d(TAG, "pushTreatmentSyncToWatch Add treatment to UploaderQueue.");
    if (Pref.getBooleanDefaultFalse("wear_sync")) {
        if (UploaderQueue.newEntryForWatch(is_new ? "insert" : "update", bgReading) != null) {
            SyncService.startSyncService(3000); // sync in 3 seconds
        }
    }
}
 
Example 15
Source File: BloodTest.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
public static BloodTest create(long timestamp_ms, double mgdl, String source, String suggested_uuid) {

        if ((timestamp_ms == 0) || (mgdl == 0)) {
            UserError.Log.e(TAG, "Either timestamp or mgdl is zero - cannot create reading");
            return null;
        }

        if (timestamp_ms < 1487759433000L) {
            UserError.Log.d(TAG, "Timestamp really too far in the past @ " + timestamp_ms);
            return null;
        }

        final long now = JoH.tsl();
        if (timestamp_ms > now) {
            if ((timestamp_ms - now) > 600000) {
                UserError.Log.wtf(TAG, "Timestamp is > 10 minutes in the future! Something is wrong: " + JoH.dateTimeText(timestamp_ms));
                return null;
            }
            timestamp_ms = now; // force to now if it showed up to 10 mins in the future
        }

        final BloodTest match = getForPreciseTimestamp(timestamp_ms, CLOSEST_READING_MS);
        if (match == null) {
            final BloodTest bt = new BloodTest();
            bt.timestamp = timestamp_ms;
            bt.mgdl = mgdl;
            bt.uuid = suggested_uuid == null ? UUID.randomUUID().toString() : suggested_uuid;
            bt.created_timestamp = JoH.tsl();
            bt.state = STATE_VALID;
            bt.source = source;
            bt.saveit();
            if (UploaderQueue.newEntry("insert", bt) != null) {
                SyncService.startSyncService(3000); // sync in 3 seconds
            }

            if (Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations_auto")) {
                if ((JoH.msSince(bt.timestamp) < Constants.MINUTE_IN_MS * 5) && (JoH.msSince(bt.timestamp) > 0)) {
                    UserError.Log.d(TAG, "Blood test value recent enough to send to G5");
                    //Ob1G5StateMachine.addCalibration((int) bt.mgdl, timestamp_ms);
                    NativeCalibrationPipe.addCalibration((int) bt.mgdl, timestamp_ms);
                }
            }

            return bt;
        } else {
            UserError.Log.d(TAG, "Not creating new reading as timestamp is too close");
        }
        return null;
    }
 
Example 16
Source File: BloodTest.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
public static BloodTest create(long timestamp_ms, double mgdl, String source, String suggested_uuid) {

        if ((timestamp_ms == 0) || (mgdl == 0)) {
            UserError.Log.e(TAG, "Either timestamp or mgdl is zero - cannot create reading");
            return null;
        }

        if (timestamp_ms < 1487759433000L) {
            UserError.Log.d(TAG, "Timestamp really too far in the past @ " + timestamp_ms);
            return null;
        }

        final long now = JoH.tsl();
        if (timestamp_ms > now) {
            if ((timestamp_ms - now) > 600000) {
                UserError.Log.wtf(TAG, "Timestamp is > 10 minutes in the future! Something is wrong: " + JoH.dateTimeText(timestamp_ms));
                return null;
            }
            timestamp_ms = now; // force to now if it showed up to 10 mins in the future
        }

        final BloodTest match = getForPreciseTimestamp(timestamp_ms, CLOSEST_READING_MS);
        if (match == null) {
            final BloodTest bt = new BloodTest();
            bt.timestamp = timestamp_ms;
            bt.mgdl = mgdl;
            bt.uuid = suggested_uuid == null ? UUID.randomUUID().toString() : suggested_uuid;
            bt.created_timestamp = JoH.tsl();
            bt.state = STATE_VALID;
            bt.source = source;
            bt.saveit();
            if (UploaderQueue.newEntry("insert", bt) != null) {
                SyncService.startSyncService(3000); // sync in 3 seconds
            }

            if (Pref.getBooleanDefaultFalse("bluetooth_meter_for_calibrations_auto")) {
                if ((JoH.msSince(bt.timestamp) < Constants.MINUTE_IN_MS * 5) && (JoH.msSince(bt.timestamp) > 0)) {
                    UserError.Log.d(TAG, "Blood test value recent enough to send to G5");
                    //Ob1G5StateMachine.addCalibration((int) bt.mgdl, timestamp_ms);
                    NativeCalibrationPipe.addCalibration((int) bt.mgdl, timestamp_ms);
                }
            }

            return bt;
        } else {
            UserError.Log.d(TAG, "Not creating new reading as timestamp is too close");
        }
        return null;
    }