Search in sources :

Example 1 with BasicEditPoiFragment

use of net.osmand.plus.plugins.osmedit.fragments.BasicEditPoiFragment in project Osmand by osmandapp.

the class OpeningHoursHoursDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle args = getArguments();
    final boolean isStart = args.getBoolean(IS_START);
    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 newTimeSpan = timePosition == item.timesSize();
    final boolean createNew = rulePosition == -1 || newTimeSpan;
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    int time;
    if (isStart) {
        time = newTimeSpan ? DEFAULT_START_TIME : item.getStartTime(timePosition);
    } else {
        time = newTimeSpan ? DEFAULT_END_TIME : item.getEndTime(timePosition);
    }
    int hour = time / 60;
    int minute = time - hour * 60;
    final TimePicker timePicker = new TimePicker(getActivity());
    timePicker.setIs24HourView(DateFormat.is24HourFormat(getActivity()));
    timePicker.setCurrentHour(hour);
    timePicker.setCurrentMinute(minute);
    builder.setView(timePicker).setPositiveButton(isStart && createNew ? R.string.next_proceed : R.string.shared_string_save, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            timePicker.clearFocus();
            int minute = timePicker.getCurrentMinute();
            int hourOfDay = timePicker.getCurrentHour();
            int time = minute + hourOfDay * 60;
            if (newTimeSpan) {
                item.addTimeRange(DEFAULT_START_TIME, DEFAULT_END_TIME);
            }
            if (isStart && createNew) {
                item.setStartTime(time, timePosition);
                OpeningHoursHoursDialogFragment.createInstance(item, rulePosition, false, timePosition).show(getFragmentManager(), "TimePickerDialogFragment");
            } else {
                if (isStart) {
                    item.setStartTime(time, timePosition);
                } else {
                    item.setEndTime(time, timePosition);
                }
                ((BasicEditPoiFragment) getParentFragment()).setBasicOpeningHoursRule(item, rulePosition);
            }
        }
    }).setNegativeButton(R.string.shared_string_cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            BasicEditPoiFragment editPoiFragment = ((BasicEditPoiFragment) getParentFragment());
            if (editPoiFragment != null) {
                editPoiFragment.removeUnsavedOpeningHours();
            }
        }
    });
    int paddingInDp = 18;
    float density = getActivity().getResources().getDisplayMetrics().density;
    int paddingInPx = (int) (paddingInDp * density);
    final TypedValue textColorTypedValue = new TypedValue();
    getActivity().getTheme().resolveAttribute(android.R.attr.textColorPrimary, textColorTypedValue, true);
    int textColor = textColorTypedValue.data;
    TextView titleTextView = new TextView(getActivity());
    titleTextView.setText(isStart ? getActivity().getString(R.string.opening_at) : getActivity().getString(R.string.closing_at));
    titleTextView.setPadding(paddingInPx, paddingInPx, paddingInPx, paddingInPx);
    titleTextView.setGravity(Gravity.CENTER_VERTICAL);
    titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
    titleTextView.setTextColor(textColor);
    Typeface typeface = titleTextView.getTypeface();
    titleTextView.setTypeface(typeface, Typeface.BOLD);
    builder.setCustomTitle(titleTextView);
    return builder.create();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) TimePicker(android.widget.TimePicker) DialogInterface(android.content.DialogInterface) BasicEditPoiFragment(net.osmand.plus.plugins.osmedit.fragments.BasicEditPoiFragment) Typeface(android.graphics.Typeface) Bundle(android.os.Bundle) OpeningHoursParser(net.osmand.util.OpeningHoursParser) TextView(android.widget.TextView) TypedValue(android.util.TypedValue) NonNull(androidx.annotation.NonNull)

Aggregations

DialogInterface (android.content.DialogInterface)1 Typeface (android.graphics.Typeface)1 Bundle (android.os.Bundle)1 TypedValue (android.util.TypedValue)1 TextView (android.widget.TextView)1 TimePicker (android.widget.TimePicker)1 NonNull (androidx.annotation.NonNull)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 BasicEditPoiFragment (net.osmand.plus.plugins.osmedit.fragments.BasicEditPoiFragment)1 OpeningHoursParser (net.osmand.util.OpeningHoursParser)1