[apps/home/controller] Substitute m_container by AppsContainer::sharedAppsContainer()

This commit is contained in:
Ruben Dashyan
2019-05-14 17:13:35 +02:00
committed by EmilieNumworks
parent 5f8a745957
commit 2c98a6ea0d
3 changed files with 14 additions and 13 deletions

View File

@@ -1,6 +1,5 @@
#include "app.h" #include "app.h"
#include <apps/i18n.h> #include <apps/i18n.h>
#include "../apps_container.h"
extern "C" { extern "C" {
#include <assert.h> #include <assert.h>
@@ -27,7 +26,7 @@ App::Descriptor * App::Snapshot::descriptor() {
App::App(Container * container, Snapshot * snapshot) : App::App(Container * container, Snapshot * snapshot) :
::App(container, snapshot, &m_controller, I18n::Message::Warning), ::App(container, snapshot, &m_controller, I18n::Message::Warning),
m_controller(&m_modalViewController, (AppsContainer *)container, snapshot) m_controller(&m_modalViewController, snapshot)
{ {
} }

View File

@@ -47,9 +47,8 @@ void Controller::ContentView::layoutSubviews() {
m_selectableTableView.setFrame(bounds()); m_selectableTableView.setFrame(bounds());
} }
Controller::Controller(Responder * parentResponder, ::AppsContainer * container, SelectableTableViewDataSource * selectionDataSource) : Controller::Controller(Responder * parentResponder, SelectableTableViewDataSource * selectionDataSource) :
ViewController(parentResponder), ViewController(parentResponder),
m_container(container),
m_view(this, selectionDataSource), m_view(this, selectionDataSource),
m_selectionDataSource(selectionDataSource) m_selectionDataSource(selectionDataSource)
{ {
@@ -57,7 +56,8 @@ Controller::Controller(Responder * parentResponder, ::AppsContainer * container,
bool Controller::handleEvent(Ion::Events::Event event) { bool Controller::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::OK || event == Ion::Events::EXE) { 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); assert(switched);
(void) switched; // Silence compilation warning about unused variable. (void) switched; // Silence compilation warning about unused variable.
return true; return true;
@@ -119,22 +119,25 @@ int Controller::reusableCellCount() {
void Controller::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) { void Controller::willDisplayCellAtLocation(HighlightCell * cell, int i, int j) {
AppCell * appCell = (AppCell *)cell; AppCell * appCell = (AppCell *)cell;
AppsContainer * container = AppsContainer::sharedAppsContainer();
int appIndex = (j*k_numberOfColumns+i)+1; int appIndex = (j*k_numberOfColumns+i)+1;
if (appIndex >= m_container->numberOfApps()) { if (appIndex >= container->numberOfApps()) {
appCell->setVisible(false); appCell->setVisible(false);
} else { } else {
appCell->setVisible(true); appCell->setVisible(true);
::App::Descriptor * descriptor = m_container->appSnapshotAtIndex(appIndex)->descriptor(); ::App::Descriptor * descriptor = container->appSnapshotAtIndex(appIndex)->descriptor();
appCell->setAppDescriptor(descriptor); appCell->setAppDescriptor(descriptor);
} }
} }
int Controller::numberOfIcons() { int Controller::numberOfIcons() {
assert(m_container->numberOfApps() > 0); AppsContainer * container = AppsContainer::sharedAppsContainer();
return m_container->numberOfApps() - 1; assert(container->numberOfApps() > 0);
return container->numberOfApps() - 1;
} }
void Controller::tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) { void Controller::tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY, bool withinTemporarySelection) {
AppsContainer * container = AppsContainer::sharedAppsContainer();
if (withinTemporarySelection) { if (withinTemporarySelection) {
return; return;
} }
@@ -147,7 +150,7 @@ void Controller::tableViewDidChangeSelection(SelectableTableView * t, int previo
* background complete redrawing but the code is a bit * background complete redrawing but the code is a bit
* clumsy. */ * clumsy. */
if (t->selectedRow() == numberOfRows()-1) { 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, /* 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 * 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 * stay on a unvisible cell and to initialize the first cell on a visible one
* (so the previous one is always visible). */ * (so the previous one is always visible). */
int appIndex = (t->selectedColumn()+t->selectedRow()*k_numberOfColumns)+1; int appIndex = (t->selectedColumn()+t->selectedRow()*k_numberOfColumns)+1;
if (appIndex >= m_container->numberOfApps()) { if (appIndex >= container->numberOfApps()) {
t->selectCellAtLocation(previousSelectedCellX, previousSelectedCellY); t->selectCellAtLocation(previousSelectedCellX, previousSelectedCellY);
} }
} }

View File

@@ -10,7 +10,7 @@ namespace Home {
class Controller : public ViewController, public SimpleTableViewDataSource, public SelectableTableViewDelegate { class Controller : public ViewController, public SimpleTableViewDataSource, public SelectableTableViewDelegate {
public: public:
Controller(Responder * parentResponder, ::AppsContainer * container, SelectableTableViewDataSource * selectionDataSource); Controller(Responder * parentResponder, SelectableTableViewDataSource * selectionDataSource);
View * view() override; View * view() override;
@@ -40,7 +40,6 @@ private:
void layoutSubviews() override; void layoutSubviews() override;
SelectableTableView m_selectableTableView; SelectableTableView m_selectableTableView;
}; };
AppsContainer * m_container;
static constexpr KDCoordinate k_sideMargin = 4; static constexpr KDCoordinate k_sideMargin = 4;
static constexpr KDCoordinate k_bottomMargin = 14; static constexpr KDCoordinate k_bottomMargin = 14;
static constexpr KDCoordinate k_indicatorMargin = 61; static constexpr KDCoordinate k_indicatorMargin = 61;