Revert "Poi dialog design. Work in progress"

This reverts commit 5b89faeddf.
This commit is contained in:
Victor Shcherb 2015-08-18 23:33:55 +02:00
parent 560cb72898
commit 1f5c1a6c95
11 changed files with 255 additions and 769 deletions

View file

@ -1,140 +1,91 @@
<LinearLayout <android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/dashboard_background"
android:orientation="vertical" android:orientation="vertical"
tools:context="net.osmand.plus.osmedit.EditPoiFragment"> tools:context="net.osmand.plus.osmedit.EditPoiFragment">
<android.support.design.widget.CoordinatorLayout <android.support.design.widget.AppBarLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:layout_weight="1" android:theme="@style/OsmandLightTheme.DarkActionbar">
android:orientation="vertical">
<android.support.design.widget.AppBarLayout <!-- TODO change theme -->
android:layout_width="match_parent" <android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="@dimen/dashboard_map_toolbar"
app:contentInsetLeft="72dp"
app:contentInsetStart="72dp"
app:layout_scrollFlags="scroll"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:theme="@style/OsmandLightTheme.DarkActionbar"> app:layout_scrollFlags="scroll">
<!-- TODO change theme --> <android.support.design.widget.TextInputLayout
<android.support.v7.widget.Toolbar android:layout_width="match_parent"
android:id="@+id/toolbar"
android:layout_width="fill_parent"
android:layout_height="@dimen/dashboard_map_toolbar"
app:contentInsetLeft="72dp"
app:contentInsetStart="72dp"
app:layout_scrollFlags="scroll"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_scrollFlags="scroll"> android:layout_marginLeft="72dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp">
<android.support.design.widget.TextInputLayout <EditText
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="72dp" android:hint="Name"
android:layout_marginRight="16dp" android:text="@string/lorem_ipsum"/>
android:layout_marginTop="16dp">
<EditText </android.support.design.widget.TextInputLayout>
android:id="@+id/poiNameEditText" </LinearLayout>
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
tools:text="@string/lorem_ipsum"/>
</android.support.design.widget.TextInputLayout> <LinearLayout
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
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"
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.support.design.widget.TextInputLayout>
<ImageButton
android:id="@+id/onlineDocumentationButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:background="@null"
android:src="@drawable/ic_action_help"/>
</LinearLayout>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_white"
app:tabIndicatorColor="@color/osmand_orange"
app:tabSelectedTextColor="@color/osmand_orange"
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_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/> android:layout_marginBottom="8dp"
android:layout_marginLeft="72dp"
app:layout_scrollFlags="scroll">
</android.support.design.widget.CoordinatorLayout> <android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_weight="1">
<View <EditText
android:id="@+id/buttonDivider" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_action_arrow_drop_down"
android:hint="POI Type"
android:text="@string/lorem_ipsum"/>
</android.support.design.widget.TextInputLayout>
<ImageButton
android:id="@+id/onlineDocumentationButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:background="@null"
android:src="@drawable/ic_action_help"/>
</LinearLayout>
<android.support.design.widget.TabLayout
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_white"
app:tabIndicatorColor="@color/osmand_orange"
app:tabSelectedTextColor="@color/osmand_orange"
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_width="match_parent"
android:layout_height="1dp" android:layout_height="match_parent"
android:background="@color/divider_color"/> app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
<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>

View file

@ -2,7 +2,8 @@
<android.support.v4.widget.NestedScrollView <android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:background="@color/dashboard_background">
<LinearLayout <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
@ -25,5 +26,24 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Add tag"/> 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> </LinearLayout>
</android.support.v4.widget.NestedScrollView> </android.support.v4.widget.NestedScrollView>

View file

@ -3,16 +3,26 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:background="@color/dashboard_background">
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> 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 <TextView
android:id="@+id/contactInfoTextView" android:id="@+id/contactInfoTextView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/openHoursTextView"
android:layout_marginLeft="16dp" android:layout_marginLeft="16dp"
android:text="Contact info" android:text="Contact info"
android:textColor="@color/color_black"/> android:textColor="@color/color_black"/>
@ -82,13 +92,33 @@
android:layout_below="@id/webSiteEditText" android:layout_below="@id/webSiteEditText"
android:hint="Description" android:hint="Description"
android:inputType="textMultiLine"/> 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_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/descriptionEditText" android:layout_alignParentRight="true"
android:layout_marginLeft="16dp" android:layout_below="@id/buttonDivider"
android:text="Open hours" tools:text="Save"
android:textColor="@color/color_black"/> 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> </RelativeLayout>
</android.support.v4.widget.NestedScrollView> </android.support.v4.widget.NestedScrollView>

View file

@ -45,7 +45,6 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.IntermediatePointsDialog; import net.osmand.plus.activities.IntermediatePointsDialog;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
import net.osmand.plus.audionotes.DashAudioVideoNotesFragment; import net.osmand.plus.audionotes.DashAudioVideoNotesFragment;
import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.dashboard.tools.DashFragmentData;
import net.osmand.plus.dashboard.tools.DashboardSettingsDialogFragment; 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.WaypointDialogHelper;
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper; import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
import net.osmand.plus.monitoring.DashTrackFragment; import net.osmand.plus.monitoring.DashTrackFragment;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.osmedit.DashOsmEditsFragment; import net.osmand.plus.osmedit.DashOsmEditsFragment;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.osmo.DashOsMoFragment; import net.osmand.plus.osmo.DashOsMoFragment;
import net.osmand.plus.osmo.OsMoPlugin;
import net.osmand.plus.parkingpoint.DashParkingFragment; import net.osmand.plus.parkingpoint.DashParkingFragment;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.DownloadedRegionsLayer; import net.osmand.plus.views.DownloadedRegionsLayer;
import net.osmand.plus.views.OsmandMapTileView; 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.ShouldShowFunction chooseAppDirShouldShow = new ChooseAppDirShouldShow();
private static final DashFragmentData[] fragmentsData = new DashFragmentData[]{ private static final DashFragmentData[] fragmentsData = new DashFragmentData[]{
new DashFragmentData(DashRateUsFragment.TAG, DashRateUsFragment.class, "Rate us", new DashFragmentData(DashRateUsFragment.TAG, DashRateUsFragment.class, "Rate us", rateUsShouldShow, true),
rateUsShouldShow, new CanNotHideFunction()), new DashFragmentData(DashFirstTimeFragment.TAG, DashFirstTimeFragment.class, "First time", firstTimeShouldShow, true),
new DashFragmentData(DashFirstTimeFragment.TAG, DashFirstTimeFragment.class, "First time", new DashFragmentData(DashChooseAppDirFragment.TAG, DashChooseAppDirFragment.class, "Choose app dir", chooseAppDirShouldShow, true),
firstTimeShouldShow, new CanNotHideFunction()), new DashFragmentData(DashErrorFragment.TAG, DashErrorFragment.class, "Error", errorShouldShow, true),
new DashFragmentData(DashChooseAppDirFragment.TAG, DashChooseAppDirFragment.class, "Choose app dir",
chooseAppDirShouldShow, new CanNotHideFunction()),
new DashFragmentData(DashErrorFragment.TAG, DashErrorFragment.class, "Error",
errorShouldShow, new CanNotHideFunction()),
new DashFragmentData(DashNavigationFragment.TAG, DashNavigationFragment.class, "Navigation", defaultShouldShow), new DashFragmentData(DashNavigationFragment.TAG, DashNavigationFragment.class, "Navigation", defaultShouldShow),
new DashFragmentData(DashParkingFragment.TAG, DashParkingFragment.class, "Parking", new DashFragmentData(DashParkingFragment.TAG, DashParkingFragment.class, "Parking", defaultShouldShow),
defaultShouldShow, new CanHideIfPluginEnabled(ParkingPositionPlugin.class)),
new DashFragmentData(DashWaypointsFragment.TAG, DashWaypointsFragment.class, "Waypoints", defaultShouldShow), new DashFragmentData(DashWaypointsFragment.TAG, DashWaypointsFragment.class, "Waypoints", defaultShouldShow),
new DashFragmentData(DashSearchFragment.TAG, DashSearchFragment.class, "Search", defaultShouldShow), new DashFragmentData(DashSearchFragment.TAG, DashSearchFragment.class, "Search", defaultShouldShow),
new DashFragmentData(DashRecentsFragment.TAG, DashRecentsFragment.class, "Recent places", defaultShouldShow), new DashFragmentData(DashRecentsFragment.TAG, DashRecentsFragment.class, "Recent places", defaultShouldShow),
new DashFragmentData(DashFavoritesFragment.TAG, DashFavoritesFragment.class, "Favourites", defaultShouldShow), new DashFragmentData(DashFavoritesFragment.TAG, DashFavoritesFragment.class, "Favourites", defaultShouldShow),
new DashFragmentData(DashAudioVideoNotesFragment.TAG, DashAudioVideoNotesFragment.class, "Notes", new DashFragmentData(DashAudioVideoNotesFragment.TAG, DashAudioVideoNotesFragment.class, "Notes", defaultShouldShow),
defaultShouldShow, new CanHideIfPluginEnabled(AudioVideoNotesPlugin.class)), new DashFragmentData(DashTrackFragment.TAG, DashTrackFragment.class, "Track", defaultShouldShow),
new DashFragmentData(DashTrackFragment.TAG, DashTrackFragment.class, "Track", new DashFragmentData(DashOsMoFragment.TAG, DashOsMoFragment.class, "OsMo", defaultShouldShow),
defaultShouldShow, new CanHideIfPluginEnabled(OsmandMonitoringPlugin.class)), new DashFragmentData(DashOsmEditsFragment.TAG, DashOsmEditsFragment.class, "OsmEdits", defaultShouldShow),
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(DashPluginsFragment.TAG, DashPluginsFragment.class, "Plugins", defaultShouldShow), new DashFragmentData(DashPluginsFragment.TAG, DashPluginsFragment.class, "Plugins", defaultShouldShow),
new DashFragmentData(DashSimulateFragment.TAG, DashSimulateFragment.class, "Simulate", new DashFragmentData(DashSimulateFragment.TAG, DashSimulateFragment.class, "Simulate", simulateShouldShow),
simulateShouldShow, new CanHideIfPluginEnabled(OsmandDevelopmentPlugin.class)),
}; };
private MapActivity mapActivity; private MapActivity mapActivity;
@ -1001,24 +986,4 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks {
&& super.shouldShow(settings, activity, tag); && 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;
}
}
} }

View file

@ -9,16 +9,16 @@ public final class DashFragmentData {
public final Class<? extends DashBaseFragment> fragmentClass; public final Class<? extends DashBaseFragment> fragmentClass;
public final String title; public final String title;
public final ShouldShowFunction shouldShowFunction; public final ShouldShowFunction shouldShowFunction;
public final CanHideFunction canHideFunction; public final boolean customDeletionLogic;
public DashFragmentData(String tag, Class<? extends DashBaseFragment> fragmentClass, public DashFragmentData(String tag, Class<? extends DashBaseFragment> fragmentClass,
String title, ShouldShowFunction shouldShowFunction, String title, ShouldShowFunction shouldShowFunction,
CanHideFunction canHideFunction) { boolean customDeletionLogic) {
this.tag = tag; this.tag = tag;
this.fragmentClass = fragmentClass; this.fragmentClass = fragmentClass;
this.title = title; this.title = title;
this.shouldShowFunction = shouldShowFunction; this.shouldShowFunction = shouldShowFunction;
this.canHideFunction = canHideFunction; this.customDeletionLogic = customDeletionLogic;
} }
public DashFragmentData(String tag, Class<? extends DashBaseFragment> fragmentClass, public DashFragmentData(String tag, Class<? extends DashBaseFragment> fragmentClass,
@ -27,14 +27,10 @@ public final class DashFragmentData {
this.fragmentClass = fragmentClass; this.fragmentClass = fragmentClass;
this.title = title; this.title = title;
this.shouldShowFunction = shouldShowFunction; this.shouldShowFunction = shouldShowFunction;
this.canHideFunction = null; customDeletionLogic = false;
} }
public interface ShouldShowFunction { public interface ShouldShowFunction {
boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag); boolean shouldShow(OsmandSettings settings, MapActivity activity, String tag);
} }
public interface CanHideFunction {
boolean canHide();
}
} }

View file

@ -34,8 +34,7 @@ public class DashboardSettingsDialogFragment extends DialogFragment {
mapActivity = (MapActivity) activity; mapActivity = (MapActivity) activity;
ArrayList<DashFragmentData> fragmentsList = new ArrayList<>(); ArrayList<DashFragmentData> fragmentsList = new ArrayList<>();
for(DashFragmentData fragmentData : mapActivity.getDashboard().getFragmentsData()) { for(DashFragmentData fragmentData : mapActivity.getDashboard().getFragmentsData()) {
if (fragmentData.canHideFunction == null || fragmentData.canHideFunction.canHide()) if (!fragmentData.customDeletionLogic) fragmentsList.add(fragmentData);
fragmentsList.add(fragmentData);
} }
fragmentsData = fragmentsList.toArray(new DashFragmentData[fragmentsList.size()]); fragmentsData = fragmentsList.toArray(new DashFragmentData[fragmentsList.size()]);
} }

View file

@ -3,9 +3,9 @@ package net.osmand.plus.osmedit;
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;
import android.text.Editable; import android.support.v4.view.ViewPager;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -17,14 +17,10 @@ import android.widget.LinearLayout;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.osmedit.EditPoiFragment.Tag; import net.osmand.plus.osmedit.EditPoiFragment.Tag;
import java.util.Iterator;
public class AdvancedDataFragment extends Fragment { public class AdvancedDataFragment extends Fragment {
private static final String TAG = "AdvancedDataFragment"; private static final String TAG = "AdvancedDataFragment";
private TagAdapterLinearLayoutHack mAdapter; private TagAdapterLinearLayoutHack mAdapter;
private EditPoiFragment.EditPoiData.TagsChangedListener mTagsChangedListener;
private boolean mIsUserInput = true;
@Override @Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) { public void onActivityCreated(@Nullable Bundle savedInstanceState) {
@ -52,6 +48,8 @@ public class AdvancedDataFragment extends Fragment {
}); });
LinearLayout editTagsLineaLayout = LinearLayout editTagsLineaLayout =
(LinearLayout) view.findViewById(R.id.editTagsList); (LinearLayout) view.findViewById(R.id.editTagsList);
Log.v(TAG, "arguments=" + savedInstanceState + "; ll=" + editTagsLineaLayout);
Log.v(TAG, "not restored");
mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getData()); mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getData());
// setListViewHeightBasedOnChildren(editTagsLineaLayout); // setListViewHeightBasedOnChildren(editTagsLineaLayout);
Button addTagButton = (Button) view.findViewById(R.id.addTagButton); Button addTagButton = (Button) view.findViewById(R.id.addTagButton);
@ -78,29 +76,29 @@ public class AdvancedDataFragment extends Fragment {
super.onResume(); super.onResume();
// TODO read more about lifecycle // TODO read more about lifecycle
mAdapter.updateViews(); mAdapter.updateViews();
mTagsChangedListener = new EditPoiFragment.EditPoiData.TagsChangedListener() { getEditPoiFragment().addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override @Override
public void onTagsChanged() { public void onPageScrolled(int i, float v, int i1) {
mIsUserInput = false;
mAdapter.updateViews();
mIsUserInput = true;
} }
};
getData().addListener(mTagsChangedListener);
}
@Override @Override
public void onPause() { public void onPageSelected(int i) {
super.onPause(); if (i == 1) mAdapter.updateViews();
getData().deleteListener(mTagsChangedListener); }
@Override
public void onPageScrollStateChanged(int i) {
}
});
} }
@Override @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
Log.v(TAG, "onSaveInstanceState(" + "outState=" + outState + ")");
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
public class TagAdapterLinearLayoutHack { public static class TagAdapterLinearLayoutHack {
private final LinearLayout linearLayout; private final LinearLayout linearLayout;
private final EditPoiFragment.EditPoiData editPoiData; private final EditPoiFragment.EditPoiData editPoiData;
@ -113,79 +111,41 @@ public class AdvancedDataFragment extends Fragment {
public void addTag(Tag tag) { public void addTag(Tag tag) {
View view = getView(tag); View view = getView(tag);
editPoiData.tags.add(tag); editPoiData.tags.add(tag);
if (mIsUserInput)
editPoiData.notifyDatasetChanged(mTagsChangedListener);
EditText valueEditText = (EditText) view.findViewById(R.id.valueEditText); EditText valueEditText = (EditText) view.findViewById(R.id.valueEditText);
Log.v(TAG, "valueEditText text=" + valueEditText.getText());
linearLayout.addView(view); linearLayout.addView(view);
} }
public void updateViews() { public void updateViews() {
linearLayout.removeAllViews(); linearLayout.removeAllViews();
Iterator<Tag> iterator = editPoiData.tags.iterator(); Log.v(TAG, "editPoiData.tags=" + editPoiData.tags);
while (iterator.hasNext()) {
iterator.next();
}
for (Tag tag : editPoiData.tags) { for (Tag tag : editPoiData.tags) {
Log.v(TAG, "tag=" + tag);
View view = getView(tag); View view = getView(tag);
EditText valueEditText = (EditText) view.findViewById(R.id.valueEditText); EditText valueEditText = (EditText) view.findViewById(R.id.valueEditText);
Log.v(TAG, "valueEditText text=" + valueEditText.getText());
linearLayout.addView(view); linearLayout.addView(view);
} }
} }
private View getView(final Tag tag) { private View getView(final Tag tag) {
Log.v(TAG, "getView(" + "tag=" + tag + ")");
final View convertView = LayoutInflater.from(linearLayout.getContext()) final View convertView = LayoutInflater.from(linearLayout.getContext())
.inflate(R.layout.poi_tag_list_item, null, false); .inflate(R.layout.poi_tag_list_item, null, false);
final EditText tagEditText = (EditText) convertView.findViewById(R.id.tagEditText); EditText tagEditText = (EditText) convertView.findViewById(R.id.tagEditText);
tagEditText.setText(tag.tag); EditText valueEditText = (EditText) convertView.findViewById(R.id.valueEditText);
final EditText valueEditText = (EditText) convertView.findViewById(R.id.valueEditText);
ImageButton deleteItemImageButton = ImageButton deleteItemImageButton =
(ImageButton) convertView.findViewById(R.id.deleteItemImageButton); (ImageButton) convertView.findViewById(R.id.deleteItemImageButton);
tagEditText.setText(tag.tag);
valueEditText.setText(tag.value); valueEditText.setText(tag.value);
deleteItemImageButton.setOnClickListener(new View.OnClickListener() { deleteItemImageButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
linearLayout.removeView((View) v.getParent()); linearLayout.removeView((View) v.getParent());
editPoiData.tags.remove(tag); 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; return convertView;
} }
} }

View file

@ -2,61 +2,28 @@ package net.osmand.plus.osmedit;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Activity; 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.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewCompat; import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar; 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.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; 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.ImageButton;
import android.widget.Toast;
import net.osmand.access.AccessibleToast;
import net.osmand.data.Amenity; 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.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.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.util.Algorithms;
import java.io.Serializable; import java.io.Serializable;
import java.text.MessageFormat;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class EditPoiFragment extends Fragment { public class EditPoiFragment extends Fragment {
public static final String TAG = "EditPoiFragment"; public static final String TAG = "EditPoiFragment";
@ -67,43 +34,27 @@ public class EditPoiFragment extends Fragment {
private final EditPoiData editPoiData = new EditPoiData(); private final EditPoiData editPoiData = new EditPoiData();
private ViewPager viewPager; 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 @Override
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
super.onAttach(activity); super.onAttach(activity);
// poiTypes = ((OsmandApplication) activity.getApplication()).getPoiTypes(); // poiTypes = ((OsmandApplication) activity.getApplication()).getPoiTypes();
// allTranslatedSubTypes = poiTypes.getAllTranslatedNames(); // allTranslatedSubTypes = poiTypes.getAllTranslatedNames();
OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings(); // OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings();
// editPoiData.isLocalEdit = true; // editPoiData.isLocalEdit = true;
OsmEditingPlugin plugin = (OsmEditingPlugin) OsmandPlugin.getPlugin(OsmEditingPlugin.class); // if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) {
if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) { // openstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity);
openstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity);
// openstreetmapUtilToLoad = openstreetmapUtil; // openstreetmapUtilToLoad = openstreetmapUtil;
} else if (!settings.isInternetConnectionAvailable(true)) { // } else if(!settings.isInternetConnectionAvailable(true)) {
openstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity); // openstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity);
// openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(activity); // openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(activity);
} else { // } else {
isLocalEdit = false; // editPoiData.isLocalEdit = false;
openstreetmapUtil = new OpenstreetmapRemoteUtil(activity); // openstreetmapUtil = new OpenstreetmapRemoteUtil(activity);
// openstreetmapUtilToLoad = openstreetmapUtil; // openstreetmapUtilToLoad = openstreetmapUtil;
} // }
node = (Node) getArguments().getSerializable(KEY_AMENITY_NODE); // editPoiData.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.tags = new LinkedHashSet<>(); // editPoiData.tags = new LinkedHashSet<>();
} }
@ -163,190 +114,21 @@ public class EditPoiFragment extends Fragment {
Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features"))); 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; 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 @Override
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
outState.putSerializable(TAGS_LIST, editPoiData.tags); outState.putSerializable(TAGS_LIST, editPoiData.tags);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
public static EditPoiFragment createAddPoiInstance(double latitude, double longitude, public void addOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
OsmandApplication application) { viewPager.addOnPageChangeListener(listener);
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 static EditPoiFragment createInstance(Node node, Amenity amenity) { public EditPoiFragment createInstance(Node node, Amenity amenity) {
EditPoiFragment editPoiFragment = new EditPoiFragment(); EditPoiFragment editPoiFragment = new EditPoiFragment();
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putSerializable(KEY_AMENITY_NODE, node); args.putSerializable(KEY_AMENITY_NODE, node);
@ -359,78 +141,8 @@ public class EditPoiFragment extends Fragment {
return editPoiData; return editPoiData;
} }
public void setSubCategory(String subCategory) { public void send() {
poiTypeEditText.setText(subCategory); // TODO implement saving
}
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 static class MyAdapter extends FragmentPagerAdapter { public static class MyAdapter extends FragmentPagerAdapter {
@ -468,30 +180,11 @@ public class EditPoiFragment extends Fragment {
} }
public static class EditPoiData { public static class EditPoiData {
private Set<TagsChangedListener> mListeners = new HashSet<>(); // public boolean isLocalEdit;
// public Node node;
public LinkedHashSet<Tag> tags; 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 static class Tag implements Serializable {
public String tag; public String tag;
public String value; public String value;
@ -505,8 +198,11 @@ public class EditPoiFragment extends Fragment {
public boolean equals(Object o) { public boolean equals(Object o) {
if (this == o) return true; if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false; if (o == null || getClass() != o.getClass()) return false;
Tag tag1 = (Tag) o; Tag tag1 = (Tag) o;
return tag.equals(tag1.tag); return tag.equals(tag1.tag);
} }
@Override @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;
}
}
} }

View file

@ -6,11 +6,14 @@ import android.app.AlertDialog.Builder;
import android.app.Dialog; import android.app.Dialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.view.Gravity; import android.view.Gravity;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -391,15 +394,15 @@ public class EditingPOIDialogProvider implements DialogProvider {
closeChange.setVisibility(isLocalEdit ? View.GONE : View.VISIBLE); closeChange.setVisibility(isLocalEdit ? View.GONE : View.VISIBLE);
// TextView linkToOsmDoc = (TextView) view.findViewById(R.id.LinkToOsmDoc); TextView linkToOsmDoc = (TextView) view.findViewById(R.id.LinkToOsmDoc);
// linkToOsmDoc.setOnClickListener(new View.OnClickListener() { linkToOsmDoc.setOnClickListener(new View.OnClickListener() {
//
// @Override @Override
// public void onClick(View v) { public void onClick(View v) {
// activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features"))); activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features")));
// } }
// }); });
// linkToOsmDoc.setMovementMethod(LinkMovementMethod.getInstance()); linkToOsmDoc.setMovementMethod(LinkMovementMethod.getInstance());
final Amenity amenity = (Amenity) args.getSerializable(KEY_AMENITY); final Amenity amenity = (Amenity) args.getSerializable(KEY_AMENITY);
final Node node = (Node) args.getSerializable(KEY_AMENITY_NODE); final Node node = (Node) args.getSerializable(KEY_AMENITY_NODE);

View file

@ -3,34 +3,22 @@ package net.osmand.plus.osmedit;
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;
import android.text.Editable; import android.support.v4.app.FragmentManager;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.osm.edit.OSMSettings;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.osmedit.EditPoiFragment.Tag; import net.osmand.plus.osmedit.EditPoiFragment.Tag;
import java.util.HashMap;
import java.util.Map;
public class NormalDataFragment extends Fragment { 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 @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -48,79 +36,39 @@ public class NormalDataFragment extends Fragment {
ImageView descriptionImageView = (ImageView) view.findViewById(R.id.descriptionImageView); ImageView descriptionImageView = (ImageView) view.findViewById(R.id.descriptionImageView);
descriptionImageView.setImageDrawable(iconsCache.getContentIcon(R.drawable.ic_action_description)); descriptionImageView.setImageDrawable(iconsCache.getContentIcon(R.drawable.ic_action_description));
streetEditText = (EditText) view.findViewById(R.id.streetEditText); // TODO replace with constants
streetEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(), final TextView streetEditText = (TextView) view.findViewById(R.id.streetEditText);
OSMSettings.OSMTagKey.ADDR_STREET.getValue())); streetEditText.setOnFocusChangeListener(new MyOnFocusChangeListener(getData(), "addr:street"));
houseNumberEditText = (EditText) view.findViewById(R.id.houseNumberEditText); final TextView houseNumberEditText = (TextView) view.findViewById(R.id.houseNumberEditText);
houseNumberEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(), houseNumberEditText.setOnFocusChangeListener(new MyOnFocusChangeListener(getData(), "addr:housenumber"));
OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue())); final TextView phoneEditText = (TextView) view.findViewById(R.id.phoneEditText);
phoneEditText = (EditText) view.findViewById(R.id.phoneEditText); phoneEditText.setOnFocusChangeListener(new MyOnFocusChangeListener(getData(), "phone"));
phoneEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(), final TextView webSiteEditText = (TextView) view.findViewById(R.id.webSiteEditText);
OSMSettings.OSMTagKey.PHONE.getValue())); webSiteEditText.setOnFocusChangeListener(new MyOnFocusChangeListener(getData(), "website"));
webSiteEditText = (EditText) view.findViewById(R.id.webSiteEditText); final TextView descriptionEditText = (TextView) view.findViewById(R.id.descriptionEditText);
webSiteEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(), descriptionEditText.setOnFocusChangeListener(new MyOnFocusChangeListener(getData(), "description"));
OSMSettings.OSMTagKey.WEBSITE.getValue()));
descriptionEditText = (EditText) view.findViewById(R.id.descriptionEditText);
descriptionEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
OSMSettings.OSMTagKey.DESCRIPTION.getValue()));
return view;
}
@Override Button saveButton = (Button) view.findViewById(R.id.saveButton);
public void onResume() { int saveButtonTextId = //getData().isLocalEdit ? R.string.shared_string_save :
super.onResume(); R.string.default_buttons_commit;
mTagsChangedListener = new EditPoiFragment.EditPoiData.TagsChangedListener() { saveButton.setText(saveButtonTextId);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onTagsChanged() { public void onClick(View v) {
TagMapProcessor tagMapProcessor = new TagMapProcessor(); getEditPoiFragment().send();
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); Button cancelButton = (Button) view.findViewById(R.id.cancelButton);
} cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
@Override public void onClick(View v) {
public void onPause() { FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
super.onPause(); Fragment editPoiFragment = getParentFragment();
getData().deleteListener(mTagsChangedListener); fragmentManager.beginTransaction().remove(editPoiFragment).commit();
} fragmentManager.popBackStack();
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);
} }
} });
return view;
public void clearEmptyFields() {
for (String tag : mFilters.keySet()) {
mFilters.get(tag).setText(null);
}
}
} }
private EditPoiFragment getEditPoiFragment() { private EditPoiFragment getEditPoiFragment() {
@ -131,34 +79,22 @@ public class NormalDataFragment extends Fragment {
return getEditPoiFragment().getEditPoiData(); return getEditPoiFragment().getEditPoiData();
} }
private class MyOnFocusChangeListener implements TextWatcher { private static class MyOnFocusChangeListener implements View.OnFocusChangeListener {
private final EditPoiFragment.EditPoiData data; private EditPoiFragment.EditPoiData data;
private final String tagName; private String tagName;
public MyOnFocusChangeListener(EditPoiFragment.EditPoiData data, public MyOnFocusChangeListener(EditPoiFragment.EditPoiData data, String tagName) {
String tagName) {
this.data = data; this.data = data;
this.tagName = tagName; this.tagName = tagName;
} }
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void onFocusChange(View v, boolean hasFocus) {
} String string = ((EditText) v).getText().toString();
if (!TextUtils.isEmpty(string)) {
@Override Tag tag = new Tag(tagName, string);
public void onTextChanged(CharSequence s, int start, int before, int count) { data.tags.remove(tag);
} data.tags.add(tag);
@Override
public void afterTextChanged(Editable s) {
if (mIsUserInput) {
String string = s.toString();
if (!TextUtils.isEmpty(string)) {
Tag tag = new Tag(tagName, string);
data.tags.remove(tag);
data.tags.add(tag);
data.notifyDatasetChanged(mTagsChangedListener);
}
} }
} }
} }

View file

@ -69,7 +69,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
private OsmBugsLayer osmBugsLayer; private OsmBugsLayer osmBugsLayer;
private OsmEditsLayer osmEditsLayer; private OsmEditsLayer osmEditsLayer;
// private EditingPOIDialogProvider poiActions; private EditingPOIDialogProvider poiActions;
@Override @Override
public void updateLayers(OsmandMapTileView mapView, MapActivity activity) { public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
@ -120,8 +120,8 @@ public class OsmEditingPlugin extends OsmandPlugin {
@Override @Override
public void mapActivityCreate(MapActivity activity) { public void mapActivityCreate(MapActivity activity) {
// Always create new actions ! // Always create new actions !
// poiActions = new EditingPOIDialogProvider(activity, this); poiActions = new EditingPOIDialogProvider(activity, this);
// activity.addDialogProvider(getPoiActions(activity)); activity.addDialogProvider(getPoiActions(activity));
activity.addDialogProvider(getBugsLayer(activity)); activity.addDialogProvider(getBugsLayer(activity));
} }
@ -131,12 +131,12 @@ public class OsmEditingPlugin extends OsmandPlugin {
return SettingsOsmEditingActivity.class; return SettingsOsmEditingActivity.class;
} }
// public EditingPOIDialogProvider getPoiActions(MapActivity activity) { public EditingPOIDialogProvider getPoiActions(MapActivity activity) {
// if (poiActions == null) { if (poiActions == null) {
// poiActions = new EditingPOIDialogProvider(activity, this); poiActions = new EditingPOIDialogProvider(activity, this);
// } }
// return poiActions; return poiActions;
// } }
@Override @Override
public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, ContextMenuAdapter adapter, 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) { public boolean onContextMenuClick(ArrayAdapter<?> adapter, int resId, int pos, boolean isChecked) {
if (resId == R.string.context_menu_item_create_poi) { if (resId == R.string.context_menu_item_create_poi) {
//getPoiActions(mapActivity).showCreateDialog(latitude, longitude); //getPoiActions(mapActivity).showCreateDialog(latitude, longitude);
EditPoiFragment editPoiFragment =
EditPoiFragment.createAddPoiInstance(latitude, longitude,
mapActivity.getMyApplication());
mapActivity.getSupportFragmentManager().beginTransaction() mapActivity.getSupportFragmentManager().beginTransaction()
.add(R.id.fragmentContainer, editPoiFragment, EditPoiFragment.TAG) .add(R.id.fragmentContainer, new EditPoiFragment(), EditPoiFragment.TAG)
.addToBackStack(null) .addToBackStack(null)
.commit(); .commit();
} else if (resId == R.string.context_menu_item_open_bug) { } else if (resId == R.string.context_menu_item_open_bug) {
@ -159,11 +156,9 @@ public class OsmEditingPlugin extends OsmandPlugin {
} }
osmBugsLayer.openBug(latitude, longitude); osmBugsLayer.openBug(latitude, longitude);
} else if (resId == R.string.poi_context_menu_delete) { } 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) { } else if (resId == R.string.poi_context_menu_modify) {
// TODO implement edit getPoiActions(mapActivity).showEditDialog((Amenity) selectedObj);
// getPoiActions(mapActivity).showEditDialog((Amenity) selectedObj);
} }
return true; return true;
} }