[android] when changing the resource path, recreate database instead of the whole FileSource
This commit is contained in:
committed by
Łukasz Paczos
parent
3f7b70fdb0
commit
b7702995fc
@@ -19,11 +19,12 @@ FileSource::FileSource(jni::JNIEnv& _env,
|
||||
const jni::String& accessToken,
|
||||
const jni::String& _cachePath,
|
||||
const jni::Object<AssetManager>& assetManager) {
|
||||
mapbox::sqlite::setTempPath(jni::Make<std::string>(_env, _cachePath));
|
||||
std::string path = jni::Make<std::string>(_env, _cachePath);
|
||||
mapbox::sqlite::setTempPath(path);
|
||||
|
||||
// Create a core default file source
|
||||
fileSource = std::make_unique<mbgl::DefaultFileSource>(
|
||||
jni::Make<std::string>(_env, _cachePath) + "/mbgl-offline.db",
|
||||
path + DATABASE_FILE,
|
||||
std::make_unique<AssetManagerFileSource>(_env, assetManager));
|
||||
|
||||
// Set access token
|
||||
@@ -69,6 +70,12 @@ void FileSource::setResourceTransform(jni::JNIEnv& env, const jni::Object<FileSo
|
||||
}
|
||||
}
|
||||
|
||||
void FileSource::setResourceCachePath(jni::JNIEnv& env, const jni::String& path) {
|
||||
std::string newPath = jni::Make<std::string>(env, path);
|
||||
mapbox::sqlite::setTempPath(newPath);
|
||||
fileSource->setResourceCachePath(newPath + DATABASE_FILE);
|
||||
}
|
||||
|
||||
void FileSource::resume(jni::JNIEnv&) {
|
||||
if (!activationCounter) {
|
||||
activationCounter = optional<int>(1) ;
|
||||
@@ -129,6 +136,7 @@ void FileSource::registerNative(jni::JNIEnv& env) {
|
||||
METHOD(&FileSource::setAccessToken, "setAccessToken"),
|
||||
METHOD(&FileSource::setAPIBaseUrl, "setApiBaseUrl"),
|
||||
METHOD(&FileSource::setResourceTransform, "setResourceTransform"),
|
||||
METHOD(&FileSource::setResourceCachePath, "setResourceCachePath"),
|
||||
METHOD(&FileSource::resume, "activate"),
|
||||
METHOD(&FileSource::pause, "deactivate"),
|
||||
METHOD(&FileSource::isResumed, "isActivated")
|
||||
|
||||
@@ -39,6 +39,8 @@ public:
|
||||
|
||||
void setResourceTransform(jni::JNIEnv&, const jni::Object<FileSource::ResourceTransformCallback>&);
|
||||
|
||||
void setResourceCachePath(jni::JNIEnv&, const jni::String&);
|
||||
|
||||
void resume(jni::JNIEnv&);
|
||||
|
||||
void pause(jni::JNIEnv&);
|
||||
@@ -52,6 +54,7 @@ public:
|
||||
static void registerNative(jni::JNIEnv&);
|
||||
|
||||
private:
|
||||
const std::string DATABASE_FILE = "/mbgl-offline.db";
|
||||
optional<int> activationCounter;
|
||||
std::unique_ptr<Actor<ResourceTransform>> resourceTransform;
|
||||
std::unique_ptr<mbgl::DefaultFileSource> fileSource;
|
||||
|
||||
Reference in New Issue
Block a user