m_GroupsItem = new GenGroupItem("IDS_PB_OPT_GROUPS");
m_Genlist->insert(m_GroupsItem);
- for (auto &&data : m_Provider.getDataList()) {
- GroupItem *groupItem = createItem(*static_cast<Group *>(data));
- const char *name = groupItem->getGroup().getName();
- if (safeCmp(name, "Co-workers") || safeCmp(name, "Family")
- || safeCmp(name, "Friends")) {
- m_MainItems.push_back(groupItem);
+
+ m_Provider.initialize([this] {
+ for (auto &&data : m_Provider.getDataList()) {
+ Group &group = static_cast<Group &>(*data);
+ GroupItem *groupItem = createItem(group);
+
+ const char *name = group.getName();
+ if (safeCmp(name, "Co-workers")
+ || safeCmp(name, "Family")
+ || safeCmp(name, "Friends")) {
+ m_MainItems.push_back(groupItem);
+ }
+
+ insertItem(groupItem);
+ addSelectItem(groupItem);
}
- insertItem(groupItem);
- }
+ });
updateCreateItem();
return m_Genlist->getEvasObject();
}
}
-void GroupsView::onInserted(::Model::DataItem &data)
+void GroupsView::onInserted(::Model2::DataItem &data)
{
Group &group = static_cast<Group &>(data);
GroupItem *item = createItem(group);
insertItem(item);
+ addSelectItem(item);
if (m_NewGroupId == group.getId()) {
m_NewGroupId = 0;
void GroupsView::insertItem(GroupItem *item)
{
m_GroupsItem->insertSubItem(item, getNextItem(item->getGroup()));
- addSelectItem(item);
}
void GroupsView::updateItem(GroupItem *item, int changes)
setSelectCallback(nullptr);
for (auto &&groupItem : m_MainItems) {
groupItem->setExcluded(false);
- m_GroupsItem->insertSubItem(groupItem, getNextItem(groupItem->getGroup()));
+ insertItem(groupItem);
}
return false;
using namespace Contacts::Groups::Model;
using namespace Common::Database;
-using namespace Model;
+using namespace Model2;
GroupsProvider::GroupsProvider()
- : m_DbVersion(0), m_MembersDbVersion(0), m_IsFilled(false)
+ : m_DbVersion(0), m_MembersDbVersion(0), m_UpdateType(UpdateNone)
{
}
GroupsProvider::~GroupsProvider()
{
- clearDataList();
+ contacts_db_remove_changed_cb(_contacts_group._uri,
+ makeCallbackWithLastParam(&GroupsProvider::onGroupsChanged), this);
+ contacts_db_remove_changed_cb(_contacts_group_relation._uri,
+ makeCallbackWithLastParam(&GroupsProvider::onMembersChanged), this);
}
-const DataProvider::DataList &GroupsProvider::getDataList()
+void GroupsProvider::onInitialize()
{
- if (!m_IsFilled) {
- contacts_db_get_current_version(&m_DbVersion);
- m_MembersDbVersion = m_DbVersion;
- contacts_db_add_changed_cb(_contacts_group._uri,
- makeCallbackWithLastParam(&GroupsProvider::onChanged), this);
- contacts_db_add_changed_cb(_contacts_group_relation._uri,
- makeCallbackWithLastParam(&GroupsProvider::onMembersChanged), this);
-
- contacts_list_h list = nullptr;
- contacts_db_get_all_records(_contacts_group._uri, 0, 0, &list);
- for (auto &&record : makeRange(list)) {
- m_List.push_back(createGroup(record));
- }
- contacts_list_destroy(list, false);
- m_IsFilled = true;
+ contacts_db_get_current_version(&m_DbVersion);
+ m_MembersDbVersion = m_DbVersion;
+ contacts_db_add_changed_cb(_contacts_group._uri,
+ makeCallbackWithLastParam(&GroupsProvider::onGroupsChanged), this);
+ contacts_db_add_changed_cb(_contacts_group_relation._uri,
+ makeCallbackWithLastParam(&GroupsProvider::onMembersChanged), this);
+
+ contacts_list_h list = nullptr;
+ contacts_db_get_all_records(_contacts_group._uri, 0, 0, &list);
+
+ DataList dataList;
+ for (auto &&record : makeRange(list)) {
+ dataList.push_back(DataItemPtr(createGroup(record)));
}
- return m_List;
+ contacts_list_destroy(list, false);
+
+ onInitialized(std::move(dataList));
}
-void GroupsProvider::clearDataList()
+void GroupsProvider::onUpdate()
{
- contacts_db_remove_changed_cb(_contacts_group._uri,
- makeCallbackWithLastParam(&GroupsProvider::onChanged), this);
- contacts_db_remove_changed_cb(_contacts_group_relation._uri,
- makeCallbackWithLastParam(&GroupsProvider::onMembersChanged), this);
+ onUpdateStarted();
+ int updateType = m_UpdateType;
+ m_UpdateType = UpdateNone;
- for (auto &&groupData : m_List) {
- delete groupData;
+ if (updateType & UpdateGroups) {
+ updateGroups();
+ }
+ if (updateType & UpdateMembers) {
+ updateMembers();
}
- m_List.clear();
- m_IsFilled = false;
+ onUpdateFinished();
}
-void GroupsProvider::onChanged(const char *uri)
+void GroupsProvider::updateGroups()
{
contacts_list_h changes = nullptr;
contacts_db_get_changes_by_version(_contacts_group_updated_info._uri, 0,
case CONTACTS_CHANGE_UPDATED:
{
auto groupIt = findGroup(groupId);
- if (groupIt != m_List.end()) {
+ if (groupIt != getDataList().end()) {
updateGroup(groupIt);
}
break;
case CONTACTS_CHANGE_DELETED:
{
auto groupIt = findGroup(groupId);
- if (groupIt != m_List.end()) {
+ if (groupIt != getDataList().end()) {
deleteGroup(groupIt);
}
break;
contacts_list_destroy(changes, true);
}
-void GroupsProvider::onMembersChanged(const char *uri)
+void GroupsProvider::updateMembers()
{
contacts_list_h changes = nullptr;
contacts_db_get_changes_by_version(_contacts_grouprel_updated_info._uri, 0,
for (auto &&record : makeRange(changes)) {
auto groupIt = findGroup(getRecordInt(record, _contacts_grouprel_updated_info.group_id));
- if (groupIt != m_List.end()) {
- Group *group = static_cast<Group *>(*groupIt);
+ if (groupIt != getDataList().end()) {
+ Group *group = static_cast<Group *>(groupIt->get());
group->updateMembersCount();
}
}
contacts_list_destroy(changes, true);
}
+void GroupsProvider::onGroupsChanged(const char *uri)
+{
+ m_UpdateType |= UpdateGroups;
+ update();
+}
+
+void GroupsProvider::onMembersChanged(const char *uri)
+{
+ m_UpdateType |= UpdateMembers;
+ update();
+}
+
void GroupsProvider::insertGroup(int id)
{
contacts_record_h record = nullptr;
contacts_db_get_record(_contacts_group._uri, id, &record);
if (record) {
- m_List.push_back(createGroup(record));
- onInserted(*m_List.back());
+ insertDataItem(DataItemPtr(createGroup(record)));
}
}
void GroupsProvider::updateGroup(DataList::const_iterator groupIt)
{
- Group *group = static_cast<Group *>(*groupIt);
+ Group *group = static_cast<Group *>(groupIt->get());
contacts_record_h record = nullptr;
contacts_db_get_record(_contacts_group._uri, group->getId(), &record);
group->update(record);
void GroupsProvider::deleteGroup(DataList::const_iterator groupIt)
{
- Group *group = static_cast<Group *>(*groupIt);
- m_List.erase(groupIt);
- group->onDeleted();
- delete group;
+ deleteDataItem(**groupIt);
}
Group *GroupsProvider::createGroup(contacts_record_h record)
DataProvider::DataList::const_iterator GroupsProvider::findGroup(int id)
{
- return std::find_if(m_List.begin(), m_List.end(),
- [id](DataItem *dataItem) {
- Group *group = static_cast<Group *>(dataItem);
+ return std::find_if(getDataList().begin(), getDataList().end(),
+ [id](const DataItemPtr &dataItem) {
+ Group *group = static_cast<Group *>(dataItem.get());
return group->getId() == id;
}
);