diff --git a/apps/apps_container.cpp b/apps/apps_container.cpp index 2dbdf049b..cfd0880be 100644 --- a/apps/apps_container.cpp +++ b/apps/apps_container.cpp @@ -14,7 +14,7 @@ AppsContainer::AppsContainer() : m_emptyBatteryWindow(), m_globalContext(), m_variableBoxController(&m_globalContext), - m_examPopUpController(), + m_examPopUpController(this), m_updateController(), m_ledTimer(LedTimer()), m_batteryTimer(BatteryTimer(this)), @@ -90,8 +90,9 @@ bool AppsContainer::dispatchEvent(Ion::Events::Event event) { if (Ion::USB::isPlugged()) { if (GlobalPreferences::sharedGlobalPreferences()->examMode() == GlobalPreferences::ExamMode::Activate) { displayExamModePopUp(false); + } else { + Ion::USB::enable(); } - Ion::USB::enable(); Ion::Backlight::setBrightness(Ion::Backlight::MaxBrightness); } else { Ion::USB::disable(); @@ -208,6 +209,12 @@ void AppsContainer::redrawWindow() { m_window.redraw(); } +void AppsContainer::examDeactivatingPopUpIsDismissed() { + if (Ion::USB::isPlugged()) { + Ion::USB::enable(); + } +} + Window * AppsContainer::window() { return &m_window; } diff --git a/apps/apps_container.h b/apps/apps_container.h index 2596afdfa..eb1b75516 100644 --- a/apps/apps_container.h +++ b/apps/apps_container.h @@ -11,6 +11,7 @@ #include "math_toolbox.h" #include "variable_box_controller.h" #include "exam_pop_up_controller.h" +#include "exam_pop_up_controller_delegate.h" #include "led_timer.h" #include "battery_timer.h" #include "suspend_timer.h" @@ -23,7 +24,7 @@ #include -class AppsContainer : public Container { +class AppsContainer : public Container, ExamPopUpControllerDelegate { public: AppsContainer(); static bool poincareCircuitBreaker(); @@ -47,6 +48,8 @@ public: void setShiftAlphaStatus(Ion::Events::ShiftAlphaStatus newStatus); OnBoarding::UpdateController * updatePopUpController(); void redrawWindow(); + // Exam pop-up controller delegate + void examDeactivatingPopUpIsDismissed() override; protected: Home::App::Snapshot * homeAppSnapshot() { return &m_homeSnapshot; } private: diff --git a/apps/exam_pop_up_controller.cpp b/apps/exam_pop_up_controller.cpp index d938b0aee..c4821007f 100644 --- a/apps/exam_pop_up_controller.cpp +++ b/apps/exam_pop_up_controller.cpp @@ -4,17 +4,31 @@ #include "global_preferences.h" #include -ExamPopUpController::ExamPopUpController() : +ExamPopUpController::ExamPopUpController(ExamPopUpControllerDelegate * delegate) : ViewController(nullptr), m_contentView(this), - m_isActivatingExamMode(false) + m_isActivatingExamMode(false), + m_delegate(delegate) { } +void ExamPopUpController::setActivatingExamMode(bool activatingExamMode) { + if (m_isActivatingExamMode != activatingExamMode) { + m_isActivatingExamMode = activatingExamMode; + m_contentView.setMessages(activatingExamMode); + } +} + View * ExamPopUpController::view() { return &m_contentView; } +void ExamPopUpController::viewDidDisappear() { + if (m_isActivatingExamMode == false) { + m_delegate->examDeactivatingPopUpIsDismissed(); + } +} + void ExamPopUpController::didBecomeFirstResponder() { m_contentView.setSelectedButton(0, app()); } @@ -31,17 +45,6 @@ bool ExamPopUpController::handleEvent(Ion::Events::Event event) { return false; } -void ExamPopUpController::setActivatingExamMode(bool activatingExamMode) { - if (m_isActivatingExamMode != activatingExamMode) { - m_isActivatingExamMode = activatingExamMode; - m_contentView.setMessages(activatingExamMode); - } -} - -bool ExamPopUpController::isActivatingExamMode() { - return m_isActivatingExamMode; -} - ExamPopUpController::ContentView::ContentView(Responder * parentResponder) : m_cancelButton(parentResponder, I18n::Message::Cancel, Invocation([](void * context, void * sender) { ExamPopUpController * controller = (ExamPopUpController *)context; diff --git a/apps/exam_pop_up_controller.h b/apps/exam_pop_up_controller.h index a507a2d25..5cf9e2b44 100644 --- a/apps/exam_pop_up_controller.h +++ b/apps/exam_pop_up_controller.h @@ -2,15 +2,19 @@ #define APPS_EXAM_POP_UP_CONTROLLER_H #include +#include "exam_pop_up_controller_delegate.h" class ExamPopUpController : public ViewController { public: - ExamPopUpController(); + ExamPopUpController(ExamPopUpControllerDelegate * delegate); + void setActivatingExamMode(bool activingExamMode); + bool isActivatingExamMode() const { return m_isActivatingExamMode; } + // View Controller View * view() override; + void viewDidDisappear() override; + // Responder void didBecomeFirstResponder() override; bool handleEvent(Ion::Events::Event event) override; - void setActivatingExamMode(bool activingExamMode); - bool isActivatingExamMode(); private: class ContentView : public View { public: @@ -36,6 +40,7 @@ private: }; ContentView m_contentView; bool m_isActivatingExamMode; + ExamPopUpControllerDelegate * m_delegate; }; #endif diff --git a/apps/exam_pop_up_controller_delegate.h b/apps/exam_pop_up_controller_delegate.h new file mode 100644 index 000000000..4d0567792 --- /dev/null +++ b/apps/exam_pop_up_controller_delegate.h @@ -0,0 +1,10 @@ +#ifndef APPS_EXAM_POP_UP_CONTROLLER_DELEGATE_H +#define APPS_EXAM_POP_UP_CONTROLLER_DELEGATE_H + +class ExamPopUpControllerDelegate { +public: + virtual void examDeactivatingPopUpIsDismissed() = 0; +}; + +#endif +