mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-19 21:13:35 +00:00
[android] Make it possible to set a custom map download URL
Signed-off-by: NoelClick <dev@noel.click>
This commit is contained in:
@@ -43,6 +43,7 @@
|
|||||||
<string name="pref_backup" translatable="false">Backup</string>
|
<string name="pref_backup" translatable="false">Backup</string>
|
||||||
<string name="pref_left_button" translatable="false">LeftButton</string>
|
<string name="pref_left_button" translatable="false">LeftButton</string>
|
||||||
<string name="pref_power" translatable="false">pref_power</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_ltr" translatable="false">%1$s: %2$s</string>
|
||||||
<string name="notification_ticker_rtl" translatable="false">%2$s :%1$s</string>
|
<string name="notification_ticker_rtl" translatable="false">%2$s :%1$s</string>
|
||||||
|
|||||||
@@ -42,12 +42,16 @@ using namespace std::placeholders;
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
std::unique_ptr<MapFilesDownloader> & LegacyDownloader()
|
||||||
|
{
|
||||||
|
static auto downloader = storage::GetDownloader();
|
||||||
|
return downloader;
|
||||||
|
}
|
||||||
|
|
||||||
static std::vector<platform::CountryFile> g_filesToDownload;
|
static std::vector<platform::CountryFile> g_filesToDownload;
|
||||||
static int g_totalDownloadedBytes;
|
static int g_totalDownloadedBytes;
|
||||||
static int g_totalBytesToDownload;
|
static int g_totalBytesToDownload;
|
||||||
static std::shared_ptr<HttpRequest> g_currentRequest;
|
static std::shared_ptr<HttpRequest> g_currentRequest;
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
@@ -152,11 +156,11 @@ JNIEXPORT jint JNICALL Java_app_organicmaps_sdk_DownloadResourcesLegacyActivity_
|
|||||||
return ERR_NO_MORE_FILES;
|
return ERR_NO_MORE_FILES;
|
||||||
|
|
||||||
/// @todo One downloader instance with cached servers. All this routine will be refactored some time.
|
/// @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();
|
storage::Storage const & storage = g_framework->GetStorage();
|
||||||
downloader->SetDataVersion(storage.GetCurrentDataVersion());
|
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 & curFile = g_filesToDownload.back();
|
||||||
auto const fileName = curFile.GetFileName(MapFileType::Map);
|
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));
|
LOG(LDEBUG, ("cancelCurrentFile, currentRequest=", g_currentRequest));
|
||||||
g_currentRequest.reset();
|
g_currentRequest.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_app_organicmaps_sdk_DownloadResourcesLegacyActivity_nativeResetMetaConfig(JNIEnv *,
|
||||||
|
jclass)
|
||||||
|
{
|
||||||
|
auto & downloader = LegacyDownloader();
|
||||||
|
if (downloader)
|
||||||
|
downloader->ResetMetaConfig();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,4 +27,5 @@ public class DownloadResourcesLegacyActivity
|
|||||||
public static native int nativeGetBytesToDownload();
|
public static native int nativeGetBytesToDownload();
|
||||||
public static native int nativeStartNextFileDownload(Listener listener);
|
public static native int nativeStartNextFileDownload(Listener listener);
|
||||||
public static native void nativeCancelCurrentFile();
|
public static native void nativeCancelCurrentFile();
|
||||||
|
public static native void nativeResetMetaConfig();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package app.organicmaps.sdk;
|
package app.organicmaps.sdk;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import androidx.annotation.Keep;
|
import androidx.annotation.Keep;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -348,4 +349,13 @@ public class Framework
|
|||||||
|
|
||||||
public static native void nativeMemoryWarning();
|
public static native void nativeMemoryWarning();
|
||||||
public static native void nativeSaveRoute();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package app.organicmaps.sdk;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.lifecycle.DefaultLifecycleObserver;
|
import androidx.lifecycle.DefaultLifecycleObserver;
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
@@ -167,6 +169,11 @@ public final class OrganicMaps implements DefaultLifecycleObserver
|
|||||||
/* isTablet */ false);
|
/* isTablet */ false);
|
||||||
Config.setStoragePath(writablePath);
|
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;
|
mPlatformInitialized = true;
|
||||||
Logger.i(TAG, "Platform initialized");
|
Logger.i(TAG, "Platform initialized");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,4 +3,5 @@
|
|||||||
<string name="pref_file_name" translatable="false">OrganicMapsPrefs</string>
|
<string name="pref_file_name" translatable="false">OrganicMapsPrefs</string>
|
||||||
<string name="pref_enable_logging" translatable="false">EnableLogging</string>
|
<string name="pref_enable_logging" translatable="false">EnableLogging</string>
|
||||||
<string name="pref_emulate_bad_external_storage" translatable="false">EmulateBadExternalStorage</string>
|
<string name="pref_emulate_bad_external_storage" translatable="false">EmulateBadExternalStorage</string>
|
||||||
|
<string name="pref_custom_map_download_url" translatable="false">CustomMapDownloadUrl</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user