[apps/statistics] Add pop-up to confirm parameter discard

Change-Id: I0d0d7dca0e167cfcb40f4b26d8208e12056ebf40
This commit is contained in:
Hugo Saint-Vignes
2020-10-21 15:35:45 +02:00
committed by Émilie Feral
parent a922e44558
commit b2d7ee800a
2 changed files with 18 additions and 1 deletions

View File

@@ -10,7 +10,12 @@ namespace Statistics {
HistogramParameterController::HistogramParameterController(Responder * parentResponder, InputEventHandlerDelegate * inputEventHandlerDelegate, Store * store) :
FloatParameterController<double>(parentResponder),
m_cells{},
m_store(store)
m_store(store),
m_confirmPopUpController(Invocation([](void * context, void * sender) {
Container::activeApp()->dismissModalViewController();
((HistogramParameterController *)context)->stackController()->pop();
return true;
}, this))
{
for (int i = 0; i < k_numberOfCells; i++) {
m_cells[i].setParentResponder(&m_selectableTableView);
@@ -39,6 +44,15 @@ void HistogramParameterController::willDisplayCellForIndex(HighlightCell * cell,
FloatParameterController::willDisplayCellForIndex(cell, index);
}
bool HistogramParameterController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::Back && (extractParameterAtIndex(0) != parameterAtIndex(0) || extractParameterAtIndex(1) != parameterAtIndex(1))) {
// Temporary values are different, open pop-up to confirm discarding values
Container::activeApp()->displayModalViewController(&m_confirmPopUpController, 0.f, 0.f, Metric::ExamPopUpTopMargin, Metric::PopUpRightMargin, Metric::ExamPopUpBottomMargin, Metric::PopUpLeftMargin);
return true;
}
return false;
}
double HistogramParameterController::extractParameterAtIndex(int index) {
assert(index >= 0 && index < k_numberOfCells);
return index == 0 ? m_store->barWidth() : m_store->firstDrawnBarAbscissa();