From 269b11efef1306d964fc804ba80c8cb7e9ab9bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 25 Oct 2016 16:26:32 +0200 Subject: [PATCH] [apps/probability] Use selectable table view in law controller Change-Id: I286599de512fa9004846dbbe666d5ab8ed117407 --- apps/probability/law/law_controller.cpp | 37 ++++++------------------- apps/probability/law/law_controller.h | 5 +--- 2 files changed, 9 insertions(+), 33 deletions(-) diff --git a/apps/probability/law/law_controller.cpp b/apps/probability/law/law_controller.cpp index 09a249401..8d264a8cd 100644 --- a/apps/probability/law/law_controller.cpp +++ b/apps/probability/law/law_controller.cpp @@ -14,15 +14,14 @@ static const char * sMessages[] = { Probability::LawController::LawController(Responder * parentResponder) : ViewController(parentResponder), - m_tableView(TableView(this, Metric::TopMargin, Metric::RightMargin, - Metric::BottomMargin, Metric::LeftMargin)), - m_activeCell(0) + m_selectableTableView(SelectableTableView(this, this, Metric::TopMargin, Metric::RightMargin, + Metric::BottomMargin, Metric::LeftMargin)) { m_messages = sMessages; } View * Probability::LawController::view() { - return &m_tableView; + return &m_selectableTableView; } const char * Probability::LawController::title() const { @@ -30,30 +29,16 @@ const char * Probability::LawController::title() const { } void Probability::LawController::didBecomeFirstResponder() { - setActiveCell(0); -} - -void Probability::LawController::setActiveCell(int index) { - if (index < 0 || index >= k_totalNumberOfModels) { - return; + if (m_selectableTableView.selectedRow() == -1) { + m_selectableTableView.setSelectedCellAtLocation(0, 0); + } else { + m_selectableTableView.setSelectedCellAtLocation(m_selectableTableView.selectedColumn(), m_selectableTableView.selectedRow()); } - ListViewCell * previousCell = (ListViewCell *)(m_tableView.cellAtLocation(0, m_activeCell)); - previousCell->setHighlighted(false); - - m_activeCell = index; - m_tableView.scrollToCell(0, index); - ListViewCell * cell = (ListViewCell *)(m_tableView.cellAtLocation(0, index)); - cell->setHighlighted(true); + app()->setFirstResponder(&m_selectableTableView); } bool Probability::LawController::handleEvent(Ion::Events::Event event) { switch (event) { - case Ion::Events::Event::DOWN_ARROW: - setActiveCell(m_activeCell+1); - return true; - case Ion::Events::Event::UP_ARROW: - setActiveCell(m_activeCell-1); - return true; case Ion::Events::Event::ENTER: ((Probability::App *)app())->setLaw(App::Law::Normal); return true; @@ -79,12 +64,6 @@ int Probability::LawController::reusableCellCount() { void Probability::LawController::willDisplayCellForIndex(TableViewCell * cell, int index) { ListViewCell * myCell = (ListViewCell *)cell; myCell->textView()->setText(m_messages[index]); - if (m_activeCell == index) { - myCell->textView()->setBackgroundColor(Palette::FocusCellBackgroundColor); - } else { - myCell->textView()->setBackgroundColor(Palette::CellBackgroundColor); - } - myCell->textView()->setTextColor(KDColorBlack); myCell->textView()->setAlignment(0., 0.5); } diff --git a/apps/probability/law/law_controller.h b/apps/probability/law/law_controller.h index 6fae03eb1..ba9320b50 100644 --- a/apps/probability/law/law_controller.h +++ b/apps/probability/law/law_controller.h @@ -9,8 +9,6 @@ class LawController : public ViewController, public SimpleListViewDataSource { public: LawController(Responder * parentResponder); - void setActiveCell(int index); - View * view() override; const char * title() const override; bool handleEvent(Ion::Events::Event event) override; @@ -27,9 +25,8 @@ private: // !!! CAUTION: The order here is important // The cells should be initialized *before* the listview! ListViewCell m_cells[k_maxNumberOfCells]; - TableView m_tableView; + SelectableTableView m_selectableTableView; const char ** m_messages; - int m_activeCell; }; }