Skip to content

Commit

Permalink
Android: Calendar.listCalendars (actually Calendar._findCalendars) re…
Browse files Browse the repository at this point in the history
…sults in a crash #12
  • Loading branch information
EddyVerbruggen committed Nov 22, 2016
1 parent 3b05a4a commit b476468
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
11 changes: 5 additions & 6 deletions calendar.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ Calendar._hasPermission = function(perms) {
return true;
}

var ctx = utils.ad.getApplicationContext();
for (var p in perms) {
var permission = perms[p];
if (android.content.pm.PackageManager.PERMISSION_GRANTED !== android.support.v4.content.ContextCompat.checkSelfPermission(ctx, permission)) {
if (android.content.pm.PackageManager.PERMISSION_GRANTED !== android.support.v4.content.ContextCompat.checkSelfPermission(utils.ad.getApplicationContext(), permission)) {
return false;
}
}
Expand Down Expand Up @@ -113,7 +112,7 @@ Calendar._findCalendars = function (filterByName) {
var selections = null;
var selection = "visible=1";

var contentResolver = application.android.foregroundActivity.getContentResolver();
var contentResolver = utils.ad.getApplicationContext().getContentResolver();
var uriBuilder = android.provider.CalendarContract.Calendars.CONTENT_URI.buildUpon();
var uri = uriBuilder.build();
var cursor = contentResolver.query(
Expand Down Expand Up @@ -179,7 +178,7 @@ Calendar._findEvents = function(arg) {
var uriBuilder = android.provider.CalendarContract.Instances.CONTENT_URI.buildUpon();
android.content.ContentUris.appendId(uriBuilder, settings.startDate.getTime());
android.content.ContentUris.appendId(uriBuilder, settings.endDate.getTime());
var contentResolver = application.android.foregroundActivity.getContentResolver();
var contentResolver = utils.ad.getApplicationContext().getContentResolver();
var uri = uriBuilder.build();
var cursor = contentResolver.query(
uri,
Expand Down Expand Up @@ -265,7 +264,7 @@ Calendar.deleteEvents = function(arg) {

var onPermissionGranted = function() {
var events = Calendar._findEvents(arg);
var ContentResolver = application.android.foregroundActivity.getContentResolver();
var ContentResolver = utils.ad.getApplicationContext().getContentResolver();
var deletedEventIds = [];
for (var e in events) {
var event = events[e];
Expand Down Expand Up @@ -321,7 +320,7 @@ Calendar.createEvent = function(arg) {
}
}
ContentValues.put(Calendar._fields.MESSAGE, description);
var ContentResolver = application.android.foregroundActivity.getContentResolver();
var ContentResolver = utils.ad.getApplicationContext().getContentResolver();
ContentValues.put(Calendar._fields.HAS_ALARM, new java.lang.Integer(settings.reminders.first || settings.reminders.second ? 1 : 0));
var calendarId = null;
if (settings.calendar.name !== null) {
Expand Down
1 change: 0 additions & 1 deletion calendar.ios.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var Calendar = require("./calendar-common");
var application = require("application");

Calendar._eventStore = null;

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nativescript-calendar",
"version": "1.1.3",
"version": "1.1.4",
"description": "Interact with the native calendar. Add, Update, Read, you name it.",
"main": "calendar.js",
"typings": "index.d.ts",
Expand Down

0 comments on commit b476468

Please sign in to comment.