[android] Make it possible to set a custom map download URL

Signed-off-by: NoelClick <dev@noel.click>
This commit is contained in:
NoelClick
2025-11-15 19:24:42 -08:00
committed by Konstantin Pastbin
parent 6e7ba078c8
commit 023afecaa2
6 changed files with 39 additions and 7 deletions

View File

@@ -43,6 +43,7 @@
<string name="pref_backup" translatable="false">Backup</string>
<string name="pref_left_button" translatable="false">LeftButton</string>
<string name="pref_power" translatable="false">pref_power</string>
<string name="pref_custom_map_download_url" translatable="false">CustomMapDownloadUrl</string>
<string name="notification_ticker_ltr" translatable="false">%1$s: %2$s</string>
<string name="notification_ticker_rtl" translatable="false">%2$s :%1$s</string>

View File

@@ -42,12 +42,16 @@ using namespace std::placeholders;
namespace
{
std::unique_ptr<MapFilesDownloader> & LegacyDownloader()
{
static auto downloader = storage::GetDownloader();
return downloader;
}
static std::vector<platform::CountryFile> g_filesToDownload;
static int g_totalDownloadedBytes;
static int g_totalBytesToDownload;
static std::shared_ptr<HttpRequest> g_currentRequest;
} // namespace
extern "C"
@@ -152,11 +156,11 @@ JNIEXPORT jint JNICALL Java_app_organicmaps_sdk_DownloadResourcesLegacyActivity_
return ERR_NO_MORE_FILES;
/// @todo One downloader instance with cached servers. All this routine will be refactored some time.
static auto downloader = storage::GetDownloader();
auto & downloader = LegacyDownloader();
storage::Storage const & storage = g_framework->GetStorage();
downloader->SetDataVersion(storage.GetCurrentDataVersion());
downloader->EnsureMetaConfigReady([&storage, ptr = jni::make_global_ref(listener)]()
downloader->EnsureMetaConfigReady([&storage, ptr = jni::make_global_ref(listener), &downloader]()
{
auto const & curFile = g_filesToDownload.back();
auto const fileName = curFile.GetFileName(MapFileType::Map);
@@ -177,4 +181,12 @@ JNIEXPORT void JNICALL Java_app_organicmaps_sdk_DownloadResourcesLegacyActivity_
LOG(LDEBUG, ("cancelCurrentFile, currentRequest=", g_currentRequest));
g_currentRequest.reset();
}
JNIEXPORT void JNICALL Java_app_organicmaps_sdk_DownloadResourcesLegacyActivity_nativeResetMetaConfig(JNIEnv *,
jclass)
{
auto & downloader = LegacyDownloader();
if (downloader)
downloader->ResetMetaConfig();
}
}

View File

@@ -27,4 +27,5 @@ public class DownloadResourcesLegacyActivity
public static native int nativeGetBytesToDownload();
public static native int nativeStartNextFileDownload(Listener listener);
public static native void nativeCancelCurrentFile();
public static native void nativeResetMetaConfig();
}

View File

@@ -1,5 +1,6 @@
package app.organicmaps.sdk;
import android.content.Context;
import android.graphics.Bitmap;
import androidx.annotation.Keep;
import androidx.annotation.NonNull;
@@ -348,4 +349,13 @@ public class Framework
public static native void nativeMemoryWarning();
public static native void nativeSaveRoute();
public static native void nativeSetCustomMapDownloadUrl(String url);
public static void applyCustomMapDownloadUrl(@NonNull Context context, @Nullable String url)
{
String trimmed = url != null ? url.trim() : "";
nativeSetCustomMapDownloadUrl(trimmed);
// Reset the legacy downloader too (world/coasts).
app.organicmaps.sdk.DownloadResourcesLegacyActivity.nativeResetMetaConfig();
}
}

View File

@@ -2,6 +2,8 @@ package app.organicmaps.sdk;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import androidx.annotation.NonNull;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.LifecycleOwner;
@@ -167,6 +169,11 @@ public final class OrganicMaps implements DefaultLifecycleObserver
/* isTablet */ false);
Config.setStoragePath(writablePath);
// Use the same prefs as SettingsPrefsFragment
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
final String savedUrl = prefs.getString(mContext.getString(R.string.pref_custom_map_download_url), "");
Framework.nativeSetCustomMapDownloadUrl(savedUrl.trim());
mPlatformInitialized = true;
Logger.i(TAG, "Platform initialized");
}

View File

@@ -3,4 +3,5 @@
<string name="pref_file_name" translatable="false">OrganicMapsPrefs</string>
<string name="pref_enable_logging" translatable="false">EnableLogging</string>
<string name="pref_emulate_bad_external_storage" translatable="false">EmulateBadExternalStorage</string>
<string name="pref_custom_map_download_url" translatable="false">CustomMapDownloadUrl</string>
</resources>