[ios, osx] Privatized offline region observer
This commit is contained in:
committed by
Minh Nguyễn
parent
c335847451
commit
68ba0712f7
@@ -18,12 +18,21 @@
|
||||
} \
|
||||
} while (NO);
|
||||
|
||||
class MBGLOfflineRegionObserver;
|
||||
class MBGLOfflineRegionObserver : public mbgl::OfflineRegionObserver {
|
||||
public:
|
||||
MBGLOfflineRegionObserver(MGLOfflineTask *offlineTask_) : offlineTask(offlineTask_) {}
|
||||
|
||||
void statusChanged(mbgl::OfflineRegionStatus status) override;
|
||||
void responseError(mbgl::Response::Error error) override;
|
||||
void mapboxTileCountLimitExceeded(uint64_t limit) override;
|
||||
|
||||
private:
|
||||
__weak MGLOfflineTask *offlineTask = nullptr;
|
||||
};
|
||||
|
||||
@interface MGLOfflineTask ()
|
||||
|
||||
@property (nonatomic, readwrite) mbgl::OfflineRegion *mbglOfflineRegion;
|
||||
@property (nonatomic, readwrite) MBGLOfflineRegionObserver *mbglOfflineRegionObserver;
|
||||
@property (nonatomic, readwrite) MGLOfflineTaskState state;
|
||||
@property (nonatomic, readwrite) MGLOfflineTaskProgress progress;
|
||||
|
||||
@@ -43,17 +52,17 @@ class MBGLOfflineRegionObserver;
|
||||
if (self = [super init]) {
|
||||
_mbglOfflineRegion = region;
|
||||
_state = MGLOfflineTaskStateInactive;
|
||||
_mbglOfflineRegionObserver = new MBGLOfflineRegionObserver(self);
|
||||
|
||||
mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
|
||||
mbglFileSource->setOfflineRegionObserver(*_mbglOfflineRegion, std::make_unique<MBGLOfflineRegionObserver>(*_mbglOfflineRegionObserver));
|
||||
MBGLOfflineRegionObserver *mbglObserver = new MBGLOfflineRegionObserver(self);
|
||||
mbglFileSource->setOfflineRegionObserver(*_mbglOfflineRegion, std::make_unique<MBGLOfflineRegionObserver>(*mbglObserver));
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
delete _mbglOfflineRegionObserver;
|
||||
_mbglOfflineRegionObserver = nullptr;
|
||||
mbgl::DefaultFileSource *mbglFileSource = [[MGLOfflineStorage sharedOfflineStorage] mbglFileSource];
|
||||
mbglFileSource->setOfflineRegionObserver(*_mbglOfflineRegion, nullptr);
|
||||
}
|
||||
|
||||
- (id <MGLOfflineRegion>)region {
|
||||
|
||||
@@ -2,27 +2,12 @@
|
||||
|
||||
#include <mbgl/storage/default_file_source.hpp>
|
||||
|
||||
class MBGLOfflineRegionObserver;
|
||||
|
||||
@interface MGLOfflineTask (Private)
|
||||
|
||||
@property (nonatomic) mbgl::OfflineRegion *mbglOfflineRegion;
|
||||
@property (nonatomic, readonly) MBGLOfflineRegionObserver *mbglOfflineRegionObserver;
|
||||
|
||||
- (instancetype)initWithMBGLRegion:(mbgl::OfflineRegion *)region;
|
||||
|
||||
- (void)invalidate;
|
||||
|
||||
@end
|
||||
|
||||
class MBGLOfflineRegionObserver : public mbgl::OfflineRegionObserver {
|
||||
public:
|
||||
MBGLOfflineRegionObserver(MGLOfflineTask *offlineTask_) : offlineTask(offlineTask_) {}
|
||||
|
||||
void statusChanged(mbgl::OfflineRegionStatus status) override;
|
||||
void responseError(mbgl::Response::Error error) override;
|
||||
void mapboxTileCountLimitExceeded(uint64_t limit) override;
|
||||
|
||||
private:
|
||||
__weak MGLOfflineTask *offlineTask = nullptr;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user