health_kit_api.dart 3.63 KB
import 'package:pigeon/pigeon.dart';

class HealthUploadResult {
  HealthUploadResult({
    required this.commonUploadSuccess,
    required this.sleepUploadSuccess,
    this.errorMessage,
  });

  bool commonUploadSuccess;
  bool sleepUploadSuccess;
  String? errorMessage;
}

class HealthUploadDataPoint {
  HealthUploadDataPoint({
    required this.dataType,
    required this.time,
    required this.value,
  });

  int dataType;
  int time;
  double value;
}

class HealthSleepUploadDataPoint {
  HealthSleepUploadDataPoint({
    required this.dataType,
    required this.fromTime,
    required this.toTime,
  });

  int dataType;
  int fromTime;
  int toTime;
}

class HealthActivityTargetData {
  HealthActivityTargetData({
    this.move,
    this.stand,
  });

  int? move;
  int? stand;
}

class HealthAuthorization {
  /// -1: AppleHealth不可用, 0: 需要请求授权, 1: 已被授权且能获取到部分数据, 2: 已被拒绝或者没有数据
  final int status;
  final bool hasData;

  HealthAuthorization({required this.status, required this.hasData});
}

@ConfigurePigeon(
  PigeonOptions(
    dartOut: 'lib/pigeon/health_kit_api.g.dart',
    dartPackageName: 'doublefeel_flutter',
    dartOptions: DartOptions(),
    kotlinOut:
        'android/app/src/main/kotlin/com/doublefeel/app/pigeon/HealthKitApi.kt',
    kotlinOptions: KotlinOptions(
      package: 'com.doublefeel.app.pigeon',
    ),
    swiftOut: 'ios/Runner/Pigeon/HealthKitApi.swift',
    swiftOptions: SwiftOptions(),
    arkTSOut: 'ohos/entry/src/main/ets/pigeon/HealthKitApi.ets',
    copyrightHeader: 'pigeon/copyright.txt',
  ),
)
@HostApi()
abstract class HealthKitHostApi {
  // @optional

  @async
  String getHealthServerAuthUrl();

  bool cancelHealthAppAuthorization();

  /// Runs native health read and server upload pipeline.
  @async
  HealthUploadResult performHealthUpload();

  /// 获取当前已上传的健康数据点,主要用于调试
  // List<HealthUploadDataPoint> getDebugCurrentUploadedData();

// @required

  /// Opens Huawei Health client authorization UI. Returns whether user granted.
  @async
  HealthAuthorization checkHealthAppAuthorization();

  @async
  bool requestHealthClientAuthorization();

  @async
  List<HealthUploadDataPoint> fetchHrvData(int startTime, int endTime);

  @async
  List<HealthUploadDataPoint> fetchHeartRateData(int startTime, int endTime);

  @async
  List<HealthUploadDataPoint> fetchWalkingHeartRateData(
    int startTime,
    int endTime,
  );

  @async
  List<HealthUploadDataPoint> fetchRestingHeartRateData(
    int startTime,
    int endTime,
  );

  @async
  List<HealthUploadDataPoint> fetchSleepingHeartRateData(
    int startTime,
    int endTime,
  );

  @async
  List<HealthUploadDataPoint> fetchOxygenSaturationData(
    int startTime,
    int endTime,
  );

  @async
  List<HealthUploadDataPoint> fetchActiveEnergyData(
    int startTime,
    int endTime,
  );

  @async
  List<HealthUploadDataPoint> fetchExerciseData(int startTime, int endTime);

  @async
  List<HealthUploadDataPoint> fetchStandData(int startTime, int endTime);

  @async
  List<HealthUploadDataPoint> fetchStepCountData(int startTime, int endTime);

  @async
  List<HealthSleepUploadDataPoint> fetchSleepData(int startTime, int endTime);

  @async
  List<HealthUploadDataPoint> fetchSleepingWristTemperatureData(
    int startTime,
    int endTime,
  );

  @async
  List<HealthUploadDataPoint> fetchRespiratoryRateData(
    int startTime,
    int endTime,
  );

  @async
  List<HealthUploadDataPoint> fetchIrregularHeartRhythmData(
    int startTime,
    int endTime,
  );

  @async
  HealthActivityTargetData? fetchActivityTargetData(
    int startTime,
    int endTime,
  );
}