Add time span is working

This commit is contained in:
GaidamakUA 2015-12-30 18:29:29 +02:00
parent 86a465c291
commit d74ed25045
5 changed files with 76 additions and 40 deletions

View file

@ -547,6 +547,10 @@ public class OpeningHoursParser {
endTimes.add(endTime); endTimes.add(endTime);
} }
public int timesSize() {
return startTimes.size();
}
public void deleteTimeRange(int position) { public void deleteTimeRange(int position) {
startTimes.removeAt(position); startTimes.removeAt(position);
endTimes.removeAt(position); endTimes.removeAt(position);

View file

@ -26,4 +26,5 @@
<string name="hint_tag">Tag</string> <string name="hint_tag">Tag</string>
<string name="hint_value">Value</string> <string name="hint_value">Value</string>
<string name="clear_updates_proposition_message">"You can remove downloaded updates and free "</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> </resources>

View file

@ -4,52 +4,69 @@
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="vertical">
<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"/>
<LinearLayout <LinearLayout
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="16dp" android:orientation="horizontal">
android:layout_marginTop="16dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView <ImageView
android:id="@+id/daysTextView" android:id="@+id/clockIconImageView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="?android:textColorPrimary" android:layout_margin="16dp"
android:textSize="@dimen/default_list_text_size" android:src="@drawable/ic_action_time"/>
tools:text="Mo-We"/>
<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
<LinearLayout android:id="@+id/addTimeSpanButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:layout_marginLeft="60dp"
android:id="@+id/timeListContainer"> android:text="@string/add_time_span"
<!--<include layout="@layout/time_from_to_layout"/>--> android:layout_toRightOf="@id/clockIconImageView"
android:layout_below="@id/timeListContainer"
</LinearLayout> android:textColor="?attr/color_dialog_buttons"
style="@style/Widget.AppCompat.Button.Borderless"/>
<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"/>
</LinearLayout> </LinearLayout>

View file

@ -251,6 +251,7 @@ public class BasicEditPoiFragment extends Fragment
LinearLayout timeListContainer = (LinearLayout) view.findViewById(R.id.timeListContainer); LinearLayout timeListContainer = (LinearLayout) view.findViewById(R.id.timeListContainer);
ImageButton deleteItemImageButton = (ImageButton) view.findViewById(R.id.deleteItemImageButton); ImageButton deleteItemImageButton = (ImageButton) view.findViewById(R.id.deleteItemImageButton);
Button addTimeSpanButton = (Button) view.findViewById(R.id.addTimeSpanButton);
if (openingHours.getRules().get(position) instanceof BasicOpeningHourRule) { if (openingHours.getRules().get(position) instanceof BasicOpeningHourRule) {
final OpeningHoursParser.BasicOpeningHourRule rule = final OpeningHoursParser.BasicOpeningHourRule rule =
@ -320,6 +321,15 @@ public class BasicEditPoiFragment extends Fragment
} }
deleteItemImageButton.setVisibility(View.GONE); 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) { } else if (openingHours.getRules().get(position) instanceof OpeningHoursParser.UnparseableRule) {
daysTextView.setText(openingHours.getRules().get(position).toRuleString(false)); daysTextView.setText(openingHours.getRules().get(position).toRuleString(false));
timeListContainer.removeAllViews(); timeListContainer.removeAllViews();
@ -333,6 +343,7 @@ public class BasicEditPoiFragment extends Fragment
updateViews(); updateViews();
} }
}); });
addTimeSpanButton.setVisibility(View.GONE);
} }
return view; return view;
} }

View file

@ -33,9 +33,12 @@ public class OpeningHoursHoursDialogFragment extends DialogFragment {
final int rulePosition = args.getInt(RULE_POSITION); final int rulePosition = args.getInt(RULE_POSITION);
final int timePosition = args.getInt(TIME_POSITION); final int timePosition = args.getInt(TIME_POSITION);
final boolean createNew = rulePosition == -1; boolean newTimeSpan = timePosition == item.timesSize();
AlertDialog.Builder builder = if (newTimeSpan) {
new AlertDialog.Builder(getActivity()); 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 time = isStart ? item.getStartTime(timePosition) : item.getEndTime(timePosition);
int hour = time / 60; int hour = time / 60;