Opening hours dialog is implemented, EditPoiFragment scroll bug fix, icons fix

This commit is contained in:
GaidamakUA 2015-08-25 17:48:08 +03:00
parent 7d3b58da8e
commit e60c133519
6 changed files with 127 additions and 37 deletions

View file

@ -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);
}
}

View file

@ -84,5 +84,9 @@
android:layout_height="wrap_content"
android:text="Add tag"/>
<!--XXX due to bug in NestedScroolView-->
<Space
android:layout_width="match_parent"
android:layout_height="500dp"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

View file

@ -106,5 +106,10 @@
android:layout_below="@id/openHoursContainer"
android:layout_marginLeft="72dp"
android:text="Add opening hours"/>
<!--XXX due to bug in NestedScroolView-->
<Space
android:layout_width="match_parent"
android:layout_height="500dp"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>

View file

@ -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<String, EditText> mFilters = new HashMap<>();
private final Map<String, TagFilter> 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,17 +284,23 @@ 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));
}
if (mIsUserInput) {
Tag openHours = new Tag(OSMSettings.OSMTagKey.OPENING_HOURS.getValue(),
openingHours.toString());
openingHours.toStringNoMoths());
data.tags.remove(openHours);
data.tags.add(openHours);
data.notifyDatasetChanged(null);
}
}
private View getView(final int position) {
OpeningHoursParser.BasicOpeningHourRule rule =
@ -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,8 +337,8 @@ public class NormalDataFragment extends Fragment {
});
return view;
}
private static String formatTime(int h, int t){
}
private static String formatTime(int h, int t) {
StringBuilder b = new StringBuilder();
if (h < 10) {
b.append("0"); //$NON-NLS-1$
@ -283,5 +350,4 @@ public class NormalDataFragment extends Fragment {
b.append(t);
return b.toString();
}
}
}

View file

@ -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),