M changelog.md => changelog.md +2 -0
@@ 14,6 14,8 @@
* `[audio]` Enabled sounds priorities, looping and merging
* `[renderer]` Add drawing circles and arcs functionality.
* `[bluetooth]` Added scan and pairing support.
+* `[phonebook]` Scrolling contacts list with a particular letter - part 2.
+
### Changed
* `[special input]` Added emoji selector and changed special character selector.
M module-apps/application-phonebook/data/ContactsMap.hpp => module-apps/application-phonebook/data/ContactsMap.hpp +8 -1
@@ 3,11 3,17 @@
#include <cstdint>
#include <map>
-namespace phonebookContacMap
+namespace phonebookContactsMap
{
constexpr uint32_t NO_MATCH_FOUND = 0;
}
+enum class ContactQuerySection
+{
+ Favourites = 0,
+ Mixed,
+};
+
enum class ContactDisplayMode
{
Regular = 0,
@@ 24,4 30,5 @@ struct ContactsMapData
{
std::map<std::string, std::uint32_t> firstLetterDictionary;
std::uint32_t favouritesCount;
+ std::uint32_t itemCount;
};
M module-apps/application-phonebook/models/PhonebookModel.cpp => module-apps/application-phonebook/models/PhonebookModel.cpp +9 -9
@@ 26,6 26,12 @@ PhonebookModel::PhonebookModel(app::Application *app,
auto PhonebookModel::requestRecordsCount() -> unsigned int
{
+
+ auto dispMode = static_cast<ContactDisplayMode>(getDisplayMode());
+ if (dispMode == ContactDisplayMode::SortedByLetter) {
+ return letterMap.itemCount;
+ }
+
auto [code, msg] = DBServiceAPI::GetQueryWithReply(
application,
db::Interface::Name::Contact,
@@ 53,7 59,6 @@ void PhonebookModel::requestRecords(const uint32_t offset, const uint32_t limit)
query->setQueryListener(
db::QueryCallback::fromFunction([this](auto response) { return handleQueryResponse(response); }));
DBServiceAPI::GetQuery(application, db::Interface::Name::Contact, std::move(query));
- lastRequestedOffset = offset;
}
auto PhonebookModel::requestLetterMap() -> ContactsMapData
@@ 117,7 122,7 @@ auto PhonebookModel::getItem(gui::Order order) -> gui::ListItem *
auto item = new gui::PhonebookItem();
item->setContact(contact);
- item->setLabelMarkerDisplayMode(getLabelMarkerDisplayMode());
+ item->setLabelMarkerDisplayMode(getLabelMarkerDisplayMode(contact->contactPosOnList));
item->activatedCallback = [this, item, contact](gui::Item &) {
if (messagesSelectCallback && messagesSelectCallback(item)) {
return true;
@@ 170,14 175,9 @@ auto PhonebookModel::handleQueryResponse(db::QueryResult *queryResult) -> bool
return this->updateRecords(std::move(records));
}
-auto PhonebookModel::getLastRequestedOffset() -> std::uint32_t
-{
- return lastRequestedOffset;
-}
-
-auto PhonebookModel::getLabelMarkerDisplayMode() -> LabelMarkerDisplayMode
+auto PhonebookModel::getLabelMarkerDisplayMode(uint32_t posOnList) -> LabelMarkerDisplayMode
{
- if (getLastRequestedOffset() < letterMap.favouritesCount) {
+ if (posOnList < letterMap.favouritesCount) {
return LabelMarkerDisplayMode::IncludeFavourites;
}
else {
M module-apps/application-phonebook/models/PhonebookModel.hpp => module-apps/application-phonebook/models/PhonebookModel.hpp +1 -1
@@ 48,7 48,7 @@ class PhonebookModel : public app::DatabaseModel<ContactRecord>, public gui::Lis
void setDisplayMode(std::uint32_t displayMode);
auto getDisplayMode() -> std::uint32_t;
auto getLastRequestedOffset() -> std::uint32_t;
- auto getLabelMarkerDisplayMode() -> LabelMarkerDisplayMode;
+ auto getLabelMarkerDisplayMode(uint32_t posOnList) -> LabelMarkerDisplayMode;
// onClick callback to register
std::function<bool(gui::PhonebookItem *item)> messagesSelectCallback = nullptr;
M module-apps/application-phonebook/windows/PhonebookMainWindow.cpp => module-apps/application-phonebook/windows/PhonebookMainWindow.cpp +7 -3
@@ 90,7 90,11 @@ namespace gui
void PhonebookMainWindow::onBeforeShow(ShowMode mode, SwitchData *data)
{
LOG_INFO("onBeforeShow");
- rebuild();
+
+ phonebookModel->letterMap = phonebookModel->requestLetterMap();
+ phonebookModel->setDisplayMode(static_cast<uint32_t>(ContactDisplayMode::SortedByLetter));
+ contactsList->rebuildList(style::listview::RebuildType::Full, 0);
+
auto contactRequest = dynamic_cast<PhonebookSearchReuqest *>(data);
requestedSearch = contactRequest != nullptr;
if (requestedSearch) {
@@ 116,11 120,10 @@ namespace gui
char letter = static_cast<char>(code);
std::string filterLetter;
filterLetter.push_back(letter);
- phonebookModel->letterMap = phonebookModel->requestLetterMap();
LOG_DEBUG("Number of favourites contacts : %" PRIu32, phonebookModel->letterMap.favouritesCount);
uint32_t dataOffset = phonebookModel->letterMap.firstLetterDictionary[filterLetter];
- if (dataOffset != phonebookContacMap::NO_MATCH_FOUND) {
+ if (dataOffset != phonebookContactsMap::NO_MATCH_FOUND) {
LOG_DEBUG("PhoneBook Data Offset : %" PRIu32, dataOffset);
phonebookModel->setDisplayMode(static_cast<uint32_t>(ContactDisplayMode::SortedByLetter));
contactsList->rebuildList(style::listview::RebuildType::OnOffset, dataOffset);
@@ 166,6 169,7 @@ namespace gui
if (msgNotification->dataModified()) {
+ phonebookModel->letterMap = phonebookModel->requestLetterMap();
rebuild();
return true;
M module-audio/Audio/decoder/taglib => module-audio/Audio/decoder/taglib +1 -1
@@ 1,1 1,1 @@
-Subproject commit b2a6e50aedf0cfe1f808eb23dc9f572a848ddffe
+Subproject commit fa37896f615f3d347a41f0db711e23746774b15f
M module-db/Interface/ContactRecord.cpp => module-db/Interface/ContactRecord.cpp +3 -1
@@ 197,7 197,9 @@ auto ContactRecordInterface::getQuery(std::shared_ptr<db::Query> query) -> std::
std::vector<ContactRecord> result(ids.size());
std::transform(std::begin(ids), std::end(ids), std::begin(result), [this](uint32_t id) { return GetByID(id); });
-
+ for (uint32_t idx = 0; idx < static_cast<uint32_t>(ids.size()); idx++) {
+ result[idx].contactPosOnList = offset + idx;
+ }
auto response = std::make_unique<db::query::ContactGetResult>(result);
response->setRequestQuery(query);
return response;
M module-db/Interface/ContactRecord.hpp => module-db/Interface/ContactRecord.hpp +1 -0
@@ 21,6 21,7 @@ struct ContactRecord : public Record
{
UTF8 primaryName = "";
UTF8 alternativeName = "";
+ uint32_t contactPosOnList = 0;
struct Number
{
M module-db/Tables/ContactsTable.cpp => module-db/Tables/ContactsTable.cpp +58 -30
@@ 153,34 153,48 @@ std::vector<ContactsTableRow> ContactsTable::Search(const std::string &primaryNa
return ret;
}
-std::string ContactsTable::GetSortedByNameQueryString(std::uint32_t limit, std::uint32_t offset)
+std::string ContactsTable::GetSortedByNameQueryString(ContactQuerySection section)
{
- std::string query = "SELECT contacts._id, contact_name.name_alternative, 'Favourites' AS ContactType FROM contacts"
- " INNER JOIN contact_name ON contact_name.contact_id == contacts._id "
- " LEFT JOIN contact_match_groups ON contact_match_groups.contact_id == contacts._id AND "
- " contact_match_groups.group_id = 1 "
- " WHERE group_id= 1 "
- " UNION ALL "
- " SELECT contacts._id, contact_name.name_alternative, 'All' FROM contacts "
- " INNER JOIN contact_name ON contact_name.contact_id == contacts._id "
- " LEFT JOIN contact_match_groups ON contact_match_groups.contact_id == contacts._id AND "
- " contact_match_groups.group_id = 1 "
- " ORDER BY ContactType DESC, contact_name.name_alternative ";
- if (limit > 0) {
- query += " LIMIT " + std::to_string(limit);
- query += " OFFSET " + std::to_string(offset);
+ std::string query;
+ if (section == ContactQuerySection::Favourites) {
+ query = "SELECT contacts._id FROM contacts"
+ " INNER JOIN contact_name ON contact_name.contact_id == contacts._id "
+ " LEFT JOIN contact_match_groups ON contact_match_groups.contact_id == contacts._id AND "
+ " contact_match_groups.group_id = 1 "
+ " WHERE group_id= 1 "
+ " ORDER BY (contact_name.name_alternative ='') ASC "
+ " , UPPER(contact_name.name_alternative) ; ";
+ }
+ else if (section == ContactQuerySection::Mixed) {
+ query = " SELECT contacts._id, contact_name.name_alternative FROM contacts "
+ " INNER JOIN contact_name ON contact_name.contact_id == contacts._id "
+ " LEFT JOIN contact_match_groups ON contact_match_groups.contact_id == contacts._id AND "
+ " contact_match_groups.group_id = 1 "
+ " ORDER BY (contact_name.name_alternative ='') ASC "
+ " , UPPER(contact_name.name_alternative) ; ";
}
- query += " ;";
return query;
}
std::vector<std::uint32_t> ContactsTable::GetIDsSortedByName(std::uint32_t limit, std::uint32_t offset)
{
std::vector<std::uint32_t> ids;
- std::string query = GetSortedByNameQueryString(limit, offset);
+ std::vector<std::uint32_t> ids_limit;
+ std::string query = GetSortedByNameQueryString(ContactQuerySection::Favourites);
LOG_DEBUG("query: %s", query.c_str());
auto queryRet = db->query(query.c_str());
+ if (queryRet == nullptr) {
+
+ return ids;
+ }
+ do {
+ ids.push_back((*queryRet)[0].getUInt32());
+ } while (queryRet->nextRow());
+
+ query = GetSortedByNameQueryString(ContactQuerySection::Mixed);
+ LOG_DEBUG("query: %s", query.c_str());
+ queryRet = db->query(query.c_str());
if ((queryRet == nullptr) || (queryRet->getRowCount() == 0)) {
return ids;
}
@@ 188,6 202,13 @@ std::vector<std::uint32_t> ContactsTable::GetIDsSortedByName(std::uint32_t limit
ids.push_back((*queryRet)[0].getUInt32());
} while (queryRet->nextRow());
+ if (limit > 0) {
+ for (uint32_t a = 0; a < limit; a++) {
+ ids_limit.push_back(ids[a + offset]);
+ }
+ return ids_limit;
+ }
+
return ids;
}
@@ 198,29 219,36 @@ ContactsMapData ContactsTable::GetPosOfFirstLetters()
std::string FirstLetterOfNameOld;
std::uint32_t PositionOnList = 0;
std::uint32_t favouritesCount = 0;
- std::string query = GetSortedByNameQueryString();
+ std::string query;
- LOG_DEBUG("query: %s", query.c_str());
+ query = GetSortedByNameQueryString(ContactQuerySection::Favourites);
auto queryRet = db->query(query.c_str());
+ if (queryRet == nullptr) {
+ return contactMap;
+ }
+ do {
+ favouritesCount++;
+ PositionOnList++;
+ } while (queryRet->nextRow());
+
+ query = GetSortedByNameQueryString(ContactQuerySection::Mixed);
+ queryRet = db->query(query.c_str());
if ((queryRet == nullptr) || (queryRet->getRowCount() == 0)) {
return contactMap;
}
do {
- if ((*queryRet)[2].getString() == "All") {
- UTF8 FirstLetterOfNameUtf = (*queryRet)[1].getString();
- FirstLetterOfName = FirstLetterOfNameUtf.substr(0, 1);
- if (FirstLetterOfName != FirstLetterOfNameOld) {
- contactMap.firstLetterDictionary.insert(
- std::pair<std::string, std::uint32_t>(FirstLetterOfName, PositionOnList));
- }
- FirstLetterOfNameOld = FirstLetterOfName;
- }
- else {
- favouritesCount++;
+ UTF8 FirstLetterOfNameUtf = (*queryRet)[1].getString();
+ FirstLetterOfName = FirstLetterOfNameUtf.substr(0, 1);
+ if (FirstLetterOfName != FirstLetterOfNameOld) {
+ contactMap.firstLetterDictionary.insert(
+ std::pair<std::string, std::uint32_t>(FirstLetterOfName, PositionOnList));
}
+ FirstLetterOfNameOld = FirstLetterOfName;
PositionOnList++;
} while (queryRet->nextRow());
+
contactMap.favouritesCount = favouritesCount;
+ contactMap.itemCount = PositionOnList;
return contactMap;
}
M module-db/Tables/ContactsTable.hpp => module-db/Tables/ContactsTable.hpp +1 -1
@@ 83,7 83,7 @@ class ContactsTable : public Table<ContactsTableRow, ContactTableFields>
std::vector<std::uint32_t> GetIDsSortedByName(std::uint32_t limit = 0, std::uint32_t offset = 0);
ContactsMapData GetPosOfFirstLetters();
- std::string GetSortedByNameQueryString(std::uint32_t limit = 0, std::uint32_t offset = 0);
+ std::string GetSortedByNameQueryString(ContactQuerySection section);
private:
const char *createTableQuery =
A null.d => null.d +1 -0
@@ 0,0 1,1 @@
+null.o: /dev/null