| 1509 | } |
| 1510 | |
| 1511 | void BookmarkManager::GetSortedCategory(SortParams const & params) |
| 1512 | { |
| 1513 | CHECK_THREAD_CHECKER(m_threadChecker, ()); |
| 1514 | CHECK(params.m_onResults != nullptr, ()); |
| 1515 | |
| 1516 | auto const * group = GetGroup(params.m_groupId); |
| 1517 | |
| 1518 | std::vector<SortBookmarkData> bookmarksForSort; |
| 1519 | bookmarksForSort.reserve(group->GetUserMarks().size()); |
| 1520 | for (auto markId : group->GetUserMarks()) |
| 1521 | { |
| 1522 | auto const * bm = GetBookmark(markId); |
| 1523 | bookmarksForSort.emplace_back(bm->GetData(), bm->GetAddress()); |
| 1524 | } |
| 1525 | |
| 1526 | std::vector<SortTrackData> tracksForSort; |
| 1527 | tracksForSort.reserve(group->GetUserLines().size()); |
| 1528 | for (auto trackId : group->GetUserLines()) |
| 1529 | { |
| 1530 | auto const * track = GetTrack(trackId); |
| 1531 | tracksForSort.emplace_back(track->GetData()); |
| 1532 | } |
| 1533 | |
| 1534 | if (m_testModeEnabled) |
| 1535 | { |
| 1536 | // Sort bookmarks synchronously. |
| 1537 | std::unique_lock const lock(m_regionAddressMutex); |
| 1538 | if (m_regionAddressGetter == nullptr) |
| 1539 | { |
| 1540 | LOG(LWARNING, ("Region address getter is not set, bookmarks sorting failed.")); |
| 1541 | params.m_onResults({} /* sortedBlocks */, SortParams::Status::Cancelled); |
| 1542 | return; |
| 1543 | } |
| 1544 | AddressesCollection newAddresses; |
| 1545 | if (params.m_sortingType == SortingType::ByDistance) |
| 1546 | PrepareBookmarksAddresses(bookmarksForSort, newAddresses); |
| 1547 | |
| 1548 | SortedBlocksCollection sortedBlocks; |
| 1549 | GetSortedCategoryImpl(params, bookmarksForSort, tracksForSort, sortedBlocks); |
| 1550 | params.m_onResults(std::move(sortedBlocks), SortParams::Status::Completed); |
| 1551 | return; |
| 1552 | } |
| 1553 | |
| 1554 | GetPlatform().RunTask(Platform::Thread::Background, [this, params, bookmarksForSort = std::move(bookmarksForSort), |
| 1555 | tracksForSort = std::move(tracksForSort)]() mutable |
| 1556 | { |
| 1557 | std::unique_lock const lock(m_regionAddressMutex); |
| 1558 | if (m_regionAddressGetter == nullptr) |
| 1559 | { |
| 1560 | GetPlatform().RunTask(Platform::Thread::Gui, [params] |
| 1561 | { |
| 1562 | LOG(LWARNING, ("Region address getter is not set, bookmarks sorting failed.")); |
| 1563 | params.m_onResults({} /* sortedBlocks */, SortParams::Status::Cancelled); |
| 1564 | }); |
| 1565 | return; |
| 1566 | } |
| 1567 | |
| 1568 | AddressesCollection newAddresses; |