Refactored DatePopup to make it more generic, moved to Ux namespace. 04/79904/3
authorEugene Kurzberg <i.kurtsberg@samsung.com>
Wed, 13 Jul 2016 10:23:07 +0000 (13:23 +0300)
committerAleksandr Sapozhnik <a.sapozhnik@samsung.com>
Fri, 15 Jul 2016 08:01:43 +0000 (01:01 -0700)
Change-Id: I2f501f8f02ca6de88008a94198b795cc802fa081
Signed-off-by: Eugene Kurzberg <i.kurtsberg@samsung.com>
lib-apps-common/inc/Ux/DatePopup.h [moved from lib-apps-common/inc/Ui/DatePopup.h with 53% similarity]
lib-apps-common/src/Ux/DatePopup.cpp [moved from lib-apps-common/src/Ui/DatePopup.cpp with 62% similarity]
lib-contacts/src/Contacts/Input/ContactDateFieldControl.cpp
lib-contacts/src/Contacts/Input/InputView.cpp

similarity index 53%
rename from lib-apps-common/inc/Ui/DatePopup.h
rename to lib-apps-common/inc/Ux/DatePopup.h
index e955556..7ed39e3 100644 (file)
  *
  */
 
-#ifndef UI_DATE_POPUP_H
-#define UI_DATE_POPUP_H
+#ifndef UX_DATE_POPUP_H
+#define UX_DATE_POPUP_H
 
 #include "Ui/Popup.h"
+#include <string>
 
-namespace Ui
+namespace Ux
 {
        /**
         * @brief Popup with date picker.
         */
-       class EXPORT_API DatePopup : public Popup
+       class EXPORT_API DatePopup : public Ui::Popup
        {
        public:
                /**
                 * @brief Date input result callback.
                 * @param[in]   Inputed date
                 */
-               typedef std::function<void(const tm&)> ResultCallback;
+               typedef std::function<void(const tm &)> ResultCallback;
+
+               /**
+                * @brief Translatable strings table for popup elements.
+                */
+               struct Strings
+               {
+                       const char *popupTitle;   /**< Popup title */
+                       const char *buttonDone;   /**< "Done" button text */
+                       const char *buttonCancel; /**< "Cancel" button text */
+               };
 
                /**
                 * @brief Create date popup.
+                * @param[in]   format  Data format for elm_datetime_format_set()
                 * @param[in]   date    Initial date value
                 */
-               DatePopup(tm date);
+               DatePopup(const char *format, tm date);
+
+               /**
+                * @brief Set translatable strings for popup.
+                * @remark Should be called before create().
+                * @param[in]   strings    Translatable strings table
+                */
+               void setStrings(Strings strings);
 
                /**
                 * @brief Set date input result callback.
@@ -46,14 +65,28 @@ namespace Ui
                 */
                void setResultCallback(ResultCallback callback);
 
-       private:
+               /**
+                * @return Contained date picker.
+                */
+               Evas_Object *getDatePicker() const;
+
+       protected:
+               /**
+                * @brief Creates date picker and popup buttons.
+                * @see Control::onCreate()
+                */
                virtual void onCreated() override;
-               void onSetPressed();
 
+       private:
+               bool onDonePressed();
+
+               std::string m_Format;
                tm m_Date;
-               ResultCallback m_OnResult;
+
                Evas_Object *m_DatePicker;
+               ResultCallback m_OnResult;
+               Strings m_Strings;
        };
 }
 
-#endif /* UI_DATE_POPUP_H */
+#endif /* UX_DATE_POPUP_H */
similarity index 62%
rename from lib-apps-common/src/Ui/DatePopup.cpp
rename to lib-apps-common/src/Ux/DatePopup.cpp
index dbad5b0..71dbfca 100644 (file)
  *
  */
 
-#include "Ui/DatePopup.h"
+#include "Ux/DatePopup.h"
 
-using namespace Ui;
+using namespace Ux;
 
-DatePopup::DatePopup(tm date)
-       : m_Date(date), m_DatePicker(nullptr)
+DatePopup::DatePopup(const char *format, tm date)
+       : m_Format(format ? format : ""), m_Date(date),
+         m_DatePicker(nullptr), m_Strings{ nullptr }
 {
 }
 
+void DatePopup::setStrings(Strings strings)
+{
+       m_Strings = strings;
+}
+
 void DatePopup::setResultCallback(ResultCallback callback)
 {
        m_OnResult = std::move(callback);
 }
 
+Evas_Object *DatePopup::getDatePicker() const
+{
+       return m_DatePicker;
+}
+
 void DatePopup::onCreated()
 {
-       setTitle("IDS_TPLATFORM_HEADER_SET_DATE");
-       addButton("IDS_PB_BUTTON_CANCEL");
-       addButton("IDS_ST_BUTTON_SET", [this] {
-               onSetPressed();
-               return true;
-       });
+       setTitle(m_Strings.popupTitle);
+       addButton(m_Strings.buttonCancel);
+       addButton(m_Strings.buttonDone, std::bind(&DatePopup::onDonePressed, this));
 
        m_DatePicker = elm_datetime_add(getEvasObject());
-       elm_datetime_format_set(m_DatePicker, "%%d %%b %%Y");
+       elm_datetime_format_set(m_DatePicker, m_Format.c_str());
        elm_datetime_value_set(m_DatePicker, &m_Date);
        setContent(m_DatePicker);
 }
 
-void DatePopup::onSetPressed()
+bool DatePopup::onDonePressed()
 {
        if (m_OnResult) {
                elm_datetime_value_get(m_DatePicker, &m_Date);
                m_OnResult(m_Date);
        }
+
+       return true;
 }
index 25eb006..b639596 100644 (file)
@@ -18,7 +18,7 @@
 #include "Contacts/Input/ContactDateFieldControl.h"
 #include "Contacts/Model/ContactDateField.h"
 
-#include "Ui/DatePopup.h"
+#include "Ux/DatePopup.h"
 #include "Utils/Callback.h"
 
 #include "AppsCommonButtons.h"
@@ -65,7 +65,11 @@ void ContactDateFieldControl::onCreated()
 
 void ContactDateFieldControl::onButtonPressed(Evas_Object *button, void *eventInfo)
 {
-       Ui::DatePopup *popup = new Ui::DatePopup(m_Field.getValue());
+       Ux::DatePopup *popup = new Ux::DatePopup("%%d %%b %%Y", m_Field.getValue());
+       popup->setStrings({
+               "IDS_TPLATFORM_HEADER_SET_DATE",
+               "IDS_ST_BUTTON_SET",
+               "IDS_PB_BUTTON_CANCEL" });
        popup->setResultCallback([this](const tm &date) {
                m_Field.setValue(date);
                update();
index 06a14e9..f35ae13 100644 (file)
 
 #include "App/AppControlRequest.h"
 #include "App/Path.h"
-#include "Ui/DatePopup.h"
 #include "Ui/Genlist.h"
 #include "Ui/Navigator.h"
 #include "Ui/Popup.h"
+#include "Ux/DatePopup.h"
 #include "Utils/Callback.h"
 #include "Utils/Logger.h"
 #include "Utils/Range.h"
@@ -291,7 +291,11 @@ void InputView::removeFieldItem(ContactFieldItem *item)
 void InputView::addEventField()
 {
        time_t now = time(nullptr);
-       Ui::DatePopup *popup = new Ui::DatePopup(*localtime(&now));
+       Ux::DatePopup *popup = new Ux::DatePopup("%%d %%b %%Y", *localtime(&now));
+       popup->setStrings({
+               "IDS_TPLATFORM_HEADER_SET_DATE",
+               "IDS_ST_BUTTON_SET",
+               "IDS_PB_BUTTON_CANCEL" });
        popup->setResultCallback([this](const tm &date) {
                ContactObject &field = addField(FieldEvent);
                field.getField<ContactDateField>(0)->setValue(date);