[android] Add custom map download URL setting

Signed-off-by: NoelClick <dev@noel.click>
This commit is contained in:
NoelClick
2025-11-15 19:34:17 -08:00
committed by jeanbaptisteC
parent 4ba0fc51a5
commit 6c92264fb0
3 changed files with 32 additions and 0 deletions

View File

@@ -8,6 +8,7 @@ import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.preference.EditTextPreference;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
@@ -73,6 +74,7 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment implements La
initScreenSleepEnabledPrefsCallbacks();
initShowOnLockScreenPrefsCallbacks();
initLeftButtonPrefs();
initCustomMapDownloadUrlPrefsCallbacks();
}
private void initLeftButtonPrefs()
@@ -535,6 +537,20 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment implements La
});
}
private void initCustomMapDownloadUrlPrefsCallbacks()
{
EditTextPreference customUrlPref = getPreference(getString(R.string.pref_custom_map_download_url));
customUrlPref.setOnPreferenceChangeListener((preference, newValue) -> {
String url = newValue != null ? ((String) newValue).trim() : "";
Framework.applyCustomMapDownloadUrl(requireContext(), url);
return true; // save the value
});
// Ensure native side is updated when the screen opens
String current = customUrlPref.getText();
Framework.applyCustomMapDownloadUrl(requireContext(), current != null ? current.trim() : "");
}
private void removePreference(@NonNull String categoryKey, @NonNull Preference preference)
{
final PreferenceCategory category = getPreference(categoryKey);

View File

@@ -966,4 +966,11 @@
<string name="offline_explanation_title">Offline Maps</string>
<string name="offline_explanation_text">A map needs to be downloaded to view and navigate the area.\nDownload maps for areas you want to travel.</string>
<string name="list_description_empty">Edit the list to add a description</string>
<!-- Custom Download URL -->
<string name="pref_custom_map_download_url_title">Custom map server</string>
<string name="pref_custom_map_download_url_summary">Leave empty to use the default CoMaps servers. Example: https://example.org/servers</string>
<string name="download_resources_advanced">Advanced…</string>
<string name="download_resources_custom_url_title">Custom map server</string>
<string name="download_resources_custom_url_message">Override the default map download server used for map downloads. Leave empty to use CoMaps default server.</string>
<string name="download_resources_custom_url_hint">https://comaps.app/servers/</string>
</resources>

View File

@@ -212,5 +212,14 @@
android:defaultValue="true"
android:widgetLayout="@layout/preference_switch"
android:order="2"/>
<EditTextPreference
android:key="@string/pref_custom_map_download_url"
android:title="@string/pref_custom_map_download_url_title"
android:summary="@string/pref_custom_map_download_url_summary"
android:inputType="textUri"
android:singleLine="true"
android:defaultValue=""
android:order="3"/>
</androidx.preference.PreferenceCategory>
</androidx.preference.PreferenceScreen>