*
*/
-#include "Contacts/Common/Chooser.h"
+#include "Contacts/Chooser/ChooserView.h"
+#include "Contacts/Chooser/ContactsGroupsNavigator.h"
+
#include "Contacts/Details/DetailsView.h"
+#include "Contacts/Groups/GroupsView.h"
#include "Contacts/List/ListView.h"
#include "Contacts/Settings/ExportController.h"
+
#include "Common/Actions.h"
#include "Common/Database/Queries.h"
using namespace Common::Database;
using namespace Contacts;
-using namespace Contacts::Common;
+using namespace Contacts::Chooser;
using namespace Contacts::List;
using namespace Contacts::Details;
using namespace Ux;
using namespace std::placeholders;
-Chooser::Chooser(SelectMode selectMode, ResultType resultType, size_t selectLimit)
+ChooserView::ChooserView(SelectMode selectMode, ResultType resultType, size_t selectLimit)
: m_SelectMode(selectMode), m_ResultType(resultType),
- m_FilterType(getFilterType(m_ResultType)), m_SelectLimit(selectLimit)
+ m_FilterType(getFilterType(m_ResultType)), m_SelectLimit(selectLimit),
+ m_ListView(nullptr), m_ContactsGroups(nullptr)
{
}
-void Chooser::setSelectCallback(SelectCallback callback)
+void ChooserView::setSelectCallback(SelectCallback callback)
{
m_OnSelected = std::move(callback);
}
-void Chooser::onCreated()
+void ChooserView::onCreated()
{
m_ListView = new ListView(m_FilterType);
m_ListView->setSelectMode(m_SelectMode);
m_ListView->setSelectLimit(m_SelectLimit);
+ m_ListView->setCancelCallback([this] {
+ getPage()->close();
+ return false;
+ });
switch (m_ResultType) {
case ResultPerson:
- m_ListView->setSelectCallback(std::bind(&Chooser::onSelected, this, _1));
+ m_ListView->setSelectCallback(std::bind(&ChooserView::onSelected, this, _1));
break;
case ResultNumber:
case ResultEmail:
if (m_SelectMode == SelectSingle) {
- m_ListView->setSelectCallback(std::bind(&Chooser::onSinglePersonSelected, this, _1));
+ m_ListView->setSelectCallback(std::bind(&ChooserView::onSinglePersonSelected, this, _1));
} else {
- m_ListView->setCheckCallback(std::bind(&Chooser::onPersonChecked, this, _1, _2, _3));
- m_ListView->setSelectCallback(std::bind(&Chooser::onSelected, this, _1));
+ m_ListView->setCheckCallback(std::bind(&ChooserView::onPersonChecked, this, _1, _2, _3));
+ m_ListView->setSelectCallback(std::bind(&ChooserView::onSelected, this, _1));
}
break;
case ResultVcard:
- m_ListView->setSelectCallback(std::bind(&Chooser::onSelectedForVcard, this, _1));
+ m_ListView->setSelectCallback(std::bind(&ChooserView::onSelectedForVcard, this, _1));
break;
case ResultAction:
- m_ListView->setSelectCallback(std::bind(&Chooser::onSelectedForAction, this, _1));
+ m_ListView->setSelectCallback(std::bind(&ChooserView::onSelectedForAction, this, _1));
break;
default:
break;
}
-
- navigateTo(m_ListView);
}
-void Chooser::onPageAttached(Ui::NavigatorPage *page)
+void ChooserView::onPageAttached(Ui::NavigatorPage *page)
{
- page->setTitleVisibility(false);
+ if (m_SelectMode == SelectSingle) {
+ page->setTitleVisibility(false);
+ navigateTo(m_ListView);
+ } else {
+ m_ContactsGroups = new ContactsGroupsNavigator();
+ navigateTo(m_ContactsGroups);
+
+ m_ContactsGroups->addContactsView(m_ListView);
+ m_ContactsGroups->addGroupsView(new Groups::GroupsView());
+ }
}
-bool Chooser::onPersonChecked(SelectItem *item, bool isChecked, bool isSelectAll)
+bool ChooserView::onPersonChecked(SelectItem *item, bool isChecked, bool isSelectAll)
{
if (isChecked) {
if (item->hasCustomResult()) {
: CONTACTS_PERSON_PROPERTY_EMAIL;
contacts_person_get_default_property(property, item->getSelectResult().value.id, &id);
item->setCustomResult({ m_ResultType, id });
+
+ if (m_ContactsGroups) {
+ m_ContactsGroups->addSelectedItem(item);
+ }
return true;
}
- return selectSingleResult(item->getSelectResult(), [item](SelectResults results) {
+ return selectSingleResult(item->getSelectResult(), [this, item](SelectResults results) {
item->setCustomResult(results.front());
item->setChecked(true);
+
+ if (m_ContactsGroups) {
+ m_ContactsGroups->addSelectedItem(item);
+ }
return true;
});
}
item->unsetCustomResult();
+ if (m_ContactsGroups) {
+ m_ContactsGroups->removeSelectedItem(item);
+ }
+
return true;
}
-bool Chooser::onSinglePersonSelected(SelectResults results)
+bool ChooserView::onSinglePersonSelected(SelectResults results)
{
- return selectSingleResult(results.front(), std::bind(&Chooser::onSelected, this, _1));
+ return selectSingleResult(results.front(), std::bind(&ChooserView::onSelected, this, _1));
}
-bool Chooser::onSelectedForAction(SelectResults results)
+bool ChooserView::onSelectedForAction(SelectResults results)
{
selectSingleResult(results.front(), [this](SelectResults results) {
SelectResult result = results.front();
return false;
}
-bool Chooser::onSelectedForVcard(SelectResults results)
+bool ChooserView::onSelectedForVcard(SelectResults results)
{
using namespace Settings;
return false;
}
-bool Chooser::onSelected(SelectResults results)
+bool ChooserView::onSelected(SelectResults results)
{
if (!m_OnSelected || m_OnSelected(std::move(results))) {
getPage()->close();
return false;
}
-bool Chooser::selectSingleResult(SelectResult person, SelectCallback callback)
+bool ChooserView::selectSingleResult(SelectResult person, SelectCallback callback)
{
SelectResult result = getSingleResult(person.value.id);
if (result.value.id > 0) {
DetailsView::Type(person.type), m_FilterType);
view->setSelectMode(SelectSingle);
view->setSelectCallback(callback);
- navigateTo(view);
+ getNavigator()->navigateTo(view);
return false;
}
-SelectResult Chooser::getSingleResult(int personId)
+SelectResult ChooserView::getSingleResult(int personId)
{
int count = 0;
return result;
}
-int Chooser::getResultCount(int personId, ResultType resultType, int *resultId)
+int ChooserView::getResultCount(int personId, ResultType resultType, int *resultId)
{
const char *uri = nullptr;
unsigned personIdProp = 0;
return count;
}
-std::string Chooser::getResultValue(SelectResult result)
+std::string ChooserView::getResultValue(SelectResult result)
{
std::string value;
return value;
}
-int Chooser::getFilterType(ResultType resultType)
+int ChooserView::getFilterType(ResultType resultType)
{
switch (resultType) {
case ResultNumber: