Files
Upsilon/apps/settings/sub_menu/exam_mode_controller.cpp
Émilie Feral f57fb84429 [apps/settings] Create a class SelectableViewWithMessages used in
ExamModeController for future factorization
2020-02-12 15:13:25 +01:00

73 lines
2.7 KiB
C++

#include "exam_mode_controller.h"
#include "../../global_preferences.h"
#include "../../apps_container.h"
#include <apps/i18n.h>
#include <assert.h>
#include <cmath>
using namespace Poincare;
using namespace Shared;
namespace Settings {
ExamModeController::ExamModeController(Responder * parentResponder) :
GenericSubController(parentResponder),
m_contentView(&m_selectableTableView),
m_cell{MessageTableCell(I18n::Message::ExamModeActive, KDFont::LargeFont), MessageTableCell(I18n::Message::ActivateDutchExamMode, KDFont::LargeFont)}
{
}
bool ExamModeController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::OK || event == Ion::Events::EXE) {
AppsContainer::sharedAppsContainer()->displayExamModePopUp(examMode());
return true;
}
return GenericSubController::handleEvent(event);
}
void ExamModeController::didEnterResponderChain(Responder * previousFirstResponder) {
/* When a pop-up is dismissed, the exam mode status might have changed. We
* reload the selection as the number of rows might have also changed. We
* force to reload the entire data because they might have changed. */
selectCellAtLocation(0, initialSelectedRow());
m_selectableTableView.reloadData();
// We add a message when the mode exam is on
if (GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
I18n::Message deactivateMessages[] = {I18n::Message::ToDeactivateExamMode1, I18n::Message::ToDeactivateExamMode2, I18n::Message::ToDeactivateExamMode3};
m_contentView.setMessages(deactivateMessages, k_numberOfDeactivationMessageLines);
} else if (numberOfCautionLines() > 0) {
I18n::Message cautionMessages[] = {I18n::Message::ExamModeWarning1, I18n::Message::ExamModeWarning2, I18n::Message::ExamModeWarning3, I18n::Message::ExamModeWarning4, I18n::Message::ExamModeWarning5, I18n::Message::ExamModeWarning6};
m_contentView.setMessages(cautionMessages, numberOfCautionLines());
}
}
HighlightCell * ExamModeController::reusableCell(int index, int type) {
assert(type == 0);
assert(index >= 0 && index < k_maxNumberOfCells);
return &m_cell[index];
}
int ExamModeController::reusableCellCount(int type) {
return k_maxNumberOfCells;
}
void ExamModeController::willDisplayCellForIndex(HighlightCell * cell, int index) {
GenericSubController::willDisplayCellForIndex(cell, index);
if (GlobalPreferences::sharedGlobalPreferences()->isInExamMode()) {
MessageTableCell * myCell = (MessageTableCell *)cell;
myCell->setMessage(I18n::Message::ExamModeActive);
}
}
int ExamModeController::initialSelectedRow() const {
int row = selectedRow();
if (row >= numberOfRows()) {
return numberOfRows()-1;
} else if (row < 0) {
return 0;
}
return row;
}
}