From 2c98a6ea0d3233542994d53fc6dfbd73b80dce88 Mon Sep 17 00:00:00 2001 From: Ruben Dashyan Date: Tue, 14 May 2019 17:13:35 +0200 Subject: [PATCH] [apps/home/controller] Substitute m_container by AppsContainer::sharedAppsContainer() --- apps/home/app.cpp | 3 +-- apps/home/controller.cpp | 21 ++++++++++++--------- apps/home/controller.h | 3 +-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/apps/home/app.cpp b/apps/home/app.cpp index b7fa2ff0b..1fbbd39df 100644 --- a/apps/home/app.cpp +++ b/apps/home/app.cpp @@ -1,6 +1,5 @@ #include "app.h" #include -#include "../apps_container.h" extern "C" { #include @@ -27,7 +26,7 @@ App::Descriptor * App::Snapshot::descriptor() { App::App(Container * container, Snapshot * snapshot) : ::App(container, snapshot, &m_controller, I18n::Message::Warning), - m_controller(&m_modalViewController, (AppsContainer *)container, snapshot) + m_controller(&m_modalViewController, snapshot) { } diff --git a/apps/home/controller.cpp b/apps/home/controller.cpp index f177204ec..e4ca4b43e 100644 --- a/apps/home/controller.cpp +++ b/apps/home/controller.cpp @@ -47,9 +47,8 @@ void Controller::ContentView::layoutSubviews() { m_selectableTableView.setFrame(bounds()); } -Controller::Controller(Responder * parentResponder, ::AppsContainer * container, SelectableTableViewDataSource * selectionDataSource) : +Controller::Controller(Responder * parentResponder, SelectableTableViewDataSource * selectionDataSource) : ViewController(parentResponder), - m_container(container), m_view(this, selectionDataSource), m_selectionDataSource(selectionDataSource) { @@ -57,7 +56,8 @@ Controller::Controller(Responder * parentResponder, ::AppsContainer * container, bool Controller::handleEvent(Ion::Events::Event event) { if (event == Ion::Events::OK || event == Ion::Events::EXE) { - bool switched = m_container->switchTo(m_container->appSnapshotAtIndex(m_selectionDataSource->selectedRow()*k_numberOfColumns+m_selectionDataSource->selectedColumn()+1)); + AppsContainer * container = AppsContainer::sharedAppsContainer(); + bool switched = container->switchTo(container->appSnapshotAtIndex(m_selectionDataSource->selectedRow()*k_numberOfColumns+m_selectionDataSource->selectedColumn()+1)); assert(switched); (void) switched; // Silence compilation warning about unused variable. return true; @@ -119,22 +119,25 @@ int Controller::reusableCellCount() { void Controller::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { AppCell * appCell = (AppCell *)cell; + AppsContainer * container = AppsContainer::sharedAppsContainer(); int appIndex = (j*k_numberOfColumns+i)+1; - if (appIndex >= m_container->numberOfApps()) { + if (appIndex >= container->numberOfApps()) { appCell->setVisible(false); } else { appCell->setVisible(true); - ::App::Descriptor * descriptor = m_container->appSnapshotAtIndex(appIndex)->descriptor(); + ::App::Descriptor * descriptor = container->appSnapshotAtIndex(appIndex)->descriptor(); appCell->setAppDescriptor(descriptor); } } int Controller::numberOfIcons() { - assert(m_container->numberOfApps() > 0); - return m_container->numberOfApps() - 1; + AppsContainer * container = AppsContainer::sharedAppsContainer(); + assert(container->numberOfApps() > 0); + return container->numberOfApps() - 1; } void Controller::tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) { + AppsContainer * container = AppsContainer::sharedAppsContainer(); if (withinTemporarySelection) { return; } @@ -147,7 +150,7 @@ void Controller::tableViewDidChangeSelection(SelectableTableView * t, int previo * background complete redrawing but the code is a bit * clumsy. */ if (t->selectedRow() == numberOfRows()-1) { - m_view.reloadBottomRow(this, m_container->numberOfApps()-1, k_numberOfColumns); + m_view.reloadBottomRow(this, container->numberOfApps()-1, k_numberOfColumns); } /* To prevent the selectable table view to select cells that are unvisible, * we reselect the previous selected cell as soon as the selected cell is @@ -155,7 +158,7 @@ void Controller::tableViewDidChangeSelection(SelectableTableView * t, int previo * stay on a unvisible cell and to initialize the first cell on a visible one * (so the previous one is always visible). */ int appIndex = (t->selectedColumn()+t->selectedRow()*k_numberOfColumns)+1; - if (appIndex >= m_container->numberOfApps()) { + if (appIndex >= container->numberOfApps()) { t->selectCellAtLocation(previousSelectedCellX, previousSelectedCellY); } } diff --git a/apps/home/controller.h b/apps/home/controller.h index 116b6291a..d31fd4632 100644 --- a/apps/home/controller.h +++ b/apps/home/controller.h @@ -10,7 +10,7 @@ namespace Home { class Controller : public ViewController, public SimpleTableViewDataSource, public SelectableTableViewDelegate { public: - Controller(Responder * parentResponder, ::AppsContainer * container, SelectableTableViewDataSource * selectionDataSource); + Controller(Responder * parentResponder, SelectableTableViewDataSource * selectionDataSource); View * view() override; @@ -40,7 +40,6 @@ private: void layoutSubviews() override; SelectableTableView m_selectableTableView; }; - AppsContainer * m_container; static constexpr KDCoordinate k_sideMargin = 4; static constexpr KDCoordinate k_bottomMargin = 14; static constexpr KDCoordinate k_indicatorMargin = 61;