Small fixes 60/210260/3 accepted/tizen/unified/20190722.074741 submit/tizen/20190718.020831 submit/tizen/20190719.015332 submit/tizen/20190722.022144
authorOskar Chodowicz <o.chodowicz@samsung.com>
Wed, 17 Jul 2019 09:48:17 +0000 (11:48 +0200)
committerOskar Chodowicz <o.chodowicz@samsung.com>
Wed, 17 Jul 2019 13:21:20 +0000 (15:21 +0200)
this patch introduce these changes:
1. use actions in modal presenter what allows to disable buttons
2. set focus on entry in modal view

Change-Id: I71c29a17daf20bfc6880514af442616b2d71daed

src/presenter/AlreadyMappedSwitchModalPresenter.cpp
src/presenter/EntryNameModalPresenter.cpp
src/presenter/EntryNameModalPresenter.hpp
src/presenter/ModalPresenter.cpp
src/presenter/ModalPresenter.hpp
src/presenter/NoSwitchesModalPresenter.cpp
src/presenter/RemoveSwitchesModalPresenter.cpp
src/ui/Widget.cpp
src/ui/Widget.hpp
src/view/ModalView.cpp

index 1d0c337..0f7d7b3 100644 (file)
@@ -1,8 +1,13 @@
 #include "AlreadyMappedSwitchModalPresenter.hpp"
 
+#include "AppContext.hpp"
+#include "Singleton.hpp"
+
 AlreadyMappedSwitchModalPresenter::AlreadyMappedSwitchModalPresenter()
 {
        setTitle("IDS_ACCS_UNIVERSAL_SWITCH_UNABLE_TO_ADD");
        text_ = "IDS_ACCS_UNIVERSAL_SWITCH_ALREADY_ADDED";
-       cancelText_ = "IDS_ACCS_UNIVERSAL_SWITCH_OK";
+       addAction(std::make_unique<Action>("doneAction", "IDS_ACCS_UNIVERSAL_SWITCH_OK", [](auto action) {
+               Singleton<AppContext>::instance().popModal();
+       }));
 }
index 0ecec72..ce9b755 100644 (file)
@@ -7,14 +7,15 @@
 EntryNameModalPresenter::EntryNameModalPresenter(std::string switchId)
 {
        setTitle("IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH");
-       entryAction_ = addAction(std::make_unique<Action>("modalEntry", "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_NAME", std::function<void(Action *)>{}));
-       doneText_ = "IDS_ACCS_UNIVERSAL_SWITCH_SAVE";
-       cancelText_ = "IDS_ACCS_UNIVERSAL_SWITCH_CANCEL";
-       doneCb_ = [this, switchId]() {
+       entryAction_ = addAction(std::make_unique<Action>("modalEntry", "IDS_ACCS_UNIVERSAL_SWITCH_ADD_SWITCH_NAME", [this](auto action) {
+               doneAction_->enabled_ = !entryAction_->title_.value().empty();
+       }));
+
+       addAction(std::make_unique<Action>("cancelAction", "IDS_ACCS_UNIVERSAL_SWITCH_CANCEL", std::function<void(Action *)>{}));
+       doneAction_ = addAction(std::make_unique<Action>("doneAction", "IDS_ACCS_UNIVERSAL_SWITCH_SAVE", [this, switchId](auto action) {
                auto switchUserName = this->entryAction_->title_.value();
-               if (!switchUserName.empty()) {
-                       Singleton<AppContext>::instance().popModal();
-                       Singleton<AppContext>::instance().push(std::make_unique<SelectActionPagePresenter>(switchId, switchUserName, ChangeType::ADD, 2));
-               }
-       };
+               Singleton<AppContext>::instance().popModal();
+               Singleton<AppContext>::instance().push(std::make_unique<SelectActionPagePresenter>(switchId, switchUserName, ChangeType::ADD, 2));
+       },
+               false));
 }
\ No newline at end of file
index 05999f7..a6a089f 100644 (file)
@@ -10,6 +10,7 @@ class EntryNameModalPresenter : public ModalPresenter
 
        private:
        Action *entryAction_ = nullptr;
+       Action *doneAction_ = nullptr;
 };
 
 #endif
\ No newline at end of file
index 351142d..02cef08 100644 (file)
@@ -1,26 +1,6 @@
 #include "ModalPresenter.hpp"
 
-std::function<void()> ModalPresenter::getDoneCb()
-{
-       return doneCb_;
-}
-
-std::function<void()> ModalPresenter::getCancelCb()
-{
-       return cancelCb_;
-}
-
 std::string ModalPresenter::getText()
 {
        return text_;
-}
-
-std::string ModalPresenter::getDoneText()
-{
-       return doneText_;
-}
-
-std::string ModalPresenter::getCancelText()
-{
-       return cancelText_;
 }
\ No newline at end of file
index 852eea8..f306e00 100644 (file)
@@ -6,20 +6,12 @@
 class ModalPresenter : public Presenter
 {
        public:
-       std::function<void()> getDoneCb();
-       std::function<void()> getCancelCb();
        std::string getText();
-       std::string getDoneText();
-       std::string getCancelText();
 
        protected:
        using Presenter::Presenter;
 
-       std::function<void()> doneCb_;
-       std::function<void()> cancelCb_;
        std::string text_;
-       std::string doneText_;
-       std::string cancelText_;
 };
 
 #endif
\ No newline at end of file
index 40ac5a8..0831f5f 100644 (file)
@@ -8,10 +8,9 @@ NoSwitchesModalPresenter::NoSwitchesModalPresenter()
        setTitle("IDS_ACCS_UNIVERSAL_SWITCH_NO_SWITCHES_TITLE");
        text_ = "IDS_ACCS_UNIVERSAL_SWITCH_NO_SWITCHES_TEXT";
 
-       cancelText_ = "IDS_ACCS_UNIVERSAL_SWITCH_CANCEL";
-       doneText_ = "IDS_ACCS_UNIVERSAL_SWITCH_POPUP_ADD";
-       doneCb_ = [this]() {
+       addAction(std::make_unique<Action>("cancelAction", "IDS_ACCS_UNIVERSAL_SWITCH_CANCEL", std::function<void(Action *)>{}));
+       addAction(std::make_unique<Action>("doneAction", "IDS_ACCS_UNIVERSAL_SWITCH_POPUP_ADD", [this](auto action) {
                Singleton<AppContext>::instance().popModal();
                Singleton<AppContext>::instance().push(std::make_unique<AddSwitchPagePresenter>());
-       };
+       }));
 }
\ No newline at end of file
index 8bbc19f..d0ce44f 100644 (file)
@@ -13,12 +13,10 @@ RemoveSwitchesModalPresenter::RemoveSwitchesModalPresenter(std::vector<SwitchCon
                text_ = std::to_string(switchesToRemove_.size()) + " " + TranslatedString{"IDS_ACCS_UNIVERSAL_SWITCH_DELETE_SWITCHES_DESC"}.str();
        }
 
-       doneText_ = "IDS_ACCS_DELETE";
-       cancelText_ = "IDS_ST_BUTTON_CANCEL";
-
-       doneCb_ = [this]() {
+       addAction(std::make_unique<Action>("cancelAction", "IDS_ST_BUTTON_CANCEL", std::function<void(Action *)>{}));
+       addAction(std::make_unique<Action>("doneAction", "IDS_ACCS_DELETE", [this](auto action) {
                model_.removeSwitches(switchesToRemove_);
                Singleton<AppContext>::instance().popModal();
                Singleton<AppContext>::instance().pop();
-       };
+       }));
 }
\ No newline at end of file
index b806122..ee2a28f 100644 (file)
@@ -123,6 +123,11 @@ void Widget::emitSignal(const std::string &signal)
        elm_object_signal_emit(uniqueObj_.get(), signal.c_str(), "");
 }
 
+void Widget::setFocus(bool focus)
+{
+       elm_object_focus_set(uniqueObj_.get(), focus ? EINA_TRUE : EINA_FALSE);
+}
+
 void Widget::show()
 {
        evas_object_show(uniqueObj_.get());
index 53b0bf6..0003a33 100644 (file)
@@ -48,6 +48,7 @@ class Widget
        void setPartContent(const std::string &part, Widget *content);
        void setHomogeneousDimensions();
        void setPropagateEvents(bool prop);
+       void setFocus(bool focus);
        void disable(bool disable);
        void emitSignal(const std::string &signal);
        void show();
index 8877051..08a6be7 100644 (file)
@@ -33,40 +33,54 @@ ModalView::ModalView(const NavigationContext &context, ModalPresenter *presenter
                });
                layout_->setPartContent(PRT_ACCESSORY_POPUP_ENTRY, entry_);
                popup_->setContent(layout_);
+               entry_->show();
+               entry_->setFocus(true);
        } else {
                if (!text.empty())
                        popup_->setText(text);
        }
 
        auto removeCb = [this]() {
-               auto c = presenter_->getCancelCb();
-               if (c)
-                       c();
-               else
-                       Singleton<AppContext>::instance().popModal();
+               auto cancelAction = presenter_->getAction("cancelAction");
+               if (cancelAction) {
+                       auto c = cancelAction->onInvoke_;
+                       if (c) {
+                               c(cancelAction);
+                               return;
+                       }
+               }
+               Singleton<AppContext>::instance().popModal();
        };
        popup_->setEextEventCallback(EEXT_CALLBACK_BACK, removeCb);
        popup_->setEvasSmartCallback("dismissed", removeCb);
        popup_->setEvasSmartCallback("block,clicked", removeCb);
 
-       auto cancelText = presenter_->getCancelText();
-       if (!cancelText.empty()) {
-               auto cancelBtn = Widget::make<Button>(popup_, removeCb, cancelText, "bottom");
+       auto cancelAction = presenter_->getAction("cancelAction");
+       if (cancelAction) {
+               auto cancelBtn = Widget::make<Button>(popup_, removeCb, cancelAction->title_.value(), "bottom");
                popup_->setPartContent("button1", cancelBtn);
+               cancelBtn->disable(!cancelAction->enabled_.value());
+               cancelAction->enabled_.attach([cancelBtn](auto value) {
+                       cancelBtn->disable(!value);
+               });
        }
 
-       auto doneText = presenter_->getDoneText();
-       if (!doneText.empty()) {
-               auto doneBtn = Widget::make<Button>(popup_, [this]() {
-                       auto c = presenter_->getDoneCb();
+       auto doneAction = presenter_->getAction("doneAction");
+       if (doneAction) {
+               auto doneBtn = Widget::make<Button>(popup_, [doneAction]() {
+                       auto c = doneAction->onInvoke_;
                        if (c)
-                               c();
+                               c(doneAction);
                        else
                                Singleton<AppContext>::instance().popModal();
                },
-                       doneText,
+                       doneAction->title_.value(),
                        "bottom");
-               popup_->setPartContent(cancelText.empty() ? "button1" : "button2", doneBtn);
+               popup_->setPartContent(cancelAction ? "button2" : "button1", doneBtn);
+               doneBtn->disable(!doneAction->enabled_.value());
+               doneAction->enabled_.attach([doneBtn](auto value) {
+                       doneBtn->disable(!value);
+               });
        }
 }