[android] Unify custom map server dialog logic and UI

- Add setting icon for custom map server download option.
- Extract shared custom map server dialog helper.
- Clean up based on reviewers' feedback.

Signed-off-by: NoelClick <dev@noel.click>
This commit is contained in:
NoelClick
2025-12-03 12:18:12 -08:00
committed by jeanbaptisteC
parent 76ecd8209e
commit 2b630964d0
15 changed files with 147 additions and 170 deletions

View File

@@ -124,6 +124,7 @@ dependencies {
implementation libs.androidx.lifecycle.process
implementation libs.androidx.media
implementation libs.androidx.recyclerview
implementation libs.androidx.preference
implementation libs.android.material
testImplementation libs.junit

View File

@@ -42,16 +42,16 @@ using namespace std::placeholders;
namespace
{
std::unique_ptr<MapFilesDownloader> & LegacyDownloader()
{
static auto downloader = storage::GetDownloader();
return downloader;
}
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;
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"

View File

@@ -356,14 +356,16 @@ public class Framework
public static void applyCustomMapDownloadUrl(@NonNull Context context, @Nullable String url)
{
String normalizedUrl = url != null ? url.trim() : "";
// Normalize
if (!normalizedUrl.isEmpty() && !normalizedUrl.endsWith("/"))
normalizedUrl = normalizedUrl + "/";
nativeSetCustomMapDownloadUrl(normalizedUrl);
nativeSetCustomMapDownloadUrl(normalizeServerUrl(url));
// Reset the legacy downloader too (world/coasts).
app.organicmaps.sdk.DownloadResourcesLegacyActivity.nativeResetMetaConfig();
}
public static String normalizeServerUrl(@Nullable String url)
{
String out = url != null ? url.trim() : "";
if (!out.isEmpty() && !out.endsWith("/"))
out = out + "/";
return out;
}
}

View File

@@ -2,12 +2,13 @@ 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;
import androidx.lifecycle.ProcessLifecycleOwner;
import androidx.preference.PreferenceManager;
import app.organicmaps.sdk.bookmarks.data.BookmarkManager;
import app.organicmaps.sdk.bookmarks.data.Icon;
import app.organicmaps.sdk.downloader.Android7RootCertificateWorkaround;
@@ -27,6 +28,7 @@ import app.organicmaps.sdk.util.SharedPropertiesUtils;
import app.organicmaps.sdk.util.StorageUtils;
import app.organicmaps.sdk.util.log.Logger;
import app.organicmaps.sdk.util.log.LogsManager;
import java.io.IOException;
public final class OrganicMaps implements DefaultLifecycleObserver