Revert "Poi dialog design. Work in progress"
This reverts commit 5b89faeddf
.
This commit is contained in:
parent
560cb72898
commit
1f5c1a6c95
11 changed files with 255 additions and 769 deletions
|
@ -1,19 +1,12 @@
|
|||
<LinearLayout
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/dashboard_background"
|
||||
android:orientation="vertical"
|
||||
tools:context="net.osmand.plus.osmedit.EditPoiFragment">
|
||||
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -41,11 +34,10 @@
|
|||
android:layout_marginTop="16dp">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/poiNameEditText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:hint="Name"
|
||||
tools:text="@string/lorem_ipsum"/>
|
||||
android:text="@string/lorem_ipsum"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
</LinearLayout>
|
||||
|
@ -54,30 +46,21 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginLeft="72dp"
|
||||
app:layout_scrollFlags="scroll">
|
||||
<!--android:layout_marginLeft="72dp"-->
|
||||
<ImageButton
|
||||
android:id="@+id/poiTypeButton"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="@null"
|
||||
android:src="@drawable/ic_action_label"/>
|
||||
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginLeft="24dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<AutoCompleteTextView
|
||||
android:id="@+id/poiTypeEditText"
|
||||
<EditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:drawableRight="@drawable/ic_action_arrow_drop_down"
|
||||
android:hint="POI Type"
|
||||
tools:text="@string/lorem_ipsum"/>
|
||||
android:text="@string/lorem_ipsum"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
|
@ -100,41 +83,9 @@
|
|||
app:tabTextColor="@android:color/darker_gray"/>
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
|
||||
<android.support.v4.view.ViewPager
|
||||
android:id="@+id/viewpager"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/buttonDivider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/divider_color"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:gravity="right">
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancelButton"
|
||||
style="?android:attr/borderlessButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/shared_string_cancel"
|
||||
android:textColor="@color/dashboard_general_button_text_light"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/saveButton"
|
||||
style="?android:attr/borderlessButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/dashboard_general_button_text_light"
|
||||
tools:text="Save"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
<android.support.v4.widget.NestedScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/dashboard_background">
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
|
@ -25,5 +26,24 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:text="Add tag"/>
|
||||
|
||||
<android.support.v7.widget.CardView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Added tags"/>
|
||||
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/added_tags_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
</android.support.v7.widget.CardView>
|
||||
</LinearLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
||||
|
|
|
@ -3,16 +3,26 @@
|
|||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/dashboard_background">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/openHoursTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:text="Open hours"
|
||||
android:textColor="@color/color_black"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/contactInfoTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/openHoursTextView"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:text="Contact info"
|
||||
android:textColor="@color/color_black"/>
|
||||
|
@ -82,13 +92,33 @@
|
|||
android:layout_below="@id/webSiteEditText"
|
||||
android:hint="Description"
|
||||
android:inputType="textMultiLine"/>
|
||||
<TextView
|
||||
android:id="@+id/openHoursTextView"
|
||||
|
||||
<View
|
||||
android:id="@+id/buttonDivider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_below="@id/descriptionEditText"
|
||||
android:background="@color/divider_color"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/saveButton"
|
||||
style="?android:attr/borderlessButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/descriptionEditText"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:text="Open hours"
|
||||
android:textColor="@color/color_black"/>
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_below="@id/buttonDivider"
|
||||
tools:text="Save"
|
||||
android:textColor="@color/dashboard_general_button_text_light"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancelButton"
|
||||
style="?android:attr/borderlessButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/buttonDivider"
|
||||
android:layout_toLeftOf="@id/saveButton"
|
||||
android:text="Cancel"
|
||||
android:textColor="@color/dashboard_general_button_text_light"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
|
@ -45,7 +45,6 @@ import net.osmand.plus.OsmandSettings;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.IntermediatePointsDialog;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
||||
import net.osmand.plus.audionotes.DashAudioVideoNotesFragment;
|
||||
import net.osmand.plus.dashboard.tools.DashFragmentData;
|
||||
import net.osmand.plus.dashboard.tools.DashboardSettingsDialogFragment;
|
||||
|
@ -58,13 +57,9 @@ import net.osmand.plus.helpers.AndroidUiHelper;
|
|||
import net.osmand.plus.helpers.WaypointDialogHelper;
|
||||
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
|
||||
import net.osmand.plus.monitoring.DashTrackFragment;
|
||||
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
||||
import net.osmand.plus.osmedit.DashOsmEditsFragment;
|
||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
import net.osmand.plus.osmo.DashOsMoFragment;
|
||||
import net.osmand.plus.osmo.OsMoPlugin;
|
||||
import net.osmand.plus.parkingpoint.DashParkingFragment;
|
||||
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.views.DownloadedRegionsLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
|
@ -92,32 +87,22 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
private static final DashFragmentData.ShouldShowFunction chooseAppDirShouldShow = new ChooseAppDirShouldShow();
|
||||
|
||||
private static final DashFragmentData[] fragmentsData = new DashFragmentData[]{
|
||||
new DashFragmentData(DashRateUsFragment.TAG, DashRateUsFragment.class, "Rate us",
|
||||
rateUsShouldShow, new CanNotHideFunction()),
|
||||
new DashFragmentData(DashFirstTimeFragment.TAG, DashFirstTimeFragment.class, "First time",
|
||||
firstTimeShouldShow, new CanNotHideFunction()),
|
||||
new DashFragmentData(DashChooseAppDirFragment.TAG, DashChooseAppDirFragment.class, "Choose app dir",
|
||||
chooseAppDirShouldShow, new CanNotHideFunction()),
|
||||
new DashFragmentData(DashErrorFragment.TAG, DashErrorFragment.class, "Error",
|
||||
errorShouldShow, new CanNotHideFunction()),
|
||||
new DashFragmentData(DashRateUsFragment.TAG, DashRateUsFragment.class, "Rate us", rateUsShouldShow, true),
|
||||
new DashFragmentData(DashFirstTimeFragment.TAG, DashFirstTimeFragment.class, "First time", firstTimeShouldShow, true),
|
||||
new DashFragmentData(DashChooseAppDirFragment.TAG, DashChooseAppDirFragment.class, "Choose app dir", chooseAppDirShouldShow, true),
|
||||
new DashFragmentData(DashErrorFragment.TAG, DashErrorFragment.class, "Error", errorShouldShow, true),
|
||||
new DashFragmentData(DashNavigationFragment.TAG, DashNavigationFragment.class, "Navigation", defaultShouldShow),
|
||||
new DashFragmentData(DashParkingFragment.TAG, DashParkingFragment.class, "Parking",
|
||||
defaultShouldShow, new CanHideIfPluginEnabled(ParkingPositionPlugin.class)),
|
||||
new DashFragmentData(DashParkingFragment.TAG, DashParkingFragment.class, "Parking", defaultShouldShow),
|
||||
new DashFragmentData(DashWaypointsFragment.TAG, DashWaypointsFragment.class, "Waypoints", defaultShouldShow),
|
||||
new DashFragmentData(DashSearchFragment.TAG, DashSearchFragment.class, "Search", defaultShouldShow),
|
||||
new DashFragmentData(DashRecentsFragment.TAG, DashRecentsFragment.class, "Recent places", defaultShouldShow),
|
||||
new DashFragmentData(DashFavoritesFragment.TAG, DashFavoritesFragment.class, "Favourites", defaultShouldShow),
|
||||
new DashFragmentData(DashAudioVideoNotesFragment.TAG, DashAudioVideoNotesFragment.class, "Notes",
|
||||
defaultShouldShow, new CanHideIfPluginEnabled(AudioVideoNotesPlugin.class)),
|
||||
new DashFragmentData(DashTrackFragment.TAG, DashTrackFragment.class, "Track",
|
||||
defaultShouldShow, new CanHideIfPluginEnabled(OsmandMonitoringPlugin.class)),
|
||||
new DashFragmentData(DashOsMoFragment.TAG, DashOsMoFragment.class, "OsMo",
|
||||
defaultShouldShow, new CanHideIfPluginEnabled(OsMoPlugin.class)),
|
||||
new DashFragmentData(DashOsmEditsFragment.TAG, DashOsmEditsFragment.class, "OsmEdits",
|
||||
defaultShouldShow, new CanHideIfPluginEnabled(OsmEditingPlugin.class)),
|
||||
new DashFragmentData(DashAudioVideoNotesFragment.TAG, DashAudioVideoNotesFragment.class, "Notes", defaultShouldShow),
|
||||
new DashFragmentData(DashTrackFragment.TAG, DashTrackFragment.class, "Track", defaultShouldShow),
|
||||
new DashFragmentData(DashOsMoFragment.TAG, DashOsMoFragment.class, "OsMo", defaultShouldShow),
|
||||
new DashFragmentData(DashOsmEditsFragment.TAG, DashOsmEditsFragment.class, "OsmEdits", defaultShouldShow),
|
||||
new DashFragmentData(DashPluginsFragment.TAG, DashPluginsFragment.class, "Plugins", defaultShouldShow),
|
||||
new DashFragmentData(DashSimulateFragment.TAG, DashSimulateFragment.class, "Simulate",
|
||||
simulateShouldShow, new CanHideIfPluginEnabled(OsmandDevelopmentPlugin.class)),
|
||||
new DashFragmentData(DashSimulateFragment.TAG, DashSimulateFragment.class, "Simulate", simulateShouldShow),
|
||||
};
|
||||
|
||||
private MapActivity mapActivity;
|
||||
|
@ -1001,24 +986,4 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
|
|||
&& super.shouldShow(settings, activity, tag);
|
||||
}
|
||||
}
|
||||
|
||||
private static class CanNotHideFunction implements DashFragmentData.CanHideFunction {
|
||||
@Override
|
||||
public boolean canHide() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static class CanHideIfPluginEnabled implements DashFragmentData.CanHideFunction {
|
||||
private final Class<? extends OsmandPlugin> pluginClass;
|
||||
|
||||
public CanHideIfPluginEnabled(Class<? extends OsmandPlugin> pluginClass) {
|
||||
this.pluginClass = pluginClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHide() {
|
||||
return OsmandPlugin.getEnabledPlugin(pluginClass) != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,16 +9,16 @@ public final class DashFragmentData {
|
|||
public final Class<? extends DashBaseFragment> fragmentClass;
|
||||
public final String title;
|
||||
public final ShouldShowFunction shouldShowFunction;
|
||||
public final CanHideFunction canHideFunction;
|
||||
public final boolean customDeletionLogic;
|
||||
|
||||
public DashFragmentData(String tag, Class<? extends DashBaseFragment> fragmentClass,
|
||||
String title, ShouldShowFunction shouldShowFunction,
|
||||
CanHideFunction canHideFunction) {
|
||||
boolean customDeletionLogic) {
|
||||
this.tag = tag;
|
||||
this.fragmentClass = fragmentClass;
|
||||
this.title = title;
|
||||
this.shouldShowFunction = shouldShowFunction;
|
||||
this.canHideFunction = canHideFunction;
|
||||
this.customDeletionLogic = customDeletionLogic;
|
||||
}
|
||||
|
||||
public DashFragmentData(String tag, Class<? extends DashBaseFragment> fragmentClass,
|
||||
|
@ -27,14 +27,10 @@ public final class DashFragmentData {
|
|||
this.fragmentClass = fragmentClass;
|
||||
this.title = title;
|
||||
this.shouldShowFunction = shouldShowFunction;
|
||||
this.canHideFunction = null;
|
||||
customDeletionLogic = false;
|
||||
}
|
||||
|
||||
public interface ShouldShowFunction {
|
||||
boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag);
|
||||
}
|
||||
|
||||
public interface CanHideFunction {
|
||||
boolean canHide();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,8 +34,7 @@ public class DashboardSettingsDialogFragment extends DialogFragment {
|
|||
mapActivity = (MapActivity) activity;
|
||||
ArrayList<DashFragmentData> fragmentsList = new ArrayList<>();
|
||||
for(DashFragmentData fragmentData : mapActivity.getDashboard().getFragmentsData()) {
|
||||
if (fragmentData.canHideFunction == null || fragmentData.canHideFunction.canHide())
|
||||
fragmentsList.add(fragmentData);
|
||||
if (!fragmentData.customDeletionLogic) fragmentsList.add(fragmentData);
|
||||
}
|
||||
fragmentsData = fragmentsList.toArray(new DashFragmentData[fragmentsList.size()]);
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@ package net.osmand.plus.osmedit;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.Editable;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -17,14 +17,10 @@ import android.widget.LinearLayout;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.osmedit.EditPoiFragment.Tag;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class AdvancedDataFragment extends Fragment {
|
||||
private static final String TAG = "AdvancedDataFragment";
|
||||
|
||||
private TagAdapterLinearLayoutHack mAdapter;
|
||||
private EditPoiFragment.EditPoiData.TagsChangedListener mTagsChangedListener;
|
||||
private boolean mIsUserInput = true;
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
|
||||
|
@ -52,6 +48,8 @@ public class AdvancedDataFragment extends Fragment {
|
|||
});
|
||||
LinearLayout editTagsLineaLayout =
|
||||
(LinearLayout) view.findViewById(R.id.editTagsList);
|
||||
Log.v(TAG, "arguments=" + savedInstanceState + "; ll=" + editTagsLineaLayout);
|
||||
Log.v(TAG, "not restored");
|
||||
mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getData());
|
||||
// setListViewHeightBasedOnChildren(editTagsLineaLayout);
|
||||
Button addTagButton = (Button) view.findViewById(R.id.addTagButton);
|
||||
|
@ -78,29 +76,29 @@ public class AdvancedDataFragment extends Fragment {
|
|||
super.onResume();
|
||||
// TODO read more about lifecycle
|
||||
mAdapter.updateViews();
|
||||
mTagsChangedListener = new EditPoiFragment.EditPoiData.TagsChangedListener() {
|
||||
getEditPoiFragment().addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
||||
@Override
|
||||
public void onTagsChanged() {
|
||||
mIsUserInput = false;
|
||||
mAdapter.updateViews();
|
||||
mIsUserInput = true;
|
||||
}
|
||||
};
|
||||
getData().addListener(mTagsChangedListener);
|
||||
public void onPageScrolled(int i, float v, int i1) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
getData().deleteListener(mTagsChangedListener);
|
||||
public void onPageSelected(int i) {
|
||||
if (i == 1) mAdapter.updateViews();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageScrollStateChanged(int i) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
Log.v(TAG, "onSaveInstanceState(" + "outState=" + outState + ")");
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
public class TagAdapterLinearLayoutHack {
|
||||
public static class TagAdapterLinearLayoutHack {
|
||||
private final LinearLayout linearLayout;
|
||||
private final EditPoiFragment.EditPoiData editPoiData;
|
||||
|
||||
|
@ -113,79 +111,41 @@ public class AdvancedDataFragment extends Fragment {
|
|||
public void addTag(Tag tag) {
|
||||
View view = getView(tag);
|
||||
editPoiData.tags.add(tag);
|
||||
if (mIsUserInput)
|
||||
editPoiData.notifyDatasetChanged(mTagsChangedListener);
|
||||
EditText valueEditText = (EditText) view.findViewById(R.id.valueEditText);
|
||||
Log.v(TAG, "valueEditText text=" + valueEditText.getText());
|
||||
linearLayout.addView(view);
|
||||
}
|
||||
|
||||
public void updateViews() {
|
||||
linearLayout.removeAllViews();
|
||||
Iterator<Tag> iterator = editPoiData.tags.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
iterator.next();
|
||||
}
|
||||
Log.v(TAG, "editPoiData.tags=" + editPoiData.tags);
|
||||
for (Tag tag : editPoiData.tags) {
|
||||
Log.v(TAG, "tag=" + tag);
|
||||
View view = getView(tag);
|
||||
EditText valueEditText = (EditText) view.findViewById(R.id.valueEditText);
|
||||
Log.v(TAG, "valueEditText text=" + valueEditText.getText());
|
||||
linearLayout.addView(view);
|
||||
}
|
||||
}
|
||||
|
||||
private View getView(final Tag tag) {
|
||||
Log.v(TAG, "getView(" + "tag=" + tag + ")");
|
||||
final View convertView = LayoutInflater.from(linearLayout.getContext())
|
||||
.inflate(R.layout.poi_tag_list_item, null, false);
|
||||
final EditText tagEditText = (EditText) convertView.findViewById(R.id.tagEditText);
|
||||
tagEditText.setText(tag.tag);
|
||||
final EditText valueEditText = (EditText) convertView.findViewById(R.id.valueEditText);
|
||||
EditText tagEditText = (EditText) convertView.findViewById(R.id.tagEditText);
|
||||
EditText valueEditText = (EditText) convertView.findViewById(R.id.valueEditText);
|
||||
ImageButton deleteItemImageButton =
|
||||
(ImageButton) convertView.findViewById(R.id.deleteItemImageButton);
|
||||
tagEditText.setText(tag.tag);
|
||||
valueEditText.setText(tag.value);
|
||||
deleteItemImageButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
linearLayout.removeView((View) v.getParent());
|
||||
editPoiData.tags.remove(tag);
|
||||
if (mIsUserInput)
|
||||
editPoiData.notifyDatasetChanged(mTagsChangedListener);
|
||||
}
|
||||
});
|
||||
tagEditText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
editPoiData.tags.remove(tag);
|
||||
tag.tag = tagEditText.getText().toString();
|
||||
editPoiData.tags.add(tag);
|
||||
if (mIsUserInput)
|
||||
editPoiData.notifyDatasetChanged(mTagsChangedListener);
|
||||
}
|
||||
});
|
||||
valueEditText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
editPoiData.tags.remove(tag);
|
||||
tag.value = valueEditText.getText().toString();
|
||||
editPoiData.tags.add(tag);
|
||||
if (mIsUserInput)
|
||||
editPoiData.notifyDatasetChanged(mTagsChangedListener);
|
||||
}
|
||||
});
|
||||
Log.v(TAG, "convertView=" + convertView);
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,61 +2,28 @@ package net.osmand.plus.osmedit;
|
|||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.Toast;
|
||||
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.osm.MapPoiTypes;
|
||||
import net.osmand.osm.PoiCategory;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.osm.edit.EntityInfo;
|
||||
import net.osmand.osm.edit.Node;
|
||||
import net.osmand.osm.edit.OSMSettings;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class EditPoiFragment extends Fragment {
|
||||
public static final String TAG = "EditPoiFragment";
|
||||
|
@ -67,43 +34,27 @@ public class EditPoiFragment extends Fragment {
|
|||
|
||||
private final EditPoiData editPoiData = new EditPoiData();
|
||||
private ViewPager viewPager;
|
||||
private boolean isLocalEdit;
|
||||
private boolean mIsUserInput = true;
|
||||
private EditText poiNameEditText;
|
||||
private EditPoiData.TagsChangedListener mTagsChangedListener;
|
||||
private AutoCompleteTextView poiTypeEditText;
|
||||
private Node node;
|
||||
private Map<String, PoiType> allTranslatedSubTypes;
|
||||
private String poiTypeTag;
|
||||
private Amenity amenity;
|
||||
private OpenstreetmapUtil openstreetmapUtil;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
// poiTypes = ((OsmandApplication) activity.getApplication()).getPoiTypes();
|
||||
// allTranslatedSubTypes = poiTypes.getAllTranslatedNames();
|
||||
OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings();
|
||||
// OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings();
|
||||
// editPoiData.isLocalEdit = true;
|
||||
OsmEditingPlugin plugin = (OsmEditingPlugin) OsmandPlugin.getPlugin(OsmEditingPlugin.class);
|
||||
if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) {
|
||||
openstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity);
|
||||
// if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) {
|
||||
// openstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity);
|
||||
// openstreetmapUtilToLoad = openstreetmapUtil;
|
||||
} else if (!settings.isInternetConnectionAvailable(true)) {
|
||||
openstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity);
|
||||
// } else if(!settings.isInternetConnectionAvailable(true)) {
|
||||
// openstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity);
|
||||
// openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(activity);
|
||||
} else {
|
||||
isLocalEdit = false;
|
||||
openstreetmapUtil = new OpenstreetmapRemoteUtil(activity);
|
||||
// } else {
|
||||
// editPoiData.isLocalEdit = false;
|
||||
// openstreetmapUtil = new OpenstreetmapRemoteUtil(activity);
|
||||
// openstreetmapUtilToLoad = openstreetmapUtil;
|
||||
}
|
||||
// }
|
||||
|
||||
node = (Node) getArguments().getSerializable(KEY_AMENITY_NODE);
|
||||
allTranslatedSubTypes = ((OsmandApplication) activity.getApplication()).getPoiTypes()
|
||||
.getAllTranslatedNames();
|
||||
// TODO implement normal name
|
||||
poiTypeTag = "amenity";
|
||||
amenity = (Amenity) getArguments().getSerializable(KEY_AMENITY);
|
||||
// editPoiData.node = (Node) getArguments().getSerializable(KEY_AMENITY_NODE);
|
||||
// editPoiData.tags = new LinkedHashSet<>();
|
||||
}
|
||||
|
||||
|
@ -163,190 +114,21 @@ public class EditPoiFragment extends Fragment {
|
|||
Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features")));
|
||||
}
|
||||
});
|
||||
ImageButton poiTypeButton = (ImageButton) view.findViewById(R.id.poiTypeButton);
|
||||
poiTypeButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
DialogFragment fragment = PoiTypeDialogFragment.createInstance(amenity);
|
||||
fragment.show(getChildFragmentManager(), "PoiTypeDialogFragment");
|
||||
}
|
||||
});
|
||||
|
||||
poiNameEditText = (EditText) view.findViewById(R.id.poiNameEditText);
|
||||
poiNameEditText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
final Tag tag = new Tag(OSMSettings.OSMTagKey.NAME.getValue(), s.toString());
|
||||
if (mIsUserInput) {
|
||||
getEditPoiData().tags.remove(tag);
|
||||
getEditPoiData().tags.add(tag);
|
||||
getEditPoiData().notifyDatasetChanged(mTagsChangedListener);
|
||||
}
|
||||
}
|
||||
});
|
||||
poiTypeEditText = (AutoCompleteTextView) view.findViewById(R.id.poiTypeEditText);
|
||||
poiTypeEditText.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
final Tag tag = new Tag(poiTypeTag, s.toString());
|
||||
if (mIsUserInput) {
|
||||
getEditPoiData().tags.remove(tag);
|
||||
getEditPoiData().tags.add(tag);
|
||||
getEditPoiData().notifyDatasetChanged(mTagsChangedListener);
|
||||
}
|
||||
}
|
||||
});
|
||||
poiTypeEditText.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(poiTypeEditText.getText().length() == 0 && amenity.getType() != null){
|
||||
DialogFragment dialogFragment = PoiSubTypeDialogFragment.createInstance(amenity);
|
||||
dialogFragment.show(getChildFragmentManager(), "PoiSubTypeDialogFragment");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Button saveButton = (Button) view.findViewById(R.id.saveButton);
|
||||
int saveButtonTextId = isLocalEdit ? R.string.shared_string_save :
|
||||
R.string.default_buttons_commit;
|
||||
saveButton.setText(saveButtonTextId);
|
||||
saveButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// TODO implement saving
|
||||
OsmPoint.Action action = node.getId() == -1 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY;
|
||||
String description = "";
|
||||
for (Tag tag : editPoiData.tags) {
|
||||
if (tag.tag.equals(poiTypeTag)) {
|
||||
if (allTranslatedSubTypes.get(tag.value) != null) {
|
||||
PoiType pt = allTranslatedSubTypes.get(tag.value);
|
||||
node.putTag(pt.getOsmTag(), pt.getOsmValue());
|
||||
if (pt.getOsmTag2() != null) {
|
||||
node.putTag(pt.getOsmTag2(), pt.getOsmValue2());
|
||||
}
|
||||
} else {
|
||||
node.putTag(amenity.getType().getDefaultTag(), tag.value);
|
||||
}
|
||||
} else if (tag.tag.equals(OSMSettings.OSMTagKey.DESCRIPTION.getValue())) {
|
||||
description = tag.value;
|
||||
} else {
|
||||
if (tag.value.length() > 0) {
|
||||
node.putTag(tag.tag, tag.value);
|
||||
} else {
|
||||
node.removeTag(tag.tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
commitNode(action, node, openstreetmapUtil.getEntityInfo(),
|
||||
"",
|
||||
false,//closeChange.isSelected(),
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isLocalEdit) {
|
||||
AccessibleToast.makeText(
|
||||
getActivity(), R.string.osm_changes_added_to_local_edits,
|
||||
Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
final String message = node.getId() == -1 ? getResources().getString(R.string.poi_action_add)
|
||||
: getResources().getString(R.string.poi_action_change);
|
||||
|
||||
AccessibleToast.makeText(
|
||||
getActivity(),
|
||||
MessageFormat.format(
|
||||
getResources().getString(
|
||||
R.string.poi_action_succeded_template), message),
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
if (getActivity() instanceof MapActivity) {
|
||||
((MapActivity) getActivity()).getMapView().refreshMap(true);
|
||||
}
|
||||
FragmentManager fragmentManager =
|
||||
getActivity().getSupportFragmentManager();
|
||||
fragmentManager.beginTransaction().remove(EditPoiFragment.this)
|
||||
.commit();
|
||||
fragmentManager.popBackStack();
|
||||
}
|
||||
}, getActivity());
|
||||
|
||||
}
|
||||
});
|
||||
Button cancelButton = (Button) view.findViewById(R.id.cancelButton);
|
||||
cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
|
||||
fragmentManager.beginTransaction().remove(EditPoiFragment.this).commit();
|
||||
fragmentManager.popBackStack();
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mTagsChangedListener = new EditPoiFragment.EditPoiData.TagsChangedListener() {
|
||||
@Override
|
||||
public void onTagsChanged() {
|
||||
Log.v(TAG, "onTagsChanged(" + ")");
|
||||
mIsUserInput = false;
|
||||
String poiName = null;
|
||||
String poiType = null;
|
||||
for (Tag tag : editPoiData.tags) {
|
||||
// TODO replace with constants
|
||||
if (tag.tag.equals(OSMSettings.OSMTagKey.NAME.getValue())) poiName = tag.value;
|
||||
if (tag.tag.equals(poiTypeTag)) poiType = tag.value;
|
||||
}
|
||||
poiNameEditText.setText(poiName);
|
||||
poiTypeEditText.setText(poiType);
|
||||
mIsUserInput = true;
|
||||
}
|
||||
};
|
||||
editPoiData.addListener(mTagsChangedListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
editPoiData.deleteListener(mTagsChangedListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
outState.putSerializable(TAGS_LIST, editPoiData.tags);
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
public static EditPoiFragment createAddPoiInstance(double latitude, double longitude,
|
||||
OsmandApplication application) {
|
||||
Node node = new Node(latitude, longitude, -1);
|
||||
Amenity amenity;
|
||||
amenity = new Amenity();
|
||||
amenity.setType(application.getPoiTypes().getOtherPoiCategory());
|
||||
amenity.setSubType("");
|
||||
amenity.setAdditionalInfo(OSMSettings.OSMTagKey.OPENING_HOURS.getValue(), "");
|
||||
return createInstance(node, amenity);
|
||||
public void addOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
|
||||
viewPager.addOnPageChangeListener(listener);
|
||||
}
|
||||
|
||||
public static EditPoiFragment createInstance(Node node, Amenity amenity) {
|
||||
public EditPoiFragment createInstance(Node node, Amenity amenity) {
|
||||
EditPoiFragment editPoiFragment = new EditPoiFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable(KEY_AMENITY_NODE, node);
|
||||
|
@ -359,78 +141,8 @@ public class EditPoiFragment extends Fragment {
|
|||
return editPoiData;
|
||||
}
|
||||
|
||||
public void setSubCategory(String subCategory) {
|
||||
poiTypeEditText.setText(subCategory);
|
||||
}
|
||||
|
||||
public void commitNode(final OsmPoint.Action action,
|
||||
final Node n,
|
||||
final EntityInfo info,
|
||||
final String comment,
|
||||
final boolean closeChangeSet,
|
||||
final Runnable successAction,
|
||||
final Activity activity) {
|
||||
if (info == null && OsmPoint.Action.CREATE != action) {
|
||||
AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_info_not_loaded), Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
new AsyncTask<Void, Void, Node>() {
|
||||
ProgressDialog progress;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
progress = ProgressDialog.show(activity, activity.getString(R.string.uploading), activity.getString(R.string.uploading_data));
|
||||
super.onPreExecute();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Node doInBackground(Void... params) {
|
||||
Node node = openstreetmapUtil.commitNodeImpl(action, n, info, comment, closeChangeSet);
|
||||
return node;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Node result) {
|
||||
progress.dismiss();
|
||||
if (result != null) {
|
||||
successAction.run();
|
||||
}
|
||||
}
|
||||
|
||||
;
|
||||
}.execute();
|
||||
}
|
||||
|
||||
private void updateType(Amenity amenity) {
|
||||
// TODO implement
|
||||
Log.v(TAG, "updateType(" + "amenity=" + amenity + ")");
|
||||
poiTypeEditText.setText(amenity.getSubType());
|
||||
|
||||
final Map<String, PoiType> subCategories = new LinkedHashMap<>();
|
||||
for (Map.Entry<String, PoiType> s : allTranslatedSubTypes.entrySet()) {
|
||||
if (!subCategories.containsKey(s.getKey())) {
|
||||
subCategories.put(Algorithms.capitalizeFirstLetterAndLowercase(s.getKey()), s.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
final ArrayAdapter<Object> adapter = new ArrayAdapter<>(getActivity(),
|
||||
R.layout.list_textview, subCategories.keySet().toArray());
|
||||
poiTypeEditText.setAdapter(adapter);
|
||||
poiTypeEditText.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
Object item = parent.getAdapter().getItem(position);
|
||||
if (subCategories.containsKey(item)) {
|
||||
String kn = subCategories.get(item).getKeyName();
|
||||
poiTypeEditText.setText(kn);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
}
|
||||
});
|
||||
public void send() {
|
||||
// TODO implement saving
|
||||
}
|
||||
|
||||
public static class MyAdapter extends FragmentPagerAdapter {
|
||||
|
@ -468,29 +180,10 @@ public class EditPoiFragment extends Fragment {
|
|||
}
|
||||
|
||||
public static class EditPoiData {
|
||||
private Set<TagsChangedListener> mListeners = new HashSet<>();
|
||||
// public boolean isLocalEdit;
|
||||
// public Node node;
|
||||
public LinkedHashSet<Tag> tags;
|
||||
|
||||
public void notifyDatasetChanged(TagsChangedListener listenerToSkip) {
|
||||
Log.v(TAG, "notifyDatasetChanged(" + "listenerToSkip=" + listenerToSkip + ")" + mListeners);
|
||||
for (TagsChangedListener listener : mListeners) {
|
||||
if (listener != listenerToSkip) listener.onTagsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener(TagsChangedListener listener) {
|
||||
mListeners.add(listener);
|
||||
}
|
||||
|
||||
public void deleteListener(TagsChangedListener listener) {
|
||||
mListeners.remove(listener);
|
||||
}
|
||||
|
||||
public interface TagsChangedListener {
|
||||
void onTagsChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class Tag implements Serializable {
|
||||
public String tag;
|
||||
|
@ -505,8 +198,11 @@ public class EditPoiFragment extends Fragment {
|
|||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Tag tag1 = (Tag) o;
|
||||
|
||||
return tag.equals(tag1.tag);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -522,69 +218,4 @@ public class EditPoiFragment extends Fragment {
|
|||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
public static class PoiTypeDialogFragment extends DialogFragment {
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
MapPoiTypes poiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes();
|
||||
final Amenity amenity = (Amenity) getArguments().getSerializable(KEY_AMENITY);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
final List<PoiCategory> categories = poiTypes.getCategories(false);
|
||||
String[] vals = new String[categories.size()];
|
||||
for (int i = 0; i < vals.length; i++) {
|
||||
vals[i] = categories.get(i).getTranslation();
|
||||
}
|
||||
builder.setItems(vals, new Dialog.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
PoiCategory aType = categories.get(which);
|
||||
if (aType != amenity.getType()) {
|
||||
amenity.setType(aType);
|
||||
amenity.setSubType(""); //$NON-NLS-1$
|
||||
((EditPoiFragment) getParentFragment()).updateType(amenity);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
public static PoiTypeDialogFragment createInstance(Amenity amenity) {
|
||||
PoiTypeDialogFragment poiTypeDialogFragment = new PoiTypeDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable(KEY_AMENITY, amenity);
|
||||
poiTypeDialogFragment.setArguments(args);
|
||||
return poiTypeDialogFragment;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PoiSubTypeDialogFragment extends DialogFragment {
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
MapPoiTypes poiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes();
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
final Amenity a = (Amenity) getArguments().getSerializable(KEY_AMENITY);
|
||||
final Map<String, PoiType> allTranslatedNames = poiTypes.getAllTranslatedNames(a.getType(), true);
|
||||
// (=^.^=)
|
||||
final String[] subCats = allTranslatedNames.keySet().toArray(new String[0]);
|
||||
builder.setItems(subCats, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
((EditPoiFragment) getParentFragment()).setSubCategory(subCats[which]);
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
public static PoiSubTypeDialogFragment createInstance(Amenity amenity) {
|
||||
PoiSubTypeDialogFragment fragment = new PoiSubTypeDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putSerializable(KEY_AMENITY, amenity);
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,11 +6,14 @@ import android.app.AlertDialog.Builder;
|
|||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -391,15 +394,15 @@ public class EditingPOIDialogProvider implements DialogProvider {
|
|||
closeChange.setVisibility(isLocalEdit ? View.GONE : View.VISIBLE);
|
||||
|
||||
|
||||
// TextView linkToOsmDoc = (TextView) view.findViewById(R.id.LinkToOsmDoc);
|
||||
// linkToOsmDoc.setOnClickListener(new View.OnClickListener() {
|
||||
//
|
||||
// @Override
|
||||
// public void onClick(View v) {
|
||||
// activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features")));
|
||||
// }
|
||||
// });
|
||||
// linkToOsmDoc.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
TextView linkToOsmDoc = (TextView) view.findViewById(R.id.LinkToOsmDoc);
|
||||
linkToOsmDoc.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features")));
|
||||
}
|
||||
});
|
||||
linkToOsmDoc.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
|
||||
final Amenity amenity = (Amenity) args.getSerializable(KEY_AMENITY);
|
||||
final Node node = (Node) args.getSerializable(KEY_AMENITY_NODE);
|
||||
|
|
|
@ -3,34 +3,22 @@ package net.osmand.plus.osmedit;
|
|||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.Editable;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.osm.edit.OSMSettings;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.osmedit.EditPoiFragment.Tag;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class NormalDataFragment extends Fragment {
|
||||
private static final String TAG = "NormalDataFragment";
|
||||
private EditText streetEditText;
|
||||
private EditText houseNumberEditText;
|
||||
private EditText phoneEditText;
|
||||
private EditText webSiteEditText;
|
||||
private EditText descriptionEditText;
|
||||
private EditPoiFragment.EditPoiData.TagsChangedListener mTagsChangedListener;
|
||||
private boolean mIsUserInput = true;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
@ -48,81 +36,41 @@ public class NormalDataFragment extends Fragment {
|
|||
ImageView descriptionImageView = (ImageView) view.findViewById(R.id.descriptionImageView);
|
||||
descriptionImageView.setImageDrawable(iconsCache.getContentIcon(R.drawable.ic_action_description));
|
||||
|
||||
streetEditText = (EditText) view.findViewById(R.id.streetEditText);
|
||||
streetEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
|
||||
OSMSettings.OSMTagKey.ADDR_STREET.getValue()));
|
||||
houseNumberEditText = (EditText) view.findViewById(R.id.houseNumberEditText);
|
||||
houseNumberEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
|
||||
OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue()));
|
||||
phoneEditText = (EditText) view.findViewById(R.id.phoneEditText);
|
||||
phoneEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
|
||||
OSMSettings.OSMTagKey.PHONE.getValue()));
|
||||
webSiteEditText = (EditText) view.findViewById(R.id.webSiteEditText);
|
||||
webSiteEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
|
||||
OSMSettings.OSMTagKey.WEBSITE.getValue()));
|
||||
descriptionEditText = (EditText) view.findViewById(R.id.descriptionEditText);
|
||||
descriptionEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
|
||||
OSMSettings.OSMTagKey.DESCRIPTION.getValue()));
|
||||
// TODO replace with constants
|
||||
final TextView streetEditText = (TextView) view.findViewById(R.id.streetEditText);
|
||||
streetEditText.setOnFocusChangeListener(new MyOnFocusChangeListener(getData(), "addr:street"));
|
||||
final TextView houseNumberEditText = (TextView) view.findViewById(R.id.houseNumberEditText);
|
||||
houseNumberEditText.setOnFocusChangeListener(new MyOnFocusChangeListener(getData(), "addr:housenumber"));
|
||||
final TextView phoneEditText = (TextView) view.findViewById(R.id.phoneEditText);
|
||||
phoneEditText.setOnFocusChangeListener(new MyOnFocusChangeListener(getData(), "phone"));
|
||||
final TextView webSiteEditText = (TextView) view.findViewById(R.id.webSiteEditText);
|
||||
webSiteEditText.setOnFocusChangeListener(new MyOnFocusChangeListener(getData(), "website"));
|
||||
final TextView descriptionEditText = (TextView) view.findViewById(R.id.descriptionEditText);
|
||||
descriptionEditText.setOnFocusChangeListener(new MyOnFocusChangeListener(getData(), "description"));
|
||||
|
||||
Button saveButton = (Button) view.findViewById(R.id.saveButton);
|
||||
int saveButtonTextId = //getData().isLocalEdit ? R.string.shared_string_save :
|
||||
R.string.default_buttons_commit;
|
||||
saveButton.setText(saveButtonTextId);
|
||||
saveButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
getEditPoiFragment().send();
|
||||
}
|
||||
});
|
||||
Button cancelButton = (Button) view.findViewById(R.id.cancelButton);
|
||||
cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
|
||||
Fragment editPoiFragment = getParentFragment();
|
||||
fragmentManager.beginTransaction().remove(editPoiFragment).commit();
|
||||
fragmentManager.popBackStack();
|
||||
}
|
||||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mTagsChangedListener = new EditPoiFragment.EditPoiData.TagsChangedListener() {
|
||||
@Override
|
||||
public void onTagsChanged() {
|
||||
TagMapProcessor tagMapProcessor = new TagMapProcessor();
|
||||
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.ADDR_STREET.getValue(),
|
||||
streetEditText);
|
||||
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue(),
|
||||
houseNumberEditText);
|
||||
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.PHONE.getValue(),
|
||||
phoneEditText);
|
||||
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.WEBSITE.getValue(),
|
||||
webSiteEditText);
|
||||
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.DESCRIPTION.getValue(),
|
||||
descriptionEditText);
|
||||
|
||||
mIsUserInput = false;
|
||||
for (Tag tag : getData().tags) {
|
||||
tagMapProcessor.process(tag);
|
||||
}
|
||||
tagMapProcessor.clearEmptyFields();
|
||||
mIsUserInput = true;
|
||||
}
|
||||
};
|
||||
getData().addListener(mTagsChangedListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
getData().deleteListener(mTagsChangedListener);
|
||||
}
|
||||
|
||||
private static class TagMapProcessor {
|
||||
private final Map<String, EditText> mFilters = new HashMap<>();
|
||||
|
||||
public void addFilter(String tag, EditText editText) {
|
||||
mFilters.put(tag, editText);
|
||||
}
|
||||
|
||||
public void process(Tag tag) {
|
||||
if (mFilters.containsKey(tag.tag)) {
|
||||
final EditText editText = mFilters.get(tag.tag);
|
||||
editText.setText(tag.value);
|
||||
mFilters.remove(tag.tag);
|
||||
}
|
||||
}
|
||||
|
||||
public void clearEmptyFields() {
|
||||
for (String tag : mFilters.keySet()) {
|
||||
mFilters.get(tag).setText(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private EditPoiFragment getEditPoiFragment() {
|
||||
return (EditPoiFragment) getParentFragment();
|
||||
}
|
||||
|
@ -131,34 +79,22 @@ public class NormalDataFragment extends Fragment {
|
|||
return getEditPoiFragment().getEditPoiData();
|
||||
}
|
||||
|
||||
private class MyOnFocusChangeListener implements TextWatcher {
|
||||
private final EditPoiFragment.EditPoiData data;
|
||||
private final String tagName;
|
||||
private static class MyOnFocusChangeListener implements View.OnFocusChangeListener {
|
||||
private EditPoiFragment.EditPoiData data;
|
||||
private String tagName;
|
||||
|
||||
public MyOnFocusChangeListener(EditPoiFragment.EditPoiData data,
|
||||
String tagName) {
|
||||
public MyOnFocusChangeListener(EditPoiFragment.EditPoiData data, String tagName) {
|
||||
this.data = data;
|
||||
this.tagName = tagName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (mIsUserInput) {
|
||||
String string = s.toString();
|
||||
public void onFocusChange(View v, boolean hasFocus) {
|
||||
String string = ((EditText) v).getText().toString();
|
||||
if (!TextUtils.isEmpty(string)) {
|
||||
Tag tag = new Tag(tagName, string);
|
||||
data.tags.remove(tag);
|
||||
data.tags.add(tag);
|
||||
data.notifyDatasetChanged(mTagsChangedListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,7 +69,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
|
|||
|
||||
private OsmBugsLayer osmBugsLayer;
|
||||
private OsmEditsLayer osmEditsLayer;
|
||||
// private EditingPOIDialogProvider poiActions;
|
||||
private EditingPOIDialogProvider poiActions;
|
||||
|
||||
@Override
|
||||
public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
|
||||
|
@ -120,8 +120,8 @@ public class OsmEditingPlugin extends OsmandPlugin {
|
|||
@Override
|
||||
public void mapActivityCreate(MapActivity activity) {
|
||||
// Always create new actions !
|
||||
// poiActions = new EditingPOIDialogProvider(activity, this);
|
||||
// activity.addDialogProvider(getPoiActions(activity));
|
||||
poiActions = new EditingPOIDialogProvider(activity, this);
|
||||
activity.addDialogProvider(getPoiActions(activity));
|
||||
activity.addDialogProvider(getBugsLayer(activity));
|
||||
}
|
||||
|
||||
|
@ -131,12 +131,12 @@ public class OsmEditingPlugin extends OsmandPlugin {
|
|||
return SettingsOsmEditingActivity.class;
|
||||
}
|
||||
|
||||
// public EditingPOIDialogProvider getPoiActions(MapActivity activity) {
|
||||
// if (poiActions == null) {
|
||||
// poiActions = new EditingPOIDialogProvider(activity, this);
|
||||
// }
|
||||
// return poiActions;
|
||||
// }
|
||||
public EditingPOIDialogProvider getPoiActions(MapActivity activity) {
|
||||
if (poiActions == null) {
|
||||
poiActions = new EditingPOIDialogProvider(activity, this);
|
||||
}
|
||||
return poiActions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, ContextMenuAdapter adapter,
|
||||
|
@ -146,11 +146,8 @@ public class OsmEditingPlugin extends OsmandPlugin {
|
|||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int resId, int pos, boolean isChecked) {
|
||||
if (resId == R.string.context_menu_item_create_poi) {
|
||||
//getPoiActions(mapActivity).showCreateDialog(latitude, longitude);
|
||||
EditPoiFragment editPoiFragment =
|
||||
EditPoiFragment.createAddPoiInstance(latitude, longitude,
|
||||
mapActivity.getMyApplication());
|
||||
mapActivity.getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.fragmentContainer, editPoiFragment, EditPoiFragment.TAG)
|
||||
.add(R.id.fragmentContainer, new EditPoiFragment(), EditPoiFragment.TAG)
|
||||
.addToBackStack(null)
|
||||
.commit();
|
||||
} else if (resId == R.string.context_menu_item_open_bug) {
|
||||
|
@ -159,11 +156,9 @@ public class OsmEditingPlugin extends OsmandPlugin {
|
|||
}
|
||||
osmBugsLayer.openBug(latitude, longitude);
|
||||
} else if (resId == R.string.poi_context_menu_delete) {
|
||||
// TODO implement delete
|
||||
// getPoiActions(mapActivity).showDeleteDialog((Amenity) selectedObj);
|
||||
getPoiActions(mapActivity).showDeleteDialog((Amenity) selectedObj);
|
||||
} else if (resId == R.string.poi_context_menu_modify) {
|
||||
// TODO implement edit
|
||||
// getPoiActions(mapActivity).showEditDialog((Amenity) selectedObj);
|
||||
getPoiActions(mapActivity).showEditDialog((Amenity) selectedObj);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue