From a6d6cb8a8ba4816d80edf5c09ff4adfefbd214cd Mon Sep 17 00:00:00 2001 From: simonpoole Date: Sat, 9 Dec 2023 16:17:16 +0100 Subject: [PATCH] Allow for translations of the wms hint in layer names --- .../android/dialogs/ImageryListAdapter.java | 17 ++++++++------ .../java/de/blau/android/dialogs/Layers.java | 7 +++--- .../android/resources/TileLayerSource.java | 22 ++++++++++++++----- src/main/res/values/strings.xml | 1 + 4 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/main/java/de/blau/android/dialogs/ImageryListAdapter.java b/src/main/java/de/blau/android/dialogs/ImageryListAdapter.java index 8a87fd62e3..21bc93a485 100644 --- a/src/main/java/de/blau/android/dialogs/ImageryListAdapter.java +++ b/src/main/java/de/blau/android/dialogs/ImageryListAdapter.java @@ -1,5 +1,6 @@ package de.blau.android.dialogs; +import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -39,16 +40,17 @@ public ImageryViewHolder(@NonNull View v) { /** * Create a new adapter - * + * + * @param ctx an Android Context * @param ids an array with imagery ids * @param currentId the current imagery id * @param isOverlay true if overlay should be displayed * @param buttonLayoutParams layout params for the RadioButtons * @param groupChangeListener a listener to call when a RadioButton has been selected */ - public ImageryListAdapter(@NonNull String[] ids, String currentId, @Nullable boolean isOverlay, @NonNull LayoutParams buttonLayoutParams, - @NonNull android.widget.RadioGroup.OnCheckedChangeListener groupChangeListener) { - setIds(ids, isOverlay, false); + public ImageryListAdapter(@NonNull Context ctx, @NonNull String[] ids, String currentId, @Nullable boolean isOverlay, + @NonNull LayoutParams buttonLayoutParams, @NonNull android.widget.RadioGroup.OnCheckedChangeListener groupChangeListener) { + setIds(ctx, ids, isOverlay, false); this.currentId = currentId; this.buttonLayoutParams = buttonLayoutParams; this.groupChangeListener = groupChangeListener; @@ -111,14 +113,15 @@ public int getItemCount() { /** * Set the ids and name arrays that are going to be display - * + * + * @param ctx an Android context * @param ids the array of imagery ids * @param isOverlay true if this is for overlay selection * @param update if true this is an update of an existing adapter */ - void setIds(@NonNull String[] ids, boolean isOverlay, boolean update) { + void setIds(@NonNull Context ctx, @NonNull String[] ids, boolean isOverlay, boolean update) { this.ids = ids; - names = isOverlay ? TileLayerSource.getOverlayNames(ids) : TileLayerSource.getNames(ids); + names = isOverlay ? TileLayerSource.getOverlayNames(ctx, ids) : TileLayerSource.getNames(ctx, ids); if (update) { notifyDataSetChanged(); } diff --git a/src/main/java/de/blau/android/dialogs/Layers.java b/src/main/java/de/blau/android/dialogs/Layers.java index dcab5d029f..182cdea599 100644 --- a/src/main/java/de/blau/android/dialogs/Layers.java +++ b/src/main/java/de/blau/android/dialogs/Layers.java @@ -1146,8 +1146,9 @@ private void showImagerySelectDialog(@Nullable final TableRow row, @Nullable fin LinearLayoutManager layoutManager = new LinearLayoutManager(activity); imageryList.setLayoutManager(layoutManager); - final ImageryListAdapter adapter = new ImageryListAdapter(ids, newLayer ? TileLayerSource.LAYER_NONE : layer.getTileLayerConfiguration().getId(), - isOverlay, buttonLayoutParams, new LayerOnCheckedChangeListener(activity, dialog, row, layer, ids)); + final ImageryListAdapter adapter = new ImageryListAdapter(activity, ids, + newLayer ? TileLayerSource.LAYER_NONE : layer.getTileLayerConfiguration().getId(), isOverlay, buttonLayoutParams, + new LayerOnCheckedChangeListener(activity, dialog, row, layer, ids)); adapter.addInfoClickListener((String id) -> { TileLayerSource l = TileLayerSource.get(getContext(), id, true); if (l != null) { @@ -1171,7 +1172,7 @@ private void showImagerySelectDialog(@Nullable final TableRow row, @Nullable fin } else { prefs.setBackgroundCategory(category); } - adapter.setIds(idsForButtons, isOverlay, true); + adapter.setIds(getContext(), idsForButtons, isOverlay, true); adapter.setOnCheckedChangeListener(new LayerOnCheckedChangeListener(activity, dialog, row, layer, idsForButtons)); }); dialog.show(); diff --git a/src/main/java/de/blau/android/resources/TileLayerSource.java b/src/main/java/de/blau/android/resources/TileLayerSource.java index 896c7a6a33..e2f4059a24 100644 --- a/src/main/java/de/blau/android/resources/TileLayerSource.java +++ b/src/main/java/de/blau/android/resources/TileLayerSource.java @@ -51,6 +51,7 @@ import de.blau.android.App; import de.blau.android.Logic; import de.blau.android.Main; +import de.blau.android.R; import de.blau.android.contract.FileExtensions; import de.blau.android.contract.Files; import de.blau.android.contract.MimeTypes; @@ -1620,27 +1621,34 @@ public static String[] getNames(@Nullable Map map, @Nul * * @param ctx an Android context * @param ids array containing the ids + * * @return array containing the names */ @NonNull - public static String[] getNames(@NonNull String[] ids) { - return getNames(backgroundServerList, ids); + public static String[] getNames(@NonNull Context ctx, @NonNull String[] ids) { + return getNames(ctx, backgroundServerList, ids); } /** * Get tile server names from list of ids * + * @param ctx an Android context * @param map Map containing with id to layer mapping * @param ids array containing the ids + * * @return array containing the names */ @NonNull - public static String[] getNames(@Nullable Map map, @NonNull String[] ids) { + private static String[] getNames(@NonNull Context ctx, @Nullable Map map, @NonNull String[] ids) { List names = new ArrayList<>(); if (map != null) { for (String key : ids) { TileLayerSource osmts = map.get(key); - names.add(osmts.name + (TYPE_WMS.equals(osmts.type) ? " [wms]" : "")); + if (TYPE_WMS.equals(osmts.type)) { + names.add(ctx.getString(R.string.wms_hint, osmts.name)); + } else { + names.add(osmts.name); + } } } return names.toArray(new String[names.size()]); @@ -1675,12 +1683,14 @@ public static String[] getOverlayNames(@Nullable BoundingBox box, boolean filter /** * Get tile server names from list of ids * + * @param ctx an Android context * @param ids id list + * * @return list of names */ @NonNull - public static String[] getOverlayNames(@NonNull String[] ids) { - return getNames(overlayServerList, ids); + public static String[] getOverlayNames(Context ctx, @NonNull String[] ids) { + return getNames(ctx, overlayServerList, ids); } /** diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 33216a649b..0b5f892a29 100755 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -1030,6 +1030,7 @@ Enable bookmark layer Configure… Align imagery… + %1$s [wms] Apply stored offset to imagery Contrast