presenter-api: fixed menu state for messenger #379

This commit is contained in:
Alex Andres 2024-08-16 19:11:45 +02:00
parent f7d598acbd
commit 4ec0db7d63
No known key found for this signature in database
GPG key ID: 340764C7851D7041
3 changed files with 34 additions and 8 deletions

View file

@ -45,9 +45,12 @@ public class StartCourseFeaturePresenter extends Presenter<StartCourseFeatureVie
private Course course;
/** The action that is executed when the saving process has been aborted. */
/** The action that is executed when the user clicked the start button. */
private Action startAction;
/** The action that is executed when the process has been aborted. */
private Action abortAction;
@Inject
StartCourseFeaturePresenter(ApplicationContext context,
@ -105,6 +108,10 @@ public class StartCourseFeaturePresenter extends Presenter<StartCourseFeatureVie
PresenterContext presenterContext = (PresenterContext) context;
presenterContext.setStreamStarted(false);
if (nonNull(abortAction)) {
abortAction.execute();
}
}
@Override
@ -120,6 +127,10 @@ public class StartCourseFeaturePresenter extends Presenter<StartCourseFeatureVie
startAction = action;
}
public void setOnAbort(Action action) {
abortAction = action;
}
private void onStart() {
dispose();

View file

@ -27,19 +27,27 @@ public class StartCourseFeatureCommand extends ShowPresenterCommand<StartCourseF
private final Action startAction;
private final Action abortAction;
private final Course course;
public StartCourseFeatureCommand(Course course, Action startAction) {
this(course, startAction, null);
}
public StartCourseFeatureCommand(Course course, Action startAction, Action abortAction) {
super(StartCourseFeaturePresenter.class);
this.course = course;
this.startAction = startAction;
this.abortAction = abortAction;
}
@Override
public void execute(StartCourseFeaturePresenter presenter) {
presenter.setCourse(course);
presenter.setOnStart(startAction);
presenter.setOnAbort(abortAction);
}
}

View file

@ -127,9 +127,10 @@ public class StreamService {
context.getCourse() :
null;
eventBus.post(new StartCourseFeatureCommand(course, () -> {
startQuizInternal(quiz);
}));
eventBus.post(new StartCourseFeatureCommand(course,
() -> {
startQuizInternal(quiz);
}));
}
}
@ -270,7 +271,7 @@ public class StreamService {
}
private void startMessenger() {
if (!webRtcStreamService.stopped()) {
if (webRtcStreamService.started()) {
startMessengerInternal();
}
else {
@ -278,9 +279,15 @@ public class StreamService {
context.getCourse() :
null;
eventBus.post(new StartCourseFeatureCommand(course, () -> {
startMessengerInternal();
}));
eventBus.post(new StartCourseFeatureCommand(course,
() -> {
// On start.
startMessengerInternal();
},
() -> {
// On abort.
context.setMessengerStarted(false);
}));
}
}