Implemented common popup with editfield. 48/82148/1
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Wed, 13 Jul 2016 10:16:24 +0000 (13:16 +0300)
committerEugene Kurzberg <i.kurtsberg@samsung.com>
Mon, 1 Aug 2016 06:38:57 +0000 (09:38 +0300)
Change-Id: I1e287987b73d2ad3273b04299088eee01251849c
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
lib-apps-common/inc/Ux/EditfieldPopup.h [new file with mode: 0644]
lib-apps-common/src/Ux/EditfieldPopup.cpp [moved from lib-contacts/src/Contacts/Input/ContactTypedFieldLabelPopup.cpp with 58% similarity]
lib-contacts/inc/Contacts/Input/ContactTypedFieldLabelPopup.h [deleted file]
lib-contacts/src/Contacts/Input/ContactTypedFieldControl.cpp

diff --git a/lib-apps-common/inc/Ux/EditfieldPopup.h b/lib-apps-common/inc/Ux/EditfieldPopup.h
new file mode 100644 (file)
index 0000000..398c3ca
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef UX_EDITFIELD_POPUP_H
+#define UX_EDITFIELD_POPUP_H
+
+#include "Ui/Popup.h"
+
+namespace Ui
+{
+       class Editfield;
+}
+
+namespace Ux
+{
+       /**
+        * @brief Popup with editfield.
+        */
+       class EXPORT_API EditfieldPopup : public Ui::Popup
+       {
+       public:
+               /**
+                * @brief Called when user confirmation button is pressed.
+                * @param[in]   Inputed text
+                */
+               typedef std::function<void(const char *)> ResultCallback;
+
+               /**
+                * @brief Translatable strings table for popup elements.
+                */
+               struct Strings
+               {
+                       const char *popupTitle;   /**< Popup title */
+                       const char *guideText;    /**< Entry guide text */
+                       const char *buttonDone;   /**< "Done" button text */
+                       const char *buttonCancel; /**< "Cancel" button text */
+               };
+
+               EditfieldPopup();
+
+               /**
+                * @brief Set translatable strings for popup.
+                * @remark Should be called before create().
+                * @param[in]   strings    Translatable strings table
+                */
+               void setStrings(Strings strings);
+
+               /**
+                * @brief Set result callback.
+                * @param[in]   callback    Result callback
+                */
+               void setResultCallback(ResultCallback callback);
+
+               /**
+                * @return Contained editfield.
+                */
+               Ui::Editfield *getEditfield() const;
+
+       protected:
+               /**
+                * @brief Creates editfield and popup buttons.
+                * @see Control::onCreated()
+                */
+               virtual void onCreated() override;
+
+       private:
+               bool onDoneButtonPressed();
+               void onDoneKeyPressed(Evas_Object *entry, void *eventInfo);
+               static void onEntryChanged(Evas_Object *button, Evas_Object *entry, void *eventInfo);
+
+               Ui::Editfield *m_Editfield;
+               ResultCallback m_OnResult;
+               Strings m_Strings;
+       };
+}
+
+#endif /* UX_EDITFIELD_POPUP_H */
  *
  */
 
-#include "Contacts/Input/ContactTypedFieldLabelPopup.h"
+#include "Ux/EditfieldPopup.h"
 #include "Ui/Editfield.h"
 #include "Utils/Callback.h"
 
-using namespace Contacts::Input;
+using namespace Ui;
+using namespace Ux;
 
-ContactTypedFieldLabelPopup::ContactTypedFieldLabelPopup()
-       : m_Editfield(nullptr)
+EditfieldPopup::EditfieldPopup()
+       : m_Editfield(nullptr), m_Strings{ nullptr }
 {
 }
 
-void ContactTypedFieldLabelPopup::setResultCallback(ResultCallback callback)
+void EditfieldPopup::setStrings(Strings strings)
+{
+       m_Strings = strings;
+}
+
+void EditfieldPopup::setResultCallback(ResultCallback callback)
 {
        m_OnResult = std::move(callback);
 }
 
-void ContactTypedFieldLabelPopup::onCreated()
+Editfield *EditfieldPopup::getEditfield() const
+{
+       return m_Editfield;
+}
+
+void EditfieldPopup::onCreated()
 {
-       setTitle("IDS_PB_HEADER_ENTER_CUSTOM_LABEL_ABB");
+       m_Editfield = Editfield::create(getEvasObject(), m_Strings.guideText);
 
-       m_Editfield = Ui::Editfield::create(getEvasObject(), "IDS_PB_NPBODY_CUSTOM_TYPE_ABB");
+       setTitle(m_Strings.popupTitle);
        setContent(m_Editfield->getEvasObject());
-       addButton("IDS_PB_BUTTON_CANCEL");
-       Evas_Object *button = addButton("IDS_PB_BUTTON_CREATE_ABB2", [this] {
-               onCreatePressed();
-               return true;
-       });
-       elm_object_disabled_set(button, EINA_TRUE);
+       addButton(m_Strings.buttonCancel);
 
+       Evas_Object *button = addButton(m_Strings.buttonDone, std::bind(&EditfieldPopup::onDoneButtonPressed, this));
        Evas_Object *entry = m_Editfield->getEntry();
        elm_entry_input_panel_return_key_autoenabled_set(entry, EINA_TRUE);
        elm_entry_input_panel_return_key_type_set(entry, ELM_INPUT_PANEL_RETURN_KEY_TYPE_DONE);
+
        evas_object_smart_callback_add(entry, "changed",
-                       (Evas_Smart_Cb) &ContactTypedFieldLabelPopup::onEntryChanged, button);
+                       (Evas_Smart_Cb) &EditfieldPopup::onEntryChanged, button);
        evas_object_smart_callback_add(entry, "activated",
-                       makeCallback(&ContactTypedFieldLabelPopup::onDonePressed), this);
+                       makeCallback(&EditfieldPopup::onDoneKeyPressed), this);
+
+       elm_object_disabled_set(button, EINA_TRUE);
        elm_object_focus_set(entry, EINA_TRUE);
 }
 
-void ContactTypedFieldLabelPopup::onCreatePressed()
+bool EditfieldPopup::onDoneButtonPressed()
 {
        if (m_OnResult) {
                char *text = elm_entry_markup_to_utf8(elm_entry_entry_get(m_Editfield->getEntry()));
                m_OnResult(text);
                free(text);
        }
+
+       return true;
 }
 
-void ContactTypedFieldLabelPopup::onDonePressed(Evas_Object *entry, void *eventInfo)
+void EditfieldPopup::onDoneKeyPressed(Evas_Object *entry, void *eventInfo)
 {
-       onCreatePressed();
+       onDoneButtonPressed();
        delete this;
 }
 
-void ContactTypedFieldLabelPopup::onEntryChanged(Evas_Object *button, Evas_Object *entry, void *eventInfo)
+void EditfieldPopup::onEntryChanged(Evas_Object *button, Evas_Object *entry, void *eventInfo)
 {
        elm_object_disabled_set(button, elm_entry_is_empty(entry));
 }
diff --git a/lib-contacts/inc/Contacts/Input/ContactTypedFieldLabelPopup.h b/lib-contacts/inc/Contacts/Input/ContactTypedFieldLabelPopup.h
deleted file mode 100644 (file)
index 49879e3..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#ifndef CONTACTS_INPUT_CONTACT_TYPED_FIELD_LABEL_POPUP_H
-#define CONTACTS_INPUT_CONTACT_TYPED_FIELD_LABEL_POPUP_H
-
-#include "Ui/Popup.h"
-
-namespace Ui
-{
-       class Editfield;
-}
-
-namespace Contacts
-{
-       namespace Input
-       {
-               /**
-                * @brief Popup for editing object's custom type label.
-                *
-                * @see ContactTypedObject
-                */
-               class ContactTypedFieldLabelPopup : public Ui::Popup
-               {
-               public:
-                       /**
-                        * @brief User input result callback.
-                        * @param[in]   Inputed custom type label
-                        */
-                       typedef std::function<void(const char *)> ResultCallback;
-
-                       ContactTypedFieldLabelPopup();
-
-                       /**
-                        * @brief Set user input result callback.
-                        * @param[in]   callback    Callback to be called when user confirmed inputed label
-                        */
-                       void setResultCallback(ResultCallback callback);
-
-               private:
-                       virtual void onCreated() override;
-                       void onCreatePressed();
-                       void onDonePressed(Evas_Object *entry, void *eventInfo);
-                       static void onEntryChanged(Evas_Object *button, Evas_Object *entry, void *eventInfo);
-
-                       ResultCallback m_OnResult;
-                       Ui::Editfield *m_Editfield;
-               };
-
-       }
-}
-
-#endif /* CONTACTS_INPUT_CONTACT_TYPED_FIELD_LABEL_POPUP_H */
index a6a36e7..7800e5c 100644 (file)
  */
 
 #include "Contacts/Input/ContactTypedFieldControl.h"
-#include "Contacts/Input/ContactTypedFieldLabelPopup.h"
 #include "Contacts/Model/ContactEnumField.h"
 #include "Contacts/Model/ContactTextField.h"
 #include "Common/Strings.h"
+
+#include "Ux/EditfieldPopup.h"
 #include "Utils/Logger.h"
 
 using namespace Common;
@@ -56,7 +57,12 @@ void ContactTypedFieldControl::onCreated()
 bool ContactTypedFieldControl::onSelected(int value)
 {
        if (value == m_TypeField.getCustomValue()) {
-               auto popup = new ContactTypedFieldLabelPopup();
+               auto popup = new Ux::EditfieldPopup();
+               popup->setStrings({
+                       "IDS_PB_HEADER_ENTER_CUSTOM_LABEL_ABB",
+                       "IDS_PB_NPBODY_CUSTOM_TYPE_ABB",
+                       "IDS_PB_BUTTON_CREATE_ABB2",
+                       "IDS_PB_BUTTON_CANCEL" });
                popup->setResultCallback([this, value](const char *label) {
                        m_TypeField.setValue(value);
                        m_LabelField.setValue(label);