Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - keep observer when timeout occurs, make observer param nu…
Browse files Browse the repository at this point in the history
…llable, fixup log messages
  • Loading branch information
tobrun committed May 8, 2017
1 parent 45545e1 commit 6f8c2be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Looper;
import android.support.annotation.IntDef;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.mapbox.mapboxsdk.storage.FileSource;

Expand Down Expand Up @@ -205,7 +206,7 @@ private boolean deliverMessages() {

/**
* Constructor
*
* <p>
* For JNI use only, to create a new offline region, use
* {@link OfflineManager#createOfflineRegion} instead.
*/
Expand Down Expand Up @@ -247,15 +248,17 @@ private Handler getHandler() {
*
* @param observer the observer to be notified
*/
public void setObserver(@NonNull final OfflineRegionObserver observer) {
public void setObserver(@Nullable final OfflineRegionObserver observer) {
setOfflineRegionObserver(new OfflineRegionObserver() {
@Override
public void onStatusChanged(final OfflineRegionStatus status) {
if (deliverMessages()) {
getHandler().post(new Runnable() {
@Override
public void run() {
observer.onStatusChanged(status);
if (observer != null) {
observer.onStatusChanged(status);
}
}
});
}
Expand All @@ -267,7 +270,9 @@ public void onError(final OfflineRegionError error) {
getHandler().post(new Runnable() {
@Override
public void run() {
observer.onError(error);
if (observer != null) {
observer.onError(error);
}
}
});
}
Expand All @@ -279,7 +284,9 @@ public void mapboxTileCountLimitExceeded(final long limit) {
getHandler().post(new Runnable() {
@Override
public void run() {
observer.mapboxTileCountLimitExceeded(limit);
if (observer != null) {
observer.mapboxTileCountLimitExceeded(limit);
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,22 +274,20 @@ public void onStatusChanged(OfflineRegionStatus status) {
}

// Debug
Timber.d(String.format("%s/%s resources; %s bytes downloaded.",
Timber.d("%s/%s resources; %s bytes downloaded.",
String.valueOf(status.getCompletedResourceCount()),
String.valueOf(status.getRequiredResourceCount()),
String.valueOf(status.getCompletedResourceSize())));
String.valueOf(status.getCompletedResourceSize()));
}

@Override
public void onError(OfflineRegionError error) {
Timber.e("onError reason: " + error.getReason());
Timber.e("onError message: " + error.getMessage());
offlineRegion.setObserver(null);
Timber.e("onError: %s, %s", error.getReason(), error.getMessage());
}

@Override
public void mapboxTileCountLimitExceeded(long limit) {
Timber.e("Mapbox tile count limit exceeded: " + limit);
Timber.e("Mapbox tile count limit exceeded: %s", limit);
}
});

Expand Down

0 comments on commit 6f8c2be

Please sign in to comment.