Created
January 22, 2018 08:46
-
-
Save whalemare/c1fca31497473b5f6b7461ebd7273916 to your computer and use it in GitHub Desktop.
CalendarEventDelegate for create intent for pass it to app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add event to calendars using pretty api | |
* @since 2018 | |
* @author Anton Vlasov - whalemare | |
*/ | |
class CalendarEventDelegate { | |
var title = "" | |
var description = "" | |
var startMillis = Long.MIN_VALUE | |
var place = "" | |
fun create(): Intent { | |
val intent = Intent(Intent.ACTION_EDIT) | |
intent.apply { | |
data = ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, System.currentTimeMillis()) | |
if (title.isNotBlank()) { | |
putExtra(CalendarContract.Events.TITLE, title) | |
} | |
if (description.isNotBlank()) { | |
putExtra(CalendarContract.Events.DESCRIPTION, description) | |
} | |
if (startMillis != Long.MIN_VALUE) { | |
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startMillis) | |
} | |
if (place.isNotBlank()) { | |
putExtra(CalendarContract.Events.EVENT_LOCATION, place) | |
} | |
} | |
return intent | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment