From da3eefe59fd5f350403b3fcc696f232d2809e9da Mon Sep 17 00:00:00 2001 From: Nataliia Kamyshna Date: Tue, 7 Jun 2016 15:39:42 +0300 Subject: [PATCH] TizenRefApp-6474 Implement show of all logs in Log Details Change-Id: I1d0582a23b3b830f0f8f5e05c038f5053a7eda81 Signed-off-by: Nataliia Kamyshna --- lib-logs/inc/Logs/Details/ActionItem.h | 10 ++- lib-logs/inc/Logs/Details/BasicInfoItem.h | 12 +-- lib-logs/inc/Logs/Details/DetailsView.h | 22 +++-- lib-logs/inc/Logs/Model/Log.h | 6 +- lib-logs/inc/Logs/Model/LogProvider.h | 6 +- lib-logs/inc/Logs/Model/NumberLogProvider.h | 48 ++++++++++ lib-logs/src/Logs/Details/ActionItem.cpp | 17 ++-- lib-logs/src/Logs/Details/BasicInfoItem.cpp | 16 +++- lib-logs/src/Logs/Details/DetailsView.cpp | 108 +++++++++++++++------- lib-logs/src/Logs/List/LogItem.cpp | 3 +- lib-logs/src/Logs/Model/Log.cpp | 11 ++- lib-logs/src/Logs/Model/LogProvider.cpp | 125 ++++++++++++++------------ lib-logs/src/Logs/Model/NumberLogProvider.cpp | 39 ++++++++ 13 files changed, 303 insertions(+), 120 deletions(-) create mode 100644 lib-logs/inc/Logs/Model/NumberLogProvider.h create mode 100644 lib-logs/src/Logs/Model/NumberLogProvider.cpp diff --git a/lib-logs/inc/Logs/Details/ActionItem.h b/lib-logs/inc/Logs/Details/ActionItem.h index 73b3360..edc8b50 100644 --- a/lib-logs/inc/Logs/Details/ActionItem.h +++ b/lib-logs/inc/Logs/Details/ActionItem.h @@ -42,8 +42,14 @@ namespace Logs * @brief Create action item. * @param[in] group Log group for display */ - ActionItem(Model::LogGroup *group); - virtual ~ActionItem(); + explicit ActionItem(Model::LogGroup *group); + virtual ~ActionItem() override; + + /** + * @brief Update log and item fields. + * @param[in] group Log group for display + */ + void updateGroup(Model::LogGroup *group); protected: /** diff --git a/lib-logs/inc/Logs/Details/BasicInfoItem.h b/lib-logs/inc/Logs/Details/BasicInfoItem.h index f41d75e..ecdbe6a 100644 --- a/lib-logs/inc/Logs/Details/BasicInfoItem.h +++ b/lib-logs/inc/Logs/Details/BasicInfoItem.h @@ -47,11 +47,7 @@ namespace Logs * @brief Create basic info item. * @param[in] group Log group for display */ - BasicInfoItem(Model::LogGroup *group); - - /** - * @brief Destroy basic info item. - */ + explicit BasicInfoItem(Model::LogGroup *group); virtual ~BasicInfoItem() override; /** @@ -60,6 +56,12 @@ namespace Logs */ void setBackCallback(BackCallback callback); + /** + * @brief Update log and item fields. + * @param[in] group Log group for display + */ + void updateGroup(Model::LogGroup *group); + protected: /** * @see GenlistItem::getItemClass() diff --git a/lib-logs/inc/Logs/Details/DetailsView.h b/lib-logs/inc/Logs/Details/DetailsView.h index f1161be..9431e53 100644 --- a/lib-logs/inc/Logs/Details/DetailsView.h +++ b/lib-logs/inc/Logs/Details/DetailsView.h @@ -20,6 +20,7 @@ #include "Logs/Model/LogGroup.h" #include "Ux/SelectView.h" +#include "Logs/Model/NumberLogProvider.h" namespace Ui { @@ -52,12 +53,11 @@ namespace Logs public: /** * @brief Create log details view. - * @param[in] group Log group + * @param[in] number Number */ - DetailsView(Model::LogGroup *group); + explicit DetailsView(const char *number); private: - virtual ~DetailsView() override; virtual Evas_Object *onCreate(Evas_Object *parent) override; virtual void onCreated() override; virtual void onMenuPressed() override; @@ -68,22 +68,28 @@ namespace Logs void fillGenList(); void insertBasicInfoItem(); void insertActionItem(); - void insertLogGroupItem(); + void insertLogGroupList(); + void insertLogGroupItem(Model::LogGroup *group); + void insertLogDetailItems(Model::LogGroup *group); void insertLogDetailItem(Model::Log *log); - void insertLogDetailItems(); + + List::LogGroupItem *getLastGroupItem(); + void setLastGroupItem(List::LogGroupItem *groupItem); bool onSelected(Ux::SelectResults results); bool onCanceled(); - void onGroupChanged(int type); + + void onLogGroupInserted(Model::LogGroup *group); + void onGroupChanged(Model::LogGroup *group, List::LogGroupItem *groupItem, int type); void onLogAdded(Model::Log *log); void onLogRemoved(LogDetailItem *logItem); Model::LogGroup *m_Group; + Model::NumberLogProvider m_LogProvider; Ui::Genlist *m_Genlist; BasicInfoItem *m_BasicInfoItem; ActionItem *m_ActionItem; - List::LogGroupItem *m_GroupItem; - Model::LogGroup::ChangeCbHandle m_GroupChangeCbHandle; + List::LogGroupItem *m_LastGroupItem; }; } } diff --git a/lib-logs/inc/Logs/Model/Log.h b/lib-logs/inc/Logs/Model/Log.h index f346c45..3dd8bb5 100644 --- a/lib-logs/inc/Logs/Model/Log.h +++ b/lib-logs/inc/Logs/Model/Log.h @@ -139,9 +139,13 @@ namespace Logs */ void updateContactRecord(); /** - * @return Remove log from database + * @brief Remove log from database */ void remove(); + /** + * @brief Called when Log is destroyed + */ + void onDestroy(); private: contacts_record_h getContactRecord(); diff --git a/lib-logs/inc/Logs/Model/LogProvider.h b/lib-logs/inc/Logs/Model/LogProvider.h index 5d1be55..aeda679 100644 --- a/lib-logs/inc/Logs/Model/LogProvider.h +++ b/lib-logs/inc/Logs/Model/LogProvider.h @@ -118,16 +118,18 @@ namespace Logs */ static bool compareDate(const tm &firstDate, const tm &secondDate); + protected: + virtual bool shouldGroupLogs(Log &log, Log &prevLog); + virtual contacts_filter_h getFilter(); + private: void fillList(); size_t fillGroupList(LogIterator begin, LogIterator end); - bool shouldGroupLogs(Log &log, Log &prevLog); bool mergeGroup(GroupIterator group); LogIterator updateLogs(); void updateGroups(LogIterator newBegin, LogIterator newEnd); - contacts_filter_h getFilter(); contacts_list_h fetchLogList(); void onLogsChanged(const char *viewUri); diff --git a/lib-logs/inc/Logs/Model/NumberLogProvider.h b/lib-logs/inc/Logs/Model/NumberLogProvider.h new file mode 100644 index 0000000..b9735d0 --- /dev/null +++ b/lib-logs/inc/Logs/Model/NumberLogProvider.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016 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_MODEL_NUMBER_LOG_PROVIDER_H +#define LOGS_MODEL_NUMBER_LOG_PROVIDER_H + +#include "Logs/Model/LogProvider.h" + +namespace Logs +{ + namespace Model + { + /** + * @brief Provides list of logs by number + */ + class NumberLogProvider : public LogProvider + { + public: + /** + * @brief Create Number log provider. + * @param[in] number Log number + */ + explicit NumberLogProvider(std::string number); + + private: + virtual contacts_filter_h getFilter() override; + virtual bool shouldGroupLogs(Log &log, Log &prevLog) override; + + std::string m_Number; + }; + } +} + +#endif /* LOGS_MODEL_NUMBER_LOG_PROVIDER_H */ diff --git a/lib-logs/src/Logs/Details/ActionItem.cpp b/lib-logs/src/Logs/Details/ActionItem.cpp index 23fa5f3..d703411 100644 --- a/lib-logs/src/Logs/Details/ActionItem.cpp +++ b/lib-logs/src/Logs/Details/ActionItem.cpp @@ -40,7 +40,7 @@ namespace } ActionItem::ActionItem(LogGroup *group) - : m_Group(group) + : m_Group(group) { m_Log = m_Group->getLogList().back(); m_GroupChangeCbHandle = m_Group->addChangeCallback(std::bind(&ActionItem::onGroupChanged, this, _1)); @@ -53,6 +53,16 @@ ActionItem::~ActionItem() } } +void ActionItem::updateGroup(LogGroup *group) +{ + m_Group = group; + if (m_Group) { + m_Log = m_Group->getLogList().back(); + m_GroupChangeCbHandle = m_Group->addChangeCallback(std::bind(&ActionItem::onGroupChanged, this, _1)); + elm_genlist_item_fields_update(getObjectItem(), PART_NUMBER_TYPE, ELM_GENLIST_ITEM_FIELD_TEXT); + } +} + Elm_Genlist_Item_Class *ActionItem::getItemClass() const { static Elm_Genlist_Item_Class itc = createItemClass(LOGS_DETAILS_ACTION_ITEM_STYLE); @@ -149,10 +159,7 @@ void ActionItem::onButtonPressed(Evas_Object *button, void *eventInfo) void ActionItem::onGroupChanged(int type) { - if (type & LogGroup::ChangeRemoved) { - m_Group = nullptr; - delete this; - } else { + if (!(type & LogGroup::ChangeRemoved)) { m_Log = m_Group->getLogList().back(); elm_genlist_item_fields_update(getObjectItem(), PART_NUMBER_TYPE, ELM_GENLIST_ITEM_FIELD_TEXT); } diff --git a/lib-logs/src/Logs/Details/BasicInfoItem.cpp b/lib-logs/src/Logs/Details/BasicInfoItem.cpp index 80e4e78..c992a28 100644 --- a/lib-logs/src/Logs/Details/BasicInfoItem.cpp +++ b/lib-logs/src/Logs/Details/BasicInfoItem.cpp @@ -47,11 +47,21 @@ BasicInfoItem::~BasicInfoItem() } } + void BasicInfoItem::setBackCallback(BackCallback callback) { m_OnBackPressed = std::move(callback); } +void BasicInfoItem::updateGroup(LogGroup *group) +{ + m_Group = group; + if (m_Group) { + m_Log = m_Group->getLogList().back(); + m_GroupChangeCbHandle = m_Group->addChangeCallback(std::bind(&BasicInfoItem::onGroupChanged, this, _1)); + } +} + Elm_Genlist_Item_Class *BasicInfoItem::getItemClass() const { static Elm_Genlist_Item_Class itc = createItemClass(LOGS_DETAILS_ITEM_STYLE); @@ -163,10 +173,7 @@ void BasicInfoItem::onUpdatePressed() void BasicInfoItem::onGroupChanged(int type) { - if (type & LogGroup::ChangeRemoved) { - m_Group = nullptr; - delete this; - } else { + if (!(type & LogGroup::ChangeRemoved)) { m_Log = m_Group->getLogList().back(); if (type & LogGroup::ChangePerson) { elm_genlist_item_fields_update(getObjectItem(), STATE_SAVED, ELM_GENLIST_ITEM_FIELD_STATE); @@ -180,3 +187,4 @@ void BasicInfoItem::onGroupChanged(int type) } } } + diff --git a/lib-logs/src/Logs/Details/DetailsView.cpp b/lib-logs/src/Logs/Details/DetailsView.cpp index fe2fe17..751b8d4 100644 --- a/lib-logs/src/Logs/Details/DetailsView.cpp +++ b/lib-logs/src/Logs/Details/DetailsView.cpp @@ -37,9 +37,13 @@ using namespace Logs::List; using namespace Ux; using namespace std::placeholders; -DetailsView::DetailsView(LogGroup *group) - : m_Group(group), m_Genlist(nullptr), m_BasicInfoItem(nullptr), m_ActionItem(nullptr), - m_GroupItem(nullptr) +DetailsView::DetailsView(const char *number) + : m_Group(nullptr) + , m_LogProvider(number) + , m_Genlist(nullptr) + , m_BasicInfoItem(nullptr) + , m_ActionItem(nullptr) + , m_LastGroupItem(nullptr) { auto strings = Common::getSelectViewStrings(); strings.buttonDone = "IDS_TPLATFORM_ACBUTTON_DELETE_ABB"; @@ -48,19 +52,6 @@ DetailsView::DetailsView(LogGroup *group) setSelectCallback(std::bind(&DetailsView::onSelected, this, _1)); setCancelCallback(std::bind(&DetailsView::onCanceled, this)); - m_Group->setLogAddCallback(std::bind(&DetailsView::onLogAdded, this, _1)); - m_GroupChangeCbHandle = m_Group->addChangeCallback(std::bind(&DetailsView::onGroupChanged, this, _1)); -} - -DetailsView::~DetailsView() -{ - if (m_Group) { - for (auto &log : m_Group->getLogList()) { - log->unsetRemoveCallback(); - } - m_Group->unsetLogAddCallback(); - m_Group->removeChangeCallback(m_GroupChangeCbHandle); - } } Evas_Object *DetailsView::onCreate(Evas_Object *parent) @@ -73,6 +64,8 @@ Evas_Object *DetailsView::onCreate(Evas_Object *parent) void DetailsView::onCreated() { + m_LogProvider.setInsertCallback(std::bind(&DetailsView::onLogGroupInserted, this, _1)); + m_Group = m_LogProvider.getLogGroupList().back().get(); fillGenList(); } @@ -118,8 +111,7 @@ void DetailsView::fillGenList() insertBasicInfoItem(); insertActionItem(); } - insertLogGroupItem(); - insertLogDetailItems(); + insertLogGroupList(); } void DetailsView::insertBasicInfoItem() @@ -138,27 +130,64 @@ void DetailsView::insertActionItem() elm_genlist_item_select_mode_set(m_ActionItem->getObjectItem(), ELM_OBJECT_SELECT_MODE_NONE); } -void DetailsView::insertLogGroupItem() +void DetailsView::insertLogGroupList() +{ + for (auto &&group : m_LogProvider.getLogGroupList()) { + insertLogGroupItem(group.get()); + insertLogDetailItems(group.get()); + } +} + +void DetailsView::insertLogGroupItem(LogGroup *group) +{ + Log *log = group->getLogList().back(); + LogGroupItem *groupItem = new LogGroupItem(log->getTime()); + m_Genlist->insert(groupItem, nullptr, getLastGroupItem()); + elm_genlist_item_select_mode_set(groupItem->getObjectItem(), ELM_OBJECT_SELECT_MODE_NONE); + setLastGroupItem(groupItem); + group->setLogAddCallback(std::bind(&DetailsView::onLogAdded, this, _1)); + group->addChangeCallback(std::bind(&DetailsView::onGroupChanged, this, group, groupItem, _1)); +} + +void DetailsView::insertLogDetailItems(LogGroup *group) { - Log *log = m_Group->getLogList().back(); - m_GroupItem = new LogGroupItem(log->getTime()); - m_Genlist->insert(m_GroupItem); - elm_genlist_item_select_mode_set(m_GroupItem->getObjectItem(), ELM_OBJECT_SELECT_MODE_NONE); + for (auto &log : group->getLogList()) { + insertLogDetailItem(log); + } } void DetailsView::insertLogDetailItem(Log *log) { LogDetailItem *logItem = new LogDetailItem(log); - m_Genlist->insert(logItem, m_GroupItem, m_GroupItem, Ui::Genlist::After); + m_Genlist->insert(logItem, getLastGroupItem(), *getLastGroupItem()->begin()); log->setRemoveCallback(std::bind(&DetailsView::onLogRemoved, this, logItem)); addSelectItem(logItem); } -void DetailsView::insertLogDetailItems() +LogGroupItem *DetailsView::getLastGroupItem() { - for (auto &log : m_Group->getLogList()) { - insertLogDetailItem(log); + if (!m_LastGroupItem) { + for (auto &&item : *m_Genlist) { + if (((Ui::GenlistItem *)item)->isGroupItem()) { + setLastGroupItem(dynamic_cast(item)); + break; + } + } } + + return m_LastGroupItem; +} + +void DetailsView::setLastGroupItem(LogGroupItem *groupItem) +{ + if (m_LastGroupItem) { + m_LastGroupItem->setDestroyCallback(nullptr); + } + + m_LastGroupItem = groupItem; + m_LastGroupItem->setDestroyCallback([this] { + m_LastGroupItem = nullptr; + }); } bool DetailsView::onSelected(SelectResults results) @@ -177,11 +206,29 @@ bool DetailsView::onCanceled() return false; } -void DetailsView::onGroupChanged(int type) +void DetailsView::onLogGroupInserted(LogGroup *group) +{ + if (m_Genlist) { + insertLogGroupItem(group); + insertLogDetailItems(group); + } +} + +void DetailsView::onGroupChanged(LogGroup *group, LogGroupItem *groupItem, int type) { if (type & LogGroup::ChangeRemoved) { - getPage()->close(); - m_Group = nullptr; + if (m_LogProvider.getLogGroupList().empty()) { + m_BasicInfoItem->updateGroup(nullptr); + m_ActionItem->updateGroup(nullptr); + getPage()->close(); + return; + } + delete groupItem; + if (m_Group == group) { + m_Group = m_LogProvider.getLogGroupList().back().get(); + m_BasicInfoItem->updateGroup(m_Group); + m_ActionItem->updateGroup(m_Group); + } } } @@ -194,4 +241,5 @@ void DetailsView::onLogRemoved(LogDetailItem *logItem) { removeSelectItem(logItem); delete logItem; + } diff --git a/lib-logs/src/Logs/List/LogItem.cpp b/lib-logs/src/Logs/List/LogItem.cpp index 1a32e2d..ba1ccfa 100644 --- a/lib-logs/src/Logs/List/LogItem.cpp +++ b/lib-logs/src/Logs/List/LogItem.cpp @@ -152,8 +152,7 @@ void LogItem::onInfoIconPressed() if (!navigator) { return; } - - navigator->navigateTo(new DetailsView(getGroup())); + navigator->navigateTo(new DetailsView(getGroup()->getLogList().back()->getNumber())); } Evas_Object *LogItem::createThumbnail(Evas_Object *parent) diff --git a/lib-logs/src/Logs/Model/Log.cpp b/lib-logs/src/Logs/Model/Log.cpp index 86644d1..12d40c3 100644 --- a/lib-logs/src/Logs/Model/Log.cpp +++ b/lib-logs/src/Logs/Model/Log.cpp @@ -34,9 +34,7 @@ Log::~Log() if (m_Group) { m_Group->removeLog(this); } - if (m_OnRemoved) { - m_OnRemoved(); - } + contacts_record_destroy(m_LogRecord, true); if (m_ContactRecord) { contacts_record_destroy(m_ContactRecord, true); @@ -218,3 +216,10 @@ void Log::remove() { contacts_db_delete_record(_contacts_phone_log._uri, getId()); } + +void Log::onDestroy() +{ + if (m_OnRemoved) { + m_OnRemoved(); + } +} diff --git a/lib-logs/src/Logs/Model/LogProvider.cpp b/lib-logs/src/Logs/Model/LogProvider.cpp index 3129e18..148934f 100644 --- a/lib-logs/src/Logs/Model/LogProvider.cpp +++ b/lib-logs/src/Logs/Model/LogProvider.cpp @@ -81,6 +81,38 @@ void LogProvider::unsetInsertCallback() m_InsertCallback = nullptr; } +bool LogProvider::compareDate(const tm &firstDate, const tm &secondDate) +{ + if (firstDate.tm_year == secondDate.tm_year && + firstDate.tm_mon == secondDate.tm_mon && + firstDate.tm_mday == secondDate.tm_mday) { + return true; + } + return false; +} + +bool LogProvider::shouldGroupLogs(Log &log, Log &prevLog) +{ + int type = log.getType(); + return (type == prevLog.getType() + && type != CONTACTS_PLOG_TYPE_VOICE_INCOMING_UNSEEN + && type != CONTACTS_PLOG_TYPE_VOICE_INCOMING_SEEN + && strcmp(log.getNumber(), prevLog.getNumber()) == 0 + && compareDate(log.getTime(), prevLog.getTime())); +} + +contacts_filter_h LogProvider::getFilter() +{ + contacts_filter_h filter = nullptr; + contacts_filter_create(_contacts_phone_log._uri, &filter); + + contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMING); + contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND); + contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED); + + return filter; +} + void LogProvider::fillList() { contacts_list_h list = fetchLogList(); @@ -120,26 +152,6 @@ size_t LogProvider::fillGroupList(LogIterator begin, LogIterator end) return newGroupsCount; } -bool LogProvider::shouldGroupLogs(Log &log, Log &prevLog) -{ - int type = log.getType(); - return (type == prevLog.getType() - && type != CONTACTS_PLOG_TYPE_VOICE_INCOMING_UNSEEN - && type != CONTACTS_PLOG_TYPE_VOICE_INCOMING_SEEN - && strcmp(log.getNumber(), prevLog.getNumber()) == 0 - && compareDate(log.getTime(), prevLog.getTime())); -} - -bool LogProvider::compareDate(const tm &firstDate, const tm &secondDate) -{ - if (firstDate.tm_year == secondDate.tm_year && - firstDate.tm_mon == secondDate.tm_mon && - firstDate.tm_mday == secondDate.tm_mday) { - return true; - } - return false; -} - bool LogProvider::mergeGroup(GroupIterator group) { if (group == m_Groups.begin()) { @@ -156,41 +168,6 @@ bool LogProvider::mergeGroup(GroupIterator group) return false; } -contacts_filter_h LogProvider::getFilter() -{ - contacts_filter_h filter = nullptr; - contacts_filter_create(_contacts_phone_log._uri, &filter); - - contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_GREATER_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VOICE_INCOMING); - contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND); - contacts_filter_add_int(filter, _contacts_phone_log.log_type, CONTACTS_MATCH_LESS_THAN_OR_EQUAL, CONTACTS_PLOG_TYPE_VIDEO_BLOCKED); - - return filter; -} - -contacts_list_h LogProvider::fetchLogList() -{ - contacts_list_h list = nullptr; - contacts_query_h query = nullptr; - contacts_filter_h filter = getFilter(); - - contacts_query_create(_contacts_phone_log._uri, &query); - contacts_query_set_filter(query, filter); - contacts_query_set_sort(query, _contacts_phone_log.log_time, true); - contacts_db_get_records_with_query(query, 0, 0, &list); - - contacts_filter_destroy(filter); - contacts_query_destroy(query); - - return list; -} - -void LogProvider::onLogsChanged(const char *viewUri) -{ - LogIterator newBegin = updateLogs(); - updateGroups(newBegin, m_Logs.end()); -} - LogProvider::LogIterator LogProvider::updateLogs() { contacts_list_h list = fetchLogList(); @@ -204,6 +181,7 @@ LogProvider::LogIterator LogProvider::updateLogs() Log *log = (Log *)(*oldIt); if (id != log->getId()) { + log->onDestroy(); delete *oldIt; oldIt = m_Logs.erase(oldIt); } else { @@ -214,6 +192,7 @@ LogProvider::LogIterator LogProvider::updateLogs() } while (oldIt != m_Logs.end()) { + ((Log *)*oldIt)->onDestroy(); delete *oldIt; oldIt = m_Logs.erase(oldIt); } @@ -251,8 +230,16 @@ void LogProvider::updateGroups(LogIterator newBegin, LogIterator newEnd) wasDeleted = false; } - (*updateIt)->onChange(); - updateIt = isEmpty ? m_Groups.erase(updateIt) : ++updateIt; + if (isEmpty) { + LogGroup *group = updateIt->release(); + updateIt = m_Groups.erase(updateIt); + group->onChange(); + delete group; + } else { + (*updateIt)->onChange(); + ++updateIt; + } + --updateCount; } @@ -264,6 +251,29 @@ void LogProvider::updateGroups(LogIterator newBegin, LogIterator newEnd) } } +contacts_list_h LogProvider::fetchLogList() +{ + contacts_list_h list = nullptr; + contacts_query_h query = nullptr; + contacts_filter_h filter = getFilter(); + + contacts_query_create(_contacts_phone_log._uri, &query); + contacts_query_set_filter(query, filter); + contacts_query_set_sort(query, _contacts_phone_log.log_time, true); + contacts_db_get_records_with_query(query, 0, 0, &list); + + contacts_filter_destroy(filter); + contacts_query_destroy(query); + + return list; +} + +void LogProvider::onLogsChanged(const char *viewUri) +{ + LogIterator newBegin = updateLogs(); + updateGroups(newBegin, m_Logs.end()); +} + void LogProvider::onContactChanged(const char *viewUri) { contacts_changed_e changeType; @@ -309,4 +319,3 @@ void LogProvider::onContactChanged(const char *viewUri) contacts_list_destroy(list, true); } - diff --git a/lib-logs/src/Logs/Model/NumberLogProvider.cpp b/lib-logs/src/Logs/Model/NumberLogProvider.cpp new file mode 100644 index 0000000..fec413d --- /dev/null +++ b/lib-logs/src/Logs/Model/NumberLogProvider.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2016 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/Model/NumberLogProvider.h" + +using namespace Logs::Model; + +NumberLogProvider::NumberLogProvider(std::string number) + : m_Number(std::move(number)) +{ +} + +bool NumberLogProvider::shouldGroupLogs(Log &log, Log &prevLog) +{ + return compareDate(log.getTime(), prevLog.getTime()); +} + +contacts_filter_h NumberLogProvider::getFilter() +{ + contacts_filter_h filter = LogProvider::getFilter(); + contacts_filter_add_operator(filter, CONTACTS_FILTER_OPERATOR_AND); + contacts_filter_add_str(filter, _contacts_phone_log.address, CONTACTS_MATCH_EXACTLY, m_Number.c_str()); + + return filter; +} -- 2.7.4