[android] Add custom world map download URL option

- Allow setting a custom map download URL in the "world-download" screen.

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

View File

@@ -14,8 +14,10 @@ import android.annotation.SuppressLint;
import android.app.Dialog; import android.app.Dialog;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.location.Location; import android.location.Location;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.View; import android.view.View;
import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.ActivityResultLauncher;
@@ -42,6 +44,7 @@ import com.google.android.material.button.MaterialButton;
import com.google.android.material.checkbox.MaterialCheckBox; import com.google.android.material.checkbox.MaterialCheckBox;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.progressindicator.LinearProgressIndicator; import com.google.android.material.progressindicator.LinearProgressIndicator;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textview.MaterialTextView; import com.google.android.material.textview.MaterialTextView;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
@@ -54,6 +57,7 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity
private MaterialTextView mTvMessage; private MaterialTextView mTvMessage;
private LinearProgressIndicator mProgress; private LinearProgressIndicator mProgress;
private MaterialButton mBtnDownload; private MaterialButton mBtnDownload;
private MaterialButton mBtnAdvanced;
private MaterialCheckBox mChbDownloadCountry; private MaterialCheckBox mChbDownloadCountry;
private String mCurrentCountry; private String mCurrentCountry;
@@ -267,6 +271,9 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity
mProgress = findViewById(R.id.progressbar); mProgress = findViewById(R.id.progressbar);
mBtnDownload = findViewById(R.id.btn_download_resources); mBtnDownload = findViewById(R.id.btn_download_resources);
mChbDownloadCountry = findViewById(R.id.chb_download_country); mChbDownloadCountry = findViewById(R.id.chb_download_country);
mBtnAdvanced = findViewById(R.id.btn_advanced);
mBtnAdvanced.setOnClickListener(v -> openCustomServerDialog());
mBtnListeners = new View.OnClickListener[BTN_COUNT]; mBtnListeners = new View.OnClickListener[BTN_COUNT];
mBtnNames = new String[BTN_COUNT]; mBtnNames = new String[BTN_COUNT];
@@ -291,6 +298,11 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity
{ {
mBtnDownload.setOnClickListener(mBtnListeners[action]); mBtnDownload.setOnClickListener(mBtnListeners[action]);
mBtnDownload.setText(mBtnNames[action]); mBtnDownload.setText(mBtnNames[action]);
// Allow changing server only when idle or after an error.
boolean advancedEnabled = (action == DOWNLOAD || action == TRY_AGAIN);
mBtnAdvanced.setEnabled(advancedEnabled);
mBtnAdvanced.setAlpha(advancedEnabled ? 1f : 0.5f);
} }
private void doDownload() private void doDownload()
@@ -390,6 +402,39 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity
} }
} }
private void openCustomServerDialog()
{
View dialogView = getLayoutInflater().inflate(R.layout.dialog_custom_map_server, null);
TextInputEditText edit = dialogView.findViewById(R.id.edit_custom_map_server);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String current = prefs.getString(getString(R.string.pref_custom_map_download_url), "");
edit.setText(current);
new MaterialAlertDialogBuilder(this, R.style.MwmTheme_AlertDialog)
.setTitle(R.string.download_resources_custom_url_title)
.setMessage(R.string.download_resources_custom_url_message)
.setView(dialogView)
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(R.string.save, (dialog, which) -> {
String url = "";
if (edit.getText() != null)
url = edit.getText().toString().trim();
// Persist for future runs + Settings screen
prefs.edit()
.putString(getString(R.string.pref_custom_map_download_url), url)
.apply();
// Apply to native + reset meta configs
Framework.applyCustomMapDownloadUrl(this, url);
// Recompute total bytes (it can change with another server)
prepareFilesDownload(false);
})
.show();
}
private void showErrorDialog(int result) private void showErrorDialog(int result)
{ {
if (mAlertDialog != null && mAlertDialog.isShowing()) if (mAlertDialog != null && mAlertDialog.isShowing())

View File

@@ -6,6 +6,15 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<com.google.android.material.button.MaterialButton
android:id="@+id/btn_advanced"
style="@style/MwmWidget.M3.Button.Secondary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_base_plus"
android:layout_marginEnd="@dimen/margin_base_plus"
android:text="@string/download_resources_advanced"
android:textAppearance="@style/MwmTextAppearance.Body2"/>
<com.google.android.material.checkbox.MaterialCheckBox <com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/chb_download_country" android:id="@+id/chb_download_country"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.textfield.TextInputLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/download_resources_custom_url_title"
app:placeholderText="@string/download_resources_custom_url_hint">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_custom_map_server"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_base"
android:layout_marginEnd="@dimen/margin_base"
android:inputType="textUri"
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>