forked from organicmaps/organicmaps
Fixed redundant notifications in BM
This commit is contained in:
parent
48f4c45df6
commit
0b1f559e95
11 changed files with 142 additions and 2 deletions
|
@ -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<bool>(enabled));
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL
|
||||
Java_com_mapswithme_maps_bookmarks_data_BookmarkManager_nativeAreNotificationsEnabled(
|
||||
JNIEnv * env, jobject thiz)
|
||||
{
|
||||
return static_cast<jboolean>(frm()->GetBookmarkManager().AreNotificationsEnabled());
|
||||
}
|
||||
} // extern "C"
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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?) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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")));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue