Fix runtime and design issues 92/203592/4
authorLukasz Wlazly <l.wlazly@partner.samsung.com>
Tue, 16 Apr 2019 06:08:02 +0000 (08:08 +0200)
committerLukasz Wlazly <l.wlazly@partner.samsung.com>
Wed, 17 Apr 2019 10:00:02 +0000 (12:00 +0200)
This patch:
1. Adds classes for abstract ListItem and ListGroup
2. Adds stack for views

Change-Id: I6ea212ae38ebeb1fd660dbeeff57ebbc64f8fbe2

20 files changed:
src/AppContext.cpp [deleted file]
src/AppContext.hpp [deleted file]
src/main.cpp
src/presenter/AppContext.cpp [new file with mode: 0644]
src/presenter/AppContext.hpp [new file with mode: 0644]
src/presenter/ListGroup.hpp [new file with mode: 0644]
src/presenter/ListItem.cpp [new file with mode: 0644]
src/presenter/ListItem.hpp [new file with mode: 0644]
src/presenter/ListPresenter.cpp
src/presenter/ListPresenter.hpp
src/presenter/MainPage.cpp [deleted file]
src/presenter/MainPage.hpp [deleted file]
src/presenter/MainPagePresenter.cpp [new file with mode: 0644]
src/presenter/MainPagePresenter.hpp [new file with mode: 0644]
src/view/ListView.cpp
src/view/ListView.hpp
src/view/NavigationContext.cpp
src/view/NavigationContext.hpp
src/view/View.cpp
src/view/View.hpp

diff --git a/src/AppContext.cpp b/src/AppContext.cpp
deleted file mode 100644 (file)
index 64221cc..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#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();
-}
diff --git a/src/AppContext.hpp b/src/AppContext.hpp
deleted file mode 100644 (file)
index d3ef7f2..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-#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
index 932fff8594cc7fd788938bfacec2ea5ff310bac0..212259b838c247a84251ecfc1c44d492dacfc89e 100644 (file)
@@ -15,7 +15,7 @@
  */
 
 #include "AccessibilitySettingLog.hpp"
-#include "MainPage.hpp"
+#include "MainPagePresenter.hpp"
 #include "Singleton.hpp"
 #include "setting-accessibility.h"
 
@@ -24,7 +24,7 @@
 
 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;
 }
 
diff --git a/src/presenter/AppContext.cpp b/src/presenter/AppContext.cpp
new file mode 100644 (file)
index 0000000..d0c7395
--- /dev/null
@@ -0,0 +1,32 @@
+#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();
+}
diff --git a/src/presenter/AppContext.hpp b/src/presenter/AppContext.hpp
new file mode 100644 (file)
index 0000000..d3ef7f2
--- /dev/null
@@ -0,0 +1,31 @@
+#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
diff --git a/src/presenter/ListGroup.hpp b/src/presenter/ListGroup.hpp
new file mode 100644 (file)
index 0000000..3bfb52d
--- /dev/null
@@ -0,0 +1,15 @@
+#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
diff --git a/src/presenter/ListItem.cpp b/src/presenter/ListItem.cpp
new file mode 100644 (file)
index 0000000..4fd9c38
--- /dev/null
@@ -0,0 +1,17 @@
+#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
diff --git a/src/presenter/ListItem.hpp b/src/presenter/ListItem.hpp
new file mode 100644 (file)
index 0000000..b479b8b
--- /dev/null
@@ -0,0 +1,36 @@
+#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
index 52645571f0e06f2b060d158e5b6bd250ff71ff04..e3e8b28a832cd00455b2a876597f6d1635c158a3 100644 (file)
@@ -1,6 +1,6 @@
 #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
index c5bfaf313500dda5491bdaf2d93ba186c1e1efde..519e8437c18fb2769aa09a017c741c3d236a8fb0 100644 (file)
@@ -1,18 +1,19 @@
 #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
diff --git a/src/presenter/MainPage.cpp b/src/presenter/MainPage.cpp
deleted file mode 100644 (file)
index e79dcca..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-#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
diff --git a/src/presenter/MainPage.hpp b/src/presenter/MainPage.hpp
deleted file mode 100644 (file)
index 40ddc7b..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#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
diff --git a/src/presenter/MainPagePresenter.cpp b/src/presenter/MainPagePresenter.cpp
new file mode 100644 (file)
index 0000000..2193573
--- /dev/null
@@ -0,0 +1,24 @@
+#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
diff --git a/src/presenter/MainPagePresenter.hpp b/src/presenter/MainPagePresenter.hpp
new file mode 100644 (file)
index 0000000..b48b02b
--- /dev/null
@@ -0,0 +1,22 @@
+#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
index 7714ceb29b9bb935353a0161a1bcd2c4f4e603ea..90bb23e9d529bfafd263d937073d57862935f0b8 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "Genlist.hpp"
 #include "ListPresenter.hpp"
+#include "NavigationContext.hpp"
 
 ListView::ListView(const NavigationContext &context, Presenter *presenter)
        : View(context), listPresenter_(dynamic_cast<ListPresenter *>(presenter))
@@ -15,16 +16,39 @@ ListView::ListView(const NavigationContext &context, Presenter *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
index 0851655b7baf9dc958f5f6dd778c2cccfe370a4a..5980b38749d28c88c5c3f058bf759c1f75b32c5f 100644 (file)
@@ -12,6 +12,7 @@ class ListView : public View
 
        private:
        void addItemsToGenlist();
+       GenlistItem::WidgetType translateType(ListItem::WidgetType t);
 
        ListPresenter *listPresenter_ = nullptr;
        Genlist *genlist_ = nullptr;
index 3e4d87e3d324657dfb14614c7db3b909e92196fa..fb0eb3d1f0fd2d758637ff90f20a6abc073fa0ce 100644 (file)
@@ -1,6 +1,8 @@
 #include "NavigationContext.hpp"
 
 #include "Conformant.hpp"
+#include "ListPresenter.hpp"
+#include "ListView.hpp"
 
 NavigationContext::NavigationContext()
 {
@@ -31,4 +33,24 @@ Window *NavigationContext::getWindow()
 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
index cd14fda7fa9ae340320851a8262b46fd1e8fbb3b..dca463a062068d65f42b3f6ad36e87d7293e92e6 100644 (file)
@@ -2,10 +2,13 @@
 #define NAVIGATION_CONTEXT_HPP
 
 #include "Naviframe.hpp"
+#include "Presenter.hpp"
+#include "View.hpp"
 #include "Window.hpp"
 
 #include <memory>
 
+class View;
 class NavigationContext
 {
        public:
@@ -13,10 +16,13 @@ class NavigationContext
 
        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
index 38f62572ce664f0e8c10f35cb5c8a877f31e9f8e..a5a1170889ffac8b11d7297418997f9fb094e09b 100644 (file)
@@ -1,5 +1,7 @@
 #include "View.hpp"
 
+#include "NavigationContext.hpp"
+
 View::View(const NavigationContext &context)
 {
        prevButton_ = Widget::make<Button>(context.getNaviframe(),
index 38945e2e225267bcff4bbc9f9e28ac7c70616090..14519a41a3154218a19bcedffbb72e44348f2257 100644 (file)
@@ -2,9 +2,9 @@
 #define VIEW_HPP
 
 #include "Button.hpp"
-#include "NavigationContext.hpp"
 #include "Presenter.hpp"
 
+class NavigationContext;
 class View
 {
        public: