TizenRefApp-8012 Implement automatic launch of alarm's create when there are no alarm... 94/115294/10
authorSergii Kyryliuk <s.kyryliuk@partner.samsung.com>
Thu, 16 Feb 2017 16:02:49 +0000 (18:02 +0200)
committerSergii Kyryliuk <s.kyryliuk@partner.samsung.com>
Mon, 20 Feb 2017 15:15:07 +0000 (17:15 +0200)
Change-Id: I5c3becd1291d2f27fe0181fcbcede48035ad4ef0
Signed-off-by: Sergii Kyryliuk <s.kyryliuk@partner.samsung.com>
alarm-app/inc/Input/InputView.h
alarm-app/inc/OperationAddController.h [new file with mode: 0644]
alarm-app/src/AlarmApp.cpp
alarm-app/src/Input/InputView.cpp
alarm-app/src/List/AlarmItem.cpp
alarm-app/src/OperationAddController.cpp [new file with mode: 0644]
alarm-app/tizen-manifest.xml
alarm-widget/inc/AlarmWidget.h
alarm-widget/src/AlarmWidget.cpp
lib-common/inc/Common/Model/AlarmConsumer.h
lib-common/src/Common/Model/AlarmConsumer.cpp

index 19b41396db8cdc3c90512db666abc9381c0b6a44..ed95cc3bf9e476c531741d01f736a5ca712c2694 100644 (file)
@@ -31,12 +31,25 @@ namespace Input
        class InputView : public Ui::ScrollNavigator
        {
        public:
+
+               /**
+                * @brief Called when alarm is created.
+                * @param   id   Created Alarm ID
+                */
+               typedef std::function<void(int id)> CreateCallback;
+
                /**
                 * @brief Create view.
                 * @param[in]   alarm   Alarm to edit
                 */
                explicit InputView(Common::Model::Alarm alarm);
 
+               /**
+                * @brief Set alarm create callback.
+                * @param[in]   callback   Alarm create callback.
+                */
+               void setCreateCallback(CreateCallback callback);
+
        private:
                virtual Evas_Object *onCreate(Evas_Object *parent) override;
                virtual void onCreated() override;
@@ -60,6 +73,8 @@ namespace Input
                Evas_Object *m_Button;
                bool m_HasDeleteButton;
 
+               CreateCallback m_OnCreated;
+
                SetTimeView *m_TimeView;
                SetRepeatView *m_RepeatView;
                Common::Model::Alarm m_Alarm;
diff --git a/alarm-app/inc/OperationAddController.h b/alarm-app/inc/OperationAddController.h
new file mode 100644 (file)
index 0000000..5e2246a
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * 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 OPERATION_ADD_CONTROLLER_H
+#define OPERATION_ADD_CONTROLLER_H
+
+#include "App/OperationController.h"
+
+class OperationAddController : public App::OperationController
+{
+private:
+       virtual void onRequest(const char *operation, app_control_h request) override;
+       void onCreated(int alarmId);
+};
+
+#endif /* OPERATION_ADD_CONTROLLER_H */
index 33b83f958303b1960ca40dacda66b5268ac5359e..073c137634a6b1a0ffc731d89dd9a9b65fba071e 100644 (file)
@@ -24,6 +24,7 @@
 #include "DaySelectorPath.h"
 #include "ListPath.h"
 
+#include "OperationAddController.h"
 #include "OperationAlertController.h"
 #include "OperationDefaultController.h"
 #include "OperationEditController.h"
 
 App::OperationController *AlarmApp::createController(const char *operation)
 {
+
        if (strcmp(operation, APP_CONTROL_OPERATION_DEFAULT) == 0
         || strcmp(operation, APP_CONTROL_OPERATION_MAIN) == 0) {
                return new OperationDefaultController();
+       } else if (strcmp(operation, APP_CONTROL_OPERATION_ADD) == 0) {
+               return new OperationAddController();
        } else if (strcmp(operation, APP_CONTROL_OPERATION_PICK) == 0) {
                return new OperationPickController();
        } else if (strcmp(operation, APP_CONTROL_OPERATION_EDIT) == 0) {
index cce5378ed26e5faebba602fcd3174852476b724c..4f9e5ced511757d2c1cd28615448f8cb1083fd0b 100644 (file)
@@ -106,6 +106,11 @@ void InputView::updateButton()
        elm_object_translatable_text_set(m_Button, text);
 }
 
+void InputView::setCreateCallback(CreateCallback callback)
+{
+       m_OnCreated = std::move(callback);
+}
+
 void InputView::saveAlarm()
 {
        tm time = m_TimeView->getTimePicker()->getTime();
@@ -114,13 +119,17 @@ void InputView::saveAlarm()
        m_Alarm.setEnabled(true);
 
        elm_object_disabled_set(m_Button, EINA_TRUE);
-       AlarmConsumer::getInstance().saveAlarm(m_Alarm, [this](bool isSuccess) {
+       AlarmConsumer::getInstance().saveAlarm(m_Alarm, [this](bool isSuccess, int alarmId) {
                if (!isSuccess) {
                        /* TODO: Show error message */
                        elm_object_disabled_set(m_Button, EINA_FALSE);
                        return;
                }
 
+               if (m_OnCreated){
+                       m_OnCreated(alarmId);
+               }
+
                auto popup = new Common::AlarmSetPopup(m_Alarm);
                popup->create(getEvasObject());
                popup->show();
@@ -131,7 +140,7 @@ void InputView::saveAlarm()
 void InputView::deleteAlarm()
 {
        elm_object_disabled_set(m_Button, EINA_TRUE);
-       AlarmConsumer::getInstance().deleteAlarm(m_Alarm.getId(), [this](bool isSuccess) {
+       AlarmConsumer::getInstance().deleteAlarm(m_Alarm.getId(), [this](bool isSuccess, int alarmId) {
                if (!isSuccess) {
                        /* TODO: Show error message */
                        elm_object_disabled_set(m_Button, EINA_FALSE);
index e9edd58e1800562866413d41c1314737878ea990..6a06bfb80ce86cb12f363693122c81bd6e50f802 100644 (file)
@@ -121,7 +121,7 @@ void AlarmItem::onSelected()
 void AlarmItem::onAlarmEnabled(Evas_Object *check, void *eventInfo)
 {
        m_Alarm.setEnabled(elm_check_state_get(check));
-       AlarmConsumer::getInstance().updateAlarm(m_Alarm, [this](bool isSuccess) {
+       AlarmConsumer::getInstance().updateAlarm(m_Alarm, [this](bool isSuccess, int alarmId) {
                if (isSuccess && m_Alarm.isEnabled()) {
                        auto popup = new Common::AlarmSetPopup(m_Alarm);
                        popup->create(getParent()->getEvasObject());
diff --git a/alarm-app/src/OperationAddController.cpp b/alarm-app/src/OperationAddController.cpp
new file mode 100644 (file)
index 0000000..ec99867
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2017 Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://floralicense.org/license/
+ *
+ * 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.
+ */
+
+#include "OperationAddController.h"
+#include "App/AppControl.h"
+#include "Input/InputView.h"
+#include "Ui/Navigator.h"
+#include <string>
+
+using namespace std::placeholders;
+
+void OperationAddController::onRequest(const char *operation, app_control_h request)
+{
+       Input::InputView *view = new Input::InputView({ });
+       view->setCreateCallback(std::bind(&OperationAddController::onCreated, this, _1));
+       getNavigator()->navigateTo(view);
+}
+
+void OperationAddController::onCreated(int alarmId)
+{
+       app_control_h reply = nullptr;
+       app_control_create(&reply);
+       app_control_add_extra_data(reply, APP_CONTROL_DATA_ID, std::to_string(alarmId).c_str());
+       app_control_reply_to_launch_request(reply, getRequest(), APP_CONTROL_RESULT_SUCCEEDED);
+       app_control_destroy(reply);
+
+}
index 88d712842c6252257fb959800e8fe1b72bf2623e..3a4eaa6a9abbcf33ee911db75042628aa8c268c3 100644 (file)
         <label xml:lang="zh-hk">鬧鐘</label>
         <label xml:lang="zh-tw">鬧鐘</label>
         <icon>org.tizen.alarm.png</icon>
+        <app-control>
+            <operation name="http://tizen.org/appcontrol/operation/add"/>
+            <mime name="application/vnd.tizen.alarm"/>
+        </app-control>
         <app-control>
             <operation name="http://tizen.org/appcontrol/operation/pick"/>
             <mime name="application/vnd.tizen.alarm"/>
index 0ab740623a2466554382d44ba82859e6fed449e2..00408ff923256c0585a6eda02149939bf76f62c7 100644 (file)
@@ -49,6 +49,7 @@ private:
        void onContentPressed(Evas_Object *obj, void *eventInfo);
 
        void onPickReply(app_control_h request, app_control_h reply, app_control_result_e result);
+       void onCreateReply(app_control_h request, app_control_h reply, app_control_result_e result);
        void setAlarm(Common::Model::Alarm *alarm);
 
        Evas_Object *m_Layout;
index efd4a77279d4838ff87b15d7e62d308e5bf83973..4f31a80cb5dbe9224e7521577649eb8d299383d5 100644 (file)
@@ -115,9 +115,21 @@ void AlarmWidget::onCheckedPressed(Evas_Object *obj, void *eventInfo)
 
 void AlarmWidget::onCreatePressed(Evas_Object *obj, void *eventInfo)
 {
-       App::AppControl request(APP_CONTROL_OPERATION_PICK, APP_CONTROL_MIME_ALARM);
-       request.launch(makeCallbackWithLastParam(&AlarmWidget::onPickReply), this);
-       request.detach();
+       AlarmConsumer::getInstance().getAlarms([this](AlarmConsumer::DataList dataList) {
+               if (dataList.empty()) {
+                       App::AppControl request(APP_CONTROL_OPERATION_ADD, APP_CONTROL_MIME_ALARM);
+                       request.launch(makeCallbackWithLastParam(&AlarmWidget::onCreateReply), this);
+                       request.detach();
+               } else {
+                       App::AppControl request(APP_CONTROL_OPERATION_PICK, APP_CONTROL_MIME_ALARM);
+                       request.launch(makeCallbackWithLastParam(&AlarmWidget::onPickReply), this);
+                       request.detach();
+               }
+
+               for (auto &&alarm : dataList) {
+                       delete alarm;
+               }
+       });
 }
 
 void AlarmWidget::onContentPressed(Evas_Object *obj, void *eventInfo)
@@ -137,6 +149,15 @@ void AlarmWidget::onPickReply(app_control_h request, app_control_h reply, app_co
        });
 }
 
+void AlarmWidget::onCreateReply(app_control_h request, app_control_h reply, app_control_result_e result)
+{
+       std::string id = App::getStringExtraData(reply, APP_CONTROL_DATA_ID);
+       AlarmConsumer::getInstance().getAlarm(atoi(id.c_str()), [this](AlarmConsumer::DataList dataList) {
+               setAlarm(static_cast<Alarm *>(dataList.front()));
+               updateEmptyState();
+       });
+}
+
 void AlarmWidget::setAlarm(Alarm *alarm)
 {
        m_Alarm = alarm;
index 7824156d4ce8569b20ff4b4bcc48ed469fa0aeb3..3fe7d1677ef72807093ad46c3ea772d3556b69c7 100644 (file)
@@ -43,8 +43,9 @@ namespace Common
                        /**
                         * @brief Called when result of insert, update or delete is received.
                         * @param[in]   isSuccess   Whether operation was successful
+                        * @param[in]   alarmId     Alarm Id if alarm was inserted
                         */
-                       typedef std::function<void(bool isSuccess)> ResultCallback;
+                       typedef std::function<void(bool isSuccess, int alarmId)> ResultCallback;
 
                        /**
                         * @return Consumer singleton instance.
index a3d8c53dfa9db297d237fe861323d24979186231..d6986bf43e6226001feb87941ec0c2b357957f2d 100644 (file)
@@ -160,17 +160,17 @@ void AlarmConsumer::onSelectResponse(int requestId, data_control_h provider,
 void AlarmConsumer::onInsertResponse(int requestId, data_control_h provider,
                long long id, bool isSuccess, const char *error)
 {
-       sendResponse(m_ResultCallbacks, requestId, isSuccess);
+       sendResponse(m_ResultCallbacks, requestId, isSuccess, id);
 }
 
 void AlarmConsumer::onUpdateResponse(int requestId, data_control_h provider,
                bool isSuccess, const char *error)
 {
-       sendResponse(m_ResultCallbacks, requestId, isSuccess);
+       sendResponse(m_ResultCallbacks, requestId, isSuccess, -1);
 }
 
 void AlarmConsumer::onDeleteResponse(int requestId, data_control_h provider,
                bool isSuccess, const char *error)
 {
-       sendResponse(m_ResultCallbacks, requestId, isSuccess);
+       sendResponse(m_ResultCallbacks, requestId, isSuccess, -1);
 }