mangstadt / ez-vcard

A vCard parser library for Java
Other
398 stars 92 forks source link

Migration to 0.12.0 while still supporting Android API 21..25 #129

Open AndroidDeveloperLB opened 1 year ago

AndroidDeveloperLB commented 1 year ago

After updating to 0.12.0 , I've noticed that it has some changes that I hope I've found proper alternatives to them:

  1. Doesn't support File class as parameter for VCardWriter and maybe also others. There is Path instead, but it requires API 26 while the app I work on is for Android API 21 and above. Is it ok to use this instead:
vCardWriter = VCardWriter(BufferedOutputStream(FileOutputStream(vcfFile)), VCardVersion.V4_0)

?

Does it auto-close the stream?

  1. The class Birthday doesn't support providing Date class to it. I can't use Temporal as it requires API 26 . Is it ok to convert to PartialDate ? Would work the same? Meaning like this:
val vCard = VCard()
//birthdate is of type Date
val date =
    PartialDate.builder().year(birthdate.year).month(birthdate.month).date(birthdate.date).build()
vCard.birthday = Birthday(date)

I tried to find information on the repository, but found only what has changed, and not how to migrate: https://github.com/mangstadt/ez-vcard/wiki/Changelog

Please help.

mangstadt commented 1 year ago
  1. Yes it's OK to pass a BufferedOutputStream into the VCardWriter constructor. The output stream is closed when you call VCardWriter.close().
  2. You can use PartialDate for the birthday property, as long as you're creating a 4.0 vCard.
AndroidDeveloperLB commented 1 year ago

@mangstadt

  1. OK
  2. How can I convert from the old Date (or Calendar) into PartialDate? After converting, it should work fine as before, right?
AndroidDeveloperLB commented 1 year ago

Maybe as such:

val partialDate =
    PartialDate.builder().date(birthdate.date).month(birthdate.month + 1).year(birthdate.year + 1900).build()

?

aberaud commented 1 year ago

Not sure why the support for File was removed? It's an old API that is very widely used and not deprecated. It didn't prevent adding support for Path in any way.

mangstadt commented 1 year ago

It was something I did as a personal project because the new APIs are more pleasant to work with.

Apart from the jump to the newer APIs, not much changed in this version (see the Changelog). So if you are worried about missing out on bug/security fixes or new features, there were none (not counting the dependency updates, which you can exclude from your build if your project does not use them).

ez-vcard is very stable and I don't expect there to be many more updates.

mangstadt commented 1 year ago

Self note: Support for java.time and java.nio.file was added in API 26 (Android 8.0), which was released on 8/21/2017.

See "Updated Java language support" section in: https://developer.android.com/about/versions/oreo/android-8.0