Added normal editing of timespans other than 1st one.

This commit is contained in:
GaidamakUA 2015-12-03 13:36:30 +02:00
parent 4a226142ed
commit 233cec7962
4 changed files with 95 additions and 24 deletions

View file

@ -268,6 +268,48 @@ public class OpeningHoursParser {
startTimes = new int[]{0};
}
}
/**
* Set single start time. If position exceeds index of last item by one
* then new value will be added.
* If value is between 0 and last index, then value in the position p will be overwritten
* with new one.
* Else exception will be thrown.
* @param s - value
* @param position - position to add
*/
public void setStartTime(int s, int position) {
if (position > startTimes.length) {
throw new IllegalArgumentException("It is possible to only create 1 new " +
"position. Size=" + startTimes.length + ", position=" + position);
} else if (position == startTimes.length) {
startTimes = addValueToArray(startTimes, s);
endTimes = addValueToArray(endTimes, 0);
} else {
startTimes[position] = s;
}
}
/**
* Set single end time. If position exceeds index of last item by one
* then new value will be added.
* If value is between 0 and last index, then value in the position p will be overwritten
* with new one.
* Else exception will be thrown.
* @param s - value
* @param position - position to add
*/
public void setEndTime(int s, int position) {
if (position > endTimes.length) {
throw new IllegalArgumentException("It is possible to create only 1 new position." +
" Size=" + endTimes.length + ", position=" + position);
} else if (position == endTimes.length) {
endTimes = addValueToArray(endTimes, s);
startTimes = addValueToArray(startTimes, 0);
} else {
endTimes[position] = s;
}
}
/**
* get a single start time
@ -279,6 +321,15 @@ public class OpeningHoursParser {
}
return startTimes[0];
}
/**
* get a single start time in position
* @param position position to get value from
* @return a single start time
*/
public int getStartTime(int position) {
return startTimes[position];
}
/**
* get a single end time
@ -291,6 +342,15 @@ public class OpeningHoursParser {
return endTimes[0];
}
/**
* get a single end time in position
* @param position position to get value from
* @return a single end time
*/
public int getEndTime(int position) {
return endTimes[position];
}
/**
* get all start times as independent list
* @return all start times
@ -502,7 +562,13 @@ public class OpeningHoursParser {
startTimes = newStartTimes;
endTimes = newEndTimes;
}
private int[] addValueToArray(int[] src, int newValue) {
final int[] dest = new int[startTimes.length + 1];
System.arraycopy(startTimes, 0, dest, 0, startTimes.length);
dest[startTimes.length] = newValue;
return dest;
}
}
public static class UnparseableRule implements OpeningHoursParser.OpeningHoursRule {

View file

@ -159,7 +159,6 @@ public class BasicEditPoiFragment extends Fragment
}
public void setBasicOpeningHoursRule(BasicOpeningHourRule item, int position) {
LOG.debug("item=" + item.toRuleString(false));
mOpeningHoursAdapter.setOpeningHoursRule(item, position);
}
@ -191,7 +190,6 @@ public class BasicEditPoiFragment extends Fragment
if (openingHours == null) {
openingHours = new OpeningHoursParser.OpeningHours();
}
LOG.debug("openingHours=" + openingHours);
mOpeningHoursAdapter.replaceOpeningHours(openingHours);
mOpeningHoursAdapter.updateViews();
}
@ -281,20 +279,22 @@ public class BasicEditPoiFragment extends Fragment
(TextView) timeFromToLayout.findViewById(R.id.closingTextView);
closingTextView.setText(Algorithms.formatMinutesDuration(endTimes.get(i)));
openingTextView.setTag(i);
openingTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OpeningHoursHoursDialogFragment fragment =
OpeningHoursHoursDialogFragment.createInstance(rule, position, true);
fragment.show(getChildFragmentManager(), "OpeningHoursHoursDialogFragment");
int index = (int) v.getTag();
OpeningHoursHoursDialogFragment.createInstance(rule, position, true, index)
.show(getChildFragmentManager(), "OpeningHoursHoursDialogFragment");
}
});
closingTextView.setTag(i);
closingTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OpeningHoursHoursDialogFragment fragment =
OpeningHoursHoursDialogFragment.createInstance(rule, position, false);
fragment.show(getChildFragmentManager(), "OpeningHoursHoursDialogFragment");
int index = (int) v.getTag();
OpeningHoursHoursDialogFragment.createInstance(rule, position, false, index)
.show(getChildFragmentManager(), "OpeningHoursHoursDialogFragment");
}
});
timeListContainer.addView(timeFromToLayout);

View file

@ -66,7 +66,7 @@ public class OpeningHoursDaysDialogFragment extends DialogFragment {
days[(first + 5 + i) % 7] = dayToShow[i];
}
if (createNew) {
OpeningHoursHoursDialogFragment.createInstance(item, positionToAdd, true)
OpeningHoursHoursDialogFragment.createInstance(item, positionToAdd, true, 0)
.show(getFragmentManager(), "TimePickerDialogFragment");
} else {
((BasicEditPoiFragment) getParentFragment())

View file

@ -18,23 +18,26 @@ import net.osmand.plus.osmedit.BasicEditPoiFragment;
import net.osmand.util.OpeningHoursParser;
public class OpeningHoursHoursDialogFragment extends DialogFragment {
public static final String IS_START = "is_start";
public static final String BASIC_OPENING_HOUR_RULE = "basic_opening_hour_rule";
public static final String POSITION_TO_ADD = "position_to_add";
private static final String IS_START = "is_start";
private static final String BASIC_OPENING_HOUR_RULE = "basic_opening_hour_rule";
private static final String RULE_POSITION = "rule_position";
private static final String TIME_POSITION = "time_position";
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Bundle args = getArguments();
final boolean isStart = args.getBoolean(IS_START);
final int positionToAdd = args.getInt(POSITION_TO_ADD);
final boolean createNew = positionToAdd == -1;
final OpeningHoursParser.BasicOpeningHourRule item = (OpeningHoursParser.BasicOpeningHourRule)
args.getSerializable(BASIC_OPENING_HOUR_RULE);
final int rulePosition = args.getInt(RULE_POSITION);
final int timePosition = args.getInt(TIME_POSITION);
final boolean createNew = rulePosition == -1;
AlertDialog.Builder builder =
new AlertDialog.Builder(getActivity());
int time = isStart ? item.getStartTime() : item.getEndTime();
int time = isStart ? item.getStartTime(timePosition) : item.getEndTime(timePosition);
int hour = time / 60;
int minute = time - hour * 60;
@ -53,18 +56,18 @@ public class OpeningHoursHoursDialogFragment extends DialogFragment {
int hourOfDay = timePicker.getCurrentHour();
int time = minute + hourOfDay * 60;
if (isStart && createNew) {
item.setStartTime(time);
item.setStartTime(time, timePosition);
OpeningHoursHoursDialogFragment
.createInstance(item, positionToAdd, false)
.createInstance(item, rulePosition, false, timePosition)
.show(getFragmentManager(), "TimePickerDialogFragment");
} else {
if (isStart) {
item.setStartTime(time);
item.setStartTime(time, timePosition);
} else {
item.setEndTime(time);
item.setEndTime(time, timePosition);
}
((BasicEditPoiFragment) getParentFragment())
.setBasicOpeningHoursRule(item, positionToAdd);
.setBasicOpeningHoursRule(item, rulePosition);
}
}
})
@ -94,13 +97,15 @@ public class OpeningHoursHoursDialogFragment extends DialogFragment {
public static OpeningHoursHoursDialogFragment createInstance(
@NonNull OpeningHoursParser.BasicOpeningHourRule item,
int positionToAdd,
boolean isStart) {
int rulePosition,
boolean isStart,
int timePosition) {
OpeningHoursHoursDialogFragment fragment = new OpeningHoursHoursDialogFragment();
Bundle bundle = new Bundle();
bundle.putSerializable(BASIC_OPENING_HOUR_RULE, item);
bundle.putSerializable(POSITION_TO_ADD, positionToAdd);
bundle.putInt(RULE_POSITION, rulePosition);
bundle.putBoolean(IS_START, isStart);
bundle.putInt(TIME_POSITION, timePosition);
fragment.setArguments(bundle);
return fragment;
}