[apps/on_boarding] Added country to onboarding

Change-Id: I55c50330baf226826e44467756bcd9e5c89d4262
This commit is contained in:
Gabriel Ozouf
2020-06-19 15:22:53 +02:00
committed by Émilie Feral
parent a96b5d1bc4
commit 509a7e4628
8 changed files with 85 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
app_on_boarding_src = $(addprefix apps/on_boarding/,\
app.cpp \
country_controller.cpp \
language_controller.cpp \
logo_controller.cpp \
logo_view.cpp \

View File

@@ -13,8 +13,10 @@ App::Descriptor * App::Snapshot::descriptor() {
}
App::App(Snapshot * snapshot) :
::App(snapshot, &m_languageController),
m_languageController(&m_modalViewController),
::App(snapshot, &m_stackController),
m_stackController(&m_modalViewController, &m_languageController),
m_languageController(&m_stackController),
m_countryController(&m_languageController),
m_logoController()
{
}
@@ -45,6 +47,7 @@ void App::didBecomeActive(Window * window) {
void App::reinitOnBoarding() {
m_languageController.resetSelection();
m_countryController.resetSelection();
displayModalViewController(&m_logoController, 0.5f, 0.5f);
}

View File

@@ -2,6 +2,7 @@
#define ON_BOARDING_APP_H
#include <escher.h>
#include "country_controller.h"
#include "language_controller.h"
#include "logo_controller.h"
@@ -14,6 +15,12 @@ public:
App * unpack(Container * container) override;
Descriptor * descriptor() override;
};
static App * app() {
return static_cast<App *>(Container::activeApp());
}
CountryController * countryController() { return &m_countryController; }
int numberOfTimers() override;
Timer * timerAtIndex(int i) override;
bool processEvent(Ion::Events::Event) override;
@@ -21,7 +28,9 @@ public:
private:
App(Snapshot * snapshot);
void reinitOnBoarding();
StackViewController m_stackController;
LanguageController m_languageController;
CountryController m_countryController;
LogoController m_logoController;
};

View File

@@ -0,0 +1,43 @@
#include "country_controller.h"
#include "../apps_container.h"
#include <escher/scroll_view_indicator.h>
#include <algorithm>
namespace OnBoarding {
CountryController::CountryController(Responder * parentResponder) :
Shared::CountryController(
parentResponder,
std::max(
static_cast<int>(Metric::CommonLeftMargin),
(Ion::Display::Height - I18n::NumberOfCountries*Metric::ParameterCellHeight)/2))
{
static_cast<ScrollViewIndicator *>(m_selectableTableView.decorator()->indicatorAtIndex(1))->setMargin(
std::max(
static_cast<int>(Metric::CommonLeftMargin),
(Ion::Display::Height - I18n::NumberOfCountries*Metric::ParameterCellHeight)/2));
}
void CountryController::resetSelection() {
m_selectableTableView.deselectTable();
/* The base ::CountryController behaviour is to highlight the previously
* chosen country. On boarding, we want the highlighted cell to be the first
* alphabetically, but with the default behaviour, it would be Canada, as it
* is the country of value 0. */
selectCellAtLocation(0, 0);
}
bool CountryController::handleEvent(Ion::Events::Event event) {
if (Shared::CountryController::handleEvent(event)) {
AppsContainer * appsContainer = AppsContainer::sharedAppsContainer();
if (appsContainer->promptController()) {
Container::activeApp()->displayModalViewController(appsContainer->promptController(), 0.5f, 0.5f);
} else {
appsContainer->switchTo(appsContainer->appSnapshotAtIndex(0));
}
return true;
}
return false;
}
}

View File

@@ -0,0 +1,19 @@
#ifndef ON_BOARDING_COUNTRY_CONTROLLER_H
#define ON_BOARDING_COUNTRY_CONTROLLER_H
#include <escher.h>
#include "../shared/country_controller.h"
namespace OnBoarding {
class CountryController : public Shared::CountryController {
public:
CountryController(Responder * parentResponder);
void resetSelection() override;
bool handleEvent(Ion::Events::Event event) override;
ViewController::DisplayParameter displayParameter() override { return ViewController::DisplayParameter::WantsMaximumSpace; }
};
}
#endif

View File

@@ -1,6 +1,8 @@
#include "language_controller.h"
#include "../global_preferences.h"
#include "../apps_container.h"
#include "app.h"
#include "country_controller.h"
#include <escher/scroll_view_indicator.h>
#include <algorithm>
@@ -23,7 +25,7 @@ bool LanguageController::handleEvent(Ion::Events::Event event) {
if (appsContainer->promptController()) {
Container::activeApp()->displayModalViewController(appsContainer->promptController(), 0.5f, 0.5f);
} else {
appsContainer->switchTo(appsContainer->appSnapshotAtIndex(0));
stackController()->push(App::app()->countryController());
}
return true;
}

View File

@@ -3,7 +3,6 @@
#include <escher.h>
#include "../shared/language_controller.h"
#include "logo_controller.h"
namespace OnBoarding {
@@ -11,6 +10,10 @@ class LanguageController : public Shared::LanguageController {
public:
LanguageController(Responder * parentResponder);
bool handleEvent(Ion::Events::Event event) override;
ViewController::DisplayParameter displayParameter() override { return ViewController::DisplayParameter::DoNotShowOwnTitle; }
private:
StackViewController * stackController() { return static_cast<StackViewController *>(parentResponder()); }
};
}

View File

@@ -12,7 +12,7 @@ public:
static I18n::Country CountryAtIndex(int i);
CountryController(Responder * parentResponder, KDCoordinate verticalMargin);
void resetSelection();
virtual void resetSelection();
View * view() override { return &m_selectableTableView; }
const char * title() override {return I18n::translate(I18n::Message::Country); }