Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No notification banner for all surveys not triggered initially with ImmediateTrigger() #316

Open
Z-Setiadi opened this issue Jul 30, 2024 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@Z-Setiadi
Copy link

Device Hardware / Emulator and OS

  • Hardware: Motorola moto g play - 2023
  • SDK: Android API level 31
  • App version: 2.0
  • App deployment mode: local

Describe the bug

I have multiple survey tasks in the protocol, and most of them utilize either the RecurrentScheduledTrigger() or the RandomRecurrentTrigger(). While the surveys are triggered, there are no notification banners for them. The only trigger that gives me a notification banner is the ImmediateTrigger(). I have all notifications allowed and each of the RPAppTasks has the notification parameter set to true.

To Reproduce

  1. Create a LocalStudyProtocolManager that implements the StudyProtocolManager (I based this off of the code from the CARP's Pulmonary App's study_protocol_manager.dart file).
  2. In the LocalStudyProtocolManager, add a task (ours is in the form of a survey) that is triggered by an ImmediateTrigger().
  3. Do the same as step 2, but with RandomRecurrentTrigger() and RecurrentScheduledTrigger().
  4. In /blocs/sensing.dart, on line 112, change "LocalResourceManager()" to "LocalStudyProtocolManager()"
  5. Run locally.

Expected behavior

I expected all three tasks to produce a notification banner.

Actual behavior

Only the task triggered by ImmediateTrigger() gives me a notification banner. The rest of the tasks are triggered but do not notify me.

@SlimShadyIAm
Copy link
Collaborator

Hi @Z-Setiadi,

I have also experienced this issue with the RecurrentScheduledTrigger() and am personally using the CronScheduledTrigger which I have found to work consistently with notifications as well. Nonetheless this should be investigated.

Could you provide me with an example of a protocol you used to produce this behavior?

@SlimShadyIAm SlimShadyIAm added bug Something isn't working good first issue Good for newcomers labels Aug 2, 2024
@Z-Setiadi
Copy link
Author

Here is an example of the protocol:

class LocalStudyProtocolManager implements StudyProtocolManager {
  @override
  Future<void> initialize() async {}

  @override
  Future<SmartphoneStudyProtocol> getStudyProtocol(String studyId) async {
    SmartphoneStudyProtocol protocol = SmartphoneStudyProtocol(
      name: 'blank',
      ownerId: 'blank',
    );
    protocol.studyDescription = StudyDescription(
        title: 'blank',
        description:
            "???",
        purpose:
            "???",
        responsible: StudyResponsible(
          id: 'blank',
          title: 'blank',
          address: 'blank',
          affiliation: 'blank',
          email: 'blank',
          name: 'blank',
        ));

    // Define the data end point , i.e., where to store data.
    // This example app only stores data locally in a SQLite DB
    protocol.dataEndPoint = SQLiteDataEndPoint();

    // Define which devices are used for data collection.
    Smartphone phone = Smartphone();
    protocol.addPrimaryDevice(phone);

    SamplingPackageRegistry().register(SurveySamplingPackage());

    // task triggered by ImmediateTrigger()
    // this should produce a notification banner
    protocol.addTaskControl(
        ImmediateTrigger(),
        RPAppTask(
          type: SurveyUserTask.SURVEY_TYPE,
          title: surveys.selfReport.title,
          description: surveys.selfReport.description,
          minutesToComplete: surveys.selfReport.minutesToComplete,
          notification: true,
          rpTask: surveys.selfReport.survey,
        ),
        phone);

    // task triggered by RecurrentScheduledTrigger()
    // this currently does not produce a notification banner
    protocol.addTaskControl(
        RecurrentScheduledTrigger(
            type: RecurrentType.daily,
            time: const TimeOfDay(hour: 8)),
        RPAppTask(
          type: SurveyUserTask.SURVEY_TYPE,
          title: surveys.morning.title,
          description: surveys.morning.description,
          minutesToComplete: surveys.morning.minutesToComplete,
          notification: true,
          rpTask: surveys.morning.survey,
          expire: const Duration(hours: 1),
        ),
        phone);

    // task triggered by RandomRecurrentTrigger()
    // this currently does not produce a notification banner
    protocol.addTaskControl(
        RandomRecurrentTrigger(
          startTime: const TimeOfDay(hour: 9),
          endTime: const TimeOfDay(hour: 11),
          minNumberOfTriggers: 1,
          maxNumberOfTriggers: 1,
        ),
        RPAppTask(
          type: SurveyUserTask.SURVEY_TYPE,
          title: surveys.dailyReport.title,
          description: surveys.dailyReport.description,
          minutesToComplete: surveys.dailyReport.minutesToComplete,
          notification: true,
          rpTask: surveys.dailyReport.survey,
          expire: const Duration(hours: 1),
        ),
        phone);
}

And here is an example of a surveys file to use for this protocol:

final surveys = _Surveys();

class _Surveys {
  final Survey _morning = _MorningSurvey();
  Survey get morning => _morning;

  final Survey _dailyReport = _DailyReport();
  Survey get dailyReport => _dailyReport;

  final Survey _selfReport = _SelfReport();
  Survey get selfReport => _selfReport;
}

/// An interface for an survey from the RP package.
abstract class Survey {
  /// The title of this survey.
  String get title;

  /// A short description (one line) of this survey
  String get description;

  /// How many minutes will it take to do this survey?
  int get minutesToComplete;

  /// The survey to fill out.
  RPTask get survey;
}

class _MorningSurvey implements Survey {
  @override
  String get title => "Morning Survey";
  @override
  String get description => "A short morning check-in.";
  @override
  int get minutesToComplete => 5;

  final RPChoiceAnswerFormat _yesNo = RPChoiceAnswerFormat(
      answerStyle: RPChoiceAnswerStyle.SingleChoice,
      choices: [
        RPChoice(text: "Yes", value: 1),
        RPChoice(text: "No", value: 2),
      ]);
  RPNavigableOrderedTask get survey => RPNavigableOrderedTask(
    identifier: "morning",
    steps: [
      RPQuestionStep(
        identifier: "test",
        title: "Did you sleep well?",
        answerFormat: _yesNo,
      ),
    ],
  )
}

class _DailyReport implements Survey {
  @override
  String get title => "Daily Report";
  @override
  String get description => "A short daily check-in.";
  @override
  int get minutesToComplete => 5;

  final RPChoiceAnswerFormat _yesNo = RPChoiceAnswerFormat(
      answerStyle: RPChoiceAnswerStyle.SingleChoice,
      choices: [
        RPChoice(text: "Yes", value: 1),
        RPChoice(text: "No", value: 2),
      ]);
  RPNavigableOrderedTask get survey => RPNavigableOrderedTask(
    identifier: "daily",
    steps: [
      RPQuestionStep(
        identifier: "test",
        title: "Did you sleep well?",
        answerFormat: _yesNo,
      ),
    ],
  )
}

class _SelfReport implements Survey {
  @override
  String get title => "Self Report";
  @override
  String get description => "A short self check-in.";
  @override
  int get minutesToComplete => 5;

  final RPChoiceAnswerFormat _yesNo = RPChoiceAnswerFormat(
      answerStyle: RPChoiceAnswerStyle.SingleChoice,
      choices: [
        RPChoice(text: "Yes", value: 1),
        RPChoice(text: "No", value: 2),
      ]);
  RPNavigableOrderedTask get survey => RPNavigableOrderedTask(
    identifier: "morning",
    steps: [
      RPQuestionStep(
        identifier: "test",
        title: "Did you sleep well?",
        answerFormat: _yesNo,
      ),
    ],
  )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants