Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android-SwitchDateTimePicker app get crashed when setMinimumDateTime #24

Closed
vandanabpatel opened this issue Jun 24, 2017 · 10 comments
Closed

Comments

@vandanabpatel
Copy link

SwitchDateTimeDialogFragment dateTimeFragment = (SwitchDateTimeDialogFragment) getActivity().getSupportFragmentManager().findFragmentByTag("tv_materialDateTime");

// init datetime picker
if (dateTimeFragment == null) {
dateTimeFragment = SwitchDateTimeDialogFragment.newInstance(
getString(R.string.label_datetime_dialog),
getString(android.R.string.ok),
getString(android.R.string.cancel)
);
}

    Date currentDate = new Date();
    dateTimeFragment.setDefaultDateTime(currentDate);
 
    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.add(Calendar.MONTH, 1);
    dateTimeFragment.setMaximumDateTime(cal.getTime());
    dateTimeFragment.startAtCalendarView();
    dateTimeFragment.set24HoursMode(false);

    dateTimeFragment.setMinimumDateTime(new Date());

    // Set listener for date
    dateTimeFragment.setOnButtonClickListener(new SwitchDateTimeDialogFragment.OnButtonClickListener() {
        @Override
        public void onPositiveButtonClick(Date date) {
            textView.setText(DateTimeUtils.formatDateTime(date, DateFormats.DMMMYYYYHHMMA.getLabel()));
        }

        @Override
        public void onNegativeButtonClick(Date date) {

        }
    });

dateTimeFragment.show(getActivity().getSupportFragmentManager(), "tv_materialDateTime");

@vandanabpatel
Copy link
Author

Here, i want to disable past date.

@J-Jamet
Copy link
Member

J-Jamet commented Jun 24, 2017

And ? I do not understand what you want ? be more specific. Otherwise I see one problem, If you define a new Date after another new Date, the next one will be a little bit after (because of milliseconds), so your code can't work because you can't define a default time before the minimum date.

@vandanabpatel
Copy link
Author

suppose today, 24 june 2017 so, i want like, maximum datetime will with 24 july 2017 and want to hide past date and default date will be last selected date(will be between 24 june to 24 july).

@J-Jamet
Copy link
Member

J-Jamet commented Jun 24, 2017

As I said, it comes from the time that is after the minimum date. Simply init hours, minutes an seconds

        Calendar cal = Calendar.getInstance();
        cal.setTime(new Date());
        cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
        dateTimeFragment.setMinimumDateTime(cal.getTime());
        cal.setTime(new Date());
        cal.add(Calendar.MONTH, 1);
        dateTimeFragment.setMaximumDateTime(cal.getTime());
        dateTimeFragment.setDefaultDateTime(new Date());

@J-Jamet J-Jamet closed this as completed Jun 24, 2017
@vandanabpatel
Copy link
Author

vandanabpatel commented Jun 25, 2017

yes, its work fine thank you very much.

@vandanabpatel
Copy link
Author

vandanabpatel commented Aug 4, 2017

hi, i want to set minimum time too but it seems like it doesn't works

Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));
dateTimeFragment.setMinimumDateTime(cal.getTime());
cal.add(Calendar.MONTH, 1);
dateTimeFragment.setMaximumDateTime(cal.getTime());
dateTimeFragment.startAtCalendarView();
dateTimeFragment.set24HoursMode(false);

Please guide me.... thank you so much

@J-Jamet
Copy link
Member

J-Jamet commented Aug 4, 2017

The minimum time is planned but not yet available. (See #11)

@vandanabpatel
Copy link
Author

vandanabpatel commented Aug 5, 2017

minimum date is working fine but while i have set hour minute and secont it still allow to change it.

i wand to disable past hour minute too

cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR), cal.get(Calendar.MINUTE), cal.get(Calendar.SECOND));

dateTimeFragment.setMinimumDateTime(cal.getTime());

@J-Jamet
Copy link
Member

J-Jamet commented Aug 5, 2017

I understood correctly, it is a functionality planned, but it is necessary to modify the view of hours and minutes to disable events, to gray the numbers, and to refactor the view for a good code. It's a lot of work and not much time. :/ (You can contribute if you want the feature faster. ;))

@vandanabpatel
Copy link
Author

vandanabpatel commented Aug 5, 2017

FixTimePickerDialog.txt

Fot timepicker you can use this login can you please check once we can replace under library.
This is working for TImePicker we can implement into library can you please do it

Please refer above attached file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants