#include "Contacts/Chooser/ChooserView.h"
#include "Contacts/Chooser/ContactsGroupsNavigator.h"
-#include "Contacts/Details/DetailsView.h"
#include "Contacts/Groups/GroupsView.h"
+#include "Contacts/Groups/Model/Group.h"
+#include "Contacts/Groups/Model/MembersProvider.h"
+
#include "Contacts/List/ListView.h"
+#include "Contacts/List/PersonItem.h"
+#include "Contacts/List/Model/Person.h"
+
+#include "Contacts/Details/DetailsView.h"
#include "Contacts/Settings/ExportController.h"
#include "Common/Actions.h"
#include "Ux/SelectItem.h"
#include "Utils/Logger.h"
+#include <app_i18n.h>
+#include <notification.h>
+
+#define POPUP_BUFFER_SIZE 256
+
using namespace Common;
using namespace Common::Database;
using namespace Contacts::Chooser;
using namespace Contacts::List;
using namespace Contacts::Details;
+using namespace Contacts::Groups;
+using namespace Contacts::Groups::Model;
using namespace Ux;
using namespace std::placeholders;
SelectView *ChooserView::createGroupsView()
{
- return new Groups::GroupsView();
+ auto view = new GroupsView();
+ view->setSelectMode(SelectSingle);
+ view->setSelectCallback([this](SelectResults results) {
+ auto group = static_cast<Group *>(results.front().value.data);
+ auto view = createMembersView(group->getId());
+
+ navigateTo(view);
+ view->getPage()->setTitleVisibility(false);
+ return false;
+ });
+ return view;
+}
+
+SelectView *ChooserView::createMembersView(int groupId)
+{
+ auto view = new ListView(new MembersProvider(groupId, MembersProvider::ModeDefault, m_FilterType));
+ view->setSelectMode(SelectMulti);
+ view->setSectionVisibility(ListView::SectionFavorites, false);
+ view->setFillFinishCallback([this, view] {
+ checkMembers(view);
+ if (m_SelectLimit) {
+ size_t selectCount = m_ContactsView->getSelectCount() - view->getSelectCount();
+ view->setSelectLimit(m_SelectLimit - selectCount);
+ view->setLimitCallback([this] {
+ char buffer[POPUP_BUFFER_SIZE];
+ snprintf(buffer, sizeof(buffer), _("IDS_PB_POP_THE_MAXIMUM_NUMBER_OF_ITEMS_THAT_CAN_BE_SELECTED_HPD_HAS_BEEN_EXCEEDED"), m_SelectLimit);
+ notification_status_message_post(buffer);
+ return false;
+ });
+ }
+ });
+
+ if (m_ResultType == ResultPerson || m_ResultType == ResultVcard) {
+ view->setCheckCallback(std::bind(&ChooserView::onMemberChecked, this, _1, _2, _3));
+ } else {
+ view->setCheckCallback(std::bind(&ChooserView::onMemberCheckedForData, this, _1, _2, _3));
+ }
+
+ return view;
+}
+
+void ChooserView::checkMembers(SelectView *membersView)
+{
+ auto &members = membersView->getSelectItems();
+ auto &persons = m_ContactsView->getSelectItems();
+
+ auto memberIt = members.begin();
+ auto personIt = persons.begin();
+ auto getPersonId = [](SelectItem *item) {
+ return static_cast<PersonItem *>(item)->getPerson().getId();
+ };
+
+ while (memberIt != members.end() && personIt != persons.end()) {
+ if (getPersonId(*memberIt) == getPersonId(*personIt)) {
+ (*memberIt)->setChecked((*personIt)->isChecked());
+ (*memberIt)->setCustomResult({ 0, *personIt });
+ ++memberIt;
+ }
+ ++personIt;
+ }
+}
+
+bool ChooserView::onMemberChecked(SelectItem *item, bool isChecked, bool isSelectAll)
+{
+ if (!item->hasCustomResult()) {
+ return true;
+ }
+
+ auto personItem = (PersonItem *) item->getSelectResult().value.data;
+ return personItem->setChecked(isChecked);
+}
+
+bool ChooserView::onMemberCheckedForData(SelectItem *item, bool isChecked, bool isSelectAll)
+{
+ if (!item->hasCustomResult()) {
+ return true;
+ }
+
+ auto personItem = (PersonItem *) item->getSelectResult().value.data;
+ if (!isChecked) {
+ return personItem->setChecked(false);
+ }
+ if (personItem->hasCustomResult()) {
+ return true;
+ }
+
+ return selectSingleResult(personItem->getSelectResult(), isSelectAll,
+ [this, item, personItem](SelectResults results) {
+ onSingleResultSelected(std::move(results), personItem);
+ item->setChecked(true);
+ return true;
+ });
}
-bool ChooserView::onPersonChecked(Ux::SelectItem *item, bool isChecked, bool isSelectAll)
+bool ChooserView::onPersonChecked(SelectItem *item, bool isChecked, bool isSelectAll)
{
if (isChecked) {
m_ContactsGroups->addSelectedItem(item);