Make AppContext observable 68/206768/2 accepted/tizen/unified/20190603.095341 accepted/tizen/unified/20190604.014650 submit/tizen/20190530.111225 submit/tizen/20190531.122943 submit/tizen/20190603.083549
authorLukasz Wlazly <l.wlazly@partner.samsung.com>
Fri, 24 May 2019 10:59:17 +0000 (12:59 +0200)
committerLukasz Wlazly <l.wlazly@partner.samsung.com>
Mon, 27 May 2019 12:08:03 +0000 (14:08 +0200)
Change-Id: I0286477681de1310eb2aeacef31a8de8284b1822

14 files changed:
src/AccessoriesSwitchesPage.cpp
src/AddSwitchPage.cpp
src/CameraSwitchesPage.cpp
src/RemoveSwitchPage.cpp
src/SetValuePage.cpp
src/SwitchesPage.cpp
src/UniversalSwitchPage.cpp
src/UniversalSwitchSettingsPage.cpp
src/UpdateSwitchPage.cpp
src/main.cpp
src/presenter/AppContext.cpp
src/presenter/AppContext.hpp
src/view/NavigationContext.cpp
src/view/NavigationContext.hpp

index bc33354..7239325 100644 (file)
 #include "Button.hpp"
 #include "Entry.hpp"
 #include "Layout.hpp"
+#include "NavigationContext.hpp"
 #include "Popup.hpp"
 #include "Singleton.hpp"
 
 AccessoriesSwitchesPage::AccessoriesSwitchesPage(NaviframeItem targetItem)
        : context_(Singleton<AppContext>::instance()), targetItem_(targetItem)
 {
-       auto naviframe = context_.navContext_.getNaviframe();
+       auto naviframe = Singleton<NavigationContext>::instance().getNaviframe();
        auto layout = Widget::make<Layout>(naviframe, EDJ_ACCESSORY, GRP_ACCESSORY);
        layout->setText(PRT_ACCESSORY_LABEL, "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_ACCESSORIES_DESC");
 
@@ -68,7 +69,7 @@ void AccessoriesSwitchesPage::captureSwitchCb(void *user_data, const std::string
 
 void AccessoriesSwitchesPage::newSwitchPopup()
 {
-       auto popup = Widget::make<Popup>(context_.navContext_.getNaviframe(), "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH");
+       auto popup = Widget::make<Popup>(Singleton<NavigationContext>::instance().getNaviframe(), "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH");
        popup->setEextEventCallback(EEXT_CALLBACK_BACK, []() {});
 
        auto layout = Widget::make<Layout>(popup, EDJ_ACCESSORY_POPUP, GRP_ACCESSORY_POPUP);
@@ -99,7 +100,7 @@ void AccessoriesSwitchesPage::newSwitchPopup()
                actionPage_ = std::make_unique<ActionPage>(targetItem_);
                actionPage_->attachCallback(accessorySwitchActionCb, this);
                elm_naviframe_item_pop_cb_set(
-                       elm_naviframe_top_item_get(context_.navContext_.getNaviframe()->getObject()), renewCaptureSwitchCb, this); // TODO
+                       elm_naviframe_top_item_get(Singleton<NavigationContext>::instance().getNaviframe()->getObject()), renewCaptureSwitchCb, this); // TODO
 
                auto parent = popup->getParent();
                parent->removeChild(popup);
@@ -112,7 +113,7 @@ void AccessoriesSwitchesPage::newSwitchPopup()
 
 void AccessoriesSwitchesPage::alreadyMappedSwitchPopup()
 {
-       auto popup = Widget::make<Popup>(context_.navContext_.getNaviframe(), "IDS_ACCS_UNIVERSAL_SWITCH_UNABLE_TO_ADD");
+       auto popup = Widget::make<Popup>(Singleton<NavigationContext>::instance().getNaviframe(), "IDS_ACCS_UNIVERSAL_SWITCH_UNABLE_TO_ADD");
        popup->setEextEventCallback(EEXT_CALLBACK_BACK, []() {});
 
        auto okBtnCb = [popup, this]() {
index a8212a7..1935013 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "Button.hpp"
 #include "Genlist.hpp"
+#include "NavigationContext.hpp"
 #include "Singleton.hpp"
 #include "setting-accessibility.h"
 
@@ -26,7 +27,7 @@
 AddSwitchPage::AddSwitchPage()
        : context_(Singleton<AppContext>::instance())
 {
-       auto naviframe = context_.navContext_.getNaviframe();
+       auto naviframe = Singleton<NavigationContext>::instance().getNaviframe();
        auto genlist = Widget::make<Genlist>(naviframe);
        genlist->setMode(ELM_LIST_COMPRESS);
        genlist->setStyle("dialogue");
index 1c7f4e5..447acf4 100644 (file)
@@ -19,6 +19,7 @@
 #include "AccessibilitySettingLog.hpp"
 #include "Button.hpp"
 #include "Genlist.hpp"
+#include "NavigationContext.hpp"
 #include "Singleton.hpp"
 #include "setting-accessibility.h"
 
@@ -27,7 +28,7 @@
 CameraSwitchesPage::CameraSwitchesPage(NaviframeItem targetItem)
        : context_(Singleton<AppContext>::instance()), targetItem_(targetItem)
 {
-       auto naviframe = context_.navContext_.getNaviframe();
+       auto naviframe = Singleton<NavigationContext>::instance().getNaviframe();
        auto genlist = Widget::make<Genlist>(naviframe);
        genlist->setMode(ELM_LIST_COMPRESS);
        genlist->setStyle("dialogue");
index 6b0c207..30bccf5 100644 (file)
@@ -19,6 +19,7 @@
 #include "AccessibilitySettingLog.hpp"
 #include "Button.hpp"
 #include "Genlist.hpp"
+#include "NavigationContext.hpp"
 #include "Popup.hpp"
 #include "Singleton.hpp"
 #include "VConf.hpp"
@@ -33,7 +34,7 @@
 RemoveSwitchPage::RemoveSwitchPage()
        : context_(Singleton<AppContext>::instance())
 {
-       auto naviframe = context_.navContext_.getNaviframe();
+       auto naviframe = Singleton<NavigationContext>::instance().getNaviframe();
        layout_ = Widget::make<Layout>(naviframe, "edje/accessibility-settings-set-value.edj", "set-value-switches");
        genlist_ = Widget::make<Genlist>(layout_);
        genlist_->setMode(ELM_LIST_COMPRESS);
@@ -90,7 +91,7 @@ void RemoveSwitchPage::attachCallback(UniversalSwitchCb cb, void *cbData)
 
 void RemoveSwitchPage::createPopupForSwitchesRemoving()
 {
-       auto popup = Widget::make<Popup>(context_.navContext_.getNaviframe(), "IDS_ACCS_UNIVERSAL_SWITCH_DELETE_SWITCHES");
+       auto popup = Widget::make<Popup>(Singleton<NavigationContext>::instance().getNaviframe(), "IDS_ACCS_UNIVERSAL_SWITCH_DELETE_SWITCHES");
 
        popup->setOrientation(ELM_POPUP_ORIENT_CENTER);
        auto areAllSwitchesSelectedToRemove = switchesToRemoveCounter_ == genlist_->size();
@@ -103,7 +104,7 @@ void RemoveSwitchPage::createPopupForSwitchesRemoving()
                                 TranslatedString{"IDS_ACCS_UNIVERSAL_SWITCH_DELETE_SWITCHES_DESC"}.str();
                popup->setText(s);
        }
-       auto removeCb = [p = popup, nf = context_.navContext_.getNaviframe()]() { nf->removeChild(p); };
+       auto removeCb = [p = popup, nf = Singleton<NavigationContext>::instance().getNaviframe()]() { nf->removeChild(p); };
        popup->setEextEventCallback(EEXT_CALLBACK_BACK, removeCb);
        popup->setEvasSmartCallback("dismissed", removeCb);
        popup->setEvasSmartCallback("block,clicked", removeCb);
@@ -123,8 +124,8 @@ void RemoveSwitchPage::createPopupForSwitchesRemoving()
                }
 
                removeCb();
-               context_.navContext_.getNaviframe()->removeChild(removeSwitchPopupBtn_);
-               context_.navContext_.getNaviframe()->popBack();
+               Singleton<NavigationContext>::instance().getNaviframe()->removeChild(removeSwitchPopupBtn_);
+               Singleton<NavigationContext>::instance().getNaviframe()->popBack();
 
                if (areAllSwitchesSelectedToRemove)
                        Singleton<VConfInterface>::instance().set(VCONFKEY_SETAPPL_ACCESSIBILITY_UNIVERSAL_SWITCH_INTERACTION_SERVICE, false);
index af1c251..52132f6 100644 (file)
@@ -20,6 +20,7 @@
 #include "Button.hpp"
 #include "Genlist.hpp"
 #include "Label.hpp"
+#include "NavigationContext.hpp"
 #include "Singleton.hpp"
 #include "setting-accessibility.h"
 
@@ -52,7 +53,7 @@ SetValuePage::SetValuePage(ValueEditorType type, TranslatedString title, Navifra
                layoutGroup = "set-value-numeric";
                ERROR("Unrecognized layout type");
        }
-       auto naviframe = context_.navContext_.getNaviframe();
+       auto naviframe = Singleton<NavigationContext>::instance().getNaviframe();
        layout_ = createLayout(naviframe, layoutGroup);
 
        switch (type) {
@@ -229,7 +230,7 @@ void SetValuePage::callRadioItemChangeCbAndPopNaviframe(GenlistItem *item)
 {
        if (changeRadioItemCb_)
                changeRadioItemCb_(item->getId());
-       context_.navContext_.getNaviframe()->popBack(naviframeItem_);
+       Singleton<NavigationContext>::instance().getNaviframe()->popBack(naviframeItem_);
 }
 
 Genlist *SetValuePage::createGenlist(Widget *parent, TranslatedString title)
index 32b3f42..1c64f23 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "SwitchesPage.hpp"
 
+#include "NavigationContext.hpp"
 #include "Singleton.hpp"
 #include "setting-accessibility.h"
 
@@ -24,7 +25,7 @@
 SwitchesPage::SwitchesPage()
        : context_(Singleton<AppContext>::instance())
 {
-       auto naviframe = context_.navContext_.getNaviframe();
+       auto naviframe = Singleton<NavigationContext>::instance().getNaviframe();
        switches_ = Widget::make<Genlist>(naviframe);
        switches_->setMode(ELM_LIST_COMPRESS);
        switches_->setStyle("dialogue");
index bc6d37b..773f505 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "UniversalSwitchPage.hpp"
 
+#include "NavigationContext.hpp"
 #include "Popup.hpp"
 #include "Singleton.hpp"
 #include "setting-accessibility.h"
@@ -25,7 +26,7 @@
 UniversalSwitchPage::UniversalSwitchPage()
        : context_(Singleton<AppContext>::instance())
 {
-       auto naviframe = context_.navContext_.getNaviframe();
+       auto naviframe = Singleton<NavigationContext>::instance().getNaviframe();
        auto genlist = Widget::make<Genlist>(naviframe);
        genlist->setMode(ELM_LIST_COMPRESS);
        genlist->setStyle("dialogue");
@@ -87,7 +88,7 @@ void UniversalSwitchPage::addNewSwitch()
 
 void UniversalSwitchPage::displayAddSwitchPopup()
 {
-       auto popup = Widget::make<Popup>(context_.navContext_.getWindow());
+       auto popup = Widget::make<Popup>(Singleton<NavigationContext>::instance().getWindow());
        popup->setText("To turn on Universal switch, tap ADD SWITCH and add at least one switch");
        popup->setEextEventCallback(EEXT_CALLBACK_BACK, []() {});
 
index b3e9b98..c17893e 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "Button.hpp"
 #include "CtxPopup.hpp"
+#include "NavigationContext.hpp"
 #include "Singleton.hpp"
 #include "VConf.hpp"
 #include "setting-accessibility.h"
@@ -99,7 +100,7 @@ KeyIdPairs mediaLevel = {
 UniversalSwitchSettingsPage::UniversalSwitchSettingsPage()
        : context_(Singleton<AppContext>::instance())
 {
-       auto naviframe = context_.navContext_.getNaviframe();
+       auto naviframe = Singleton<NavigationContext>::instance().getNaviframe();
        genlist_ = Widget::make<Genlist>(naviframe);
        genlist_->setMode(ELM_LIST_COMPRESS);
        genlist_->setStyle("dialogue");
@@ -769,7 +770,7 @@ void UniversalSwitchSettingsPage::scanSpeedChangedCb(double value)
 
 void UniversalSwitchSettingsPage::createScanDirectionCtxPopup()
 {
-       auto naviframe = context_.navContext_.getNaviframe();
+       auto naviframe = Singleton<NavigationContext>::instance().getNaviframe();
        auto ctxPopup = Widget::make<CtxPopup>(naviframe, true);
        auto removeCb = [naviframe, ctxPopup]() { naviframe->removeChild(ctxPopup); };
        ctxPopup->setEvasSmartCallback("dismissed", removeCb);
@@ -786,7 +787,7 @@ void UniversalSwitchSettingsPage::createScanDirectionCtxPopup()
 
        // TODO use real genlistitem position instead click position
        int y = 0;
-       evas_pointer_output_xy_get(evas_object_evas_get(context_.navContext_.getWindow()->getObject()), NULL, &y);
+       evas_pointer_output_xy_get(evas_object_evas_get(Singleton<NavigationContext>::instance().getWindow()->getObject()), NULL, &y);
 
        auto geometry = ctxPopup->getGeometry();
        ctxPopup->setPosition({-1, y + geometry.size.height / 2});
@@ -800,7 +801,7 @@ void UniversalSwitchSettingsPage::scanDirectionCtxPopupItemClicked(ScanDirection
 
 void UniversalSwitchSettingsPage::createScanMethodCtxPopup()
 {
-       auto naviframe = context_.navContext_.getNaviframe();
+       auto naviframe = Singleton<NavigationContext>::instance().getNaviframe();
        auto ctxPopup = Widget::make<CtxPopup>(naviframe, true);
        auto removeCb = [naviframe, ctxPopup]() { naviframe->removeChild(ctxPopup); };
        ctxPopup->setEvasSmartCallback("dismissed", removeCb);
@@ -817,7 +818,7 @@ void UniversalSwitchSettingsPage::createScanMethodCtxPopup()
 
        // TODO use real genlistitem position instead click position
        int y = 0;
-       evas_pointer_output_xy_get(evas_object_evas_get(context_.navContext_.getWindow()->getObject()), NULL, &y);
+       evas_pointer_output_xy_get(evas_object_evas_get(Singleton<NavigationContext>::instance().getWindow()->getObject()), NULL, &y);
 
        auto geometry = ctxPopup->getGeometry();
        ctxPopup->setPosition({-1, y + geometry.size.height / 2});
@@ -855,7 +856,7 @@ void UniversalSwitchSettingsPage::autoMoveIntervalValueChangedCb(double value)
 
 void UniversalSwitchSettingsPage::onManageMenuOptions()
 {
-       auto naviframe = context_.navContext_.getNaviframe();
+       auto naviframe = Singleton<NavigationContext>::instance().getNaviframe();
        auto genlist = Widget::make<Genlist>(naviframe);
        genlist->setMode(ELM_LIST_COMPRESS);
        genlist->setStyle("dialogue");
index b82877f..1b0920b 100644 (file)
@@ -17,6 +17,7 @@
 #include "UpdateSwitchPage.hpp"
 
 #include "AccessibilitySettingLog.hpp"
+#include "NavigationContext.hpp"
 #include "Singleton.hpp"
 #include "Toolbar.hpp"
 #include "setting-accessibility.h"
@@ -63,7 +64,7 @@ void UpdateSwitchPage::onActionUpdate(const std::string &action, void *user_data
 
 void UpdateSwitchPage::createUpdateAccessoriesSwitchPage()
 {
-       auto naviframe = context_.navContext_.getNaviframe();
+       auto naviframe = Singleton<NavigationContext>::instance().getNaviframe();
        layout_ = Widget::make<Layout>(
                naviframe, "edje/accessibility-settings-set-value.edj", GRP_SET_VALUE_UPDATE_ACCESSORIES_SWITCH);
        layout_->setPartText(PRT_SET_VALUE_DESC, "IDS_ACCS_UNIVERSAL_SWITCH_NAME");
@@ -134,5 +135,5 @@ void UpdateSwitchPage::updateSwitchChooseAction(const std::string &action, void
                        &self->context_.config, self->config_item_to_update_.activity_type),
                [self](auto item) { self->updateSwitchAction(); }});
 
-       self->context_.navContext_.getNaviframe()->popBack();
+       Singleton<NavigationContext>::instance().getNaviframe()->popBack();
 }
index 4270717..367f473 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "AccessibilitySettingLog.hpp"
 #include "MainPagePresenter.hpp"
+#include "NavigationContext.hpp"
 #include "Singleton.hpp"
 #include "setting-accessibility.h"
 
 static bool on_app_create(void *priv)
 {
        elm_app_name_set(PACKAGE_NAME);
+       // Because of lazy initialization in Singleton class
+       // order of below calls of "instance" method is meaningful
+       Singleton<AppContext>::instance();
+       Singleton<NavigationContext>::instance();
        Singleton<AppContext>::instance().push(std::make_unique<MainPagePresenter>());
        return true;
 }
index e75205f..190a83c 100644 (file)
@@ -17,12 +17,14 @@ AppContext::AppContext()
 void AppContext::push(std::unique_ptr<Presenter> presenter)
 {
        presentersStack_.push_back(std::move(presenter));
-       navContext_.emplaceView(presentersStack_.back().get());
+       toBroadcast_ = presentersStack_.back().get();
+       notify();
 }
 
 void AppContext::pop()
 {
-       navContext_.popView();
+       toBroadcast_ = nullptr;
+       notify();
        presentersStack_.pop_back();
 
        if (presentersStack_.empty())
@@ -38,3 +40,10 @@ bool AppContext::empty()
 {
        return presentersStack_.empty();
 }
+
+void AppContext::notify()
+{
+       for (auto &c : this->onChangeCallbacks_)
+               if (c)
+                       c(toBroadcast_);
+}
index 6633439..a30baa9 100644 (file)
@@ -2,7 +2,7 @@
 #define APP_CONTEXT_HPP
 
 #include "Naviframe.hpp"
-#include "NavigationContext.hpp"
+#include "Observable.hpp"
 #include "Presenter.hpp"
 #include "ScanningProperties.hpp"
 #include "Window.hpp"
@@ -11,7 +11,7 @@
 #include <memory>
 #include <string>
 
-class AppContext
+class AppContext : public Observable<Presenter *>
 {
        public:
        AppContext();
@@ -19,14 +19,15 @@ class AppContext
        void pop();
        Presenter *back();
        bool empty();
+       void notify();
 
        // TODO: should be private
        UniversalSwitchDbusConfig config;
        ScanningProperties usScanningProperties;
-       NavigationContext navContext_;
 
        private:
        std::vector<std::unique_ptr<Presenter>> presentersStack_;
+       Presenter *toBroadcast_ = nullptr;
 };
 
 #endif
\ No newline at end of file
index fb0eb3d..b7b14b3 100644 (file)
@@ -1,8 +1,10 @@
 #include "NavigationContext.hpp"
 
+#include "AppContext.hpp"
 #include "Conformant.hpp"
 #include "ListPresenter.hpp"
 #include "ListView.hpp"
+#include "Singleton.hpp"
 
 NavigationContext::NavigationContext()
 {
@@ -23,6 +25,13 @@ NavigationContext::NavigationContext()
        conformant->show();
 
        window_->show();
+
+       Singleton<AppContext>::instance().attach([this](auto presenter) {
+               if (presenter)
+                       this->emplaceView(presenter);
+               else
+                       this->popView();
+       });
 }
 
 Window *NavigationContext::getWindow()
index dca463a..2516388 100644 (file)
@@ -16,10 +16,10 @@ class NavigationContext
 
        Window *getWindow();
        Naviframe *getNaviframe() const;
-       void emplaceView(Presenter *presenter);
-       void popView();
 
        private:
+       void emplaceView(Presenter *presenter);
+       void popView();
        std::unique_ptr<Window> window_;
        Naviframe *naviframe_;
        std::vector<std::unique_ptr<View>> viewsStack_;