xamarin / AndroidX

AndroidX bindings for .NET for Android
MIT License
182 stars 45 forks source link

MaterialDesign DatePicker uses Java.Lang.Object #266

Open DavidMarquezF opened 3 years ago

DavidMarquezF commented 3 years ago

Version Information

Describe your Issue:

MaterialDialog SetSelection, IMaterialPickerOnPositiveButtonClickListener and probably other parts of the Material dialog have Java.Lang.Object as an argument. It would be nice that it included stronger typings or even take System.DateTime.

Apparently, the original MaterialDatePicker accepts a generic. I believe the Xamarin Android Binding process doesn't handle generics very well and it has to be done by hand but I'm not sure.

https://github.com/material-components/material-components-android/blob/fb96aa859288f22fc6d0c88c28ba7826caae5175/lib/java/com/google/android/material/datepicker/MaterialDatePicker.java#L62

Steps to Reproduce (with link to sample solution if possible):

Include any relevant Exception Stack traces, build logs, adb logs:

moljac commented 3 years ago

@DavidMarquezF

It would be nice that it included stronger typings or even take System.DateTime.

It would be nice, but very often not possible due to differences between java and .net/c# worlds.

Apparently, the original MaterialDatePicker accepts a generic.

Generics are one of the biggest problems. We are trying to improve our tooling to handle such cases, but not everything is possible.

I believe the Xamarin Android Binding process doesn't handle generics very well and it has to be done by hand but I'm not sure.

Your beliefs are correct/true. Wanna help?

Checking if there is something I could do to get strongly typed arguments, but I cannot promise.

DavidMarquezF commented 3 years ago

Would it be possible to create a wrapper? I did something similar for some bindings I'm trying to do with Afollestad Material Dialogs. I created a partial class in the Additions Folder that called the functions with the strongly typed parameters. This way you have full controll how you want to work. Then in Metadata.xml it is possible to make the not strongly typed function internal I believe (if need be)? For the sake of simplicity, instead of creating a generic class it can be done so that it supports System.DateTime only.