From 798b97e05619abfd614e0a047647f60cc61d89e6 Mon Sep 17 00:00:00 2001 From: Alex Styl Date: Fri, 2 Sep 2016 20:47:11 +0100 Subject: [PATCH 1/2] Do not calculate events if cursor is invalid --- .../specialdates/events/NamedayDatabaseRefresher.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mobile/src/main/java/com/alexstyl/specialdates/events/NamedayDatabaseRefresher.java b/mobile/src/main/java/com/alexstyl/specialdates/events/NamedayDatabaseRefresher.java index f142c3bf..0d7de450 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/events/NamedayDatabaseRefresher.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/events/NamedayDatabaseRefresher.java @@ -77,6 +77,9 @@ private void initialiseNamedaysIfEnabled() { private List loadDeviceStaticNamedays() { List namedayEvents = new ArrayList<>(); Cursor cursor = DeviceContactsQuery.query(contentResolver); + if (isInvalidCursor(cursor)) { + return namedayEvents; + } Set contactIDs = new HashSet<>(); @@ -127,6 +130,10 @@ private List loadSpecialNamedays() { List namedayEvents = new ArrayList<>(); Cursor cursor = DeviceContactsQuery.query(contentResolver); + if (isInvalidCursor(cursor)) { + return namedayEvents; + } + Set contactIDs = new HashSet<>(); while (cursor.moveToNext()) { @@ -164,6 +171,10 @@ private List loadSpecialNamedays() { return namedayEvents; } + private boolean isInvalidCursor(Cursor cursor) { + return cursor == null; + } + private String getDisplayName(Cursor cursor) { return cursor.getString(DeviceContactsQuery.DISPLAY_NAME); } From c1bbddeb90bed351324dd1e57424045952771cc0 Mon Sep 17 00:00:00 2001 From: Alex Styl Date: Fri, 2 Sep 2016 20:54:32 +0100 Subject: [PATCH 2/2] Remove new line --- .../alexstyl/specialdates/events/NamedayDatabaseRefresher.java | 1 - 1 file changed, 1 deletion(-) diff --git a/mobile/src/main/java/com/alexstyl/specialdates/events/NamedayDatabaseRefresher.java b/mobile/src/main/java/com/alexstyl/specialdates/events/NamedayDatabaseRefresher.java index 0d7de450..37710774 100644 --- a/mobile/src/main/java/com/alexstyl/specialdates/events/NamedayDatabaseRefresher.java +++ b/mobile/src/main/java/com/alexstyl/specialdates/events/NamedayDatabaseRefresher.java @@ -129,7 +129,6 @@ private List loadDeviceStaticNamedays() { private List loadSpecialNamedays() { List namedayEvents = new ArrayList<>(); Cursor cursor = DeviceContactsQuery.query(contentResolver); - if (isInvalidCursor(cursor)) { return namedayEvents; }