multiple_data_view_controller.cpp
3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "multiple_data_view_controller.h"
#include "../i18n.h"
#include <assert.h>
using namespace Shared;
namespace Statistics {
MultipleDataViewController::MultipleDataViewController(Responder * parentResponder, Store * store, int * selectedBarIndex, int * selectedSeriesIndex) :
ViewController(parentResponder),
m_store(store),
m_selectedSeriesIndex(selectedSeriesIndex),
m_selectedBarIndex(selectedBarIndex)
{
}
bool MultipleDataViewController::isEmpty() const {
return m_store->isEmpty();
}
I18n::Message MultipleDataViewController::emptyMessage() {
return I18n::Message::NoDataToPlot;
}
Responder * MultipleDataViewController::defaultController() {
return tabController();
}
void MultipleDataViewController::viewWillAppear() {
multipleDataView()->setDisplayBanner(true);
if (*m_selectedSeriesIndex < 0) {
*m_selectedSeriesIndex = multipleDataView()->seriesOfSubviewAtIndex(0);
multipleDataView()->selectDataView(*m_selectedSeriesIndex);
}
reloadBannerView();
multipleDataView()->reload();
}
bool MultipleDataViewController::handleEvent(Ion::Events::Event event) {
assert(*m_selectedSeriesIndex >= 0);
if (event == Ion::Events::Down) {
int currentSelectedSubview = multipleDataView()->indexOfSubviewAtSeries(*m_selectedSeriesIndex);
if (currentSelectedSubview < m_store->numberOfNonEmptySeries() - 1) {
multipleDataView()->deselectDataView(*m_selectedSeriesIndex);
*m_selectedSeriesIndex = multipleDataView()->seriesOfSubviewAtIndex(currentSelectedSubview+1);
*m_selectedBarIndex = MultipleDataView::k_defaultSelectedBar;
multipleDataView()->selectDataView(*m_selectedSeriesIndex);
reloadBannerView();
app()->setFirstResponder(this);
return true;
}
return false;
}
if (event == Ion::Events::Up) {
int currentSelectedSubview = multipleDataView()->indexOfSubviewAtSeries(*m_selectedSeriesIndex);
if (currentSelectedSubview > 0) {
multipleDataView()->deselectDataView(*m_selectedSeriesIndex);
*m_selectedSeriesIndex = multipleDataView()->seriesOfSubviewAtIndex(currentSelectedSubview-1);
*m_selectedBarIndex = MultipleDataView::k_defaultSelectedBar;
multipleDataView()->selectDataView(*m_selectedSeriesIndex);
app()->setFirstResponder(this);
} else {
app()->setFirstResponder(tabController());
}
reloadBannerView();
return true;
}
if (*m_selectedSeriesIndex >= 0 && (event == Ion::Events::Left || event == Ion::Events::Right)) {
int direction = event == Ion::Events::Left ? -1 : 1;
moveSelectionHorizontally(direction);
return true;
}
return false;
}
void MultipleDataViewController::didBecomeFirstResponder() {
multipleDataView()->setDisplayBanner(true);
if (*m_selectedSeriesIndex < 0 || m_store->sumOfOccurrences(*m_selectedSeriesIndex) == 0) {
if (*m_selectedSeriesIndex >= 0) {
multipleDataView()->deselectDataView(*m_selectedSeriesIndex);
}
*m_selectedSeriesIndex = multipleDataView()->seriesOfSubviewAtIndex(0);
multipleDataView()->selectDataView(*m_selectedSeriesIndex);
multipleDataView()->reload();
} else {
multipleDataView()->dataViewAtIndex(*m_selectedSeriesIndex)->selectMainView(true);
}
}
void MultipleDataViewController::willExitResponderChain(Responder * nextFirstResponder) {
if (nextFirstResponder == nullptr || nextFirstResponder == tabController()) {
if (*m_selectedSeriesIndex >= 0) {
multipleDataView()->dataViewAtIndex(*m_selectedSeriesIndex)->selectMainView(false);
multipleDataView()->setDisplayBanner(false);
}
}
}
}