+++ /dev/null
-#include "AppContext.hpp"
-
-#include "AccessibilitySettingLog.hpp"
-#include "Conformant.hpp"
-#include "ListView.hpp"
-#include "MainPage.hpp"
-
-#include <app.h>
-
-AppContext::AppContext()
-{
- elm_app_base_scale_set(2.4);
-
- bindtextdomain(PACKAGE, LOCALEDIR);
- textdomain(PACKAGE);
-}
-
-void AppContext::push(std::unique_ptr<Presenter> presenter)
-{
- presentersStack_.push_back(std::move(presenter));
- ListView ls(navContext_, presentersStack_.back().get());
-}
-
-void AppContext::pop()
-{
- presentersStack_.pop_back();
-}
-
-Presenter *AppContext::back()
-{
- return presentersStack_.back().get();
-}
+++ /dev/null
-#ifndef APP_CONTEXT_HPP
-#define APP_CONTEXT_HPP
-
-#include "Naviframe.hpp"
-#include "NavigationContext.hpp"
-#include "Presenter.hpp"
-#include "ScanningProperties.hpp"
-#include "Window.hpp"
-#include "setting-accessibility-universal-switch-dbus.h"
-
-#include <memory>
-#include <string>
-
-class AppContext
-{
- public:
- AppContext();
- void push(std::unique_ptr<Presenter> presenter);
- void pop();
- Presenter *back();
-
- // TODO: should be private
- UniversalSwitchDbusConfig config;
- ScanningProperties usScanningProperties;
- NavigationContext navContext_;
-
- private:
- std::vector<std::unique_ptr<Presenter>> presentersStack_;
-};
-
-#endif
\ No newline at end of file
*/
#include "AccessibilitySettingLog.hpp"
-#include "MainPage.hpp"
+#include "MainPagePresenter.hpp"
#include "Singleton.hpp"
#include "setting-accessibility.h"
static bool on_app_create(void *priv)
{
- Singleton<AppContext>::instance().push(std::make_unique<MainPage>());
+ Singleton<AppContext>::instance().push(std::make_unique<MainPagePresenter>());
return true;
}
--- /dev/null
+#include "AppContext.hpp"
+
+#include "AccessibilitySettingLog.hpp"
+#include "Conformant.hpp"
+#include "MainPagePresenter.hpp"
+
+#include <app.h>
+
+AppContext::AppContext()
+{
+ elm_app_base_scale_set(2.4);
+
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+}
+
+void AppContext::push(std::unique_ptr<Presenter> presenter)
+{
+ presentersStack_.push_back(std::move(presenter));
+ navContext_.emplaceView(presentersStack_.back().get());
+}
+
+void AppContext::pop()
+{
+ navContext_.popView();
+ presentersStack_.pop_back();
+}
+
+Presenter *AppContext::back()
+{
+ return presentersStack_.back().get();
+}
--- /dev/null
+#ifndef APP_CONTEXT_HPP
+#define APP_CONTEXT_HPP
+
+#include "Naviframe.hpp"
+#include "NavigationContext.hpp"
+#include "Presenter.hpp"
+#include "ScanningProperties.hpp"
+#include "Window.hpp"
+#include "setting-accessibility-universal-switch-dbus.h"
+
+#include <memory>
+#include <string>
+
+class AppContext
+{
+ public:
+ AppContext();
+ void push(std::unique_ptr<Presenter> presenter);
+ void pop();
+ Presenter *back();
+
+ // TODO: should be private
+ UniversalSwitchDbusConfig config;
+ ScanningProperties usScanningProperties;
+ NavigationContext navContext_;
+
+ private:
+ std::vector<std::unique_ptr<Presenter>> presentersStack_;
+};
+
+#endif
\ No newline at end of file
--- /dev/null
+#ifndef LIST_GROUP_HPP
+#define LIST_GROUP_HPP
+
+#include "ListItem.hpp"
+
+#include <string>
+#include <vector>
+
+struct ListGroup
+{
+ std::string name_;
+ std::vector<ListItem> items_;
+};
+
+#endif
\ No newline at end of file
--- /dev/null
+#include "ListItem.hpp"
+
+ListItem::ListItem(std::string title,
+ std::string description,
+ std::function<void()> onItemSelection,
+ std::function<void()> onWidgetSelection,
+ WidgetType type,
+ bool state,
+ std::string iconPath)
+ : title_(std::move(title)),
+ description_(std::move(description)),
+ onItemSelection_(std::move(onItemSelection)),
+ onWidgetSelection_(std::move(onWidgetSelection)),
+ widgetType_(type),
+ widgetState_(state),
+ iconPath_(std::move(iconPath))
+{}
\ No newline at end of file
--- /dev/null
+#ifndef LIST_ITEM_HPP
+#define LIST_ITEM_HPP
+
+#include "Observable.hpp"
+
+#include <functional>
+#include <string>
+
+struct ListItem : public Observable<>
+{
+ enum class WidgetType
+ {
+ none,
+ check,
+ toggle,
+ radio,
+ icon
+ };
+
+ ListItem(std::string title,
+ std::string description,
+ std::function<void()> onItemSelection = {},
+ std::function<void()> onWidgetSelection = {},
+ WidgetType type = WidgetType::none,
+ bool state = false,
+ std::string iconPath = {});
+ std::string title_;
+ std::string description_;
+ std::function<void()> onItemSelection_;
+ std::function<void()> onWidgetSelection_;
+ WidgetType widgetType_ = WidgetType::none;
+ bool widgetState_ = false;
+ std::string iconPath_;
+};
+
+#endif
\ No newline at end of file
#include "ListPresenter.hpp"
-const std::vector<GenlistItem> &ListPresenter::getGenlistItems() const
+const std::vector<ListGroup> &ListPresenter::getListGroups() const
{
- return genlistItems_;
+ return groups_;
}
\ No newline at end of file
#ifndef LIST_PRESENTER_HPP
#define LIST_PRESENTER_HPP
+#include "ListGroup.hpp"
#include "Observable.hpp"
#include "Presenter.hpp"
class ListPresenter : public Presenter, public Observable<>
{
public:
- const std::vector<GenlistItem> &getGenlistItems() const;
+ const std::vector<ListGroup> &getListGroups() const;
protected:
using Presenter::Presenter;
- std::vector<GenlistItem> genlistItems_;
+ std::vector<ListGroup> groups_;
};
#endif
\ No newline at end of file
+++ /dev/null
-#include "MainPage.hpp"
-
-#include <app.h>
-
-MainPage::MainPage()
- : ListPresenter("IDS_ST_BODY_ACCESSIBILITY")
-{
- genlistItems_.emplace_back("group_index", "IDS_ST_HEADER_VISION");
-
- genlistItems_.emplace_back("type1", "IDS_ST_MBODY_SCREEN_READER_HTTS", "IDS_ST_BODY_OFF", [this](auto item) { screenReaderPage_ = std::make_unique<ScreenReaderPage>(); });
- auto &screenReaderItem = genlistItems_.back();
-
- auto onVConfValueChangeCb = [&](auto state) {
- screenReaderItem.setDescription(state ? "IDS_ST_BODY_ON" : "IDS_ST_BODY_OFF");
- screenReaderItem.update();
- };
-
- screenReaderStateHandle_ = Singleton<VConfInterface>::instance().registerAndGet<bool>({VCONFKEY_SETAPPL_ACCESSIBILITY_TTS}, false, onVConfValueChangeCb);
-
- genlistItems_.emplace_back("multiline",
- "IDS_ACCS_UNIVERSAL_SWITCH",
- "IDS_ACCS_UNIVERSAL_SWITCH_HINT",
- [this](auto item) { universalSwitchPage_ = std::make_unique<UniversalSwitchPage>(); });
-
- genlistItems_.emplace_back("multiline",
- "IDS_ACCS_ACCESSIBILITY_LAUNCHER",
- "IDS_ACCS_ACCESSIBILITY_LAUNCHER_HINT",
- [this](auto item) { accessibilityLauncherPage_ = std::make_unique<AccessibilityLauncherPage>(); });
-
- onPopCallback_ = [this]() {
- screenReaderStateHandle_ = {};
- ui_app_exit();
- };
-}
\ No newline at end of file
+++ /dev/null
-#ifndef MAIN_PAGE_HPP
-#define MAIN_PAGE_HPP
-
-#include "AccessibilityLauncherPage.hpp"
-#include "ListPresenter.hpp"
-#include "ScreenReaderPage.hpp"
-#include "UniversalSwitchPage.hpp"
-#include "VConf.hpp"
-
-class MainPage : public ListPresenter
-{
- public:
- MainPage();
-
- private:
- std::unique_ptr<ScreenReaderPage> screenReaderPage_;
- std::unique_ptr<UniversalSwitchPage> universalSwitchPage_;
- std::unique_ptr<AccessibilityLauncherPage> accessibilityLauncherPage_;
- VConfInterface::CallbackHandle screenReaderStateHandle_;
-};
-
-#endif
\ No newline at end of file
--- /dev/null
+#include "MainPagePresenter.hpp"
+
+#include <app.h>
+
+MainPagePresenter::MainPagePresenter()
+ : ListPresenter("IDS_ST_BODY_ACCESSIBILITY")
+{
+ auto group = ListGroup{"IDS_ST_HEADER_VISION"};
+ group.items_.emplace_back("IDS_ST_MBODY_SCREEN_READER_HTTS",
+ "IDS_ST_BODY_OFF",
+ [this]() { screenReaderPage_ = std::make_unique<ScreenReaderPage>(); });
+ group.items_.emplace_back("IDS_ACCS_UNIVERSAL_SWITCH",
+ "IDS_ACCS_UNIVERSAL_SWITCH_HINT",
+ [this]() { universalSwitchPage_ = std::make_unique<UniversalSwitchPage>(); });
+ group.items_.emplace_back("IDS_ACCS_ACCESSIBILITY_LAUNCHER",
+ "IDS_ACCS_ACCESSIBILITY_LAUNCHER_HINT",
+ [this]() { accessibilityLauncherPage_ = std::make_unique<AccessibilityLauncherPage>(); });
+ groups_.push_back(group);
+
+ onPopCallback_ = [this]() {
+ screenReaderStateHandle_ = {};
+ ui_app_exit();
+ };
+}
\ No newline at end of file
--- /dev/null
+#ifndef MAIN_PAGE_PRESENTER_HPP
+#define MAIN_PAGE_PRESENTER_HPP
+
+#include "AccessibilityLauncherPage.hpp"
+#include "ListPresenter.hpp"
+#include "ScreenReaderPage.hpp"
+#include "UniversalSwitchPage.hpp"
+#include "VConf.hpp"
+
+class MainPagePresenter : public ListPresenter
+{
+ public:
+ MainPagePresenter();
+
+ private:
+ std::unique_ptr<ScreenReaderPage> screenReaderPage_;
+ std::unique_ptr<UniversalSwitchPage> universalSwitchPage_;
+ std::unique_ptr<AccessibilityLauncherPage> accessibilityLauncherPage_;
+ VConfInterface::CallbackHandle screenReaderStateHandle_;
+};
+
+#endif
\ No newline at end of file
#include "Genlist.hpp"
#include "ListPresenter.hpp"
+#include "NavigationContext.hpp"
ListView::ListView(const NavigationContext &context, Presenter *presenter)
: View(context), listPresenter_(dynamic_cast<ListPresenter *>(presenter))
addItemsToGenlist();
- listPresenter_->attach([this]() {
- genlist_->clear();
- addItemsToGenlist();
- });
-
naviframe->pushBack(listPresenter_->getTitle(), genlist_, listPresenter_->getOnPopCallback(), prevButton_);
}
void ListView::addItemsToGenlist()
{
- for (auto it : listPresenter_->getGenlistItems())
- genlist_->appendItem(it);
+ for (const auto &g : listPresenter_->getListGroups()) {
+ auto groupItem = genlist_->appendItem({"group_index", g.name_});
+
+ for (const auto &it : g.items_) {
+ auto type = translateType(it.widgetType_);
+ genlist_->appendItem({"multiline", it.title_, it.description_, [it](auto item) { it.onItemSelection_(); }, [it](auto item) { it.onWidgetSelection_(); }, type}, groupItem);
+ }
+ }
+}
+
+GenlistItem::WidgetType ListView::translateType(ListItem::WidgetType t)
+{
+ switch (t) {
+ case ListItem::WidgetType::none:
+ return GenlistItem::WidgetType::none;
+
+ case ListItem::WidgetType::check:
+ return GenlistItem::WidgetType::check;
+
+ case ListItem::WidgetType::toggle:
+ return GenlistItem::WidgetType::toggle;
+
+ case ListItem::WidgetType::radio:
+ return GenlistItem::WidgetType::radio;
+
+ case ListItem::WidgetType::icon:
+ return GenlistItem::WidgetType::icon;
+ }
+ ERROR("Invalid type");
+ return {};
}
\ No newline at end of file
private:
void addItemsToGenlist();
+ GenlistItem::WidgetType translateType(ListItem::WidgetType t);
ListPresenter *listPresenter_ = nullptr;
Genlist *genlist_ = nullptr;
#include "NavigationContext.hpp"
#include "Conformant.hpp"
+#include "ListPresenter.hpp"
+#include "ListView.hpp"
NavigationContext::NavigationContext()
{
Naviframe *NavigationContext::getNaviframe() const
{
return naviframe_;
+}
+
+void NavigationContext::emplaceView(Presenter *presenter)
+{
+ /*
+ * In order to add new Presenter class, one should cast received pointer to derived type
+ * and push proper View on viewStack_
+ */
+ auto lp = dynamic_cast<ListPresenter *>(presenter);
+ if (lp) {
+ viewsStack_.push_back(std::make_unique<ListView>(*this, lp));
+ return;
+ }
+
+ ASSERT(0, "Presenter not supported");
+}
+
+void NavigationContext::popView()
+{
+ viewsStack_.pop_back();
}
\ No newline at end of file
#define NAVIGATION_CONTEXT_HPP
#include "Naviframe.hpp"
+#include "Presenter.hpp"
+#include "View.hpp"
#include "Window.hpp"
#include <memory>
+class View;
class NavigationContext
{
public:
Window *getWindow();
Naviframe *getNaviframe() const;
+ void emplaceView(Presenter *presenter);
+ void popView();
private:
std::unique_ptr<Window> window_;
Naviframe *naviframe_;
+ std::vector<std::unique_ptr<View>> viewsStack_;
};
#endif
\ No newline at end of file
#include "View.hpp"
+#include "NavigationContext.hpp"
+
View::View(const NavigationContext &context)
{
prevButton_ = Widget::make<Button>(context.getNaviframe(),
#define VIEW_HPP
#include "Button.hpp"
-#include "NavigationContext.hpp"
#include "Presenter.hpp"
+class NavigationContext;
class View
{
public: