Skip to content

Commit

Permalink
Fix of User Task issues (#345)
Browse files Browse the repository at this point in the history
* fix of #341

* fix of #340
  • Loading branch information
bardram authored Nov 4, 2024
1 parent 64b70f1 commit 3bf9d77
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 94 deletions.
12 changes: 6 additions & 6 deletions ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = "$(FLUTTER_BUILD_NUMBER)";
PRODUCT_BUNDLE_IDENTIFIER = com.cachet.carpstudyapp;
PRODUCT_BUNDLE_IDENTIFIER = dk.cachet.carpstudyapp;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
Expand All @@ -473,7 +473,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.cachet.carpstudyapp.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = dk.cachet.carpstudyapp.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -490,7 +490,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.cachet.carpstudyapp.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = dk.cachet.carpstudyapp.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
Expand All @@ -505,7 +505,7 @@
CURRENT_PROJECT_VERSION = 1;
GENERATE_INFOPLIST_FILE = YES;
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.cachet.carpstudyapp.RunnerTests;
PRODUCT_BUNDLE_IDENTIFIER = dk.cachet.carpstudyapp.RunnerTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Runner.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/Runner";
Expand Down Expand Up @@ -639,7 +639,7 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = "$(FLUTTER_BUILD_NUMBER)";
PRODUCT_BUNDLE_IDENTIFIER = com.cachet.carpstudyapp;
PRODUCT_BUNDLE_IDENTIFIER = dk.cachet.carpstudyapp;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
Expand Down Expand Up @@ -673,7 +673,7 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = "$(FLUTTER_BUILD_NUMBER)";
PRODUCT_BUNDLE_IDENTIFIER = com.cachet.carpstudyapp;
PRODUCT_BUNDLE_IDENTIFIER = dk.cachet.carpstudyapp;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator";
SUPPORTS_MACCATALYST = NO;
Expand Down
8 changes: 4 additions & 4 deletions lib/blocs/app_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,13 @@ class StudyAppBLoC extends ChangeNotifier {
Sensing().controller?.dispose();
}

/// Add a [Measurement] object to the stream of measurements.
/// Add [measurement] to the stream of collected measurements.
void addMeasurement(Measurement measurement) =>
Sensing().controller!.executor.addMeasurement(measurement);
Sensing().controller?.executor.addMeasurement(measurement);

/// Add a error to the stream of measurements.
/// Add [error] to the stream of measurements.
void addError(Object error, [StackTrace? stacktrace]) =>
Sensing().controller!.executor.addError(error, stacktrace);
Sensing().controller?.executor.addError(error, stacktrace);

/// Leave the study deployed on this phone.
///
Expand Down
8 changes: 5 additions & 3 deletions lib/ui/pages/audio_task_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ class AudioTaskPageState extends State<AudioTaskPage> {
body: SafeArea(
child: PopScope(
canPop: true,
onPopInvoked: (didPop) async =>
_showCancelConfirmationDialog() as FutureOr<bool>,
// onPopInvokedWithResult: (didPop, result) =>
// _showCancelConfirmationDialog(),
// onPopInvoked: (didPop) async =>
// _showCancelConfirmationDialog() as FutureOr<bool>,
child: Scaffold(
body: Container(
padding: const EdgeInsets.symmetric(horizontal: 15),
Expand Down Expand Up @@ -311,7 +313,7 @@ class AudioTaskPageState extends State<AudioTaskPage> {
radius: 30,
backgroundColor: CACHET.GREEN_1,
child: IconButton(
onPressed: () => Navigator.pop(context),
onPressed: () => Navigator.of(context).pop(),
padding: const EdgeInsets.all(0),
icon: const Icon(Icons.check_circle_outline,
color: Colors.white, size: 30),
Expand Down
15 changes: 11 additions & 4 deletions lib/ui/pages/camera_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,24 @@ class CameraPageState extends State<CameraPage> {

Future<void> initializeCamera() async {
cameras = await availableCameras();
_cameraController = CameraController(cameras![0], ResolutionPreset.max,
imageFormatGroup: ImageFormatGroup.yuv420, enableAudio: true);
_cameraController = CameraController(
cameras![0],
ResolutionPreset.max,
imageFormatGroup: ImageFormatGroup.yuv420,
enableAudio: true,
);
cameraInit = _cameraController.initialize();
setState(() {});
}

void toggleCamera() async {
int newCameraIndex = isFrontCamera ? 0 : 1;
_cameraController = CameraController(
cameras![newCameraIndex], ResolutionPreset.max,
imageFormatGroup: ImageFormatGroup.yuv420, enableAudio: true);
cameras![newCameraIndex],
ResolutionPreset.max,
imageFormatGroup: ImageFormatGroup.yuv420,
enableAudio: true,
);
await _cameraController.initialize();
setState(() {
isFrontCamera = !isFrontCamera;
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/pages/camera_task_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class CameraTaskPageState extends State<CameraTaskPage> {
@override
Widget build(BuildContext context) => PopScope(
canPop: true,
onPopInvoked: (didPop) async =>
_showCancelConfirmationDialog() as FutureOr<bool>,
// onPopInvoked: (didPop) async =>
// _showCancelConfirmationDialog() as FutureOr<bool>,
child: Scaffold(
body: Container(
padding: const EdgeInsets.symmetric(horizontal: 15),
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/pages/login_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class _LoginPageState extends State<LoginPage> {
showDialog<bool>(
context: context,
builder: (context) => PopScope(
onPopInvoked: (didPop) async {
onPopInvokedWithResult: (didPop, result) async {
Navigator.of(context).pop();
},
child: EnableInternetConnectionDialog(),
Expand Down
69 changes: 40 additions & 29 deletions lib/view_models/user_tasks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,27 @@ class AppUserTaskFactory implements UserTaskFactory {
];

@override
UserTask create(AppTaskExecutor executor) {
switch (executor.task.type) {
case SurveyUserTask.AUDIO_TYPE:
return AudioUserTask(executor);
case SurveyUserTask.VIDEO_TYPE:
return VideoUserTask(executor);
case SurveyUserTask.IMAGE_TYPE:
return VideoUserTask(executor);
case SurveyUserTask.HEALTH_ASSESSMENT_TYPE:
return OneTimeBackgroundSensingUserTask(executor);
default:
return BackgroundSensingUserTask(executor);
}
}
UserTask create(AppTaskExecutor executor) => switch (executor.task.type) {
SurveyUserTask.AUDIO_TYPE => AudioUserTask(executor),
SurveyUserTask.VIDEO_TYPE => VideoUserTask(executor),
SurveyUserTask.IMAGE_TYPE => VideoUserTask(executor),
SurveyUserTask.HEALTH_ASSESSMENT_TYPE =>
OneTimeBackgroundSensingUserTask(executor),
_ => BackgroundSensingUserTask(executor),
};
}

/// A user task handling audio recordings.
/// When started, creates a [AudioTaskPage] and shows it to the user.
///
/// The [widget] returns an [AudioTaskPage] that can be shown on the UI.
///
/// When the recording is started (calling the [onRecordStart] method),
/// the background task collecting sensor measures is started.
class AudioUserTask extends UserTask {
final StreamController<int> _countDownController =
StreamController.broadcast();
Stream<int>? get countDownEvents => _countDownController.stream;
Timer? _timer;

/// Total duration of audio recording in seconds.
int recordingDuration = 60;
Expand All @@ -46,7 +45,11 @@ class AudioUserTask extends UserTask {
: 60;
}

Timer? _timer;
@override
bool get hasWidget => true;

@override
Widget? get widget => AudioTaskPage(audioUserTask: this);

/// Callback when recording is to start.
void onRecordStart() {
Expand Down Expand Up @@ -80,17 +83,17 @@ class AudioUserTask extends UserTask {
/// A user task handling video and image recordings.
/// When started, creates a [CameraTaskPage].
class VideoUserTask extends UserTask {
VideoUserTask(super.executor);
DateTime? _startRecordingTime, _endRecordingTime;
XFile? _file;
MediaType _mediaType = MediaType.image;

@override
bool get hasWidget => true;

@override
Widget? get widget => CameraTaskPage(mediaUserTask: this);

DateTime? _startRecordingTime, _endRecordingTime;
XFile? _file;
MediaType _mediaType = MediaType.image;
VideoUserTask(super.executor);

/// Callback when a picture is captured.
void onPictureCapture(XFile image) {
Expand Down Expand Up @@ -123,17 +126,25 @@ class VideoUserTask extends UserTask {
void onSave() {
debug('$runtimeType - onSave(), file: ${_file?.path}');
if (_file != null) {
// create the media measurement directly here...
Media media = Media(
filename: _file!.path,
startRecordingTime: _startRecordingTime!,
endRecordingTime: _endRecordingTime,
mediaType: _mediaType)
..filename = _file!.path.split("/").last
..path = _file!.path;
// create the media measurement ...
MediaData? media = switch (_mediaType) {
MediaType.image => ImageMedia(
filename: _file!.path,
startRecordingTime: _startRecordingTime!,
endRecordingTime: _endRecordingTime)
..filename = _file!.path.split("/").last
..path = _file!.path,
MediaType.video => VideoMedia(
filename: _file!.path,
startRecordingTime: _startRecordingTime!,
endRecordingTime: _endRecordingTime)
..filename = _file!.path.split("/").last
..path = _file!.path,
_ => null,
};

// ... and add it to the sensing controller
bloc.addMeasurement(Measurement.fromData(media));
if (media != null) bloc.addMeasurement(Measurement.fromData(media));
}
backgroundTaskExecutor.stop();
super.onDone();
Expand Down
Loading

0 comments on commit 3bf9d77

Please sign in to comment.