Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
0606c8649c
1 changed files with 57 additions and 30 deletions
|
@ -4,6 +4,7 @@ import android.app.Dialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
|
@ -82,8 +83,9 @@ public class AdvancedEditPoiFragment extends Fragment
|
||||||
|
|
||||||
final MapPoiTypes mapPoiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes();
|
final MapPoiTypes mapPoiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes();
|
||||||
allTranslatedSubTypes = mapPoiTypes.getAllTranslatedNames();
|
allTranslatedSubTypes = mapPoiTypes.getAllTranslatedNames();
|
||||||
mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getData(),
|
mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getData());
|
||||||
mapPoiTypes);
|
// TODO do not restart initialization every time, and probably move initialization to appInit
|
||||||
|
new InitTagsAndValuesAutocompleteTask(mapPoiTypes).execute();
|
||||||
// setListViewHeightBasedOnChildren(editTagsLineaLayout);
|
// setListViewHeightBasedOnChildren(editTagsLineaLayout);
|
||||||
Button addTagButton = (Button) view.findViewById(R.id.addTagButton);
|
Button addTagButton = (Button) view.findViewById(R.id.addTagButton);
|
||||||
addTagButton.setOnClickListener(new View.OnClickListener() {
|
addTagButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@ -150,29 +152,16 @@ public class AdvancedEditPoiFragment extends Fragment
|
||||||
public class TagAdapterLinearLayoutHack {
|
public class TagAdapterLinearLayoutHack {
|
||||||
private final LinearLayout linearLayout;
|
private final LinearLayout linearLayout;
|
||||||
private final EditPoiData editPoiData;
|
private final EditPoiData editPoiData;
|
||||||
private final Map<String, AbstractPoiType> allTypes;
|
private final ArrayAdapter<String> tagAdapter;
|
||||||
private final HashSet<String> tagKeys;
|
private final ArrayAdapter<String> valueAdapter;
|
||||||
private final HashSet<String> valueKeys;
|
|
||||||
|
|
||||||
public TagAdapterLinearLayoutHack(LinearLayout linearLayout,
|
public TagAdapterLinearLayoutHack(LinearLayout linearLayout,
|
||||||
EditPoiData editPoiData,
|
EditPoiData editPoiData) {
|
||||||
MapPoiTypes mapPoiTypes) {
|
|
||||||
this.linearLayout = linearLayout;
|
this.linearLayout = linearLayout;
|
||||||
this.editPoiData = editPoiData;
|
this.editPoiData = editPoiData;
|
||||||
this.allTypes = mapPoiTypes.getAllTypesTranslatedNames(new StringMatcher() {
|
|
||||||
@Override
|
|
||||||
public boolean matches(String name) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
tagKeys = new HashSet<>();
|
|
||||||
valueKeys = new HashSet<>();
|
|
||||||
for (AbstractPoiType abstractPoiType : allTypes.values()) {
|
|
||||||
addPoiToStringSet(abstractPoiType, tagKeys, valueKeys);
|
|
||||||
}
|
|
||||||
addPoiToStringSet(mapPoiTypes.getOtherMapCategory(), tagKeys, valueKeys);
|
|
||||||
|
|
||||||
|
tagAdapter = new ArrayAdapter<>(linearLayout.getContext(), R.layout.list_textview);
|
||||||
|
valueAdapter = new ArrayAdapter<>(linearLayout.getContext(), R.layout.list_textview);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateViews() {
|
public void updateViews() {
|
||||||
|
@ -234,19 +223,16 @@ public class AdvancedEditPoiFragment extends Fragment
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ArrayAdapter<Object> tagAdapter = new ArrayAdapter<>(linearLayout.getContext(),
|
|
||||||
R.layout.list_textview, tagKeys.toArray());
|
|
||||||
tagEditText.setAdapter(tagAdapter);
|
tagEditText.setAdapter(tagAdapter);
|
||||||
tagEditText.setThreshold(1);
|
tagEditText.setThreshold(1);
|
||||||
tagEditText.setOnClickListener(new View.OnClickListener() {
|
tagEditText.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
final String[] tags = tagKeys.toArray(new String[tagKeys.size()]);
|
builder.setAdapter(tagAdapter, new Dialog.OnClickListener() {
|
||||||
builder.setItems(tags, new Dialog.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
tagEditText.setText(tags[which]);
|
tagAdapter.getItem(which);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -273,19 +259,17 @@ public class AdvancedEditPoiFragment extends Fragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ArrayAdapter<Object> valueAdapter = new ArrayAdapter<>(linearLayout.getContext(),
|
|
||||||
R.layout.list_textview, valueKeys.toArray());
|
|
||||||
valueEditText.setAdapter(valueAdapter);
|
valueEditText.setAdapter(valueAdapter);
|
||||||
valueEditText.setThreshold(1);
|
valueEditText.setThreshold(1);
|
||||||
valueEditText.setOnClickListener(new View.OnClickListener() {
|
valueEditText.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
final String[] values = valueKeys.toArray(new String[tagKeys.size()]);
|
builder.setAdapter(valueAdapter, new Dialog.OnClickListener() {
|
||||||
builder.setItems(values, new Dialog.OnClickListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
valueEditText.setText(values[which]);
|
valueAdapter.getItem(which);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -296,6 +280,18 @@ public class AdvancedEditPoiFragment extends Fragment
|
||||||
|
|
||||||
return convertView;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTagData(String[] tags) {
|
||||||
|
tagAdapter.clear();
|
||||||
|
tagAdapter.addAll(tags);
|
||||||
|
tagAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValueData(String[] values) {
|
||||||
|
valueAdapter.clear();
|
||||||
|
valueAdapter.addAll(values);
|
||||||
|
valueAdapter.notifyDataSetChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addPoiToStringSet(AbstractPoiType abstractPoiType, Set<String> stringSet,
|
private static void addPoiToStringSet(AbstractPoiType abstractPoiType, Set<String> stringSet,
|
||||||
|
@ -337,4 +333,35 @@ public class AdvancedEditPoiFragment extends Fragment
|
||||||
+ abstractPoiType.getClass());
|
+ abstractPoiType.getClass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class InitTagsAndValuesAutocompleteTask extends AsyncTask<Void, Void, Map<String, AbstractPoiType>> {
|
||||||
|
private final MapPoiTypes mapPoiTypes;
|
||||||
|
|
||||||
|
public InitTagsAndValuesAutocompleteTask(MapPoiTypes mapPoiTypes) {
|
||||||
|
this.mapPoiTypes = mapPoiTypes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<String, AbstractPoiType> doInBackground(Void... params) {
|
||||||
|
return mapPoiTypes.getAllTypesTranslatedNames(new StringMatcher() {
|
||||||
|
@Override
|
||||||
|
public boolean matches(String name) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Map<String, AbstractPoiType> result) {
|
||||||
|
HashSet<String> tagKeys = new HashSet<>();
|
||||||
|
HashSet<String> valueKeys = new HashSet<>();
|
||||||
|
for (AbstractPoiType abstractPoiType : result.values()) {
|
||||||
|
addPoiToStringSet(abstractPoiType, tagKeys, valueKeys);
|
||||||
|
}
|
||||||
|
addPoiToStringSet(mapPoiTypes.getOtherMapCategory(), tagKeys, valueKeys);
|
||||||
|
mAdapter.setTagData(tagKeys.toArray(new String[tagKeys.size()]));
|
||||||
|
mAdapter.setValueData(valueKeys.toArray(new String[valueKeys.size()]));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue