Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

Feature/create archive provider#1715

Merged
monsieurtanuki merged 4 commits intoosmdroid:masterfrom
pasniak:feature/createArchiveProvider
May 14, 2022
Merged

Feature/create archive provider#1715
monsieurtanuki merged 4 commits intoosmdroid:masterfrom
pasniak:feature/createArchiveProvider

Conversation

@pasniak
Copy link
Copy Markdown
Contributor

@pasniak pasniak commented Apr 18, 2021

Hi, I would like to be able to create a custom archive provider (in my own MapTileProvider inheriting from MapTileProviderBasic).

The PR has change which moves constructor to init() and adds createApproximater() createAssetsProvider() createArchiveProvider() which can be overwritten in client code.

Copy link
Copy Markdown
Collaborator

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @pasniak!
Still something I don't fully understand with the init method and removing the final keywords.

@Override
public boolean preCheck() {
if (mTileSource instanceof OnlineTileSourceBase) {
if (mTileSource!=null && mTileSource instanceof OnlineTileSourceBase) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember well, in Java a null is never an instance of anything. That fix is not needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe I was getting some exception along the lines null is not instance of OnlineTileSourceBase (instead going to else branch).

But yes, folding init() into constructor makes this redundant as final cannot be null. I will update to PR.

Note: If I force createAssetsProvider in my MapTileProviderCustom class to return null:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.debug/com.myapp.ui.activity.fullscreenactivity.FullscreenActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.osmdroid.tileprovider.modules.MapTileModuleProviderBase.getMinimumZoomLevel()' on a null object reference
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2913)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
	at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loop(Looper.java:193)
	at android.app.ActivityThread.main(ActivityThread.java:6669)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int org.osmdroid.tileprovider.modules.MapTileModuleProviderBase.getMinimumZoomLevel()' on a null object reference
	at org.osmdroid.tileprovider.modules.MapTileApproximater.computeZoomLevels(MapTileApproximater.java:64)
	at org.osmdroid.tileprovider.modules.MapTileApproximater.addProvider(MapTileApproximater.java:57)
	at org.osmdroid.tileprovider.MapTileProviderBasic.createApproximater(MapTileProviderBasic.java:133)
	at org.osmdroid.tileprovider.MapTileProviderBasic.<init>(MapTileProviderBasic.java:106)
	at org.osmdroid.tileprovider.MapTileProviderBasic.<init>(MapTileProviderBasic.java:70)
	at org.osmdroid.tileprovider.MapTileProviderBasic.<init>(MapTileProviderBasic.java:63)
	at org.osmdroid.tileprovider.MapTileProviderBasic.<init>(MapTileProviderBasic.java:56)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I guess if it doesn't exist now you could create an empty MapTileFileStorageProviderBase that returns nothing.

Or systematically test for null before adding each provider.

Or remove altogether each local variable (like assetsProvider); basically you don't need an asset provider and a cache provider and so on, you just need a list of providers, to be added to the mTileProviderList and to the MapTileApproximater. What do you think of that?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pasniak ping

private final MapTileDownloader mDownloaderProvider;
private final MapTileApproximater mApproximationProvider;
private MapTileDownloader mDownloaderProvider;
private MapTileApproximater mApproximationProvider;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no obvious reason not to keep them final.
The point of this PR is to create these fields differently, not to make it possible to change them afterwards, isn't it?

init(pRegisterReceiver, aNetworkAvailablityCheck, pTileSource, pContext, cacheWriter);
}

protected void init(IRegisterReceiver pRegisterReceiver,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't see the point of new method init. I thought the purpose was mainly to override the new create* methods.

…a (meant to provide ways to override construction of MapTileProviderBasic). Members can be final again.

	modified:   osmdroid-android/src/main/java/org/osmdroid/tileprovider/MapTileProviderBasic.java
	modified:   osmdroid-android/src/main/java/org/osmdroid/tileprovider/cachemanager/CacheManager.java
Copy link
Copy Markdown
Collaborator

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically you answered all my comments, thank you @pasniak!

But I've just answered one of your new comments, and I think there's something interesting regarding lists instead of local variables to have a look at. Tell me what you think about it.

@spyhunter99
Copy link
Copy Markdown
Collaborator

is this good to merge?

@monsieurtanuki monsieurtanuki self-requested a review May 6, 2022 06:14
Copy link
Copy Markdown
Collaborator

@monsieurtanuki monsieurtanuki left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except for the format change that does not help code review, I approve!

@monsieurtanuki monsieurtanuki merged commit a63812d into osmdroid:master May 14, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants