[apps/settings] Added message to country menu

Change-Id: Iec064d0ac86f54a10cf63236b6f958d53cecb2e2
This commit is contained in:
Gabriel Ozouf
2020-06-22 11:32:43 +02:00
committed by Émilie Feral
parent b35cdca9bb
commit 8d362ef4de
13 changed files with 128 additions and 14 deletions

View File

@@ -12,18 +12,18 @@ CountryController::CountryController(Responder * parentResponder) :
static_cast<int>(Metric::CommonLeftMargin),
(Ion::Display::Height - I18n::NumberOfCountries*Metric::ParameterCellHeight)/2))
{
static_cast<ScrollViewIndicator *>(m_selectableTableView.decorator()->indicatorAtIndex(1))->setMargin(
static_cast<ScrollViewIndicator *>(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();
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. */
* is the country of value t 0. */
selectCellAtLocation(0, 0);
}

View File

@@ -12,6 +12,7 @@ public:
void resetSelection() override;
bool handleEvent(Ion::Events::Event event) override;
ViewController::DisplayParameter displayParameter() override { return ViewController::DisplayParameter::WantsMaximumSpace; }
};
}

View File

@@ -2,6 +2,13 @@
namespace Settings {
CountryController::CountryController(Responder * parentResponder, KDCoordinate verticalMargin) :
Shared::CountryController(parentResponder, verticalMargin)
{
m_contentView.shouldDisplayTitle(false);
}
bool CountryController::handleEvent(Ion::Events::Event event) {
if (Shared::CountryController::handleEvent(event) || event == Ion::Events::Left) {
static_cast<StackViewController *>(parentResponder())->pop();

View File

@@ -8,7 +8,7 @@ namespace Settings {
class CountryController : public Shared::CountryController {
public:
using Shared::CountryController::CountryController;
CountryController(Responder * parentResponder, KDCoordinate verticalMargin);
bool handleEvent(Ion::Events::Event event) override;
};

View File

@@ -23,6 +23,8 @@ CountryNL = "Niederlande "
CountryPT = "Portugal "
CountryUS = "Vereinigte Staaten "
CountryWW = "International "
CountryWarning1 = "Diese Einstellung definiert die verwendeten"
CountryWarning2 = "mathematischen Konventionen."
DataNotSuitable = "Daten nicht geeignet"
DataTab = "Daten"
DefaultSetting = "Grundeinstellung"

View File

@@ -23,6 +23,8 @@ CountryNL = "Netherlands "
CountryPT = "Portugal "
CountryUS = "United States "
CountryWW = "International "
CountryWarning1 = "This setting defines the"
CountryWarning2 = "mathematical conventions used."
DataNotSuitable = "Data not suitable"
DataTab = "Data"
DefaultSetting = "Basic settings"

View File

@@ -23,6 +23,8 @@ CountryNL = "Países Bajos "
CountryPT = "Portugal "
CountryUS = "Estados Unidos "
CountryWW = "Internacional "
CountryWarning1 = "Este ajuste define las convenciones"
CountryWarning2 = "matemáticas utilizadas."
DataNotSuitable = "Datos no adecuados"
DataTab = "Datos"
DefaultSetting = "Ajustes básicos"

View File

@@ -23,6 +23,8 @@ CountryNL = "Pays-Bas "
CountryPT = "Portugal "
CountryUS = "Etats-Unis "
CountryWW = "International "
CountryWarning1 = "Ce réglage permet de définir les"
CountryWarning2 = "conventions mathématiques utilisées."
DataNotSuitable = "Les données ne conviennent pas"
DataTab = "Données"
DefaultSetting = "Réglages de base"

View File

@@ -23,6 +23,8 @@ CountryNL = "Paesi Bassi "
CountryPT = "Portogallo "
CountryUS = "Stati Uniti "
CountryWW = "Internazionale "
CountryWarning1 = "Questa opzione permette di definire le"
CountryWarning2 = "convenzioni matematiche utilizzate."
DataNotSuitable = "I dati non sono adeguati"
DataTab = "Dati"
DefaultSetting = "Impostazioni di base"

View File

@@ -23,6 +23,8 @@ CountryNL = "Nederland "
CountryPT = "Portugal "
CountryUS = "Verenigde Staten "
CountryWW = "Internationale "
CountryWarning1 = "Deze instelling definieert de"
CountryWarning2 = "gebruikte wiskundige conventies."
DataNotSuitable = "Gegevens niet geschikt"
DataTab = "Gegevens"
DefaultSetting = "Standaardinstelling"

View File

@@ -23,6 +23,8 @@ CountryNL = "Países Baixos "
CountryPT = "Portugal "
CountryUS = "Estados Unidos "
CountryWW = "Internacional "
CountryWarning1 = "Esta opção define as convenções"
CountryWarning2 = "matemáticas utilizadas."
DataNotSuitable = "Dados não adequados"
DataTab = "Dados"
DefaultSetting = "Configurações básicas"

View File

@@ -2,9 +2,80 @@
#include "../global_preferences.h"
#include "../apps_container.h"
#include <string.h>
#include <algorithm>
namespace Shared {
// CountryController::ContentView
constexpr int CountryController::ContentView::k_numberOfTextLines;
CountryController::ContentView::ContentView(CountryController * controller, SelectableTableViewDataSource * dataSource) :
m_selectableTableView(controller, controller, dataSource),
m_titleMessage(KDFont::LargeFont, I18n::Message::Country),
m_displayTitle(true)
{
m_titleMessage.setBackgroundColor(Palette::WallScreen);
m_titleMessage.setAlignment(0.5f, 0.5f);
I18n::Message textMessages[k_numberOfTextLines] = {I18n::Message::CountryWarning1, I18n::Message::CountryWarning2};
for (int i = 0; i < k_numberOfTextLines; i++) {
m_messageLines[i].setBackgroundColor(Palette::WallScreen);
m_messageLines[i].setFont(KDFont::SmallFont);
m_messageLines[i].setAlignment(0.5f, 0.5f);
m_messageLines[i].setMessage(textMessages[i]);
}
}
void CountryController::ContentView::drawRect(KDContext * ctx, KDRect rect) const {
ctx->fillRect(bounds(), Palette::WallScreen);
}
View * CountryController::ContentView::subviewAtIndex(int i) {
assert(i < numberOfSubviews());
switch (i) {
case 0:
return &m_selectableTableView;
case 1:
return &m_titleMessage;
default:
return &m_messageLines[i - 2];
}
}
void CountryController::ContentView::layoutSubviews(bool force) {
KDCoordinate origin = Metric::CommonTopMargin;
if (m_displayTitle) {
origin = layoutTitleSubview(force, origin) + Metric::CommonSmallMargin;
}
origin = layoutSubtitleSubview(force, origin) + Metric::CommonTopMargin;
origin = layoutTableSubview(force, origin);
assert(origin <= bounds().height());
}
KDCoordinate CountryController::ContentView::layoutTitleSubview(bool force, KDCoordinate verticalOrigin) {
KDCoordinate titleHeight = m_titleMessage.font()->glyphSize().height();
m_titleMessage.setFrame(KDRect(0, verticalOrigin, bounds().width(), titleHeight), force);
return verticalOrigin + titleHeight;
}
KDCoordinate CountryController::ContentView::layoutSubtitleSubview(bool force, KDCoordinate verticalOrigin) {
assert(k_numberOfTextLines > 0);
KDCoordinate textHeight = m_messageLines[0].font()->glyphSize().height();
for (int i = 0; i < k_numberOfTextLines; i++) {
m_messageLines[i].setFrame(KDRect(0, verticalOrigin, bounds().width(), textHeight), force);
verticalOrigin += textHeight;
}
return verticalOrigin;
}
KDCoordinate CountryController::ContentView::layoutTableSubview(bool force, KDCoordinate verticalOrigin) {
KDCoordinate tableHeight = std::min<KDCoordinate>(
bounds().height() - verticalOrigin,
m_selectableTableView.minimalSizeForOptimalDisplay().height());
m_selectableTableView.setFrame(KDRect(0, verticalOrigin, bounds().width(), tableHeight), force);
return verticalOrigin + tableHeight;
}
// CountryController
int CountryController::IndexOfCountry(I18n::Country country) {
/* As we want to order the countries alphabetically in the selected language,
* the index of a country in the table is the number of other countries that
@@ -36,17 +107,17 @@ I18n::Country CountryController::CountryAtIndex(int i) {
CountryController::CountryController(Responder * parentResponder, KDCoordinate verticalMargin) :
ViewController(parentResponder),
m_selectableTableView(this, this, this)
m_contentView(this, this)
{
m_selectableTableView.setTopMargin(verticalMargin);
m_selectableTableView.setBottomMargin(verticalMargin);
selectableTableView()->setTopMargin(0);
selectableTableView()->setBottomMargin(verticalMargin);
for (int i = 0; i < I18n::NumberOfCountries; i++) {
m_cells[i].setMessageFont(KDFont::LargeFont);
}
}
void CountryController::resetSelection() {
m_selectableTableView.deselectTable();
selectableTableView()->deselectTable();
selectCellAtLocation(0, IndexOfCountry(GlobalPreferences::sharedGlobalPreferences()->country()));
}
@@ -57,7 +128,7 @@ void CountryController::viewWillAppear() {
/* FIXME : When selecting a country, changing the language, then coming back
* to select a country, some countries' names will be cropped. We force the
* TableView to refresh to prevent that. */
m_selectableTableView.reloadData();
selectableTableView()->reloadData();
}
bool CountryController::handleEvent(Ion::Events::Event event) {

View File

@@ -14,9 +14,9 @@ public:
CountryController(Responder * parentResponder, KDCoordinate verticalMargin);
virtual void resetSelection();
View * view() override { return &m_selectableTableView; }
const char * title() override {return I18n::translate(I18n::Message::Country); }
void didBecomeFirstResponder() override {Container::activeApp()->setFirstResponder(&m_selectableTableView); }
View * view() override { return &m_contentView; }
const char * title() override { return I18n::translate(I18n::Message::Country); }
void didBecomeFirstResponder() override { Container::activeApp()->setFirstResponder(selectableTableView()); }
void viewWillAppear() override;
bool handleEvent(Ion::Events::Event event) override;
@@ -28,11 +28,32 @@ public:
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
protected:
SelectableTableView m_selectableTableView;
class ContentView : public View {
public:
ContentView(CountryController * controller, SelectableTableViewDataSource * dataSource);
SelectableTableView * selectableTableView() { return &m_selectableTableView; }
void drawRect(KDContext * ctx, KDRect rect) const override;
void shouldDisplayTitle(bool flag) { m_displayTitle = flag; }
protected:
void layoutSubviews(bool force = false) override;
KDCoordinate layoutTitleSubview(bool force, KDCoordinate verticalOrigin);
KDCoordinate layoutSubtitleSubview(bool force, KDCoordinate verticalOrigin);
KDCoordinate layoutTableSubview(bool force, KDCoordinate verticalOrigin);
private:
constexpr static int k_numberOfTextLines = 2;
int numberOfSubviews() const override { return 1 + 1 + k_numberOfTextLines; }
View * subviewAtIndex(int i) override;
SelectableTableView m_selectableTableView;
MessageTextView m_titleMessage;
MessageTextView m_messageLines[k_numberOfTextLines];
bool m_displayTitle;
};
SelectableTableView * selectableTableView() { return m_contentView.selectableTableView(); }
ContentView m_contentView;
private:
MessageTableCell m_cells[I18n::NumberOfCountries];
// TODO : Add variables for static text
};
}