Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-11-18 22:03:39 +01:00
commit 4ccc25a53b
4 changed files with 60 additions and 52 deletions

View file

@ -146,6 +146,9 @@ public class MapPoiTypes {
public Map<String, PoiType> getAllTranslatedNames(boolean skipNonEditable) { public Map<String, PoiType> getAllTranslatedNames(boolean skipNonEditable) {
Map<String, PoiType> translation = new HashMap<String, PoiType>(); Map<String, PoiType> translation = new HashMap<String, PoiType>();
for(PoiCategory pc : categories) { for(PoiCategory pc : categories) {
if(skipNonEditable && pc.isNotEditableOsm()) {
continue;
}
for(PoiType pt : pc.getPoiTypes()) { for(PoiType pt : pc.getPoiTypes()) {
if(pt.isReference() ) { if(pt.isReference() ) {
continue; continue;

View file

@ -44,7 +44,6 @@ import android.widget.ImageButton;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
@ -253,17 +252,35 @@ public class EditPoiDialogFragment extends DialogFragment {
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
if (!getEditPoiData().isInEdit()) { if (!getEditPoiData().isInEdit()) {
PoiType pt = getEditPoiData().getAllTranslatedSubTypes().get(s.toString().toLowerCase());
if(pt != null) {
poiTypeTextInputLayout.setHint(pt.getCategory().getTranslation());
}
getEditPoiData().updateTypeTag(s.toString()); getEditPoiData().updateTypeTag(s.toString());
poiTypeTextInputLayout.setHint(editPoiData.getPoiCategory().getTranslation());
} }
} }
}); });
poiNameEditText.setOnEditorActionListener(mOnEditorActionListener); poiNameEditText.setOnEditorActionListener(mOnEditorActionListener);
poiTypeEditText.setOnEditorActionListener(mOnEditorActionListener); poiTypeEditText.setOnEditorActionListener(mOnEditorActionListener);
poiTypeEditText.setText(editPoiData.getPoiTypeString()); poiTypeEditText.setText(editPoiData.getPoiTypeString());
poiTypeEditText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(final View v, MotionEvent event) {
final EditText editText = (EditText) v;
final int DRAWABLE_RIGHT = 2;
if (event.getAction() == MotionEvent.ACTION_UP) {
if (event.getX() >= (editText.getRight()
- editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width()
- editText.getPaddingRight())) {
if (editPoiData.getPoiCategory() != null) {
DialogFragment dialogFragment =
PoiSubTypeDialogFragment.createInstance(editPoiData.getPoiCategory());
dialogFragment.show(getChildFragmentManager(), "PoiSubTypeDialogFragment");
}
return true;
}
}
return false;
}
});
Button saveButton = (Button) view.findViewById(R.id.saveButton); Button saveButton = (Button) view.findViewById(R.id.saveButton);
saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil
@ -299,7 +316,7 @@ public class EditPoiDialogFragment extends DialogFragment {
HashSet<String> tagsCopy = new HashSet<>(); HashSet<String> tagsCopy = new HashSet<>();
tagsCopy.addAll(editPoiData.getTagValues().keySet()); tagsCopy.addAll(editPoiData.getTagValues().keySet());
tagsCopy.removeAll(BASIC_TAGS); tagsCopy.removeAll(BASIC_TAGS);
if (tagsCopy.isEmpty()) { if (tagsCopy.isEmpty() || editPoiData.getPoiCategory() == getMyApplication().getPoiTypes().getOtherPoiCategory()) {
poiTypeEditText.setError(getResources().getString(R.string.please_specify_poi_type)); poiTypeEditText.setError(getResources().getString(R.string.please_specify_poi_type));
} else { } else {
new SaveWithAdvancedTagsDialogFragment().show(getChildFragmentManager(), "dialog"); new SaveWithAdvancedTagsDialogFragment().show(getChildFragmentManager(), "dialog");
@ -446,41 +463,26 @@ public class EditPoiDialogFragment extends DialogFragment {
}.execute(); }.execute();
} }
public void updateType(PoiCategory type) { public void setPoiCategory(PoiCategory type) {
editPoiData.updateType(type); editPoiData.updateType(type);
poiTypeEditText.setText(editPoiData.getPoiTypeString()); poiTypeEditText.setText(editPoiData.getPoiTypeString());
poiTypeTextInputLayout.setHint(editPoiData.getPoiCategory().getTranslation());
setAdapterForPoiTypeEditText(); setAdapterForPoiTypeEditText();
poiTypeEditText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(final View v, MotionEvent event) {
final EditText editText = (EditText) v;
final int DRAWABLE_RIGHT = 2;
if (event.getAction() == MotionEvent.ACTION_UP) {
if (event.getX() >= (editText.getRight()
- editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width()
- editText.getPaddingRight())) {
if (editPoiData.getPoiCategory() != null) {
DialogFragment dialogFragment =
PoiSubTypeDialogFragment.createInstance(editPoiData.getPoiCategory());
dialogFragment.show(getChildFragmentManager(), "PoiSubTypeDialogFragment");
}
return true;
}
}
return false;
}
});
} }
private void setAdapterForPoiTypeEditText() { private void setAdapterForPoiTypeEditText() {
final Map<String, PoiType> subCategories = new LinkedHashMap<>(); final Map<String, PoiType> subCategories = new LinkedHashMap<>();
for (Map.Entry<String, PoiType> s : editPoiData.getAllTranslatedSubTypes().entrySet()) { PoiCategory ct = editPoiData.getPoiCategory();
if (!subCategories.containsKey(s.getKey())) { if(ct != null) {
subCategories.put(Algorithms.capitalizeFirstLetterAndLowercase(s.getKey()), s.getValue()); for (PoiType s : ct.getPoiTypes()) {
if(!s.isReference() && !s.isNotEditableOsm() && s.getBaseLangType() == null) {
addMapEntryAdapter(subCategories, s.getTranslation(), s);
addMapEntryAdapter(subCategories, s.getKeyName().replace('_', ' '), s);
}
} }
} }
for (Map.Entry<String, PoiType> s : editPoiData.getAllTranslatedSubTypes().entrySet()) {
addMapEntryAdapter(subCategories, s.getKey(), s.getValue());
}
final ArrayAdapter<Object> adapter; final ArrayAdapter<Object> adapter;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
adapter = new ArrayAdapter<>(getActivity(), adapter = new ArrayAdapter<>(getActivity(),
@ -513,14 +515,8 @@ public class EditPoiDialogFragment extends DialogFragment {
@Override @Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Object item = parent.getAdapter().getItem(position); Object item = parent.getAdapter().getItem(position);
//noinspection SuspiciousMethodCalls poiTypeEditText.setText(item.toString());
if (subCategories.containsKey(item.toString().toLowerCase())) { setAdapterForPoiTypeEditText();
//noinspection SuspiciousMethodCalls
PoiType pt = subCategories.get(item);
String keyName = pt.getKeyName();
poiTypeTextInputLayout.setHint(pt.getCategory().getTranslation());
poiTypeEditText.setText(keyName);
}
} }
@Override @Override
@ -530,6 +526,12 @@ public class EditPoiDialogFragment extends DialogFragment {
} }
private void addMapEntryAdapter(final Map<String, PoiType> subCategories, String key, PoiType v) {
if (!subCategories.containsKey(key.toLowerCase())) {
subCategories.put(Algorithms.capitalizeFirstLetterAndLowercase(key), v);
}
}
private OsmandApplication getMyApplication() { private OsmandApplication getMyApplication() {
return (OsmandApplication) getActivity().getApplication(); return (OsmandApplication) getActivity().getApplication();
} }

View file

@ -1,7 +1,9 @@
package net.osmand.plus.osmedit.dialogs; package net.osmand.plus.osmedit.dialogs;
import java.util.Map; import java.util.ArrayList;
import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.TreeSet;
import net.osmand.osm.MapPoiTypes; import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiCategory;
@ -24,8 +26,12 @@ public class PoiSubTypeDialogFragment extends DialogFragment {
MapPoiTypes poiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes(); MapPoiTypes poiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final PoiCategory a = poiTypes.getPoiCategoryByName((String) getArguments().getSerializable(KEY_POI_CATEGORY)); final PoiCategory a = poiTypes.getPoiCategoryByName((String) getArguments().getSerializable(KEY_POI_CATEGORY));
final Map<String, PoiType> allTranslatedNames = poiTypes.getAllTranslatedNames(a, true); Set<String> strings = new TreeSet<>();
Set<String> strings = allTranslatedNames.keySet(); for (PoiType s : a.getPoiTypes()) {
if (!s.isReference() && !s.isNotEditableOsm() && s.getBaseLangType() == null) {
strings.add(s.getTranslation());
}
}
final String[] subCats = strings.toArray(new String[strings.size()]); final String[] subCats = strings.toArray(new String[strings.size()]);
builder.setItems(subCats, new DialogInterface.OnClickListener() { builder.setItems(subCats, new DialogInterface.OnClickListener() {
@Override @Override

View file

@ -21,22 +21,19 @@ public class PoiTypeDialogFragment extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
MapPoiTypes poiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes(); MapPoiTypes poiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final List<PoiCategory> categories = poiTypes.getCategories(false); final List<PoiCategory> categories = new ArrayList<PoiCategory>();
ArrayList<String> vals = new ArrayList<>(categories.size()); ArrayList<String> vals = new ArrayList<>();
ArrayList<PoiCategory> toDelete = new ArrayList<>(); for (PoiCategory category : poiTypes.getCategories(false)) {
for (PoiCategory category : categories) { if (!category.isNotEditableOsm()) {
if (category.isNotEditableOsm()) {
toDelete.add(category);
} else {
vals.add(category.getTranslation()); vals.add(category.getTranslation());
categories.add(category);
} }
} }
categories.removeAll(toDelete);
builder.setItems(vals.toArray(new String[vals.size()]), new Dialog.OnClickListener() { builder.setItems(vals.toArray(new String[vals.size()]), new Dialog.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
PoiCategory aType = categories.get(which); PoiCategory aType = categories.get(which);
((EditPoiDialogFragment) getParentFragment()).updateType(aType); ((EditPoiDialogFragment) getParentFragment()).setPoiCategory(aType);
dismiss(); dismiss();
} }
}); });