diff --git a/android/jni/com/mapswithme/maps/bookmarks/data/BookmarkManager.cpp b/android/jni/com/mapswithme/maps/bookmarks/data/BookmarkManager.cpp index f3041eab5c..3f54f4cf72 100644 --- a/android/jni/com/mapswithme/maps/bookmarks/data/BookmarkManager.cpp +++ b/android/jni/com/mapswithme/maps/bookmarks/data/BookmarkManager.cpp @@ -532,4 +532,18 @@ Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeCancelRestoring( { frm()->GetBookmarkManager().CancelCloudRestoring(); } + +JNIEXPORT void JNICALL +Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeSetNotificationsEnabled( + JNIEnv * env, jobject thiz, jboolean enabled) +{ + frm()->GetBookmarkManager().SetNotificationsEnabled(static_cast(enabled)); +} + +JNIEXPORT jboolean JNICALL +Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeAreNotificationsEnabled( + JNIEnv * env, jobject thiz) +{ + return static_cast(frm()->GetBookmarkManager().AreNotificationsEnabled()); +} } // extern "C" diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesActivity.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesActivity.java index 1eccf9a0ff..2d52b8aa58 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesActivity.java +++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkCategoriesActivity.java @@ -1,14 +1,38 @@ package com.mapswithme.maps.bookmarks; +import android.support.annotation.CallSuper; import android.support.annotation.NonNull; import android.support.annotation.StyleRes; import android.support.v4.app.Fragment; import com.mapswithme.maps.base.BaseToolbarActivity; +import com.mapswithme.maps.bookmarks.data.BookmarkManager; import com.mapswithme.util.ThemeUtils; public class BookmarkCategoriesActivity extends BaseToolbarActivity { + @CallSuper + @Override + public void onResume() + { + super.onResume(); + + // Disable all notifications in BM on appearance of this activity. + // It allows to significantly improve performance in case of bookmarks + // modification. All notifications will be sent on activity's disappearance. + BookmarkManager.INSTANCE.setNotificationsEnabled(false); + } + + @CallSuper + @Override + public void onPause() + { + // Allow to send all notifications in BM. + BookmarkManager.INSTANCE.setNotificationsEnabled(true); + + super.onPause(); + } + @Override @StyleRes public int getThemeResourceId(@NonNull String theme) diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkListActivity.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkListActivity.java index 63d975c904..47113a719b 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarkListActivity.java +++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkListActivity.java @@ -1,14 +1,38 @@ package com.mapswithme.maps.bookmarks; +import android.support.annotation.CallSuper; import android.support.annotation.NonNull; import android.support.annotation.StyleRes; import android.support.v4.app.Fragment; import com.mapswithme.maps.base.BaseToolbarActivity; +import com.mapswithme.maps.bookmarks.data.BookmarkManager; import com.mapswithme.util.ThemeUtils; public class BookmarkListActivity extends BaseToolbarActivity { + @CallSuper + @Override + public void onResume() + { + super.onResume(); + + // Disable all notifications in BM on appearance of this activity. + // It allows to significantly improve performance in case of bookmarks + // modification. All notifications will be sent on activity's disappearance. + BookmarkManager.INSTANCE.setNotificationsEnabled(false); + } + + @CallSuper + @Override + public void onPause() + { + // Allow to send all notifications in BM. + BookmarkManager.INSTANCE.setNotificationsEnabled(true); + + super.onPause(); + } + @Override @StyleRes public int getThemeResourceId(@NonNull String theme) diff --git a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java index c7e9935a66..34dca9e9a0 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java @@ -393,6 +393,16 @@ public enum BookmarkManager nativeCancelRestoring(); } + public void setNotificationsEnabled(boolean enabled) + { + nativeSetNotificationsEnabled(enabled); + } + + public boolean areNotificationsEnabled() + { + return nativeAreNotificationsEnabled(); + } + private native int nativeGetCategoriesCount(); private native int nativeGetCategoryPositionById(long catId); @@ -477,6 +487,10 @@ public enum BookmarkManager private static native void nativeCancelRestoring(); + private static native void nativeSetNotificationsEnabled(boolean enabled); + + private static native boolean nativeAreNotificationsEnabled(); + public interface BookmarksLoadingListener { void onBookmarksLoadingStarted(); diff --git a/iphone/Maps/Bookmarks/BookmarksVC.mm b/iphone/Maps/Bookmarks/BookmarksVC.mm index 2ca2cc3b9d..d43e02d4cb 100644 --- a/iphone/Maps/Bookmarks/BookmarksVC.mm +++ b/iphone/Maps/Bookmarks/BookmarksVC.mm @@ -367,6 +367,24 @@ [super viewWillDisappear:animated]; } +- (void)viewDidAppear:(BOOL)animated +{ + // Disable all notifications in BM on appearance of this view. + // It allows to significantly improve performance in case of bookmarks + // modification. All notifications will be sent on controller's disappearance. + [MWMBookmarksManager setNotificationsEnabled: NO]; + + [super viewDidAppear:animated]; +} + +- (void)viewDidDisappear:(BOOL)animated +{ + // Allow to send all notifications in BM. + [MWMBookmarksManager setNotificationsEnabled: YES]; + + [super viewDidDisappear:animated]; +} + - (void)sendBookmarksWithExtension:(NSString *)fileExtension andType:(NSString *)mimeType andFile:(NSString *)filePath andCategory:(NSString *)catName { MWMMailViewController * mailVC = [[MWMMailViewController alloc] init]; diff --git a/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift b/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift index b48e68e167..eeac908c7b 100644 --- a/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift +++ b/iphone/Maps/Bookmarks/Categories/BMCView/BMCViewController.swift @@ -42,19 +42,20 @@ final class BMCViewController: MWMViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) + // Disable all notifications in BM on appearance of this view. // It allows to significantly improve performance in case of bookmarks // modification. All notifications will be sent on controller's disappearance. viewModel.setNotificationsEnabled(false) - viewModel.addToObserverList() + viewModel.convertAllKMLIfNeeded() } override func viewDidDisappear(_ animated: Bool) { super.viewDidDisappear(animated) + // Allow to send all notifications in BM. viewModel.setNotificationsEnabled(true) - viewModel.removeFromObserverList() } private func updateCategoryName(category: BMCCategory?) { diff --git a/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift b/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift index 74066cd04c..5156111b2c 100644 --- a/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift +++ b/iphone/Maps/Bookmarks/Categories/BMCViewModel/BMCDefaultViewModel.swift @@ -214,6 +214,14 @@ extension BMCDefaultViewModel: BMCViewModel { func removeFromObserverList() { BM.remove(self) } + + func setNotificationsEnabled(_ enabled: Bool) { + BM.setNotificationsEnabled(enabled) + } + + func areNotificationsEnabled() -> Bool { + return BM.areNotificationsEnabled() + } } extension BMCDefaultViewModel: MWMBookmarksObserver { diff --git a/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.h b/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.h index a29e581d83..0460560cbc 100644 --- a/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.h +++ b/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.h @@ -37,6 +37,9 @@ + (BOOL)areAllCategoriesInvisible; ++ (void)setNotificationsEnabled:(BOOL)enabled; ++ (BOOL)areNotificationsEnabled; + - (instancetype)init __attribute__((unavailable("call +manager instead"))); - (instancetype)copy __attribute__((unavailable("call +manager instead"))); - (instancetype)copyWithZone:(NSZone *)zone __attribute__((unavailable("call +manager instead"))); diff --git a/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.mm b/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.mm index 18c5b1a19b..94360aa1f1 100644 --- a/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.mm +++ b/iphone/Maps/Core/Bookmarks/MWMBookmarksManager.mm @@ -359,4 +359,14 @@ NSString * const CloudErrorToString(Cloud::SynchronizationResult result) return GetFramework().GetBookmarkManager().AreAllCategoriesInvisible(); } ++ (void)setNotificationsEnabled:(BOOL)enabled +{ + GetFramework().GetBookmarkManager().SetNotificationsEnabled(enabled); +} + ++ (BOOL)areNotificationsEnabled +{ + return GetFramework().GetBookmarkManager().AreNotificationsEnabled(); +} + @end diff --git a/map/bookmark_manager.cpp b/map/bookmark_manager.cpp index 5a0149b636..c3e378c399 100644 --- a/map/bookmark_manager.cpp +++ b/map/bookmark_manager.cpp @@ -586,6 +586,9 @@ void BookmarkManager::OnEditSessionClosed() void BookmarkManager::NotifyChanges() { CHECK_THREAD_CHECKER(m_threadChecker, ()); + if (!m_notificationsEnabled) + return; + if (!m_changesTracker.CheckChanges() && !m_firstDrapeNotification) return; @@ -1781,6 +1784,23 @@ void BookmarkManager::CancelCloudRestoring() m_bookmarkCloud.CancelRestoring(); } +void BookmarkManager::SetNotificationsEnabled(bool enabled) +{ + CHECK_THREAD_CHECKER(m_threadChecker, ()); + if (m_notificationsEnabled == enabled) + return; + + m_notificationsEnabled = enabled; + if (m_openedEditSessionsCount == 0) + NotifyChanges(); +} + +bool BookmarkManager::AreNotificationsEnabled() const +{ + CHECK_THREAD_CHECKER(m_threadChecker, ()); + return m_notificationsEnabled; +} + void BookmarkManager::EnableTestMode(bool enable) { UserMarkIdStorage::Instance().EnableTestMode(enable); diff --git a/map/bookmark_manager.hpp b/map/bookmark_manager.hpp index 7a939f02c9..8a69608d1e 100644 --- a/map/bookmark_manager.hpp +++ b/map/bookmark_manager.hpp @@ -265,6 +265,9 @@ public: void ApplyCloudRestoring(); void CancelCloudRestoring(); + void SetNotificationsEnabled(bool enabled); + bool AreNotificationsEnabled() const; + /// These functions are public for unit tests only. You shouldn't call them from client code. void EnableTestMode(bool enable); bool SaveBookmarkCategory(kml::MarkGroupId groupId); @@ -453,6 +456,7 @@ private: bool m_restoreApplying = false; bool m_migrationInProgress = false; bool m_conversionInProgress = false; + bool m_notificationsEnabled = true; ScreenBase m_viewport;