From: Iryna Ferenchak Date: Tue, 1 Mar 2016 09:10:19 +0000 (+0200) Subject: TizenRefApp-5796 Time should be shown as hour and minute in local time setting X-Git-Tag: submit/tizen/20160524.113145~143^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2f01cfbf1c6203b6cd3831ccbe73dcc497f34b54;p=profile%2Fmobile%2Fapps%2Fnative%2Fphone-contacts.git TizenRefApp-5796 Time should be shown as hour and minute in local time setting Change-Id: I47d6cfa40ea616dba8f876e02396403cec606c6c Signed-off-by: Iryna Ferenchak --- diff --git a/lib-apps-common/inc/Ui/RadioPopup.h b/lib-apps-common/inc/Ui/RadioPopup.h new file mode 100644 index 00000000..90bb0dc6 --- /dev/null +++ b/lib-apps-common/inc/Ui/RadioPopup.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 UI_RADIO_POPUP_H +#define UI_RADIO_POPUP_H + +#include "Ui/ListPopup.h" +#include + +namespace Ui +{ + /** + * @brief Radio popup + */ + class EXPORT_API RadioPopup : public ListPopup + { + public: + RadioPopup(); + + /** + * @brief Set selected item + * @param[in] value Selected item value + */ + void setSelectedItem(int value); + + private: + virtual Evas_Object *onCreate(Evas_Object *parent) override; + virtual Evas_Object *getItemContent(void *data, const char *part) override; + virtual void onItemSelected(void *data) override; + + Evas_Object *m_RadioGroup; + }; +} +#endif /* UI_RADIO_POPUP_H */ diff --git a/lib-apps-common/src/Ui/RadioPopup.cpp b/lib-apps-common/src/Ui/RadioPopup.cpp new file mode 100644 index 00000000..72b06dc4 --- /dev/null +++ b/lib-apps-common/src/Ui/RadioPopup.cpp @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 "Ui/RadioPopup.h" + +using namespace Ui; + +RadioPopup::RadioPopup() + : m_RadioGroup(nullptr) +{ +} + +void RadioPopup::setSelectedItem(int value) +{ + elm_radio_value_set(m_RadioGroup, value); +} + +Evas_Object *RadioPopup::onCreate(Evas_Object *parent) +{ + Evas_Object *popup = ListPopup::onCreate(parent); + + m_RadioGroup = elm_radio_add(popup); + elm_radio_state_value_set(m_RadioGroup, -1); + + return popup; +} + +Evas_Object *RadioPopup::getItemContent(void *data, const char *part) +{ + if (strcmp(part, "elm.swallow.end") == 0) { + Evas_Object *radio = elm_radio_add(getEvasObject()); + elm_radio_group_add(radio, m_RadioGroup); + elm_radio_state_value_set(radio, (long) data); + return radio; + } + + return nullptr; +} + +void RadioPopup::onItemSelected(void *data) +{ + setSelectedItem((long) data); +} diff --git a/lib-common/inc/Ui/RadioPopup.h b/lib-common/inc/Ui/RadioPopup.h deleted file mode 100644 index 90bb0dc6..00000000 --- a/lib-common/inc/Ui/RadioPopup.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 UI_RADIO_POPUP_H -#define UI_RADIO_POPUP_H - -#include "Ui/ListPopup.h" -#include - -namespace Ui -{ - /** - * @brief Radio popup - */ - class EXPORT_API RadioPopup : public ListPopup - { - public: - RadioPopup(); - - /** - * @brief Set selected item - * @param[in] value Selected item value - */ - void setSelectedItem(int value); - - private: - virtual Evas_Object *onCreate(Evas_Object *parent) override; - virtual Evas_Object *getItemContent(void *data, const char *part) override; - virtual void onItemSelected(void *data) override; - - Evas_Object *m_RadioGroup; - }; -} -#endif /* UI_RADIO_POPUP_H */ diff --git a/lib-common/src/Ui/RadioPopup.cpp b/lib-common/src/Ui/RadioPopup.cpp deleted file mode 100644 index 72b06dc4..00000000 --- a/lib-common/src/Ui/RadioPopup.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * 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 "Ui/RadioPopup.h" - -using namespace Ui; - -RadioPopup::RadioPopup() - : m_RadioGroup(nullptr) -{ -} - -void RadioPopup::setSelectedItem(int value) -{ - elm_radio_value_set(m_RadioGroup, value); -} - -Evas_Object *RadioPopup::onCreate(Evas_Object *parent) -{ - Evas_Object *popup = ListPopup::onCreate(parent); - - m_RadioGroup = elm_radio_add(popup); - elm_radio_state_value_set(m_RadioGroup, -1); - - return popup; -} - -Evas_Object *RadioPopup::getItemContent(void *data, const char *part) -{ - if (strcmp(part, "elm.swallow.end") == 0) { - Evas_Object *radio = elm_radio_add(getEvasObject()); - elm_radio_group_add(radio, m_RadioGroup); - elm_radio_state_value_set(radio, (long) data); - return radio; - } - - return nullptr; -} - -void RadioPopup::onItemSelected(void *data) -{ - setSelectedItem((long) data); -} diff --git a/lib-logs/inc/Logs/Common/Utils.h b/lib-logs/inc/Logs/Common/Utils.h new file mode 100644 index 00000000..1bd08c86 --- /dev/null +++ b/lib-logs/inc/Logs/Common/Utils.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 LOGS_COMMON_UTILS_H +#define LOGS_COMMON_UTILS_H + +#include +#include + +namespace Logs +{ + namespace Common + { + /** + * @brief Convert tm to string + * @param[in] time Time to convert + * @return string. + */ + std::string formatTime(const tm &time); + } +} + +#endif /* LOGS_COMMON_UTILS_H */ diff --git a/lib-logs/inc/Logs/List/LogItem.h b/lib-logs/inc/Logs/List/LogItem.h index d8d28b68..7d404ffc 100644 --- a/lib-logs/inc/Logs/List/LogItem.h +++ b/lib-logs/inc/Logs/List/LogItem.h @@ -20,6 +20,8 @@ #include "Ui/GenlistCheckItem.h" +#define PART_LOG_TIME "elm.text.sub.end" + namespace Logs { namespace Model @@ -80,11 +82,6 @@ namespace Logs */ Model::LogGroup *getGroup() const; - /** - * @brief Remove group - */ - void removeGroup(); - private: virtual char *getText(Evas_Object *parent, const char *part) override; virtual Evas_Object *getContent(Evas_Object *parent, const char *part) override; diff --git a/lib-logs/inc/Logs/List/LogsView.h b/lib-logs/inc/Logs/List/LogsView.h index 9e3a8302..5fe07b9e 100644 --- a/lib-logs/inc/Logs/List/LogsView.h +++ b/lib-logs/inc/Logs/List/LogsView.h @@ -20,6 +20,7 @@ #include "Ui/View.h" #include "Logs/Model/LogProvider.h" +#include namespace Ui { @@ -56,11 +57,14 @@ namespace Logs */ LogsView(FilterType filterType = FilterAll); + virtual ~LogsView() override; + private: virtual Evas_Object *onCreate(Evas_Object *parent) override; virtual void onPageAttached() override; virtual void onMenuPressed() override; + void onSettingsChanged(system_settings_key_e key); void onSelectViewBy(); void fillGenlist(); bool shouldDisplayLogs(const Model::LogGroup &group); diff --git a/lib-logs/inc/Logs/Model/Log.h b/lib-logs/inc/Logs/Model/Log.h index a53644ae..477738fc 100644 --- a/lib-logs/inc/Logs/Model/Log.h +++ b/lib-logs/inc/Logs/Model/Log.h @@ -87,6 +87,11 @@ namespace Logs */ LogGroup *getLogGroup() const; + /** + * @brief Update record + */ + void update(); + /** * @return Remove log from database */ diff --git a/lib-logs/inc/Logs/Model/LogProvider.h b/lib-logs/inc/Logs/Model/LogProvider.h index 4b4dec90..100e788c 100644 --- a/lib-logs/inc/Logs/Model/LogProvider.h +++ b/lib-logs/inc/Logs/Model/LogProvider.h @@ -83,6 +83,11 @@ namespace Logs */ const LogGroupList &getLogGroupList(); + /** + * @brief Reset log group list + */ + void resetLogGroups(); + /** * @brief Set new log callback * @param[in] callback New Log callback diff --git a/lib-logs/src/Logs/Common/Utils.cpp b/lib-logs/src/Logs/Common/Utils.cpp new file mode 100644 index 00000000..1dc933ba --- /dev/null +++ b/lib-logs/src/Logs/Common/Utils.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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 "Logs/Common/Utils.h" +#include + +using namespace Logs; + +#define BUFFER_SIZE 32 + +std::string Common::formatTime(const tm &time) +{ + char buffer[BUFFER_SIZE]; + bool is24Hours = false; + + system_settings_get_value_bool(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, &is24Hours); + strftime(buffer, sizeof(buffer), is24Hours ? "%R" : "%I:%M %p", &time); + + return buffer; +} diff --git a/lib-logs/src/Logs/List/LogItem.cpp b/lib-logs/src/Logs/List/LogItem.cpp index a5c5c1dd..98051bd5 100644 --- a/lib-logs/src/Logs/List/LogItem.cpp +++ b/lib-logs/src/Logs/List/LogItem.cpp @@ -20,6 +20,7 @@ #include "Logs/Model/LogGroup.h" #include "Logs/Details/DetailsView.h" #include "Utils/Callback.h" +#include "Logs/Common/Utils.h" #include "App/Path.h" #include "Ui/Scale.h" @@ -34,11 +35,11 @@ #define BUFFER_SIZE 32 #define LOG_TYPE_SIZE 50 +#define LOG_TIME_TEXT_SIZE 22 #define PART_LOG_NAME "elm.text" #define PART_LOG_NUMBER "elm.text.sub" #define PART_LOG_COUNT "elm.text.end" -#define PART_LOG_TYPE "elm.text.sub.end" #define PART_PERSON_THUMBNAIL "elm.swallow.icon" #define PART_END "elm.swallow.end" @@ -87,11 +88,6 @@ LogGroup *LogItem::getGroup() const return m_Group; } -void LogItem::removeGroup() -{ - m_Group->remove(); -} - char *LogItem::getText(Evas_Object *parent, const char *part) { const Log *log = m_Group->getLogList().back(); @@ -112,10 +108,9 @@ char *LogItem::getText(Evas_Object *parent, const char *part) char buffer[BUFFER_SIZE]; snprintf(buffer, sizeof(buffer), "(%zu)", m_Group->getLogList().size()); return strdup(buffer); - } else if (strcmp(part, PART_LOG_TYPE) == 0) { - tm date = log->getTime(); + } else if (strcmp(part, PART_LOG_TIME) == 0) { char buffer[BUFFER_SIZE]; - strftime(buffer, sizeof(buffer), "%X", &date); + snprintf(buffer, sizeof(buffer), "%s", LOG_TIME_TEXT_SIZE, Logs::Common::formatTime(log->getTime()).c_str()); return strdup(buffer); } diff --git a/lib-logs/src/Logs/List/LogsView.cpp b/lib-logs/src/Logs/List/LogsView.cpp index 3d2f699b..f4eac724 100644 --- a/lib-logs/src/Logs/List/LogsView.cpp +++ b/lib-logs/src/Logs/List/LogsView.cpp @@ -25,6 +25,9 @@ #include "Ui/Navigator.h" #include "Ui/RadioPopup.h" +#include "Utils/Logger.h" +#include "Utils/Callback.h" + using namespace Logs::Model; using namespace Logs::List; using namespace Logs::Details; @@ -36,6 +39,28 @@ LogsView::LogsView(FilterType filterType) m_Mode(ItemMode::Default), m_FilterType(filterType) { + system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR, makeCallbackWithLastParam(&LogsView::onSettingsChanged), this); + system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY, makeCallbackWithLastParam(&LogsView::onSettingsChanged), this); + system_settings_set_changed_cb(SYSTEM_SETTINGS_KEY_TIME_CHANGED, makeCallbackWithLastParam(&LogsView::onSettingsChanged), this); +} + +LogsView::~LogsView() +{ + system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_TIMEFORMAT_24HOUR); + system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY); + system_settings_unset_changed_cb(SYSTEM_SETTINGS_KEY_TIME_CHANGED); +} + +void LogsView::onSettingsChanged(system_settings_key_e key) +{ + if (key == SYSTEM_SETTINGS_KEY_LOCALE_COUNTRY || + key == SYSTEM_SETTINGS_KEY_TIME_CHANGED) { + elm_genlist_clear(m_Genlist->getEvasObject()); + m_LogProvider.resetLogGroups(); + fillGenlist(); + } else { + m_Genlist->update(PART_LOG_TIME, ELM_GENLIST_ITEM_FIELD_TEXT); + } } Evas_Object *LogsView::onCreate(Evas_Object *parent) @@ -81,13 +106,15 @@ void LogsView::onSelectViewBy() Ui::RadioPopup *popup = new Ui::RadioPopup(); popup->create(getEvasObject()); popup->setTitle("IDS_CLOG_OPT_VIEW_BY"); - popup->setSelectedItem(m_FilterType); popup->addItem("IDS_LOGS_BODY_ALL_CALLS", (void *) FilterAll); popup->addItem("IDS_LOGS_OPT_MISSED_CALLS", (void *) FilterMissed); + popup->setSelectedItem(m_FilterType); popup->setSelectedCallback([this](void *data) { - elm_genlist_clear(m_Genlist->getEvasObject()); - m_FilterType = (FilterType)(long)data; - fillGenlist(); + if (m_FilterType != (FilterType)(long)data) { + elm_genlist_clear(m_Genlist->getEvasObject()); + m_FilterType = (FilterType)(long)data; + fillGenlist(); + } }); } @@ -100,12 +127,15 @@ void LogsView::fillGenlist() LogGroupItem *groupItem = nullptr; for (auto &&group : m_LogProvider.getLogGroupList()) { - if (shouldDisplayLogs(*group)) { groupItem = insertLogItem(group.get(), groupItem); } } + if (!elm_genlist_items_count(m_Genlist->getEvasObject())) { + return; + } + groupItem = dynamic_cast(m_Genlist->getFirstItem()); groupItem->scrollTo(ELM_GENLIST_ITEM_SCROLLTO_TOP); } diff --git a/lib-logs/src/Logs/Model/Log.cpp b/lib-logs/src/Logs/Model/Log.cpp index 014130ad..3176eeb0 100644 --- a/lib-logs/src/Logs/Model/Log.cpp +++ b/lib-logs/src/Logs/Model/Log.cpp @@ -32,7 +32,7 @@ Log::~Log() m_Group->removeLog(this); } contacts_record_destroy(m_LogRecord, true); - if (m_ContactRecord != nullptr) { + if (m_ContactRecord) { contacts_record_destroy(m_ContactRecord, true); } } @@ -40,7 +40,7 @@ Log::~Log() const char *Log::getName() const { char *name = nullptr; - if (m_ContactRecord != nullptr) { + if (m_ContactRecord) { contacts_record_get_str_p(m_ContactRecord, _contacts_person.display_name, &name); } return name; @@ -56,7 +56,7 @@ const char *Log::getNumber() const const char *Log::getImagePath() const { char *path = nullptr; - if (m_ContactRecord != nullptr) { + if (m_ContactRecord) { contacts_record_get_str_p(m_ContactRecord, _contacts_person.image_thumbnail_path, &path); } return path; @@ -76,10 +76,7 @@ tm Log::getTime() const contacts_record_get_int(m_LogRecord, _contacts_phone_log.log_time, &time); time_t logTime = time; - struct tm logDate; - - localtime_r(&logTime, &logDate); - return logDate; + return *localtime(&logTime); } int Log::getId() const @@ -116,6 +113,13 @@ LogGroup *Log::getLogGroup() const return m_Group; } +void Log::update() +{ + int id = getId(); + contacts_record_destroy(m_LogRecord, true); + contacts_db_get_record(_contacts_phone_log._uri, id, &m_LogRecord); +} + void Log::remove() { contacts_db_delete_record(_contacts_phone_log._uri, getId()); diff --git a/lib-logs/src/Logs/Model/LogProvider.cpp b/lib-logs/src/Logs/Model/LogProvider.cpp index 43f365e4..2af95e9a 100644 --- a/lib-logs/src/Logs/Model/LogProvider.cpp +++ b/lib-logs/src/Logs/Model/LogProvider.cpp @@ -48,6 +48,12 @@ const LogProvider::LogGroupList &LogProvider::getLogGroupList() return m_Groups; } +void LogProvider::resetLogGroups() +{ + m_Groups.clear(); + fillGroupList(m_Logs, m_Groups); +} + void LogProvider::setInsertCallback(InsertCallback callback) { m_InsertCallback = std::move(callback); @@ -148,7 +154,6 @@ contacts_list_h LogProvider::fetchLogList() void LogProvider::onLogChanged(const char *viewUri) { LogList newLogList; - fillList(newLogList); LogIterator newIt = newLogList.begin(); @@ -267,14 +272,5 @@ void LogProvider::addNewLogs(LogIterator &newIt, LogList &newLogList) void LogProvider::onContactChanged(const char *viewUri) { - contacts_list_h changes = nullptr; - contacts_db_get_changes_by_version(_contacts_contact_updated_info._uri, 0, m_DbVersion, &changes, &m_DbVersion); - - contacts_record_h record = nullptr; - CONTACTS_LIST_FOREACH(changes, record) { - /* - * TODO - */ - } - contacts_list_destroy(changes, true); +/* TODO*/ }