diff --git a/apps/home/app.h b/apps/home/app.h index f54b78d4a..16335ad97 100644 --- a/apps/home/app.h +++ b/apps/home/app.h @@ -19,11 +19,18 @@ public: App * unpack(Container * container) override; Descriptor * descriptor() override; }; + Snapshot * snapshot() const { + return static_cast(::App::snapshot()); + } private: App(Snapshot * snapshot); Controller m_controller; }; +inline App * app() { + return static_cast(::app()); +} + } #endif diff --git a/apps/home/controller.cpp b/apps/home/controller.cpp index 262c68186..2d98b6f88 100644 --- a/apps/home/controller.cpp +++ b/apps/home/controller.cpp @@ -1,4 +1,5 @@ #include "controller.h" +#include "app.h" #include "../apps_container.h" extern "C" { #include @@ -49,15 +50,14 @@ void Controller::ContentView::layoutSubviews() { Controller::Controller(Responder * parentResponder, SelectableTableViewDataSource * selectionDataSource) : ViewController(parentResponder), - m_view(this, selectionDataSource), - m_selectionDataSource(selectionDataSource) + m_view(this, selectionDataSource) { } bool Controller::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::OK || event == Ion::Events::EXE) { AppsContainer * container = AppsContainer::sharedAppsContainer(); - bool switched = container->switchTo(container->appSnapshotAtIndex(m_selectionDataSource->selectedRow()*k_numberOfColumns+m_selectionDataSource->selectedColumn()+1)); + bool switched = container->switchTo(container->appSnapshotAtIndex(selectionDataSource()->selectedRow()*k_numberOfColumns+selectionDataSource()->selectedColumn()+1)); assert(switched); (void) switched; // Silence compilation warning about unused variable. return true; @@ -67,11 +67,11 @@ bool Controller::handleEvent(Ion::Events::Event event) { return m_view.selectableTableView()->selectCellAtLocation(0,0); } - if (event == Ion::Events::Right && m_selectionDataSource->selectedRow() < numberOfRows()) { - return m_view.selectableTableView()->selectCellAtLocation(0, m_selectionDataSource->selectedRow()+1); + if (event == Ion::Events::Right && selectionDataSource()->selectedRow() < numberOfRows()) { + return m_view.selectableTableView()->selectCellAtLocation(0, selectionDataSource()->selectedRow()+1); } - if (event == Ion::Events::Left && m_selectionDataSource->selectedRow() > 0) { - return m_view.selectableTableView()->selectCellAtLocation(numberOfColumns()-1, m_selectionDataSource->selectedRow()-1); + if (event == Ion::Events::Left && selectionDataSource()->selectedRow() > 0) { + return m_view.selectableTableView()->selectCellAtLocation(numberOfColumns()-1, selectionDataSource()->selectedRow()-1); } return false; @@ -158,4 +158,8 @@ void Controller::tableViewDidChangeSelection(SelectableTableView * t, int previo } } +SelectableTableViewDataSource * Controller::selectionDataSource() const { + return app()->snapshot(); +} + } diff --git a/apps/home/controller.h b/apps/home/controller.h index a7762d433..7750f1cb1 100644 --- a/apps/home/controller.h +++ b/apps/home/controller.h @@ -26,6 +26,7 @@ public: void tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) override; private: int numberOfIcons(); + SelectableTableViewDataSource * selectionDataSource() const; class ContentView : public View { public: ContentView(Controller * controller, SelectableTableViewDataSource * selectionDataSource); @@ -47,7 +48,6 @@ private: static constexpr int k_cellWidth = 104; ContentView m_view; AppCell m_cells[k_maxNumberOfCells]; - SelectableTableViewDataSource * m_selectionDataSource; }; }