Search in sources :

Example 1 with FileDeleteRequest

use of nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileDeleteRequest in project Gadgetbridge by Freeyourgadget.

the class FossilWatchAdapter method onFetchActivityData.

@Override
public void onFetchActivityData() {
    queueWrite(new FileLookupAndGetRequest(FileHandle.ACTIVITY_FILE, this) {

        @Override
        public void handleFileData(byte[] fileData) {
            try (DBHandler dbHandler = GBApplication.acquireDB()) {
                ActivityFileParser parser = new ActivityFileParser();
                ArrayList<ActivityEntry> entries = parser.parseFile(fileData);
                HybridHRActivitySampleProvider provider = new HybridHRActivitySampleProvider(getDeviceSupport().getDevice(), dbHandler.getDaoSession());
                HybridHRActivitySample[] samples = new HybridHRActivitySample[entries.size()];
                Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId();
                Long deviceId = DBHelper.getDevice(getDeviceSupport().getDevice(), dbHandler.getDaoSession()).getId();
                for (int i = 0; i < entries.size(); i++) {
                    samples[i] = entries.get(i).toDAOActivitySample(userId, deviceId);
                }
                provider.addGBActivitySamples(samples);
                queueWrite(new FileDeleteRequest(getHandle()));
                GB.toast("synced activity data", Toast.LENGTH_SHORT, GB.INFO);
            } catch (Exception ex) {
                GB.toast(getContext(), "Error saving steps data: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
                GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext());
            }
            getDeviceSupport().getDevice().sendDeviceUpdateIntent(getContext());
        }

        @Override
        public void handleFileLookupError(FILE_LOOKUP_ERROR error) {
            if (error == FILE_LOOKUP_ERROR.FILE_EMPTY) {
                GB.toast("activity file empty", Toast.LENGTH_SHORT, GB.INFO);
            }
        }
    });
}
Also used : DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) FileLookupAndGetRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileLookupAndGetRequest) ActivityFileParser(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.parser.ActivityFileParser) ArrayList(java.util.ArrayList) HybridHRActivitySampleProvider(nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.HybridHRActivitySampleProvider) FileDeleteRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileDeleteRequest) JSONException(org.json.JSONException) IOException(java.io.IOException)

Example 2 with FileDeleteRequest

use of nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileDeleteRequest in project Gadgetbridge by Freeyourgadget.

the class FossilHRWatchAdapter method onFetchActivityData.

@Override
public void onFetchActivityData() {
    if (connectionMode == CONNECTION_MODE.NOT_AUTHENTICATED) {
        GB.toast(getContext().getString(R.string.fossil_hr_unavailable_unauthed), Toast.LENGTH_LONG, GB.ERROR);
        return;
    }
    syncSettings();
    queueWrite(new FileLookupRequest(FileHandle.ACTIVITY_FILE, this) {

        @Override
        public void handleFileLookup(final short fileHandle) {
            queueWrite((FileEncryptedInterface) new FileEncryptedGetRequest(fileHandle, FossilHRWatchAdapter.this) {

                @Override
                public void handleFileData(byte[] fileData) {
                    try (DBHandler dbHandler = GBApplication.acquireDB()) {
                        ActivityFileParser parser = new ActivityFileParser();
                        ArrayList<ActivityEntry> entries = parser.parseFile(fileData);
                        HybridHRActivitySampleProvider provider = new HybridHRActivitySampleProvider(getDeviceSupport().getDevice(), dbHandler.getDaoSession());
                        HybridHRActivitySample[] samples = new HybridHRActivitySample[entries.size()];
                        Long userId = DBHelper.getUser(dbHandler.getDaoSession()).getId();
                        Long deviceId = DBHelper.getDevice(getDeviceSupport().getDevice(), dbHandler.getDaoSession()).getId();
                        for (int i = 0; i < entries.size(); i++) {
                            samples[i] = entries.get(i).toDAOActivitySample(userId, deviceId);
                        }
                        provider.addGBActivitySamples(samples);
                        if (saveRawActivityFiles) {
                            writeFile(String.valueOf(System.currentTimeMillis()), fileData);
                        }
                        queueWrite(new FileDeleteRequest(fileHandle));
                        GB.toast(getContext().getString(R.string.fossil_hr_synced_activity_data), Toast.LENGTH_SHORT, GB.INFO);
                    } catch (Exception ex) {
                        GB.toast(getContext(), "Error saving steps data: " + ex.getLocalizedMessage(), Toast.LENGTH_LONG, GB.ERROR);
                        GB.updateTransferNotification(null, "Data transfer failed", false, 0, getContext());
                    }
                    getDeviceSupport().getDevice().sendDeviceUpdateIntent(getContext());
                }
            });
        }

        @Override
        public void handleFileLookupError(FILE_LOOKUP_ERROR error) {
            if (error == FILE_LOOKUP_ERROR.FILE_EMPTY) {
                GB.toast("activity file empty yet", Toast.LENGTH_LONG, GB.ERROR);
            } else {
                throw new RuntimeException("strange lookup stuff");
            }
            getDeviceSupport().getDevice().sendDeviceUpdateIntent(getContext());
        }
    });
}
Also used : FileEncryptedInterface(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.file.FileEncryptedInterface) FileEncryptedGetRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.file.FileEncryptedGetRequest) ActivityFileParser(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.parser.ActivityFileParser) ArrayList(java.util.ArrayList) FileLookupRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileLookupRequest) JSONException(org.json.JSONException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) BufferOverflowException(java.nio.BufferOverflowException) DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) HybridHRActivitySampleProvider(nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.HybridHRActivitySampleProvider) FileDeleteRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileDeleteRequest)

Example 3 with FileDeleteRequest

use of nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileDeleteRequest in project Gadgetbridge by Freeyourgadget.

the class FossilHRWatchAdapter method uninstallApp.

@Override
public void uninstallApp(String appName) {
    for (ApplicationInformation appInfo : this.installedApplications) {
        if (appInfo.getAppName().equals(appName)) {
            byte handle = appInfo.getFileHandle();
            short fullFileHandle = (short) ((FileHandle.APP_CODE.getMajorHandle()) << 8 | handle);
            queueWrite(new FileDeleteRequest(fullFileHandle));
            listApplications();
            break;
        }
    }
}
Also used : FileDeleteRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileDeleteRequest) ApplicationInformation(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.application.ApplicationInformation)

Aggregations

FileDeleteRequest (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileDeleteRequest)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 DBHandler (nodomain.freeyourgadget.gadgetbridge.database.DBHandler)2 HybridHRActivitySampleProvider (nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.HybridHRActivitySampleProvider)2 ActivityFileParser (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.parser.ActivityFileParser)2 JSONException (org.json.JSONException)2 FileNotFoundException (java.io.FileNotFoundException)1 BufferOverflowException (java.nio.BufferOverflowException)1 FileLookupAndGetRequest (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileLookupAndGetRequest)1 FileLookupRequest (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil.file.FileLookupRequest)1 ApplicationInformation (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.application.ApplicationInformation)1 FileEncryptedGetRequest (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.file.FileEncryptedGetRequest)1 FileEncryptedInterface (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.file.FileEncryptedInterface)1