flavienlaurent / datetimepicker

DateTimePicker is a library which contains the beautiful DatePicker that can be seen in the new Google Agenda app.
1.83k stars 578 forks source link

TimePickerDialog tags not working? #77

Open Gaudon opened 10 years ago

Gaudon commented 10 years ago

Are the TimePickerDialog tags not implemented?

datePickerDialog.show(getActivity().getSupportFragmentManager(), DATE_DIALOG_START_TAG);

// ...

@Override
public void onDateSet(DatePickerDialog datePickerDialog, int year, int month, int day) {
    if(datePickerDialog.getTag().equalsIgnoreCase(DATE_DIALOG_START_TAG)) {
        // Do Stuff
    }
}

The above code works as .getTag() returns a string. However TimePickerDialog seems to operate differently.

timePickerDialog.show(getActivity().getSupportFragmentManager(), TIME_DIALOG_START_TAG);

// ...

@Override
public void onTimeSet(RadialPickerLayout radialPickerLayout, int hour, int minute) {
    if(radialPickerLayout.getTag().toString().equalsIgnoreCase(TIME_DIALOG_START_TAG)) {
        // Do Stuff
    }
}

In this case, the getTag() is an object and is null after calling .show() with a string tag supplied.

Gaudon commented 10 years ago

I've written a hack to work around this by simply setting a local tag within the fragment for the last timepickerdialog that was actively shown on the screen given that only one can be present at a time. This isn't a clean or correct solution, but it will work until a fix is issued.

prettyvoid commented 10 years ago

@Gaudon Faced same issue today, the tag that goes in timePickerDialog.show() is not the tag for the RadialPickerLayout thats gets passed to the callback. It's the tag for the listener which can't be accessed.

I've also implemented a solution similar to what you described, until it's fixed.

flavienlaurent commented 10 years ago

Instead of fixing the thing on your side, it could be great that you fix it for everyone. Feel free to PR ;)

prettyvoid commented 10 years ago

I created a pull request. I tried to approach it in the most non-intrusive way, as to avoid modifying a whole lot of stuff. https://github.com/flavienlaurent/datetimepicker/pull/78

Thanks flav