Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[offline][android] use region ids provided by MB + code cleanup #491

Merged
merged 6 commits into from
Feb 12, 2021

Conversation

shroff
Copy link
Collaborator

@shroff shroff commented Dec 21, 2020

#336 was a great step forward for offline, but there's a lot that could be cleaned up IMO. Particularly, I want to implement mergeOfflineRegions, which is hard with the current design of assigning region ids, especially since one db file can contain multiple regions.

Current Changes (android only):

  • Merge downloadOfflineRegion and downloadOfflineRegionStream
    • change format of args from single json string to obj with accessToken, channelName, and region keys (this will break iOS unless updated, but the change is simple)
  • Do not respect id passed into downloadOfflineRegion via OfflineRegionData, as it will be assigned by createOfflineRegion.
  • Do not store region id in OfflineRegionData metadata as this is unnecessary and misleading.
  • Perform deleteOfflineRegion based on ID given by mapbox at creation time rather than arbitrarily self-assigned id
  • Return OfflineRegionData result from the created OfflineRegion upon callback of onCreate in createOfflineRegion (needed to pass back ID to dart) instead of waiting for the download to finish, as there is already an event stream set up to take care of the download progress

Considered but not implemented mostly because of lack of iOS resources:

  • Restructure OfflineRegionData(native)/OfflineRegion(dart) classes into OfflineRegionDefinition and OfflineRegion classes to mirror SDK class structure. This is basically equivalient to something like OfflineRegionOptions.
  • Accept OfflineRegionDefinition as an arg to downloadOfflineRegion, and return OfflineRegion as a result

 - Merge `downloadOfflineRegion` and `downloadOfflineRegionStream`
   - change format of args from single json string to obj with `accessToken`,
   `channelName`, and `region` keys
 - Do not store region id in metadata as this is unnecessary
 - Perform `deleteOfflineRegion` based on ID given by mapbox at creation
 time rather than arbitrarily self-assigned id
 - Return `OfflineRegionData` result from the created `OfflineRegion`
 upon callback of `onCreate` in `createOfflineRegion` (needed to
 pass back ID to dart)

Considered but not implemented mostly because of lack of iOS resources:
 - Restructure `OfflineRegionData`(native)/`OfflineRegion`(dart) classes
 into `OfflineRegionDefinition` and `OfflineRegion` classes to mirror
 SDK class structure.
 - Accept `OfflineRegionDefinition` as arg to `downloadOfflineRegion`,
 and return `OfflineRegion` as a result
@felix-ht
Copy link
Collaborator

This looks really good! Could we get this merged?

@shroff
Copy link
Collaborator Author

shroff commented Feb 12, 2021

Web build failure is unrelated

@tobrun
Copy link
Collaborator

tobrun commented Feb 12, 2021

Thank you @shroff for contributing and patching based on the recent changes! Much appreciated!

@tobrun tobrun merged commit 27de579 into flutter-mapbox-gl:master Feb 12, 2021
@shroff shroff self-assigned this Feb 12, 2021
n8han added a commit that referenced this pull request Feb 16, 2021
While the Android SDK generates a region ID in createOfflineRegion, the
iOS SDK does not have this feature. To maintain a parallel interface and
relieve the client of the need to generate IDs, this change generates an
ID before submitting the download request to the iOS SDK. As in the
Android implementation, the completed OfflineRegionData is immediately
returned through the open channel.

Fixes #533

The following changes suggested in #491 are also pursued here:

* Restructure OfflineRegionData(native)/OfflineRegion(dart) classes into
  OfflineRegionDefinition and OfflineRegion classes to mirror SDK class
  structure. This is basically equivalient to something like
  OfflineRegionOptions.
* Accept OfflineRegionDefinition as an arg to downloadOfflineRegion, and
  return OfflineRegion as a result

Without those changes, the client code is `@required` to submit an id
along with the original download request, even though the id will not be
used and will be replaced by the generated ID. Furthermore, the object
returned from `downloadOfflineRegion` is now decoded so that the client
can await it to extract the generated ID.

I also made the properties of the definition and data classes immutable
on the iOS side, and renamed values dealing with the downloaded pack
context from "metadata" to "context". This is because the context is no
longer just the user-supplied metadata; it is a structure separately
holding the metadata and generated ID.

This change is not backwards compatible with regions previously
downloaded on iOS, however, offline downloading is not functional in the
latest or any release of this library because of #534.

It should be fully compatible with the existing implementation on
Android, though it would be a good idea to undertake a similar
separation of "definition" and "data" on that platform.
shroff pushed a commit that referenced this pull request Feb 28, 2021
…with iOS and Android (#545)

* Handled updated downloadOfflineRegion interface

The interface has changed to send region as a argument, as well as the
channelName. Without this change, the region download fails.

Fixes #534

* Generate offline region IDs and adapt interfaces

While the Android SDK generates a region ID in createOfflineRegion, the
iOS SDK does not have this feature. To maintain a parallel interface and
relieve the client of the need to generate IDs, this change generates an
ID before submitting the download request to the iOS SDK. As in the
Android implementation, the completed OfflineRegionData is immediately
returned through the open channel.

Fixes #533

The following changes suggested in #491 are also pursued here:

* Restructure OfflineRegionData(native)/OfflineRegion(dart) classes into
  OfflineRegionDefinition and OfflineRegion classes to mirror SDK class
  structure. This is basically equivalient to something like
  OfflineRegionOptions.
* Accept OfflineRegionDefinition as an arg to downloadOfflineRegion, and
  return OfflineRegion as a result

Without those changes, the client code is `@required` to submit an id
along with the original download request, even though the id will not be
used and will be replaced by the generated ID. Furthermore, the object
returned from `downloadOfflineRegion` is now decoded so that the client
can await it to extract the generated ID.

I also made the properties of the definition and data classes immutable
on the iOS side, and renamed values dealing with the downloaded pack
context from "metadata" to "context". This is because the context is no
longer just the user-supplied metadata; it is a structure separately
holding the metadata and generated ID.

This change is not backwards compatible with regions previously
downloaded on iOS, however, offline downloading is not functional in the
latest or any release of this library because of #534.

* OfflineRegion and OfflineRegionDefinition

To better harmonize with the Mapbox sdk data structures for offline
regions on iOS and Android, and to pave the way for polygonal offline
regions, the dart classes are revamped in 71186fb. This required changes
on the Android side which are also in this PR, and it will require changes
in any client code using the download functionality.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants