Add time span is working
This commit is contained in:
parent
86a465c291
commit
d74ed25045
5 changed files with 76 additions and 40 deletions
|
@ -547,6 +547,10 @@ public class OpeningHoursParser {
|
|||
endTimes.add(endTime);
|
||||
}
|
||||
|
||||
public int timesSize() {
|
||||
return startTimes.size();
|
||||
}
|
||||
|
||||
public void deleteTimeRange(int position) {
|
||||
startTimes.removeAt(position);
|
||||
endTimes.removeAt(position);
|
||||
|
|
|
@ -26,4 +26,5 @@
|
|||
<string name="hint_tag">Tag</string>
|
||||
<string name="hint_value">Value</string>
|
||||
<string name="clear_updates_proposition_message">"You can remove downloaded updates and free "</string>
|
||||
<string name="add_time_span">Add time span</string>
|
||||
</resources>
|
||||
|
|
|
@ -4,52 +4,69 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/clockIconImageView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:src="@drawable/ic_action_time"/>
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/daysTextView"
|
||||
<ImageView
|
||||
android:id="@+id/clockIconImageView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
tools:text="Mo-We"/>
|
||||
android:layout_margin="16dp"
|
||||
android:src="@drawable/ic_action_time"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_weight="1"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/daysTextView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
tools:text="Mo-We"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?android:textColorSecondary"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/timeListContainer"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
<!--<include layout="@layout/time_from_to_layout"/>-->
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/deleteItemImageButton"
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="top"
|
||||
android:src="@drawable/ic_action_remove_dark"/>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?android:textColorSecondary"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
<Button
|
||||
android:id="@+id/addTimeSpanButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:id="@+id/timeListContainer">
|
||||
<!--<include layout="@layout/time_from_to_layout"/>-->
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/deleteItemImageButton"
|
||||
style="@style/Widget.AppCompat.Button.Borderless"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="top"
|
||||
android:src="@drawable/ic_action_remove_dark"/>
|
||||
android:layout_marginLeft="60dp"
|
||||
android:text="@string/add_time_span"
|
||||
android:layout_toRightOf="@id/clockIconImageView"
|
||||
android:layout_below="@id/timeListContainer"
|
||||
android:textColor="?attr/color_dialog_buttons"
|
||||
style="@style/Widget.AppCompat.Button.Borderless"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -251,6 +251,7 @@ public class BasicEditPoiFragment extends Fragment
|
|||
LinearLayout timeListContainer = (LinearLayout) view.findViewById(R.id.timeListContainer);
|
||||
|
||||
ImageButton deleteItemImageButton = (ImageButton) view.findViewById(R.id.deleteItemImageButton);
|
||||
Button addTimeSpanButton = (Button) view.findViewById(R.id.addTimeSpanButton);
|
||||
|
||||
if (openingHours.getRules().get(position) instanceof BasicOpeningHourRule) {
|
||||
final OpeningHoursParser.BasicOpeningHourRule rule =
|
||||
|
@ -320,6 +321,15 @@ public class BasicEditPoiFragment extends Fragment
|
|||
}
|
||||
|
||||
deleteItemImageButton.setVisibility(View.GONE);
|
||||
addTimeSpanButton.setVisibility(View.VISIBLE);
|
||||
addTimeSpanButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
OpeningHoursHoursDialogFragment.createInstance(rule, position, true,
|
||||
startTimes.size()).show(getChildFragmentManager(),
|
||||
"TimePickerDialogFragment");
|
||||
}
|
||||
});
|
||||
} else if (openingHours.getRules().get(position) instanceof OpeningHoursParser.UnparseableRule) {
|
||||
daysTextView.setText(openingHours.getRules().get(position).toRuleString(false));
|
||||
timeListContainer.removeAllViews();
|
||||
|
@ -333,6 +343,7 @@ public class BasicEditPoiFragment extends Fragment
|
|||
updateViews();
|
||||
}
|
||||
});
|
||||
addTimeSpanButton.setVisibility(View.GONE);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
|
|
@ -33,9 +33,12 @@ public class OpeningHoursHoursDialogFragment extends DialogFragment {
|
|||
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());
|
||||
boolean newTimeSpan = timePosition == item.timesSize();
|
||||
if (newTimeSpan) {
|
||||
item.addTimeRange(9 * 60, 18 * 60);
|
||||
}
|
||||
final boolean createNew = rulePosition == -1 || newTimeSpan;
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
|
||||
int time = isStart ? item.getStartTime(timePosition) : item.getEndTime(timePosition);
|
||||
int hour = time / 60;
|
||||
|
|
Loading…
Reference in a new issue