diff options
-rw-r--r-- | alarm-app/inc/Input/InputView.h | 15 | ||||
-rw-r--r-- | alarm-app/inc/OperationAddController.h | 29 | ||||
-rw-r--r-- | alarm-app/src/AlarmApp.cpp | 4 | ||||
-rw-r--r-- | alarm-app/src/Input/InputView.cpp | 13 | ||||
-rw-r--r-- | alarm-app/src/List/AlarmItem.cpp | 2 | ||||
-rw-r--r-- | alarm-app/src/OperationAddController.cpp | 40 | ||||
-rw-r--r-- | alarm-app/tizen-manifest.xml | 4 | ||||
-rw-r--r-- | alarm-widget/inc/AlarmWidget.h | 1 | ||||
-rw-r--r-- | alarm-widget/src/AlarmWidget.cpp | 27 | ||||
-rw-r--r-- | lib-common/inc/Common/Model/AlarmConsumer.h | 3 | ||||
-rw-r--r-- | lib-common/src/Common/Model/AlarmConsumer.cpp | 6 |
11 files changed, 134 insertions, 10 deletions
diff --git a/alarm-app/inc/Input/InputView.h b/alarm-app/inc/Input/InputView.h index 19b4139..ed95cc3 100644 --- a/alarm-app/inc/Input/InputView.h +++ b/alarm-app/inc/Input/InputView.h @@ -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 index 0000000..5e2246a --- /dev/null +++ b/alarm-app/inc/OperationAddController.h @@ -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 */ diff --git a/alarm-app/src/AlarmApp.cpp b/alarm-app/src/AlarmApp.cpp index 33b83f9..073c137 100644 --- a/alarm-app/src/AlarmApp.cpp +++ b/alarm-app/src/AlarmApp.cpp @@ -24,6 +24,7 @@ #include "DaySelectorPath.h" #include "ListPath.h" +#include "OperationAddController.h" #include "OperationAlertController.h" #include "OperationDefaultController.h" #include "OperationEditController.h" @@ -31,9 +32,12 @@ 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) { diff --git a/alarm-app/src/Input/InputView.cpp b/alarm-app/src/Input/InputView.cpp index cce5378..4f9e5ce 100644 --- a/alarm-app/src/Input/InputView.cpp +++ b/alarm-app/src/Input/InputView.cpp @@ -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); diff --git a/alarm-app/src/List/AlarmItem.cpp b/alarm-app/src/List/AlarmItem.cpp index 3241614..c0fab2b 100644 --- a/alarm-app/src/List/AlarmItem.cpp +++ b/alarm-app/src/List/AlarmItem.cpp @@ -126,7 +126,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 index 0000000..ec99867 --- /dev/null +++ b/alarm-app/src/OperationAddController.cpp @@ -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); + +} diff --git a/alarm-app/tizen-manifest.xml b/alarm-app/tizen-manifest.xml index 88d7128..3a4eaa6 100644 --- a/alarm-app/tizen-manifest.xml +++ b/alarm-app/tizen-manifest.xml @@ -107,6 +107,10 @@ <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"/> </app-control> diff --git a/alarm-widget/inc/AlarmWidget.h b/alarm-widget/inc/AlarmWidget.h index 0ab7406..00408ff 100644 --- a/alarm-widget/inc/AlarmWidget.h +++ b/alarm-widget/inc/AlarmWidget.h @@ -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; diff --git a/alarm-widget/src/AlarmWidget.cpp b/alarm-widget/src/AlarmWidget.cpp index efd4a77..4f31a80 100644 --- a/alarm-widget/src/AlarmWidget.cpp +++ b/alarm-widget/src/AlarmWidget.cpp @@ -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; diff --git a/lib-common/inc/Common/Model/AlarmConsumer.h b/lib-common/inc/Common/Model/AlarmConsumer.h index 7824156..3fe7d16 100644 --- a/lib-common/inc/Common/Model/AlarmConsumer.h +++ b/lib-common/inc/Common/Model/AlarmConsumer.h @@ -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. diff --git a/lib-common/src/Common/Model/AlarmConsumer.cpp b/lib-common/src/Common/Model/AlarmConsumer.cpp index 7ed7228..f2f8b5d 100644 --- a/lib-common/src/Common/Model/AlarmConsumer.cpp +++ b/lib-common/src/Common/Model/AlarmConsumer.cpp @@ -162,17 +162,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); } |