organicmaps / organicmaps

🍃 Organic Maps is a free Android & iOS offline maps app for travelers, tourists, hikers, and cyclists. It uses crowd-sourced OpenStreetMap data and is developed with love by MapsWithMe (MapsMe) founders and our community. No ads, no tracking, no data collection, no crapware. Please donate to support the development!
https://organicmaps.app
Apache License 2.0
8.58k stars 837 forks source link

[ios] [bookmarks] Remove observer pattern during the category files exporting #7933

Closed kirylkaveryn closed 2 weeks ago

kirylkaveryn commented 2 weeks ago

For now to handle thefile sharing OM uses the observing pattern tightened to the MWMBookmarksManagers, that is too complex for this straightforward task:

  1. subscribe for the observarion
  2. register observer
  3. send sharing message
  4. wait for sharing result
  5. handle sharing result
  6. notify observers
  7. unsubscribe from observing

This is too complex because the c++ method that we interact with uses the completion handlers to return sharing results and there is no sense in wrapping the completion handle into observation:

void BookmarkManager::PrepareFileForSharing(kml::GroupIdCollection && categoriesIds, SharingHandler && handler)

This PR converts c++ completion handler into the objc and returns to the caller so we can share files easily with the MWMBookmarksManagers and handle result without additional overhead:

- (void)shareCategory:(MWMMarkGroupID)groupId completion:(SharingResultCompletionHandler)completion;
- (void)shareAllCategoriesWithCompletion:(SharingResultCompletionHandler)completion;

https://github.com/organicmaps/organicmaps/assets/79797627/7ceabaa2-0880-41e4-bfed-28c565911950

kirylkaveryn commented 2 weeks ago

Thanks, the functionality did not change, right? All cases (including errors) are properly handled now in the Bookmarks and Tracks dialog, right?

Yes! Tested on iPhone 11Pro (17.2) and iPhone 6 (12.5).

kirylkaveryn commented 2 weeks ago

Updated with documentation!