#include "Input/SetRepeatView.h"
#include "Input/SetTimeView.h"
#include "Common/AlarmDeletedPopup.h"
+#include "Common/AlarmSetPopup.h"
#include "Common/Model/AlarmConsumer.h"
#include "Ui/PageIndex.h"
tm time = m_TimeView->getTimePicker()->getTime();
m_Alarm.setTime(time.tm_hour, time.tm_min);
m_Alarm.setRepeat(m_RepeatView->getDaySelector()->getSelectedDays());
+ m_Alarm.setEnabled(true);
elm_object_disabled_set(m_Button, EINA_TRUE);
AlarmConsumer::getInstance().saveAlarm(m_Alarm, [this](bool isSuccess) {
return;
}
+ auto popup = new Common::AlarmSetPopup(m_Alarm);
+ popup->create(getEvasObject());
+ popup->show();
getPage()->close();
});
}
#include "List/AlarmItem.h"
#include "Input/InputView.h"
+#include "Common/AlarmSetPopup.h"
#include "Common/Format.h"
#include "Common/Model/Alarm.h"
#include "Common/Model/AlarmConsumer.h"
void AlarmItem::onAlarmEnabled(Evas_Object *check, void *eventInfo)
{
m_Alarm.setEnabled(elm_check_state_get(check));
- AlarmConsumer::getInstance().updateAlarm(m_Alarm, nullptr);
+ AlarmConsumer::getInstance().updateAlarm(m_Alarm, [this](bool isSuccess) {
+ if (isSuccess && m_Alarm.isEnabled()) {
+ auto popup = new Common::AlarmSetPopup(m_Alarm);
+ popup->create(getParent()->getEvasObject());
+ popup->show();
+ }
+ });
}
--- /dev/null
+/*
+ * 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 COMMON_ALARM_SET_POPUP_H
+#define COMMON_ALARM_SET_POPUP_H
+
+#include "Ui/Toast.h"
+
+namespace Common
+{
+ namespace Model
+ {
+ class Alarm;
+ }
+
+ /**
+ * @brief Toast popup notifying when alarm will go off after being set.
+ */
+ class EXPORT_API AlarmSetPopup : public Ui::Toast
+ {
+ public:
+ /**
+ * @brief Create toast popup.
+ * @param[in] alarm Alarm being set
+ */
+ explicit AlarmSetPopup(Model::Alarm &alarm);
+
+ private:
+ virtual void onCreated() override;
+
+ Model::Alarm &m_Alarm;
+ };
+}
+
+#endif /* COMMON_ALARM_SET_POPUP_H */
* @return Formatted weekday letters with highlighted repeat.
*/
EXPORT_API const char *formatRepeat(int repeat);
+
+ /**
+ * @brief Create "Alarm set for ... from now" message.
+ * @param[in] date Alarm date
+ * @return Formatted localized message.
+ */
+ EXPORT_API const char *formatAlarmSetMessage(const tm &date);
}
#endif /* COMMON_FORMAT_H */
--- /dev/null
+/*
+ * 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 "Common/AlarmSetPopup.h"
+#include "Common/Format.h"
+#include "Common/Model/Alarm.h"
+
+using namespace Common;
+
+AlarmSetPopup::AlarmSetPopup(Model::Alarm &alarm)
+ : m_Alarm(alarm)
+{
+}
+
+void AlarmSetPopup::onCreated()
+{
+ elm_object_style_set(getEvasObject(), "toast/circle");
+ setText(Common::formatAlarmSetMessage(m_Alarm.getDate()));
+}
#include "Common/Format.h"
#include <app_i18n.h>
+#include <array>
#include <string>
#include <system_settings.h>
-#define DAY_COUNT 7
+#define DAY_COUNT 7
+#define HOUR_COUNT 24
+#define MIN_COUNT 60
+#define SEC_COUNT 60
+
#define TIME_BUFFER_SIZE 64
#define DATE_BUFFER_SIZE 32
#define REPEAT_BUFFER_SIZE 256
+#define MESSAGE_BUFFER_SIZE 128
namespace
{
"WDS_ALM_BUTTON_F_M_FRIDAY_ABB",
"WDS_ALM_BUTTON_S_M_SATURDAY_ABB"
};
+
+ const struct {
+ const char *singular;
+ const char *plural;
+ } durations[] = {
+ { "1_DAY_", "DAYS_" },
+ { "1_HR_", "HRS_" },
+ { "1_MIN_", "MINS_" }
+ };
+
+ std::array<int, 3> getDateDiff(const tm &date)
+ {
+ time_t now = time(nullptr);
+ now -= now % SEC_COUNT;
+
+ int diff = (mktime((tm *) &date) - now) / SEC_COUNT;
+ int mins = diff % MIN_COUNT;
+ int hours = (diff / MIN_COUNT) % HOUR_COUNT;
+ int days = diff / MIN_COUNT / HOUR_COUNT;
+
+ return { { days, hours, mins } };
+ }
}
Utils::Range<const char **> Common::getWeekdayLetters()
}
return buffer.c_str();
}
+
+/*
+ * The function selects a translatable string such as:
+ * WDS_ALM_TPOP_ALARM_SET_FOR_1_HR_PD_MINS_FROM_NOW_ABB
+ * WDS_ALM_TPOP_ALARM_SET_FOR_P1SD_HRS_P2SD_MINS_FROM_NOW_ABB
+ * by formatting it based on date difference.
+ *
+ * Translatable strings use "PD" to represent "%d" when plural form (>1)
+ * of days, hours or minutes is used.
+ *
+ * If there are several plurals in the string - positional specifiers are used
+ * instead of "%d" such as "%1$d", "%2$d" and "%3$d" which are represented by
+ * "P1SD", "P2SD" and "P3SD" respectively.
+ */
+const char *Common::formatAlarmSetMessage(const tm &date)
+{
+ auto diffs = getDateDiff(date);
+ int args[] = { 0, 0, 0 };
+ bool isMultiPlurals = (int(diffs[0] > 1) + int(diffs[1] > 1) + int(diffs[2] > 1)) > 1;
+
+ std::string format("WDS_ALM_TPOP_ALARM_SET_FOR_");
+ for (size_t i = 0, j = 0; i < diffs.size(); ++i) {
+ auto &duration = durations[i];
+ if (diffs[i] > 0) {
+ if (diffs[i] > 1) {
+ args[j++] = diffs[i];
+ if (isMultiPlurals) {
+ format += 'P';
+ format += j + '0';
+ format += "SD_";
+ } else {
+ format += "PD_";
+ }
+ format += duration.plural;
+ } else {
+ format += duration.singular;
+ }
+ }
+ }
+ format += "FROM_NOW_ABB";
+
+ static char buffer[MESSAGE_BUFFER_SIZE];
+ snprintf(buffer, sizeof(buffer), _(format.c_str()), args[0], args[1], args[2]);
+ return buffer;
+}