Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Locationpicker Translations #873

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ public static String getTranslatedLocation(String locationName) {
String key = getLocationKeyFromName(locationName);
String translatedLocationName = getTranslatedIdentifier(key);

return StringUtils.isNotEmpty(translatedLocationName) ? translatedLocationName : locationName;
return StringUtils.isNotEmpty(translatedLocationName) && !translatedLocationName.equals(key) ? translatedLocationName : locationName;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@
import org.smartregister.R;
import org.smartregister.adapter.ServiceLocationsAdapter;
import org.smartregister.location.helper.LocationHelper;
import org.smartregister.util.Utils;
import org.smartregister.view.customcontrols.CustomFontTextView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
* @author Jason Rogena - jrogena@ona.io
Expand Down Expand Up @@ -76,7 +78,9 @@ public void init() {
Collections.sort(sortedLocations);
sortedLocations.add(0, defaultLocation);

serviceLocationsAdapter = new ServiceLocationsAdapter(context, sortedLocations);
List<String> translatedLocations = sortedLocations.stream().map(Utils::getTranslatedLocation).collect(Collectors.toList());

serviceLocationsAdapter = new ServiceLocationsAdapter(context, translatedLocations);
locationsLV.setAdapter(serviceLocationsAdapter);
locationsLV.setOnItemClickListener((parent, view, position, id) -> {
CoreLibrary.getInstance().context().allSharedPreferences().saveCurrentLocality(serviceLocationsAdapter.getLocationAt(position));
Expand All @@ -88,7 +92,7 @@ public void init() {
}
locationPickerDialog.dismiss();
});
this.setText(LocationHelper.getInstance().getOpenMrsReadableName(getSelectedItem()));
this.setText(Utils.getTranslatedLocation(LocationHelper.getInstance().getOpenMrsReadableName(getSelectedItem())));

setClickable(true);
setOnClickListener(this);
Expand All @@ -101,7 +105,7 @@ public String getSelectedItem() {
CoreLibrary.getInstance().context().allSharedPreferences().saveCurrentLocality(selectedLocation);
CoreLibrary.getInstance().context().allSharedPreferences().saveCurrentDataStrategy(AllConstants.DATA_CAPTURE_STRATEGY.NORMAL);
}
return selectedLocation;
return Utils.getTranslatedLocation(selectedLocation);
}

public void setOnLocationChangeListener(final OnLocationChangeListener onLocationChangeListener) {
Expand Down