Remove singleton Controller and AlarmProvider classes.
Add new TizenApp class to wrap basic main loop functionality.
Change-Id: If86e46dd7e3b6ccf80dd257c823b9b021ded5780
* Copyright 2016 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
+* 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/
*
#ifndef __CLOCK_H__
#define __CLOCK_H__
-#include <Elementary.h>
#include "Controller/MainController.h"
-
-#ifdef LOG_TAG
-#undef LOG_TAG
-#endif
-#define LOG_TAG "CLOCK"
-
-#if !defined(PACKAGE)
-#define PACKAGE "org.tizen.clock"
-#endif
-
-#define EDJ_FILE "edje/clock.edj"
-#define GRP_MAIN "main"
+#include "Controller/RingController.h"
+#include "Model/AlarmProvider.h"
+#include "Utils/TizenApp.h"
/**
* @defgroup Models Models
*/
/**
- * @defgroup main Main
+ * @defgroup Utils Utils
+ */
+
+/**
+ * @defgroup Main Main
*/
+
+/**
+ * @addtogroup Main
+ * @{
+ */
+class ClockApp : public utils::TizenApp {
+ public:
+ /**
+ * @brief Default constructor
+ */
+ ClockApp() {}
+
+ /**
+ * @brief Handles language changes.
+ */
+ void OnLanguageChanged(app_event_info_h event) override;
+
+ /**
+ * @brief Handles terminate request.
+ */
+ void OnTerminate() override;
+
+ /**
+ * @brief Handles resume request.
+ */
+ void OnResume() override;
+
+ /**
+ * @brief Handles pause request.
+ */
+ void OnPause() override;
+
+ /**
+ * @brief Handles service request.
+ */
+ void OnService(app_control_h app) override;
+
+ /**
+ * @brief Handles application create request.
+ */
+ bool OnCreate() override;
+ private:
+ model::AlarmProvider *provider_;
+ controller::MainController *main_ctrl_;
+ controller::RingController *ring_ctrl_;
+};
+
+/**
+ * @}
+ */
+
#endif /* __CLOCK_H__ */
#define SOUND_DEFAULT "settings/ringtone_sdk.mp3"
+#if !defined(PACKAGE)
+#define PACKAGE "org.tizen.clock"
+#endif
+
+#define EDJ_FILE "edje/clock.edj"
+#define GRP_MAIN "main"
+
#endif
class MainController {
public:
/**
- * @brief Retrieves singleton instance.
+ * @brief Constructs MainController class object.
*/
- static MainController &GetInstance();
+ MainController(model::AlarmProvider*);
/**
* @brief Destructor.
private:
/**
- * @brief Constructs MainController class object.
- */
- MainController();
-
- /**
* @brief Creates new "Edit/Create" alarm page.
*/
void CreateNewAlarmPage(utils::Event &e);
*/
void CreateNewWorldClockReorderPage(utils::Event &e);
+ model::AlarmProvider *provider_;
+
model::WorldClock *world_clock_model_;
model::StopWatch *stop_watch_model_;
model::Timer *timer_model_;
class RingController {
public:
- static RingController &GetInstance(void);
-
+ RingController(model::AlarmProvider *provider);
~RingController();
void operator=(RingController const&) = delete;
presenter::RingPresenter *presenter_;
model::Ring *model_;
view::RingView *view_;
+ model::AlarmProvider *provider_;
utils::Listener listener_;
void RingCreate(void);
void RingDestroy(utils::Event &e);
- RingController();
};
} //namespace model
* limitations under the License.
*/
-#ifndef _INTERNAL_ALARM_PROVIDER_FILE_H_
-#define _INTERNAL_ALARM_PROVIDER_FILE_H_
+#ifndef _INTERNAL_ALARM_PROVIDER_BINARY_STORAGE_H_
+#define _INTERNAL_ALARM_PROVIDER_BINARY_STORAGE_H_
+#include <functional>
#include <vector>
#include <list>
-#include "Model/AlarmProvider.h"
+#include "Model/Alarm.h"
+#include "Utils/Serialization.h"
namespace internal {
- class AlarmProviderFile : public model::AlarmProvider
+ class AlarmBinaryStorage : utils::ISerializable
{
public:
std::vector<std::reference_wrapper<model::Alarm>> GetAlarms();
model::Alarm* GetAlarmWithId(model::AlarmId id);
void Add(model::Alarm& alarm);
void Remove(std::reference_wrapper<model::Alarm> alarm);
- AlarmProviderFile(utils::IReader &r);
- ~AlarmProviderFile();
+ AlarmBinaryStorage(utils::IReader &r);
+ virtual ~AlarmBinaryStorage();
void Serialize(utils::IWriter &w) const;
int Capacity() const;
bool IsFull() const;
#ifndef _CLOCK_ALARM_PROVIDER_H_
#define _CLOCK_ALARM_PROVIDER_H_
-#include "Common/Defines.h"
+#include "Internal/AlarmBinaryStorage.h"
#include "Model/Alarm.h"
-#include "Utils/Serialization.h"
#include <vector>
#include <functional>
namespace model {
- class AlarmProvider : public utils::ISerializable {
+ class AlarmProvider {
public:
- static AlarmProvider *GetInstance();
- static void Sync();
+ /**
+ * @brief Constructs AlarmProvider class
+ */
+ AlarmProvider();
- virtual std::vector<std::reference_wrapper<Alarm>> GetAlarms() = 0;
- virtual bool HasActiveAlarms() = 0;
- virtual Alarm *GetAlarmWithId(AlarmId id) = 0;
- virtual void Add(Alarm& alarm) = 0;
- virtual void Remove(std::reference_wrapper<Alarm> alarm) = 0;
+ /**
+ * @brief AlarmProvider destructor
+ */
+ ~AlarmProvider();
+
+ /**
+ * @brief Fetch alarms from provider's internal storage
+ */
+ std::vector<std::reference_wrapper<Alarm>> GetAlarms();
+
+ /**
+ * @brief Get Alarms with specific id.
+ */
+ Alarm *GetAlarmWithId(AlarmId id);
+
+ /**
+ * @brief Add alarm to provider database.
+ */
+ void Add(Alarm& alarm);
+
+ /**
+ * @brief Remove alarm from provider's database.
+ */
+ void Remove(std::reference_wrapper<Alarm> alarm);
/**
* @brief Return capactiy of provider's internal storage
*/
- virtual int Capacity() const = 0;
+ int Capacity() const;
/**
* @brief Check if provider's internal storage is full.
*/
- virtual bool IsFull() const = 0;
- protected:
- AlarmProvider() {}
- virtual ~AlarmProvider() {}
+ bool IsFull() const;
+
+ /**
+ * @brief Sync AlarmProviderFile internal storage
+ */
+ void Sync();
+
+ /**
+ * @brief returns true if container have any active alarms.
+ */
+ bool HasActiveAlarms();
+ private:
+ /**
+ * Alarm provider private backend implementation
+ */
+ internal::AlarmBinaryStorage *impl_;
+
};
} /* model */
AlarmPresenter(view::AlarmView *view, model::AlarmProvider *model);
~AlarmPresenter();
private:
- view::AlarmView *view;
- model::AlarmProvider *model;
+ view::AlarmView *view_;
+ model::AlarmProvider *model_;
void ShowAll();
void OnItemSelected(int idx);
void OnAddButtonClicked();
EditAlarmPresenter(model::AlarmProvider *provider, model::Alarm *alarm, view::EditAlarmView& view);
~EditAlarmPresenter();
private:
- model::Alarm *alarm_;
model::AlarmProvider *provider_;
+ model::Alarm *alarm_;
view::EditAlarmView &view_;
view::EditAlarmView::AlarmViewInfo info_;
void OnEditDone();
--- /dev/null
+/*
+* Copyright 2016 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 _CLOCK_UTILS_APP_H_
+#define _CLOCK_UTILS_APP_H_
+
+#include <app.h>
+
+namespace utils {
+
+/**
+ * @addtogroup Utils
+ * @{
+ */
+
+/**
+ * @brief Tizen application main class. Starts application main loop and manages
+ * lifecycle callbacks
+ */
+class TizenApp {
+ public:
+ /*
+ * @brief Default constuctor
+ */
+ TizenApp() {}
+
+ /**
+ * @brief Default destructor
+ */
+ virtual ~TizenApp() {}
+
+ /**
+ * @brief Invoked when system language has changed.
+ */
+ virtual void OnLanguageChanged(app_event_info_h event) {};
+
+ /**
+ * @brief Invoked when application recieved terminate request.
+ */
+ virtual void OnTerminate() {};
+
+ /**
+ * @brief Invoked when application recieved resume request (going
+ * foreground)
+ */
+ virtual void OnResume() {};
+
+ /**
+ * @brief Invoked when application recieved pause request (going
+ * background)
+ */
+ virtual void OnPause() {};
+
+ /**
+ * @brief Invoked when application recieved service request (recieve
+ * app control request from other application)
+ */
+ virtual void OnService(app_control_h app) {};
+
+ /**
+ * @brief Invoked when application recieved service request (recieve
+ * app control request from other application)
+ */
+ virtual bool OnCreate() { return false; };
+
+ /**
+ * @brief Run Tizen application main loop
+ */
+ int Run(int argc, char **argv);
+};
+/**
+ * @}
+ */
+
+}
+
+#endif
#include "Utils/Log.h"
#include "app.h"
#include "Clock.h"
-#include "Controller/MainController.h"
-#include "Controller/RingController.h"
-#include "Common/Defines.h"
+#include "Utils/TizenApp.h"
+bool ClockApp::OnCreate()
+{
+ elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
+ provider_ = new model::AlarmProvider();
+ main_ctrl_ = new controller::MainController(provider_);
+ ring_ctrl_ = new controller::RingController(provider_);
+ return true;
+}
+
+void ClockApp::OnLanguageChanged(app_event_info_h event)
+{
+ int ret;
+ char *language;
-using namespace controller;
+ ret = app_event_get_language(event, &language);
+ if (ret != APP_ERROR_NONE) {
+ ERR("app_event_get_language failed[%d]: %s", ret, get_error_message(ret));
+ return;
+ }
+ if (language != NULL) {
+ elm_language_set(language);
+ free(language);
+ }
+}
-static bool
-app_create(void *data)
+void ClockApp::OnTerminate()
{
- /* Hook to take necessary actions before main event loop starts
- Initialize UI resources and application's data
- If this function returns true, the main loop of application starts
- If this function returns false, the application is terminated */
+ main_ctrl_->Deinit();
+ delete provider_;
+ delete main_ctrl_;
+ delete ring_ctrl_;
+}
- DBG("app_create");
+void ClockApp::OnResume()
+{
+ main_ctrl_->Resume();
+}
- return true;
+void ClockApp::OnPause()
+{
+ main_ctrl_->Pause();
}
-static void
-app_control(app_control_h app_control, void *data)
+void ClockApp::OnService(app_control_h app_control)
{
- DBG("app_control");
/* Handle the launch request. */
char *opData;
int ret = app_control_get_operation(app_control, &opData);
if (ret != APP_CONTROL_ERROR_NONE || opData == NULL) {
- ERR("app_control_get_operation failed");
+ ERR("app_control_get_operation failed[%d]: %s", ret, get_error_message(ret));
return;
}
DBG("Operation: %s", opData);
- if (!strcmp(opData, APP_CONTROL_OPERATION_DEFAULT))
- MainController::GetInstance().Init();
- else if (!strcmp(opData, APP_CONTROL_OPERATION_ALARM)) {
+ if (!strcmp(opData, APP_CONTROL_OPERATION_DEFAULT)) {
+ main_ctrl_->Init();
+ } else if (!strcmp(opData, APP_CONTROL_OPERATION_ALARM)) {
char *alarmID = NULL;
return;
}
- RingController::GetInstance().HandleAlarm(std::atoi(alarmID));
+ ring_ctrl_->HandleAlarm(std::atoi(alarmID));
free(alarmID);
} else if (!strcmp(opData, APP_CONTROL_OPERATION_TIMEOUT)) {
- RingController::GetInstance().HandleTimeout();
+ ring_ctrl_->HandleTimeout();
}
free(opData);
}
-static void
-app_pause(void *data)
-{
- /* Take necessary actions when application becomes invisible. */
- MainController::GetInstance().Pause();
-}
-
-static void
-app_resume(void *data)
-{
- /* Take necessary actions when application becomes visible. */
- MainController::GetInstance().Resume();
-}
-
-static void
-app_terminate(void *data)
-{
- /* Release all resources. */
- MainController::GetInstance().Deinit();
-}
-
-static void
-ui_app_lang_changed(app_event_info_h event_info, void *user_data)
-{
- /*APP_EVENT_LANGUAGE_CHANGED*/
-
- int ret;
- char *language;
-
- ret = app_event_get_language(event_info, &language);
- if (ret != APP_ERROR_NONE) {
- dlog_print(DLOG_ERROR, LOG_TAG, "app_event_get_language() failed. Err = %d.", ret);
- return;
- }
-
- if (language != NULL) {
- elm_language_set(language);
- free(language);
- }
-}
-
-static void
-ui_app_orient_changed(app_event_info_h event_info, void *user_data)
-{
- /*APP_EVENT_DEVICE_ORIENTATION_CHANGED*/
- return;
-}
-
-static void
-ui_app_region_changed(app_event_info_h event_info, void *user_data)
+int main(int argc, char **argv)
{
- /*APP_EVENT_REGION_FORMAT_CHANGED*/
-}
-
-static void
-ui_app_low_battery(app_event_info_h event_info, void *user_data)
-{
- /*APP_EVENT_LOW_BATTERY*/
-}
-
-static void
-ui_app_low_memory(app_event_info_h event_info, void *user_data)
-{
- /*APP_EVENT_LOW_MEMORY*/
-}
-
-int
-main(int argc, char *argv[])
-{
- int ret = 0;
-
- ui_app_lifecycle_callback_s event_callback = {0,};
- app_event_handler_h handlers[5] = {NULL, };
-
- event_callback.create = app_create;
- event_callback.terminate = app_terminate;
- event_callback.pause = app_pause;
- event_callback.resume = app_resume;
- event_callback.app_control = app_control;
-
- elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
-
- ui_app_add_event_handler(&handlers[APP_EVENT_LOW_BATTERY], APP_EVENT_LOW_BATTERY, ui_app_low_battery, NULL);
- ui_app_add_event_handler(&handlers[APP_EVENT_LOW_MEMORY], APP_EVENT_LOW_MEMORY, ui_app_low_memory, NULL);
- ui_app_add_event_handler(&handlers[APP_EVENT_DEVICE_ORIENTATION_CHANGED], APP_EVENT_DEVICE_ORIENTATION_CHANGED, ui_app_orient_changed, NULL);
- ui_app_add_event_handler(&handlers[APP_EVENT_LANGUAGE_CHANGED], APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, NULL);
- ui_app_add_event_handler(&handlers[APP_EVENT_REGION_FORMAT_CHANGED], APP_EVENT_REGION_FORMAT_CHANGED, ui_app_region_changed, NULL);
-
- ret = ui_app_main(argc, argv, &event_callback, NULL);
- if (ret != APP_ERROR_NONE)
- dlog_print(DLOG_ERROR, LOG_TAG, "ui_app_main() is failed. err = %d", ret);
-
- return ret;
+ ClockApp app;
+ return app.Run(argc, argv);
}
using namespace model;
using std::placeholders::_1;
-MainController &MainController::GetInstance()
-{
- static MainController instance;
- return instance;
-}
-
-MainController::MainController() :
+MainController::MainController(model::AlarmProvider *provider) :
+ provider_(provider),
world_clock_model_(nullptr), stop_watch_model_(nullptr), timer_model_(nullptr),
alarm_presenter_(nullptr), world_clock_presenter_(nullptr), stop_watch_presenter_(nullptr),
stop_watch_model_ = new model::StopWatch();
timer_model_ = new model::Timer();
- alarm_presenter_ = new AlarmPresenter((AlarmView *)main_view_.GetView(ALARM), AlarmProvider::GetInstance());
+ alarm_presenter_ = new AlarmPresenter((AlarmView *)main_view_.GetView(ALARM), provider_);
world_clock_presenter_ = new WorldClockPresenter((WorldClockView *)main_view_.GetView(WORLD_CLOCK), world_clock_model_);
stop_watch_presenter_ = new StopWatchPresenter((StopWatchView *)main_view_.GetView(STOP_WATCH), stop_watch_model_);
timer_presenter_ = new TimerPresenter((TimerView *)main_view_.GetView(TIMER), timer_model_);
delete edit_presenter_;
- edit_presenter_ = new EditAlarmPresenter(AlarmProvider::GetInstance(), nullptr, edit_page_);
+ edit_presenter_ = new EditAlarmPresenter(provider_, nullptr, edit_page_);
}
void MainController::CreateEditAlarmPage(Event &e)
delete edit_presenter_;
- edit_presenter_ = new EditAlarmPresenter(AlarmProvider::GetInstance(),
- &ev.GetAlarm(), edit_page_);
+ edit_presenter_ = new EditAlarmPresenter(provider_, &ev.GetAlarm(), edit_page_);
}
void MainController::CreateNewDeleteAlarmsPage(Event &e)
{
delete delete_presenter_;
- delete_presenter_ = new DeleteAlarmPresenter(&delete_page_, AlarmProvider::GetInstance());
+ delete_presenter_ = new DeleteAlarmPresenter(&delete_page_, provider_);
}
void MainController::CreateNewWorldClockDeletePage(utils::Event &e)
namespace controller {
-RingController &RingController::GetInstance()
-{
- static RingController instance;
- return instance;
-}
-
-RingController::RingController()
+RingController::RingController(model::AlarmProvider *provider) :
+ presenter_(nullptr), model_(nullptr), view_(nullptr), provider_(provider)
{
listener_ = utils::EventBus::AddListener<model::RingDismissEvent>(std::bind(&RingController::RingDestroy,
this, std::placeholders::_1));
void RingController::HandleAlarm(int alarmID)
{
- model::AlarmProvider *alarmProvider = model::AlarmProvider::GetInstance();
- model::Alarm *alarm = alarmProvider->GetAlarmWithId(alarmID);
+ model::Alarm *alarm = provider_->GetAlarmWithId(alarmID);
if (!alarm) {
ERR("Alarm not found");
* limitations under the License.
*/
-#include "Internal/AlarmProviderFile.h"
+#include "Internal/AlarmBinaryStorage.h"
#include "Model/AlarmProviderEvent.h"
#include "Utils/EventBus.h"
using namespace model;
using namespace utils;
-const int AlarmProviderFile::db_schema_version = 1;
+const int AlarmBinaryStorage::db_schema_version = 1;
const int AVAILABLE_ALARMS_MAX = 20;
-void AlarmProviderFile::Add(model::Alarm& alarm)
+void AlarmBinaryStorage::Add(model::Alarm& alarm)
{
auto it = std::find(alarms.begin(), alarms.end(), alarm);
AlarmAddedEvent ev(alarms.back());
EventBus::FireEvent(ev);
}
- Sync();
}
-void AlarmProviderFile::Remove(std::reference_wrapper<Alarm> alarm)
+void AlarmBinaryStorage::Remove(std::reference_wrapper<Alarm> alarm)
{
auto it = std::find(alarms.begin(), alarms.end(), alarm.get());
alarm.get().Deactivate();
alarms.erase(it);
}
- Sync();
}
-AlarmProviderFile::AlarmProviderFile(IReader &r)
+AlarmBinaryStorage::AlarmBinaryStorage(IReader &r)
{
utils::Deserialize(r, alarms);
}
-AlarmProviderFile::~AlarmProviderFile()
+AlarmBinaryStorage::~AlarmBinaryStorage()
{
}
-std::vector<std::reference_wrapper<model::Alarm>> AlarmProviderFile::GetAlarms()
+std::vector<std::reference_wrapper<model::Alarm>> AlarmBinaryStorage::GetAlarms()
{
return std::vector<std::reference_wrapper<model::Alarm>>(
alarms.begin(),
alarms.end());
}
-bool AlarmProviderFile::HasActiveAlarms()
-{
- for (auto &alarm: alarms) {
- if (alarm.IsActivated())
- return true;
- }
-
- return false;
-}
-
-Alarm* AlarmProviderFile::GetAlarmWithId(AlarmId id)
+Alarm* AlarmBinaryStorage::GetAlarmWithId(AlarmId id)
{
auto it = std::find(alarms.begin(), alarms.end(), id);
return &(*it);
}
-void AlarmProviderFile::Serialize(utils::IWriter &w) const
+void AlarmBinaryStorage::Serialize(utils::IWriter &w) const
{
utils::Serialize(w, alarms);
}
-int AlarmProviderFile::Capacity() const
+int AlarmBinaryStorage::Capacity() const
{
return AVAILABLE_ALARMS_MAX;
}
-bool AlarmProviderFile::IsFull() const
+bool AlarmBinaryStorage::IsFull() const
{
return alarms.size() >= Capacity();
}
*/
#include "Model/AlarmProvider.h"
-#include "Internal/AlarmProviderFile.h"
+#include "Internal/AlarmBinaryStorage.h"
#include "Utils/BinaryFileReader.h"
#include "Utils/BinaryFileWriter.h"
#include "Utils/Utils.h"
using namespace utils;
using namespace internal;
-AlarmProvider *AlarmProvider::GetInstance()
+AlarmProvider::AlarmProvider()
{
- static AlarmProvider *instance;
- if (!instance) {
- BinaryFileReader reader(Utils::APP_DIR_DATA, DATABASE_FILE);
- instance = new AlarmProviderFile(reader);
+ BinaryFileReader reader(Utils::APP_DIR_DATA, DATABASE_FILE);
+ impl_ = new AlarmBinaryStorage(reader);
+ if (HasActiveAlarms())
+ Notifier::GetInstance().AlarmNotiPost();
+}
- if (instance->HasActiveAlarms())
- Notifier::GetInstance().AlarmNotiPost();
- }
- return instance;
+AlarmProvider::~AlarmProvider()
+{
+ Sync();
+ delete impl_;
}
void AlarmProvider::Sync()
{
- AlarmProvider *instance = GetInstance();
-
BinaryFileWriter writer(Utils::APP_DIR_DATA, DATABASE_FILE);
- instance->Serialize(writer);
+ impl_->Serialize(writer);
writer.Flush();
- if (instance->HasActiveAlarms())
+ if (HasActiveAlarms())
Notifier::GetInstance().AlarmNotiPost();
else
Notifier::GetInstance().AlarmNotiDelete();
}
+
+std::vector<std::reference_wrapper<Alarm>> AlarmProvider::GetAlarms()
+{
+ return impl_->GetAlarms();
+}
+
+Alarm *AlarmProvider::GetAlarmWithId(AlarmId id)
+{
+ return impl_->GetAlarmWithId(id);
+}
+
+void AlarmProvider::Add(Alarm& alarm)
+{
+ impl_->Add(alarm);
+ Sync();
+}
+
+void AlarmProvider::Remove(std::reference_wrapper<Alarm> alarm)
+{
+ impl_->Remove(alarm);
+ Sync();
+}
+
+int AlarmProvider::Capacity() const
+{
+ return impl_->Capacity();
+}
+
+bool AlarmProvider::IsFull() const
+{
+ return impl_->IsFull();
+}
+
+bool AlarmProvider::HasActiveAlarms()
+{
+ for (auto &a : GetAlarms())
+ {
+ if (a.get().IsActivated())
+ return true;
+ }
+ return false;
+}
using std::placeholders::_1;
-AlarmPresenter::AlarmPresenter(AlarmView *v, AlarmProvider *m) : view(v), model(m)
+AlarmPresenter::AlarmPresenter(AlarmView *v, AlarmProvider *m) : view_(v), model_(m)
{
- view->SetButtonClickedCallback(std::bind(&AlarmPresenter::OnAddButtonClicked, this));
- view->SetDeleteItemClickedCallback(std::bind(&AlarmPresenter::OnDeleteItemClicked, this));
- view->SetItemToggleCallback(std::bind(&AlarmPresenter::OnItemActiveStatusChanged, this, _1));
- view->SetItemSelectCallback(std::bind(&AlarmPresenter::OnItemSelected, this, _1));
- view->SetMenuButtonClickedCallback(std::bind(&AlarmPresenter::OnMenuButtonClicked, this));
+ view_->SetButtonClickedCallback(std::bind(&AlarmPresenter::OnAddButtonClicked, this));
+ view_->SetDeleteItemClickedCallback(std::bind(&AlarmPresenter::OnDeleteItemClicked, this));
+ view_->SetItemToggleCallback(std::bind(&AlarmPresenter::OnItemActiveStatusChanged, this, _1));
+ view_->SetItemSelectCallback(std::bind(&AlarmPresenter::OnItemSelected, this, _1));
+ view_->SetMenuButtonClickedCallback(std::bind(&AlarmPresenter::OnMenuButtonClicked, this));
listeners_.push_back(EventBus::AddListener<AlarmAddedEvent>(
std::bind(&AlarmPresenter::OnAlarmAddedEvent, this, _1)));
void AlarmPresenter::ShowAll()
{
- std::vector<std::reference_wrapper<Alarm>> alarms = model->GetAlarms();
+ std::vector<std::reference_wrapper<Alarm>> alarms = model_->GetAlarms();
- view->Clear();
+ view_->Clear();
for (auto a: alarms) {
- int id = view->ItemAppend(
+ int id = view_->ItemAppend(
a.get().GetTime(),
a.get().GetName().c_str(),
a.get().GetWeekFlags(),
{
AlarmCreateRequestEvent ev;
- if (AlarmProvider::GetInstance()->IsFull()) {
+ if (model_->IsFull()) {
std::string text = Translate::Sprintf("IDS_CLOCK_TPOP_CANT_ADD_MORE_THAN_PD_ALARMS",
- AlarmProvider::GetInstance()->Capacity());
+ model_->Capacity());
- view->ShowPopup(text);
+ view_->ShowPopup(text);
return;
}
EventBus::FireEvent(ev);
alarm.Activate();
}
- view->ItemUpdate(idx, alarm.GetTime(), alarm.GetName().c_str(),
+ view_->ItemUpdate(idx, alarm.GetTime(), alarm.GetName().c_str(),
alarm.GetWeekFlags(), alarm.IsActivated());
- AlarmProvider::Sync();
+ model_->Sync();
}
void AlarmPresenter::OnAlarmAddedEvent(Event &e)
{
AlarmAddedEvent &ev = dynamic_cast<AlarmAddedEvent&>(e);
- int id = view->ItemAppend(
+ int id = view_->ItemAppend(
ev.GetAlarm().GetTime(),
ev.GetAlarm().GetName().c_str(),
ev.GetAlarm().GetWeekFlags(),
void AlarmPresenter::OnMenuButtonClicked()
{
if (alarms_.size() > 0)
- view->ShowDeletePopup();
+ view_->ShowDeletePopup();
}
void AlarmPresenter::OnAlarmRemovedEvent(Event &e)
for (auto it = alarms_.begin(); it != alarms_.end(); ++it) {
if (ev.GetAlarm() == it->second.get()) {
- view->RemoveItem(it->first);
+ view_->RemoveItem(it->first);
alarms_.erase(it);
break;
}
void AlarmPresenter::UpdateBackgroundLabel()
{
if (alarms_.size() == 0)
- view->ShowNoAlarmsBackgroundLabel();
+ view_->ShowNoAlarmsBackgroundLabel();
else
- view->HideNoAlarmsBackgroundLabel();
+ view_->HideNoAlarmsBackgroundLabel();
}
void AlarmPresenter::OnAlarmEditedEvent(utils::Event &e)
for (; it != alarms_.end(); ++it) {
if (ev.GetAlarm() == it->second.get()) {
Alarm &alarm = it->second.get();
- view->ItemUpdate(it->first, alarm.GetTime(), alarm.GetName().c_str(),
+ view_->ItemUpdate(it->first, alarm.GetTime(), alarm.GetName().c_str(),
alarm.GetWeekFlags(), alarm.IsActivated());
break;
}
const double time_truncate_factor = 60 * 1000; // 60 seconds
EditAlarmPresenter::EditAlarmPresenter(model::AlarmProvider *provider, model::Alarm *alarm, view::EditAlarmView& view) :
- provider_(provider), view_(view), alarm_(alarm)
+ provider_(provider), alarm_(alarm), view_(view)
{
view_.RegisterEditDoneCallback(std::bind(&EditAlarmPresenter::OnEditDone, this));
view_.RegisterEditCancelCallback(std::bind(&EditAlarmPresenter::OnEditCancel, this));
{
Alarm new_alarm;
- if (AlarmProvider::GetInstance()->IsFull()) {
+ if (provider_->IsFull()) {
std::string text = Translate::Sprintf("IDS_CLOCK_TPOP_CANT_ADD_MORE_THAN_PD_ALARMS",
provider_->Capacity());
view_.ShowPopup(text);
SetAlarmProperties(new_alarm, view_.GetData());
new_alarm.Activate();
- AlarmProvider::GetInstance()->Add(new_alarm);
+ provider_->Add(new_alarm);
}
void EditAlarmPresenter::ShowAlarmUpdatedPopup(const Time &time)
if (update_target && (update_target != alarm_)) {
UpdateAlarm(*update_target);
ShowAlarmUpdatedPopup(update_target->GetTime());
- AlarmProvider::GetInstance()->Remove(std::reference_wrapper<Alarm>(*alarm_));
+ provider_->Remove(std::reference_wrapper<Alarm>(*alarm_));
} else {
UpdateAlarm(*alarm_);
}
CreateNewAlarm();
}
- AlarmProvider::Sync();
+ provider_->Sync();
view_.PopPage();
}
--- /dev/null
+#include "Utils/TizenApp.h"
+#include "Utils/Log.h"
+
+using namespace utils;
+
+static bool
+app_create(void *data)
+{
+ TizenApp *app = static_cast<TizenApp*>(data);
+ return app->OnCreate();
+}
+
+static void
+app_control(app_control_h app_control, void *data)
+{
+ TizenApp *app = static_cast<TizenApp*>(data);
+ app->OnService(app_control);
+}
+
+static void
+app_pause(void *data)
+{
+ /* Take necessary actions when application becomes invisible. */
+ TizenApp *app = static_cast<TizenApp*>(data);
+ app->OnPause();
+}
+
+static void
+app_resume(void *data)
+{
+ /* Take necessary actions when application becomes visible. */
+ TizenApp *app = static_cast<TizenApp*>(data);
+ app->OnResume();
+}
+
+static void
+app_terminate(void *data)
+{
+ TizenApp *app = static_cast<TizenApp*>(data);
+ app->OnTerminate();
+}
+
+static void
+ui_app_lang_changed(app_event_info_h event_info, void *data)
+{
+ TizenApp *app = static_cast<TizenApp*>(data);
+ app->OnLanguageChanged(event_info);
+}
+
+int TizenApp::Run(int argc, char **argv)
+{
+ int ret = 0;
+
+ ui_app_lifecycle_callback_s event_callback = {0,};
+ app_event_handler_h handler;
+
+ event_callback.create = app_create;
+ event_callback.terminate = app_terminate;
+ event_callback.pause = app_pause;
+ event_callback.resume = app_resume;
+ event_callback.app_control = app_control;
+
+ ui_app_add_event_handler(&handler, APP_EVENT_LANGUAGE_CHANGED, ui_app_lang_changed, this);
+
+ ret = ui_app_main(argc, argv, &event_callback, this);
+ if (ret != APP_ERROR_NONE)
+ DBG("ui_app_main() is failed. err = %d", ret);
+
+ return ret;
+}
void AlarmView::DismissPopupCallback(void *data, Evas_Object *obj, void *event_info)
{
- Evas_Object *popup = static_cast<Evas_Object*>(data);
- evas_object_del(popup);
+ AlarmView *view = static_cast<AlarmView*>(data);
+ evas_object_del(view->popup_);
+ view->popup_ = nullptr;
}
void AlarmView::PopupDeleteItemCallback(void *data, Evas_Object *obj, void *event_info)
popup_ = elm_popup_add(elm_object_top_widget_get(content_));
elm_popup_align_set(popup_, ELM_NOTIFY_ALIGN_FILL, 1.0);
evas_object_size_hint_weight_set(popup_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
- evas_object_smart_callback_add(popup_, "block,clicked", AlarmView::DismissPopupCallback, popup_);
- eext_object_event_callback_add(popup_, EEXT_CALLBACK_BACK, AlarmView::DismissPopupCallback, popup_);
+ evas_object_smart_callback_add(popup_, "block,clicked", AlarmView::DismissPopupCallback, this);
+ eext_object_event_callback_add(popup_, EEXT_CALLBACK_BACK, AlarmView::DismissPopupCallback, this);
Evas_Object *list = elm_list_add(popup_);
elm_list_mode_set(list, ELM_LIST_EXPAND);