Time dialog in progress
This commit is contained in:
parent
88d86c58ff
commit
61800f7419
10 changed files with 407 additions and 169 deletions
|
@ -2,6 +2,7 @@ package net.osmand.util;
|
|||
/* Can be commented out in order to run the main function separately */
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
|
@ -199,7 +200,7 @@ public class OpeningHoursParser {
|
|||
* This implementation only supports month, day of weeks and numeral times, or the value "off"
|
||||
*
|
||||
*/
|
||||
public static class BasicOpeningHourRule implements OpeningHoursRule {
|
||||
public static class BasicOpeningHourRule implements OpeningHoursRule, Serializable {
|
||||
/**
|
||||
* represents the list on which days it is open.
|
||||
* Day number 0 is MONDAY
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
android:layout_below="@id/webSiteEditText"
|
||||
android:hint="Description"
|
||||
android:inputType="textMultiLine"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/openHoursTextView"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -90,5 +91,20 @@
|
|||
android:layout_marginLeft="16dp"
|
||||
android:text="Open hours"
|
||||
android:textColor="@color/color_black"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/openHoursContainer"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/openHoursTextView"
|
||||
android:orientation="vertical"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/addOpeningHoursButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/openHoursContainer"
|
||||
android:layout_marginLeft="72dp"
|
||||
android:text="Add opening hours"/>
|
||||
</RelativeLayout>
|
||||
</android.support.v4.widget.NestedScrollView>
|
|
@ -1,7 +1,83 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageButton
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:src="@drawable/ic_action_time"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="24dp"
|
||||
android:orientation="vertical"
|
||||
android:layout_weight="1">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="Mo-We"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/divider_color"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="08:00"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/divider_color"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="16dp"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/divider_color"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="20:00"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/divider_color"/>
|
||||
</LinearLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/deleteItemImageButton"
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:src="@drawable/ic_action_close_dark"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -19,7 +19,8 @@ import net.osmand.osm.PoiType;
|
|||
import net.osmand.osm.edit.OSMSettings;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.osmedit.EditPoiFragment.Tag;
|
||||
import net.osmand.plus.osmedit.data.EditPoiData;
|
||||
import net.osmand.plus.osmedit.data.Tag;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
@ -28,7 +29,7 @@ public class AdvancedDataFragment extends Fragment {
|
|||
private static final String TAG = "AdvancedDataFragment";
|
||||
|
||||
private TagAdapterLinearLayoutHack mAdapter;
|
||||
private EditPoiFragment.EditPoiData.TagsChangedListener mTagsChangedListener;
|
||||
private EditPoiData.TagsChangedListener mTagsChangedListener;
|
||||
private boolean mIsUserInput = true;
|
||||
|
||||
@Override
|
||||
|
@ -88,7 +89,7 @@ public class AdvancedDataFragment extends Fragment {
|
|||
super.onResume();
|
||||
// TODO read more about lifecycle
|
||||
mAdapter.updateViews();
|
||||
mTagsChangedListener = new EditPoiFragment.EditPoiData.TagsChangedListener() {
|
||||
mTagsChangedListener = new EditPoiData.TagsChangedListener() {
|
||||
@Override
|
||||
public void onTagsChanged() {
|
||||
mIsUserInput = false;
|
||||
|
@ -112,7 +113,7 @@ public class AdvancedDataFragment extends Fragment {
|
|||
|
||||
public class TagAdapterLinearLayoutHack {
|
||||
private final LinearLayout linearLayout;
|
||||
private final EditPoiFragment.EditPoiData editPoiData;
|
||||
private final EditPoiData editPoiData;
|
||||
|
||||
private final TextView nameTextView;
|
||||
private final TextView amenityTagTextView;
|
||||
|
@ -120,7 +121,7 @@ public class AdvancedDataFragment extends Fragment {
|
|||
private final Map<String, PoiType> allTranslatedSubTypes;
|
||||
|
||||
public TagAdapterLinearLayoutHack(LinearLayout linearLayout,
|
||||
EditPoiFragment.EditPoiData editPoiData,
|
||||
EditPoiData editPoiData,
|
||||
TextView nameTextView,
|
||||
TextView amenityTagTextView,
|
||||
TextView amenityTextView,
|
||||
|
@ -227,7 +228,7 @@ public class AdvancedDataFragment extends Fragment {
|
|||
return (EditPoiFragment) getParentFragment();
|
||||
}
|
||||
|
||||
private EditPoiFragment.EditPoiData getData() {
|
||||
private EditPoiData getData() {
|
||||
return getEditPoiFragment().getEditPoiData();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,16 +2,12 @@ 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.design.widget.TextInputLayout;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
|
@ -37,8 +33,6 @@ 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;
|
||||
|
@ -48,16 +42,16 @@ import net.osmand.plus.OsmandPlugin;
|
|||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.osmedit.data.EditPoiData;
|
||||
import net.osmand.plus.osmedit.data.Tag;
|
||||
import net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment;
|
||||
import net.osmand.plus.osmedit.dialogs.PoiTypeDialogFragment;
|
||||
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";
|
||||
|
@ -377,7 +371,7 @@ public class EditPoiFragment extends Fragment {
|
|||
}.execute();
|
||||
}
|
||||
|
||||
private void updateType(Amenity amenity) {
|
||||
public void updateType(Amenity amenity) {
|
||||
// TODO implement
|
||||
Log.v(TAG, "updateType(" + "amenity=" + amenity + ")");
|
||||
mIsUserInput = false;
|
||||
|
@ -445,126 +439,4 @@ public class EditPoiFragment extends Fragment {
|
|||
throw new IllegalArgumentException("Unexpected position");
|
||||
}
|
||||
}
|
||||
|
||||
public static class EditPoiData {
|
||||
private Set<TagsChangedListener> mListeners = new HashSet<>();
|
||||
public LinkedHashSet<Tag> tags;
|
||||
public Amenity amenity;
|
||||
|
||||
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;
|
||||
public String value;
|
||||
|
||||
public Tag(String tag, String value) {
|
||||
this.tag = tag;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
public int hashCode() {
|
||||
return tag.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Tag{" +
|
||||
"tag='" + tag + '\'' +
|
||||
", value='" + value + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,23 +1,36 @@
|
|||
package net.osmand.plus.osmedit;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.TimePickerDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.format.DateFormat;
|
||||
import android.util.Log;
|
||||
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.TimePicker;
|
||||
|
||||
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 net.osmand.plus.osmedit.data.EditPoiData;
|
||||
import net.osmand.plus.osmedit.data.Tag;
|
||||
import net.osmand.util.OpeningHoursParser.BasicOpeningHourRule;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -28,7 +41,7 @@ public class NormalDataFragment extends Fragment {
|
|||
private EditText phoneEditText;
|
||||
private EditText webSiteEditText;
|
||||
private EditText descriptionEditText;
|
||||
private EditPoiFragment.EditPoiData.TagsChangedListener mTagsChangedListener;
|
||||
private EditPoiData.TagsChangedListener mTagsChangedListener;
|
||||
private boolean mIsUserInput = true;
|
||||
|
||||
@Nullable
|
||||
|
@ -63,13 +76,22 @@ public class NormalDataFragment extends Fragment {
|
|||
descriptionEditText = (EditText) view.findViewById(R.id.descriptionEditText);
|
||||
descriptionEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
|
||||
OSMSettings.OSMTagKey.DESCRIPTION.getValue()));
|
||||
Button addOpeningHoursButton = (Button) view.findViewById(R.id.addOpeningHoursButton);
|
||||
addOpeningHoursButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
BasicOpeningHourRule r = new BasicOpeningHourRule();
|
||||
DaysDialogFragment fragment = DaysDialogFragment.createInstance(r, -1);
|
||||
fragment.show(getChildFragmentManager(), "OpenTimeDialogFragment");
|
||||
}
|
||||
});
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mTagsChangedListener = new EditPoiFragment.EditPoiData.TagsChangedListener() {
|
||||
mTagsChangedListener = new EditPoiData.TagsChangedListener() {
|
||||
@Override
|
||||
public void onTagsChanged() {
|
||||
TagMapProcessor tagMapProcessor = new TagMapProcessor();
|
||||
|
@ -127,15 +149,15 @@ public class NormalDataFragment extends Fragment {
|
|||
return (EditPoiFragment) getParentFragment();
|
||||
}
|
||||
|
||||
private EditPoiFragment.EditPoiData getData() {
|
||||
private EditPoiData getData() {
|
||||
return getEditPoiFragment().getEditPoiData();
|
||||
}
|
||||
|
||||
private class MyOnFocusChangeListener implements TextWatcher {
|
||||
private final EditPoiFragment.EditPoiData data;
|
||||
private final EditPoiData data;
|
||||
private final String tagName;
|
||||
|
||||
public MyOnFocusChangeListener(EditPoiFragment.EditPoiData data,
|
||||
public MyOnFocusChangeListener(EditPoiData data,
|
||||
String tagName) {
|
||||
this.data = data;
|
||||
this.tagName = tagName;
|
||||
|
@ -162,4 +184,116 @@ public class NormalDataFragment extends Fragment {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class DaysDialogFragment extends DialogFragment {
|
||||
public static final String POSITION_TO_ADD = "position_to_add";
|
||||
public static final String ITEM = "item";
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
Log.v(TAG, "onCreateDialog(" + "savedInstanceState=" + savedInstanceState + ")" + getArguments());
|
||||
final BasicOpeningHourRule item =
|
||||
(BasicOpeningHourRule) getArguments().getSerializable(ITEM);
|
||||
final int positionToAdd = getArguments().getInt(POSITION_TO_ADD);
|
||||
|
||||
AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
|
||||
|
||||
boolean add = positionToAdd > -1;
|
||||
Calendar inst = Calendar.getInstance();
|
||||
final int first = inst.getFirstDayOfWeek();
|
||||
final boolean[] dayToShow = new boolean[7];
|
||||
String[] daysToShow = new String[7];
|
||||
for (int i = 0; i < 7; i++) {
|
||||
int d = (first + i - 1) % 7 + 1;
|
||||
inst.set(Calendar.DAY_OF_WEEK, d);
|
||||
daysToShow[i] = DateFormat.format("EEEE", inst).toString(); //$NON-NLS-1$
|
||||
final int pos = (d + 5) % 7;
|
||||
dayToShow[i] = item.getDays()[pos];
|
||||
}
|
||||
b.setMultiChoiceItems(daysToShow, dayToShow, new DialogInterface.OnMultiChoiceClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
||||
dayToShow[which] = isChecked;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
b.setPositiveButton(add ? getActivity().getString(R.string.shared_string_add)
|
||||
: getActivity().getString(R.string.shared_string_apply),
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
boolean[] days = item.getDays();
|
||||
for (int i = 0; i < 7; i++) {
|
||||
days[(first + 5 + i) % 7] = dayToShow[i];
|
||||
}
|
||||
TimePickerDialogFragment.createInstance(null, true)
|
||||
.show(getFragmentManager(), "TimePickerDialogFragment");
|
||||
if (positionToAdd != -1) {
|
||||
|
||||
// time.insert(item, positionToAdd);
|
||||
// selectedRule = positionToAdd;
|
||||
} else {
|
||||
// time.notifyDataSetChanged();
|
||||
}
|
||||
// updateTimePickers();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
b.setNegativeButton(getActivity().getString(R.string.shared_string_cancel), null);
|
||||
|
||||
return b.create();
|
||||
}
|
||||
|
||||
public static DaysDialogFragment createInstance(final BasicOpeningHourRule item,
|
||||
final int positionToAdd) {
|
||||
DaysDialogFragment daysDialogFragment = new DaysDialogFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putSerializable(ITEM, item);
|
||||
bundle.putInt(POSITION_TO_ADD, positionToAdd);
|
||||
daysDialogFragment.setArguments(bundle);
|
||||
return daysDialogFragment;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TimePickerDialogFragment extends DialogFragment {
|
||||
public static final String INITIAL_TIME = "initial_time";
|
||||
public static final String IS_START = "is_start";
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
Bundle args = getArguments();
|
||||
Calendar initialState = (Calendar) args.getSerializable(INITIAL_TIME);
|
||||
if (initialState == null) initialState = Calendar.getInstance();
|
||||
TimePickerDialog.OnTimeSetListener callback = new TimePickerDialog.OnTimeSetListener() {
|
||||
@Override
|
||||
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
||||
TimePickerDialogFragment.createInstance(null, false)
|
||||
.show(getFragmentManager(), "TimePickerDialogFragment");
|
||||
}
|
||||
};
|
||||
TimePickerDialog timePickerDialog = new TimePickerDialog(getActivity(), callback,
|
||||
initialState.get(Calendar.HOUR_OF_DAY),
|
||||
initialState.get(Calendar.MINUTE),
|
||||
DateFormat.is24HourFormat(getActivity()));
|
||||
boolean isStart = args.getBoolean(IS_START);
|
||||
timePickerDialog.setTitle(isStart ? "Opening" : " Closing");
|
||||
return timePickerDialog;
|
||||
}
|
||||
|
||||
public static TimePickerDialogFragment createInstance(Calendar initialTime,
|
||||
boolean isStart) {
|
||||
TimePickerDialogFragment fragment = new TimePickerDialogFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putBoolean(IS_START, isStart);
|
||||
bundle.putSerializable(INITIAL_TIME, initialTime);
|
||||
fragment.setArguments(bundle);
|
||||
return fragment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,31 @@
|
|||
package net.osmand.plus.osmedit.data;
|
||||
|
||||
/**
|
||||
* Created by GaidamakUA on 8/19/15.
|
||||
*/
|
||||
import net.osmand.data.Amenity;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class EditPoiData {
|
||||
}
|
||||
private Set<TagsChangedListener> mListeners = new HashSet<>();
|
||||
public LinkedHashSet<Tag> tags;
|
||||
public Amenity amenity;
|
||||
|
||||
public void notifyDatasetChanged(TagsChangedListener listenerToSkip) {
|
||||
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();
|
||||
}
|
||||
}
|
|
@ -1,7 +1,34 @@
|
|||
package net.osmand.plus.osmedit.data;
|
||||
|
||||
/**
|
||||
* Created by GaidamakUA on 8/19/15.
|
||||
*/
|
||||
public class Tag {
|
||||
}
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Tag implements Serializable {
|
||||
public String tag;
|
||||
public String value;
|
||||
|
||||
public Tag(String tag, String value) {
|
||||
this.tag = tag;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
public int hashCode() {
|
||||
return tag.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Tag{" +
|
||||
"tag='" + tag + '\'' +
|
||||
", value='" + value + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -1,7 +1,47 @@
|
|||
package net.osmand.plus.osmedit.dialogs;
|
||||
|
||||
/**
|
||||
* Created by GaidamakUA on 8/19/15.
|
||||
*/
|
||||
public class PoiSubTypeDialogFragment {
|
||||
}
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.osm.MapPoiTypes;
|
||||
import net.osmand.osm.PoiType;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.osmedit.EditPoiFragment;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class PoiSubTypeDialogFragment extends DialogFragment {
|
||||
private static final String KEY_AMENITY = "amenity";
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,54 @@
|
|||
package net.osmand.plus.osmedit.dialogs;
|
||||
|
||||
/**
|
||||
* Created by GaidamakUA on 8/19/15.
|
||||
*/
|
||||
public class PoiTypeDialogFragment {
|
||||
}
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.osm.MapPoiTypes;
|
||||
import net.osmand.osm.PoiCategory;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.osmedit.EditPoiFragment;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class PoiTypeDialogFragment extends DialogFragment {
|
||||
private static final String KEY_AMENITY = "amenity";
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue