diff --git a/OsmAnd-java/src/net/osmand/util/OpeningHoursParser.java b/OsmAnd-java/src/net/osmand/util/OpeningHoursParser.java
index 800cfe9906..5ca9fb4cf2 100644
--- a/OsmAnd-java/src/net/osmand/util/OpeningHoursParser.java
+++ b/OsmAnd-java/src/net/osmand/util/OpeningHoursParser.java
@@ -147,7 +147,18 @@ public class OpeningHoursParser {
return s.substring(0, s.length()-2);
}
-
+ public String toStringNoMoths() {
+ StringBuilder s = new StringBuilder();
+ if (rules.isEmpty()) {
+ return "";
+ }
+
+ for (OpeningHoursRule r : rules) {
+ s.append(r.toRuleString(true)).append("; ");
+ }
+
+ return s.substring(0, s.length()-2);
+ }
}
diff --git a/OsmAnd/res/layout/fragment_edit_poi_advanced.xml b/OsmAnd/res/layout/fragment_edit_poi_advanced.xml
index 0e4a3edc49..d1859b17f5 100644
--- a/OsmAnd/res/layout/fragment_edit_poi_advanced.xml
+++ b/OsmAnd/res/layout/fragment_edit_poi_advanced.xml
@@ -84,5 +84,9 @@
android:layout_height="wrap_content"
android:text="Add tag"/>
+
+
diff --git a/OsmAnd/res/layout/fragment_edit_poi_normal.xml b/OsmAnd/res/layout/fragment_edit_poi_normal.xml
index 21dabfd010..ee7384c82e 100644
--- a/OsmAnd/res/layout/fragment_edit_poi_normal.xml
+++ b/OsmAnd/res/layout/fragment_edit_poi_normal.xml
@@ -106,5 +106,10 @@
android:layout_below="@id/openHoursContainer"
android:layout_marginLeft="72dp"
android:text="Add opening hours"/>
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java b/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java
index 549e5e1a26..85b7f1e354 100644
--- a/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java
+++ b/OsmAnd/src/net/osmand/plus/download/LocalIndexesFragment.java
@@ -106,7 +106,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment {
listAdapter = new LocalIndexesAdapter(getActivity());
listView.setAdapter(listAdapter);
expandAllGroups();
- setListView(listView);
+ setListView(listView);
descriptionText = (TextView) view.findViewById(R.id.memory_size);
sizeProgress = (ProgressBar) view.findViewById(R.id.memory_progress);
updateDescriptionTextWithSize();
diff --git a/OsmAnd/src/net/osmand/plus/osmedit/NormalDataFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/NormalDataFragment.java
index 8fcc97be3f..8a1bdb9ace 100644
--- a/OsmAnd/src/net/osmand/plus/osmedit/NormalDataFragment.java
+++ b/OsmAnd/src/net/osmand/plus/osmedit/NormalDataFragment.java
@@ -1,5 +1,6 @@
package net.osmand.plus.osmedit;
+import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
@@ -87,14 +88,16 @@ public class NormalDataFragment extends Fragment {
}
});
LinearLayout openHoursContainer = (LinearLayout) view.findViewById(R.id.openHoursContainer);
+ Drawable clockDrawable = iconsCache.getContentIcon(R.drawable.ic_action_time);
+ Drawable deleteDrawable = iconsCache.getContentIcon(R.drawable.ic_action_remove_dark);
if (savedInstanceState != null && savedInstanceState.containsKey(OPENING_HOURS)) {
mOpeningHoursAdapter = new OpeningHoursAdapter(
(OpeningHoursParser.OpeningHours) savedInstanceState.getSerializable(OPENING_HOURS),
- openHoursContainer, getData());
+ openHoursContainer, getData(), clockDrawable, deleteDrawable);
mOpeningHoursAdapter.updateViews();
} else {
mOpeningHoursAdapter = new OpeningHoursAdapter(new OpeningHoursParser.OpeningHours(),
- openHoursContainer, getData());
+ openHoursContainer, getData(), clockDrawable, deleteDrawable);
}
return view;
}
@@ -107,15 +110,17 @@ public class NormalDataFragment extends Fragment {
public void onTagsChanged() {
TagMapProcessor tagMapProcessor = new TagMapProcessor();
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.ADDR_STREET.getValue(),
- streetEditText);
+ new EditTextTagFilter(streetEditText));
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue(),
- houseNumberEditText);
+ new EditTextTagFilter(houseNumberEditText));
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.PHONE.getValue(),
- phoneEditText);
+ new EditTextTagFilter(phoneEditText));
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.WEBSITE.getValue(),
- webSiteEditText);
+ new EditTextTagFilter(webSiteEditText));
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.DESCRIPTION.getValue(),
- descriptionEditText);
+ new EditTextTagFilter(descriptionEditText));
+ tagMapProcessor.addFilter(OSMSettings.OSMTagKey.OPENING_HOURS.getValue(),
+ new OpenHoursTagFilter(mOpeningHoursAdapter));
mIsUserInput = false;
for (Tag tag : getData().tags) {
@@ -141,33 +146,82 @@ public class NormalDataFragment extends Fragment {
}
public void addBasicOpeningHoursRule(BasicOpeningHourRule item) {
-
LOG.debug("item=" + item.toRuleString(false));
mOpeningHoursAdapter.addOpeningHoursRule(item);
}
private static class TagMapProcessor {
- private final Map mFilters = new HashMap<>();
+ private final Map mFilters = new HashMap<>();
- public void addFilter(String tag, EditText editText) {
- mFilters.put(tag, editText);
+ public void addFilter(String tag, TagFilter filter) {
+ mFilters.put(tag, filter);
}
public void process(Tag tag) {
if (mFilters.containsKey(tag.tag)) {
- final EditText editText = mFilters.get(tag.tag);
- editText.setText(tag.value);
+ final TagFilter filter = mFilters.get(tag.tag);
+ filter.process(tag);
mFilters.remove(tag.tag);
}
}
public void clearEmptyFields() {
for (String tag : mFilters.keySet()) {
- mFilters.get(tag).setText(null);
+ mFilters.get(tag).onUntriggered();
}
}
}
+ private interface TagFilter {
+ void process(Tag tag);
+
+ void onUntriggered();
+ }
+
+ private static class EditTextTagFilter implements TagFilter {
+ private final EditText editText;
+
+ private EditTextTagFilter(EditText editText) {
+ this.editText = editText;
+ }
+
+ @Override
+ public void process(Tag tag) {
+ editText.setText(tag.value);
+ }
+
+ @Override
+ public void onUntriggered() {
+ editText.setText(null);
+ }
+ }
+
+ private static class OpenHoursTagFilter implements TagFilter {
+ private final OpeningHoursAdapter adapter;
+
+ private OpenHoursTagFilter(OpeningHoursAdapter adapter) {
+ this.adapter = adapter;
+ }
+
+ @Override
+ public void process(Tag tag) {
+ String openingHoursString = tag.value;
+ OpeningHoursParser.OpeningHours openingHours =
+ OpeningHoursParser.parseOpenedHours(openingHoursString);
+ if (openingHours == null) {
+ openingHours = new OpeningHoursParser.OpeningHours();
+ // TODO show error message
+ }
+ adapter.replaceOpeningHours(openingHours);
+ adapter.updateViews();
+ }
+
+ @Override
+ public void onUntriggered() {
+
+ }
+ }
+
private EditPoiFragment getEditPoiFragment() {
return (EditPoiFragment) getParentFragment();
}
@@ -208,16 +262,21 @@ public class NormalDataFragment extends Fragment {
}
}
- private static class OpeningHoursAdapter {
- private final OpeningHoursParser.OpeningHours openingHours;
+ private class OpeningHoursAdapter {
+ private OpeningHoursParser.OpeningHours openingHours;
private final LinearLayout linearLayout;
private final EditPoiData data;
+ private final Drawable clockDrawable;
+ private final Drawable deleteDrawable;
public OpeningHoursAdapter(OpeningHoursParser.OpeningHours openingHours,
- LinearLayout linearLayout, EditPoiData data) {
+ LinearLayout linearLayout, EditPoiData data,
+ Drawable clockDrawable, Drawable deleteDrawable) {
this.openingHours = openingHours;
this.linearLayout = linearLayout;
this.data = data;
+ this.clockDrawable = clockDrawable;
+ this.deleteDrawable = deleteDrawable;
}
public void addOpeningHoursRule(OpeningHoursParser.BasicOpeningHourRule rule) {
@@ -225,16 +284,22 @@ public class NormalDataFragment extends Fragment {
updateViews();
}
+ public void replaceOpeningHours(OpeningHoursParser.OpeningHours openingHours) {
+ this.openingHours = openingHours;
+ }
+
public void updateViews() {
linearLayout.removeAllViews();
for (int i = 0; i < openingHours.getRules().size(); i++) {
linearLayout.addView(getView(i));
}
- Tag openHours = new Tag(OSMSettings.OSMTagKey.OPENING_HOURS.getValue(),
- openingHours.toString());
- data.tags.remove(openHours);
- data.tags.add(openHours);
- data.notifyDatasetChanged(null);
+ if (mIsUserInput) {
+ Tag openHours = new Tag(OSMSettings.OSMTagKey.OPENING_HOURS.getValue(),
+ openingHours.toStringNoMoths());
+ data.tags.remove(openHours);
+ data.tags.add(openHours);
+ data.notifyDatasetChanged(null);
+ }
}
private View getView(final int position) {
@@ -244,6 +309,7 @@ public class NormalDataFragment extends Fragment {
final View view = LayoutInflater.from(linearLayout.getContext())
.inflate(R.layout.open_time_list_item, null, false);
ImageView clockIconImageView = (ImageView) view.findViewById(R.id.clockIconImageView);
+ clockIconImageView.setImageDrawable(clockDrawable);
TextView daysTextView = (TextView) view.findViewById(R.id.daysTextView);
StringBuilder stringBuilder = new StringBuilder();
@@ -261,6 +327,7 @@ public class NormalDataFragment extends Fragment {
closingTextView.setText(formatTime(enHour, enTime));
ImageButton deleteItemImageButton = (ImageButton) view.findViewById(R.id.deleteItemImageButton);
+ deleteItemImageButton.setImageDrawable(deleteDrawable);
deleteItemImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -270,18 +337,17 @@ public class NormalDataFragment extends Fragment {
});
return view;
}
-
- private static String formatTime(int h, int t){
- StringBuilder b = new StringBuilder();
- if (h < 10) {
- b.append("0"); //$NON-NLS-1$
- }
- b.append(h).append(":"); //$NON-NLS-1$
- if (t < 10) {
- b.append("0"); //$NON-NLS-1$
- }
- b.append(t);
- return b.toString();
+ }
+ private static String formatTime(int h, int t) {
+ StringBuilder b = new StringBuilder();
+ if (h < 10) {
+ b.append("0"); //$NON-NLS-1$
}
+ b.append(h).append(":"); //$NON-NLS-1$
+ if (t < 10) {
+ b.append("0"); //$NON-NLS-1$
+ }
+ b.append(t);
+ return b.toString();
}
}
diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/OpeningHoursHoursDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/OpeningHoursHoursDialogFragment.java
index 5b1ed48ac1..53570dd2e0 100644
--- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/OpeningHoursHoursDialogFragment.java
+++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/OpeningHoursHoursDialogFragment.java
@@ -40,7 +40,11 @@ public class OpeningHoursHoursDialogFragment extends DialogFragment {
}
};
Calendar initialState = (Calendar) args.getSerializable(INITIAL_TIME);
- if (initialState == null) initialState = Calendar.getInstance();
+ if (initialState == null) {
+ initialState = Calendar.getInstance();
+ initialState.set(Calendar.HOUR_OF_DAY, isStart? 8 : 20);
+ initialState.set(Calendar.MINUTE, 0);
+ }
TimePickerDialog timePickerDialog = new TimePickerDialog(getActivity(), callback,
initialState.get(Calendar.HOUR_OF_DAY),
initialState.get(Calendar.MINUTE),