-
Notifications
You must be signed in to change notification settings - Fork 216
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
387 offline mappacks #417
Draft
jezhiggins
wants to merge
18
commits into
master
Choose a base branch
from
387-offline-mappacks
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
387 offline mappacks #417
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
e820300
Add MapPacks api
jezhiggins 3acb68f
s/MapPack/Map/ in Api
jezhiggins 6681dc6
Pulling list of maps from server.
jezhiggins cf879ea
Merge branch 'master' into 387-offline-mappacks
jezhiggins 8d61959
Rename Map to VectorMap
jezhiggins ae3d9b9
Start extending MapPack so it knows if the pack is downloaded or not
jezhiggins 858a7c5
Better property names on MapPack. Use id rather than file to identify…
jezhiggins 29a90da
Remove switchMapFile.
jezhiggins f21bb75
Build path where the map packs lives (or will live)
jezhiggins 282d5ae
Set downloaded flag based on whether file exists
jezhiggins 34a0c93
s/MapPack.findByPackage/MapPack.findById/
jezhiggins 8da0c32
Bump mapsforge to version 0.14.0
jezhiggins 8b45fa8
Download map packs on first use.
jezhiggins 55b129e
Strip out some of the old map pack support.
jezhiggins 9ab2421
Tweak download notification visibility
jezhiggins 486a8d5
Capture vector map size and last modified date
jezhiggins ac94e9f
Merge branch 'master' into 387-offline-mappacks
jezhiggins c7389c8
Restore mapfile preference
jezhiggins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/Maps.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package net.cyclestreets.api | ||
|
||
import android.os.AsyncTask | ||
|
||
class Maps( | ||
private val packs: Collection<VectorMap> | ||
): Iterable<VectorMap> { | ||
val size get() = packs.size | ||
override operator fun iterator() = packs.iterator() | ||
|
||
companion object { | ||
private var loaded_: Maps? = null | ||
|
||
fun get(): Maps? { | ||
if (loaded_ == null) | ||
backgroundLoad() | ||
return loaded_ | ||
} // get | ||
|
||
|
||
private fun backgroundLoad() { | ||
GetMapsTask().execute() | ||
} | ||
|
||
private class GetMapsTask : AsyncTask<Void?, Void?, Maps?>() { | ||
override fun doInBackground(vararg params: Void?): Maps? { | ||
return load() | ||
} | ||
|
||
override fun onPostExecute(maps: Maps?) { | ||
loaded_ = maps | ||
} | ||
} | ||
|
||
private fun load(): Maps? { | ||
try { | ||
return ApiClient.getMaps() | ||
} catch (e: Exception) { | ||
println(e.message) | ||
} | ||
return null | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/VectorMap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package net.cyclestreets.api | ||
|
||
data class VectorMap( | ||
val id: String, | ||
val name: String, | ||
val url: String, | ||
val parent: String, | ||
val size: String, | ||
val lastModified: String | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
libraries/cyclestreets-core/src/main/java/net/cyclestreets/api/client/geojson/MapsFactory.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package net.cyclestreets.api.client.geojson | ||
|
||
import net.cyclestreets.api.VectorMap | ||
import net.cyclestreets.api.Maps | ||
import net.cyclestreets.api.client.geojson.AbstractObjectFactory.propertyOrDefault | ||
import org.geojson.Feature | ||
import org.geojson.FeatureCollection | ||
|
||
class MapsFactory { | ||
companion object { | ||
fun toMaps(featureCollection: FeatureCollection): Maps { | ||
return Maps( | ||
featureCollection.features | ||
.map { f -> toMap(f) } | ||
.filter { m -> isBritainOrIreland(m) } | ||
) | ||
} | ||
|
||
private fun toMap(feature: Feature): VectorMap { | ||
return VectorMap( | ||
feature.getProperty("id"), | ||
feature.getProperty("name"), | ||
feature.getProperty("url"), | ||
propertyOrDefault(feature, "parent", ""), | ||
propertyOrDefault(feature, "size", ""), | ||
propertyOrDefault(feature, "lastModified", ""), | ||
) | ||
} | ||
|
||
private fun isBritainOrIreland(m: VectorMap): Boolean { | ||
return isBritainOrIreland(m.id) | ||
} | ||
private fun isBritainOrIreland(p: String): Boolean { | ||
return p.contains("great-britain") || p.contains("ireland") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with this restriction as a starting point. We can consider adding others subsequently as part of #46.