#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");
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);
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);
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]() {
#include "Button.hpp"
#include "Genlist.hpp"
+#include "NavigationContext.hpp"
#include "Singleton.hpp"
#include "setting-accessibility.h"
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");
#include "AccessibilitySettingLog.hpp"
#include "Button.hpp"
#include "Genlist.hpp"
+#include "NavigationContext.hpp"
#include "Singleton.hpp"
#include "setting-accessibility.h"
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");
#include "AccessibilitySettingLog.hpp"
#include "Button.hpp"
#include "Genlist.hpp"
+#include "NavigationContext.hpp"
#include "Popup.hpp"
#include "Singleton.hpp"
#include "VConf.hpp"
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);
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();
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);
}
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);
#include "Button.hpp"
#include "Genlist.hpp"
#include "Label.hpp"
+#include "NavigationContext.hpp"
#include "Singleton.hpp"
#include "setting-accessibility.h"
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) {
{
if (changeRadioItemCb_)
changeRadioItemCb_(item->getId());
- context_.navContext_.getNaviframe()->popBack(naviframeItem_);
+ Singleton<NavigationContext>::instance().getNaviframe()->popBack(naviframeItem_);
}
Genlist *SetValuePage::createGenlist(Widget *parent, TranslatedString title)
#include "SwitchesPage.hpp"
+#include "NavigationContext.hpp"
#include "Singleton.hpp"
#include "setting-accessibility.h"
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");
#include "UniversalSwitchPage.hpp"
+#include "NavigationContext.hpp"
#include "Popup.hpp"
#include "Singleton.hpp"
#include "setting-accessibility.h"
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");
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, []() {});
#include "Button.hpp"
#include "CtxPopup.hpp"
+#include "NavigationContext.hpp"
#include "Singleton.hpp"
#include "VConf.hpp"
#include "setting-accessibility.h"
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");
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);
// 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});
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);
// 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});
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");
#include "UpdateSwitchPage.hpp"
#include "AccessibilitySettingLog.hpp"
+#include "NavigationContext.hpp"
#include "Singleton.hpp"
#include "Toolbar.hpp"
#include "setting-accessibility.h"
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");
&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();
}
#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;
}
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())
{
return presentersStack_.empty();
}
+
+void AppContext::notify()
+{
+ for (auto &c : this->onChangeCallbacks_)
+ if (c)
+ c(toBroadcast_);
+}
#define APP_CONTEXT_HPP
#include "Naviframe.hpp"
-#include "NavigationContext.hpp"
+#include "Observable.hpp"
#include "Presenter.hpp"
#include "ScanningProperties.hpp"
#include "Window.hpp"
#include <memory>
#include <string>
-class AppContext
+class AppContext : public Observable<Presenter *>
{
public:
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
#include "NavigationContext.hpp"
+#include "AppContext.hpp"
#include "Conformant.hpp"
#include "ListPresenter.hpp"
#include "ListView.hpp"
+#include "Singleton.hpp"
NavigationContext::NavigationContext()
{
conformant->show();
window_->show();
+
+ Singleton<AppContext>::instance().attach([this](auto presenter) {
+ if (presenter)
+ this->emplaceView(presenter);
+ else
+ this->popView();
+ });
}
Window *NavigationContext::getWindow()
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_;