Skip to content

Commit

Permalink
Allow for translations of the wms hint in layer names
Browse files Browse the repository at this point in the history
  • Loading branch information
simonpoole committed Dec 9, 2023
1 parent be8724e commit a6d6cb8
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
17 changes: 10 additions & 7 deletions src/main/java/de/blau/android/dialogs/ImageryListAdapter.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/de/blau/android/dialogs/Layers.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
Expand Down
22 changes: 16 additions & 6 deletions src/main/java/de/blau/android/resources/TileLayerSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1620,27 +1621,34 @@ public static String[] getNames(@Nullable Map<String, TileLayerSource> 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<String, TileLayerSource> map, @NonNull String[] ids) {
private static String[] getNames(@NonNull Context ctx, @Nullable Map<String, TileLayerSource> map, @NonNull String[] ids) {
List<String> 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()]);
Expand Down Expand Up @@ -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);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,7 @@
<string name="menu_layers_enable_bookmarkslayer">Enable bookmark layer</string>
<string name="menu_layers_configure">Configure…</string>
<string name="menu_layers_background_align">Align imagery…</string>
<string name="wms_hint">%1$s [wms]</string>
<!-- -->
<string name="menu_tools_apply_local_offset">Apply stored offset to imagery</string>
<string name="menu_tools_background_contrast">Contrast</string>
Expand Down

0 comments on commit a6d6cb8

Please sign in to comment.