[apps/shared] CountryController

Created a CountryController class to chose the country in the settings
and at onboarding.

Change-Id: I6787e8b45744a8a98e83f59e5d2c4760364635cb
This commit is contained in:
Gabriel Ozouf
2020-06-18 17:25:08 +02:00
committed by Émilie Feral
parent 3f9b8f03af
commit 1642276678
3 changed files with 89 additions and 0 deletions

View File

@@ -26,6 +26,7 @@ app_shared_src = $(addprefix apps/shared/,\
buffer_function_title_cell.cpp \
buffer_text_view_with_text_field.cpp \
button_with_separator.cpp \
country_controller.cpp \
cursor_view.cpp \
editable_cell_table_view_controller.cpp \
expression_field_delegate_app.cpp \

View File

@@ -0,0 +1,51 @@
#include "country_controller.h"
#include "../global_preferences.h"
#include "../apps_container.h"
namespace Shared {
CountryController::CountryController(Responder * parentResponder, KDCoordinate verticalMargin) :
ViewController(parentResponder),
m_selectableTableView(this, this, this)
{
m_selectableTableView.setTopMargin(verticalMargin);
m_selectableTableView.setBottomMargin(verticalMargin);
for (int i = 0; i < I18n::NumberOfCountries; i++) {
m_cells[i].setMessageFont(KDFont::LargeFont);
}
}
void CountryController::resetSelection() {
m_selectableTableView.deselectTable();
selectCellAtLocation(0, static_cast<int>(GlobalPreferences::sharedGlobalPreferences()->country()));
}
void CountryController::viewWillAppear() {
ViewController::viewWillAppear();
resetSelection();
/* 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();
}
bool CountryController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::OK || event == Ion::Events::EXE) {
/* TODO : Since the order in which the countries are displayed changes with
* the language, we need something more sophisticated
* than (I18n::Country)selectedRow() */
GlobalPreferences::sharedGlobalPreferences()->setCountry(static_cast<I18n::Country>(selectedRow()));
return true;
}
return false;
}
void CountryController::willDisplayCellForIndex(HighlightCell * cell, int index) {
/* TODO : We want the countries to always appear in alphabetical order. The
* index from which the country's name is fetched must take that into
* account.*/
static_cast<MessageTableCell *>(cell)->setMessage(I18n::CountryNames[index]);
}
}

View File

@@ -0,0 +1,37 @@
#ifndef SHARED_COUNTRY_CONTROLLER_H
#define SHARED_COUNTRY_CONTROLLER_H
#include <escher.h>
#include <apps/i18n.h>
namespace Shared {
class CountryController : public ViewController, public SimpleListViewDataSource, public SelectableTableViewDataSource {
public:
CountryController(Responder * parentResponder, KDCoordinate verticalMargin);
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); }
void viewWillAppear() override;
bool handleEvent(Ion::Events::Event event) override;
int numberOfRows() const override { return I18n::NumberOfCountries; }
KDCoordinate cellHeight() override { return Metric::ParameterCellHeight; }
HighlightCell * reusableCell(int index) override { return &m_cells[index]; }
int reusableCellCount() const override { return I18n::NumberOfCountries; }
void willDisplayCellForIndex(HighlightCell * cell, int index) override;
protected:
SelectableTableView m_selectableTableView;
private:
MessageTableCell m_cells[I18n::NumberOfCountries];
// TODO : Add variables for static text
};
}
#endif