From 8d362ef4de12299022985ae01e13fcbf90b00434 Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Mon, 22 Jun 2020 11:32:43 +0200 Subject: [PATCH] [apps/settings] Added message to country menu Change-Id: Iec064d0ac86f54a10cf63236b6f958d53cecb2e2 --- apps/on_boarding/country_controller.cpp | 6 +- apps/on_boarding/country_controller.h | 1 + apps/settings/sub_menu/country_controller.cpp | 7 ++ apps/settings/sub_menu/country_controller.h | 2 +- apps/shared.de.i18n | 2 + apps/shared.en.i18n | 2 + apps/shared.es.i18n | 2 + apps/shared.fr.i18n | 2 + apps/shared.it.i18n | 2 + apps/shared.nl.i18n | 2 + apps/shared.pt.i18n | 2 + apps/shared/country_controller.cpp | 81 +++++++++++++++++-- apps/shared/country_controller.h | 31 +++++-- 13 files changed, 128 insertions(+), 14 deletions(-) diff --git a/apps/on_boarding/country_controller.cpp b/apps/on_boarding/country_controller.cpp index d8d5d2482..29f04eec6 100644 --- a/apps/on_boarding/country_controller.cpp +++ b/apps/on_boarding/country_controller.cpp @@ -12,18 +12,18 @@ CountryController::CountryController(Responder * parentResponder) : static_cast(Metric::CommonLeftMargin), (Ion::Display::Height - I18n::NumberOfCountries*Metric::ParameterCellHeight)/2)) { - static_cast(m_selectableTableView.decorator()->indicatorAtIndex(1))->setMargin( + static_cast(selectableTableView()->decorator()->indicatorAtIndex(1))->setMargin( std::max( static_cast(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); } diff --git a/apps/on_boarding/country_controller.h b/apps/on_boarding/country_controller.h index 21cdf80af..737770414 100644 --- a/apps/on_boarding/country_controller.h +++ b/apps/on_boarding/country_controller.h @@ -12,6 +12,7 @@ public: void resetSelection() override; bool handleEvent(Ion::Events::Event event) override; ViewController::DisplayParameter displayParameter() override { return ViewController::DisplayParameter::WantsMaximumSpace; } + }; } diff --git a/apps/settings/sub_menu/country_controller.cpp b/apps/settings/sub_menu/country_controller.cpp index f9b450be8..8b709b369 100644 --- a/apps/settings/sub_menu/country_controller.cpp +++ b/apps/settings/sub_menu/country_controller.cpp @@ -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(parentResponder())->pop(); diff --git a/apps/settings/sub_menu/country_controller.h b/apps/settings/sub_menu/country_controller.h index bfdac2d81..a75b0f962 100644 --- a/apps/settings/sub_menu/country_controller.h +++ b/apps/settings/sub_menu/country_controller.h @@ -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; }; diff --git a/apps/shared.de.i18n b/apps/shared.de.i18n index df2df5f3d..b3a070476 100644 --- a/apps/shared.de.i18n +++ b/apps/shared.de.i18n @@ -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" diff --git a/apps/shared.en.i18n b/apps/shared.en.i18n index 589744078..bac1737fc 100644 --- a/apps/shared.en.i18n +++ b/apps/shared.en.i18n @@ -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" diff --git a/apps/shared.es.i18n b/apps/shared.es.i18n index 8b59ee580..310838d17 100644 --- a/apps/shared.es.i18n +++ b/apps/shared.es.i18n @@ -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" diff --git a/apps/shared.fr.i18n b/apps/shared.fr.i18n index c6e9ce7cf..e96fa97fd 100644 --- a/apps/shared.fr.i18n +++ b/apps/shared.fr.i18n @@ -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" diff --git a/apps/shared.it.i18n b/apps/shared.it.i18n index 579f7fcc3..854a83b2f 100644 --- a/apps/shared.it.i18n +++ b/apps/shared.it.i18n @@ -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" diff --git a/apps/shared.nl.i18n b/apps/shared.nl.i18n index b12190ca1..ed269f4ca 100644 --- a/apps/shared.nl.i18n +++ b/apps/shared.nl.i18n @@ -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" diff --git a/apps/shared.pt.i18n b/apps/shared.pt.i18n index 036d6e99e..d31171007 100644 --- a/apps/shared.pt.i18n +++ b/apps/shared.pt.i18n @@ -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" diff --git a/apps/shared/country_controller.cpp b/apps/shared/country_controller.cpp index c4a456bcb..38a80b384 100644 --- a/apps/shared/country_controller.cpp +++ b/apps/shared/country_controller.cpp @@ -2,9 +2,80 @@ #include "../global_preferences.h" #include "../apps_container.h" #include +#include 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( + 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) { diff --git a/apps/shared/country_controller.h b/apps/shared/country_controller.h index 4febf5f32..624802f86 100644 --- a/apps/shared/country_controller.h +++ b/apps/shared/country_controller.h @@ -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 }; }