forked from organicmaps/organicmaps
[bookmarks][android][iOS] Limit indexed bookmarks count.
This commit is contained in:
parent
178bcb3b35
commit
2b4d14f494
10 changed files with 84 additions and 25 deletions
|
@ -851,6 +851,20 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeIsEditableCategory
|
|||
return static_cast<jboolean>(frm()->GetBookmarkManager().IsEditableCategory(static_cast<kml::MarkGroupId>(catId)));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeIsSearchAllowed(
|
||||
JNIEnv * env, jobject thiz, jlong catId)
|
||||
{
|
||||
return static_cast<jboolean>(frm()->GetBookmarkManager().IsSearchAllowed(static_cast<kml::MarkGroupId>(catId)));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativePrepareForSearch(
|
||||
JNIEnv * env, jobject thiz, jlong catId)
|
||||
{
|
||||
frm()->GetBookmarkManager().PrepareForSearch(static_cast<kml::MarkGroupId>(catId));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeAreAllCategoriesInvisible(
|
||||
JNIEnv * env, jobject thiz, jint type)
|
||||
|
|
|
@ -147,7 +147,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
ViewGroup toolbar = ((AppCompatActivity) requireActivity()).findViewById(R.id.toolbar);
|
||||
mSearchContainer = toolbar.findViewById(R.id.frame);
|
||||
mToolbarController = new BookmarksToolbarController(toolbar, requireActivity(), this);
|
||||
|
||||
mToolbarController.setHint(R.string.search_in_the_list);
|
||||
configureRecycler();
|
||||
}
|
||||
|
||||
|
@ -322,6 +322,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
|
|||
{
|
||||
mSearchMode = true;
|
||||
BookmarkManager.INSTANCE.setNotificationsEnabled(true);
|
||||
BookmarkManager.INSTANCE.prepareForSearch(mCategoryDataSource.getData().getId());
|
||||
updateSearchVisibility();
|
||||
}
|
||||
|
||||
|
|
|
@ -588,8 +588,9 @@ public enum BookmarkManager
|
|||
|
||||
public boolean isEditableCategory(long catId) { return nativeIsEditableCategory(catId); }
|
||||
|
||||
// TODO(@darina) Implement in native BookmarkManager.
|
||||
public boolean isSearchAllowed(long catId) { return true; }
|
||||
public boolean isSearchAllowed(long catId) { return nativeIsSearchAllowed(catId); }
|
||||
|
||||
public void prepareForSearch(long catId) { nativePrepareForSearch(catId); }
|
||||
|
||||
public boolean areAllCatalogCategoriesVisible()
|
||||
{
|
||||
|
@ -862,6 +863,10 @@ public enum BookmarkManager
|
|||
|
||||
private static native boolean nativeIsEditableCategory(long catId);
|
||||
|
||||
private static native boolean nativeIsSearchAllowed(long catId);
|
||||
|
||||
private static native void nativePrepareForSearch(long catId);
|
||||
|
||||
private static native boolean nativeAreAllCategoriesVisible(int type);
|
||||
|
||||
private static native boolean nativeAreAllCategoriesInvisible(int type);
|
||||
|
|
|
@ -214,7 +214,7 @@ using namespace std;
|
|||
self.searchBar.delegate = self;
|
||||
self.statusBarBackground.backgroundColor = self.searchBar.barTintColor = searchBarColor;
|
||||
self.searchBar.backgroundImage = [UIImage imageWithColor:searchBarColor];
|
||||
self.searchBar.placeholder = L(@"search");
|
||||
self.searchBar.placeholder = L(@"search_in_the_list");
|
||||
|
||||
[self.noResultsView setTranslatesAutoresizingMaskIntoConstraints:NO];
|
||||
|
||||
|
@ -612,7 +612,8 @@ using namespace std;
|
|||
|
||||
// Allow to send all notifications in BM.
|
||||
[[MWMBookmarksManager sharedManager] setNotificationsEnabled:YES];
|
||||
|
||||
[[MWMBookmarksManager sharedManager] prepareForSearch:self.categoryId];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ typedef void (^PingCompletionBlock)(BOOL success);
|
|||
- (BOOL)isCategoryEditable:(MWMMarkGroupID)groupId;
|
||||
- (BOOL)isCategoryNotEmpty:(MWMMarkGroupID)groupId;
|
||||
- (BOOL)isSearchAllowed:(MWMMarkGroupID)groupId;
|
||||
- (void)prepareForSearch:(MWMMarkGroupID)groupId;
|
||||
- (NSString *)getCategoryName:(MWMMarkGroupID)groupId;
|
||||
- (uint64_t)getCategoryMarksCount:(MWMMarkGroupID)groupId;
|
||||
- (uint64_t)getCategoryTracksCount:(MWMMarkGroupID)groupId;
|
||||
|
|
|
@ -292,6 +292,10 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result)
|
|||
return self.bm.IsSearchAllowed(groupId);
|
||||
}
|
||||
|
||||
- (void)prepareForSearch:(MWMMarkGroupID)groupId {
|
||||
self.bm.PrepareForSearch(groupId);
|
||||
}
|
||||
|
||||
- (MWMGroupIDCollection)groupsIdList
|
||||
{
|
||||
auto const & list = self.bm.GetBmGroupsIdList();
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "map/api_mark_point.hpp"
|
||||
#include "map/local_ads_mark.hpp"
|
||||
#include "map/routing_mark.hpp"
|
||||
#include "map/search_api.hpp"
|
||||
#include "map/search_mark.hpp"
|
||||
#include "map/user.hpp"
|
||||
#include "map/user_mark.hpp"
|
||||
|
@ -1542,9 +1543,30 @@ bool BookmarkManager::IsVisible(kml::MarkGroupId groupId) const
|
|||
|
||||
bool BookmarkManager::IsSearchAllowed(kml::MarkGroupId groupId) const
|
||||
{
|
||||
// TODO(@darina) Implement.
|
||||
CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
return true;
|
||||
CHECK(m_callbacks.m_getSearchAPI != nullptr, ());
|
||||
|
||||
if (m_callbacks.m_getSearchAPI().IsIndexingOfBookmarkGroupEnabled(groupId))
|
||||
return true;
|
||||
|
||||
size_t indexedBookmarksCount = 0;
|
||||
for (auto const indexableGroupId : m_callbacks.m_getSearchAPI().GetIndexableGroups())
|
||||
{
|
||||
auto const it = m_categories.find(indexableGroupId);
|
||||
if (it == m_categories.end())
|
||||
continue;
|
||||
indexedBookmarksCount += it->second->GetUserMarks().size();
|
||||
}
|
||||
auto const bookmarksCount = GetUserMarkIds(groupId).size();
|
||||
auto const maxCount = m_callbacks.m_getSearchAPI().GetMaximumPossibleNumberOfBookmarksToIndex();
|
||||
return indexedBookmarksCount + bookmarksCount <= maxCount;
|
||||
}
|
||||
|
||||
void BookmarkManager::PrepareForSearch(kml::MarkGroupId groupId)
|
||||
{
|
||||
CHECK_THREAD_CHECKER(m_threadChecker, ());
|
||||
CHECK(m_callbacks.m_getSearchAPI != nullptr, ());
|
||||
m_callbacks.m_getSearchAPI().EnableIndexingOfBookmarkGroup(groupId, true /* enable */);
|
||||
}
|
||||
|
||||
void BookmarkManager::SetDrapeEngine(ref_ptr<df::DrapeEngine> engine)
|
||||
|
@ -2121,20 +2143,6 @@ void BookmarkManager::SendBookmarksChanges()
|
|||
m_callbacks.m_updatedBookmarksCallback(bookmarksInfo);
|
||||
}
|
||||
|
||||
if (m_callbacks.m_deletedBookmarksCallback != nullptr)
|
||||
{
|
||||
kml::MarkIdCollection bookmarkIds;
|
||||
auto const & removedIds = m_changesTracker.GetRemovedMarkIds();
|
||||
bookmarkIds.reserve(removedIds.size());
|
||||
for (auto markId : removedIds)
|
||||
{
|
||||
if (IsBookmark(markId))
|
||||
bookmarkIds.push_back(markId);
|
||||
}
|
||||
if (!bookmarkIds.empty())
|
||||
m_callbacks.m_deletedBookmarksCallback(bookmarkIds);
|
||||
}
|
||||
|
||||
std::vector<BookmarkGroupInfo> groupsInfo;
|
||||
|
||||
if (m_callbacks.m_attachedBookmarksCallback != nullptr)
|
||||
|
@ -2150,6 +2158,20 @@ void BookmarkManager::SendBookmarksChanges()
|
|||
if (!groupsInfo.empty())
|
||||
m_callbacks.m_detachedBookmarksCallback(groupsInfo);
|
||||
}
|
||||
|
||||
if (m_callbacks.m_deletedBookmarksCallback != nullptr)
|
||||
{
|
||||
kml::MarkIdCollection bookmarkIds;
|
||||
auto const & removedIds = m_changesTracker.GetRemovedMarkIds();
|
||||
bookmarkIds.reserve(removedIds.size());
|
||||
for (auto markId : removedIds)
|
||||
{
|
||||
if (IsBookmark(markId))
|
||||
bookmarkIds.push_back(markId);
|
||||
}
|
||||
if (!bookmarkIds.empty())
|
||||
m_callbacks.m_deletedBookmarksCallback(bookmarkIds);
|
||||
}
|
||||
}
|
||||
|
||||
bool BookmarkManager::HasBmCategory(kml::MarkGroupId groupId) const
|
||||
|
|
|
@ -41,6 +41,7 @@ class CountryInfoGetter;
|
|||
} // namespace storage
|
||||
|
||||
class DataSource;
|
||||
class SearchAPI;
|
||||
class User;
|
||||
|
||||
class BookmarkManager final
|
||||
|
@ -71,18 +72,22 @@ public:
|
|||
struct Callbacks
|
||||
{
|
||||
using GetStringsBundleFn = std::function<StringsBundle const &()>;
|
||||
using GetSeacrhAPIFn = std::function<SearchAPI &()>;
|
||||
using CreatedBookmarksCallback = std::function<void(std::vector<BookmarkInfo> const &)>;
|
||||
using UpdatedBookmarksCallback = std::function<void(std::vector<BookmarkInfo> const &)>;
|
||||
using DeletedBookmarksCallback = std::function<void(std::vector<kml::MarkId> const &)>;
|
||||
using AttachedBookmarksCallback = std::function<void(std::vector<BookmarkGroupInfo> const &)>;
|
||||
using DetachedBookmarksCallback = std::function<void(std::vector<BookmarkGroupInfo> const &)>;
|
||||
|
||||
template <typename StringsBundleProvider, typename CreateListener, typename UpdateListener,
|
||||
template <typename StringsBundleProvider, typename SearchAPIProvider,
|
||||
typename CreateListener, typename UpdateListener,
|
||||
typename DeleteListener, typename AttachListener, typename DetachListener>
|
||||
Callbacks(StringsBundleProvider && stringsBundleProvider, CreateListener && createListener,
|
||||
Callbacks(StringsBundleProvider && stringsBundleProvider,
|
||||
SearchAPIProvider && searchAPIProvider, CreateListener && createListener,
|
||||
UpdateListener && updateListener, DeleteListener && deleteListener,
|
||||
AttachListener && attachListener, DetachListener && detachListener)
|
||||
: m_getStringsBundle(std::forward<StringsBundleProvider>(stringsBundleProvider))
|
||||
, m_getSearchAPI(std::forward<SearchAPIProvider>(searchAPIProvider))
|
||||
, m_createdBookmarksCallback(std::forward<CreateListener>(createListener))
|
||||
, m_updatedBookmarksCallback(std::forward<UpdateListener>(updateListener))
|
||||
, m_deletedBookmarksCallback(std::forward<DeleteListener>(deleteListener))
|
||||
|
@ -91,6 +96,7 @@ public:
|
|||
{}
|
||||
|
||||
GetStringsBundleFn m_getStringsBundle;
|
||||
GetSeacrhAPIFn m_getSearchAPI;
|
||||
CreatedBookmarksCallback m_createdBookmarksCallback;
|
||||
UpdatedBookmarksCallback m_updatedBookmarksCallback;
|
||||
DeletedBookmarksCallback m_deletedBookmarksCallback;
|
||||
|
@ -240,9 +246,11 @@ public:
|
|||
void SetLastSortingType(kml::MarkGroupId groupId, SortingType sortingType);
|
||||
void ResetLastSortingType(kml::MarkGroupId groupId);
|
||||
|
||||
bool IsVisible(kml::MarkGroupId groupId) const;
|
||||
bool IsSearchAllowed(kml::MarkGroupId groupId) const;
|
||||
|
||||
void PrepareForSearch(kml::MarkGroupId groupId);
|
||||
|
||||
bool IsVisible(kml::MarkGroupId groupId) const;
|
||||
|
||||
kml::MarkGroupId CreateBookmarkCategory(kml::CategoryData && data, bool autoSave = true);
|
||||
kml::MarkGroupId CreateBookmarkCategory(std::string const & name, bool autoSave = true);
|
||||
|
||||
|
|
|
@ -496,6 +496,7 @@ Framework::Framework(FrameworkParams const & params)
|
|||
|
||||
m_bmManager = make_unique<BookmarkManager>(m_user, BookmarkManager::Callbacks(
|
||||
[this]() -> StringsBundle const & { return m_stringsBundle; },
|
||||
[this]() -> SearchAPI & { return GetSearchAPI(); },
|
||||
[this](vector<BookmarkInfo> const & marks) { GetSearchAPI().OnBookmarksCreated(marks); },
|
||||
[this](vector<BookmarkInfo> const & marks) { GetSearchAPI().OnBookmarksUpdated(marks); },
|
||||
[this](vector<kml::MarkId> const & marks) { GetSearchAPI().OnBookmarksDeleted(marks); },
|
||||
|
|
|
@ -142,6 +142,7 @@ BookmarkManager::Callbacks const bmCallbacks(
|
|||
static StringsBundle dummyBundle;
|
||||
return dummyBundle;
|
||||
},
|
||||
static_cast<BookmarkManager::Callbacks::GetSeacrhAPIFn>(nullptr),
|
||||
static_cast<BookmarkManager::Callbacks::CreatedBookmarksCallback>(nullptr),
|
||||
static_cast<BookmarkManager::Callbacks::UpdatedBookmarksCallback>(nullptr),
|
||||
static_cast<BookmarkManager::Callbacks::DeletedBookmarksCallback>(nullptr),
|
||||
|
@ -1214,6 +1215,7 @@ UNIT_CLASS_TEST(Runner, Bookmarks_Listeners)
|
|||
static StringsBundle dummyBundle;
|
||||
return dummyBundle;
|
||||
},
|
||||
static_cast<BookmarkManager::Callbacks::GetSeacrhAPIFn>(nullptr),
|
||||
onCreate, onUpdate, onDelete, onAttach, onDetach);
|
||||
|
||||
User user;
|
||||
|
|
Loading…
Add table
Reference in a new issue