2021-01-10 23:37:09 +01:00
|
|
|
/* Copyright (C) 2015-2021 Andreas Shimokawa, Carsten Pfeiffer, Daniele
|
2017-03-10 14:53:19 +01:00
|
|
|
Gobbetti, João Paulo Barraca
|
|
|
|
|
|
|
|
This file is part of Gadgetbridge.
|
|
|
|
|
|
|
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published
|
|
|
|
by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Gadgetbridge is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.devices;
|
2015-07-27 23:49:53 +02:00
|
|
|
|
2016-05-16 23:00:04 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
2019-01-26 15:52:40 +01:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
2016-05-16 23:00:04 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.entities.AbstractActivitySample;
|
|
|
|
|
2016-08-27 16:44:47 +02:00
|
|
|
/**
|
|
|
|
* Interface to retrieve samples from the database, and also create and add samples to the database.
|
|
|
|
* There are multiple device specific implementations, this interface defines the generic access.
|
2016-08-27 21:40:46 +02:00
|
|
|
*
|
|
|
|
* Note that the provided samples must typically be considered read-only, because they are immediately
|
|
|
|
* removed from the session before they are returned.
|
|
|
|
*
|
2016-08-27 16:44:47 +02:00
|
|
|
* @param <T> the device/provider specific sample type (must extend AbstractActivitySample)
|
|
|
|
*/
|
2016-05-16 23:36:54 +02:00
|
|
|
public interface SampleProvider<T extends AbstractActivitySample> {
|
2017-03-20 22:27:17 +01:00
|
|
|
// These are only used for SharedPreferences
|
2016-02-29 20:54:39 +01:00
|
|
|
int PROVIDER_PEBBLE_MORPHEUZ = 1;
|
|
|
|
int PROVIDER_PEBBLE_MISFIT = 3;
|
|
|
|
int PROVIDER_PEBBLE_HEALTH = 4;
|
2015-07-27 23:49:53 +02:00
|
|
|
|
2016-02-29 20:54:39 +01:00
|
|
|
int normalizeType(int rawType);
|
2015-07-27 23:49:53 +02:00
|
|
|
|
2016-02-29 20:54:39 +01:00
|
|
|
int toRawActivityKind(int activityKind);
|
2015-07-27 23:49:53 +02:00
|
|
|
|
2016-02-29 20:54:39 +01:00
|
|
|
float normalizeIntensity(int rawIntensity);
|
2015-07-27 23:49:53 +02:00
|
|
|
|
2016-08-27 16:44:47 +02:00
|
|
|
/**
|
|
|
|
* Returns the list of all samples, of any type, within the given time span.
|
|
|
|
* @param timestamp_from the start timestamp
|
|
|
|
* @param timestamp_to the end timestamp
|
|
|
|
* @return the list of samples of any type
|
|
|
|
*/
|
|
|
|
@NonNull
|
2016-05-16 23:00:04 +02:00
|
|
|
List<T> getAllActivitySamples(int timestamp_from, int timestamp_to);
|
|
|
|
|
2016-08-27 16:44:47 +02:00
|
|
|
/**
|
|
|
|
* Returns the list of all samples that represent user "activity", within
|
|
|
|
* the given time span. This excludes samples of type sleep, for example.
|
|
|
|
* @param timestamp_from the start timestamp
|
|
|
|
* @param timestamp_to the end timestamp
|
|
|
|
* @return the list of samples of type user activity, e.g. non-sleep
|
|
|
|
*/
|
|
|
|
@NonNull
|
2016-05-16 23:00:04 +02:00
|
|
|
List<T> getActivitySamples(int timestamp_from, int timestamp_to);
|
|
|
|
|
2016-08-27 16:44:47 +02:00
|
|
|
/**
|
|
|
|
* Returns the list of all samples that represent "sleeping", within the
|
|
|
|
* given time span.
|
|
|
|
* @param timestamp_from the start timestamp
|
|
|
|
* @param timestamp_to the end timestamp
|
|
|
|
* @return the list of samples of type sleep
|
|
|
|
*/
|
|
|
|
@NonNull
|
2016-05-16 23:00:04 +02:00
|
|
|
List<T> getSleepSamples(int timestamp_from, int timestamp_to);
|
|
|
|
|
2016-08-27 16:44:47 +02:00
|
|
|
/**
|
|
|
|
* Adds the given sample to the database. An existing sample with the same
|
|
|
|
* timestamp will be overwritten.
|
|
|
|
* @param activitySample the sample to add
|
|
|
|
*/
|
2016-05-16 23:36:54 +02:00
|
|
|
void addGBActivitySample(T activitySample);
|
|
|
|
|
2016-08-27 16:44:47 +02:00
|
|
|
/**
|
|
|
|
* Adds the given samples to the database. Existing samples with the same
|
|
|
|
* timestamp will be overwritten.
|
|
|
|
* @param activitySamples the samples to add
|
|
|
|
*/
|
2016-05-16 23:36:54 +02:00
|
|
|
void addGBActivitySamples(T[] activitySamples);
|
2016-06-16 21:54:53 +02:00
|
|
|
|
2016-08-27 16:44:47 +02:00
|
|
|
/**
|
|
|
|
* Factory method to creates an empty sample of the correct type for this sample provider
|
|
|
|
* @return the newly created "empty" sample
|
|
|
|
*/
|
2016-06-16 21:54:53 +02:00
|
|
|
T createActivitySample();
|
2016-11-22 00:03:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the activity sample with the highest timestamp. or null if none
|
|
|
|
* @return the latest sample or null
|
|
|
|
*/
|
|
|
|
@Nullable
|
|
|
|
T getLatestActivitySample();
|
2022-07-23 23:37:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the activity sample with the oldest timestamp or null if none
|
|
|
|
* @return the oldest sample or null
|
|
|
|
*/
|
|
|
|
@Nullable
|
|
|
|
T getFirstActivitySample();
|
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
}
|