summaryrefslogtreecommitdiff
path: root/src/com/android/dreams/phototable/CursorPhotoSource.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/dreams/phototable/CursorPhotoSource.java')
-rw-r--r--src/com/android/dreams/phototable/CursorPhotoSource.java15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/com/android/dreams/phototable/CursorPhotoSource.java b/src/com/android/dreams/phototable/CursorPhotoSource.java
index cb4ce6b..f010a92 100644
--- a/src/com/android/dreams/phototable/CursorPhotoSource.java
+++ b/src/com/android/dreams/phototable/CursorPhotoSource.java
@@ -39,10 +39,10 @@ public abstract class CursorPhotoSource extends PhotoSource {
@Override
protected ImageData naturalNext(ImageData current) {
- if (current.cursor == null) {
+ if (current.cursor == null || current.cursor.isClosed()) {
openCursor(current);
- findPosition(current);
}
+ findPosition(current);
current.cursor.moveToPosition(current.position);
current.cursor.moveToNext();
ImageData data = null;
@@ -56,10 +56,10 @@ public abstract class CursorPhotoSource extends PhotoSource {
@Override
protected ImageData naturalPrevious(ImageData current) {
- if (current.cursor == null) {
+ if (current.cursor == null || current.cursor.isClosed()) {
openCursor(current);
- findPosition(current);
}
+ findPosition(current);
current.cursor.moveToPosition(current.position);
current.cursor.moveToPrevious();
ImageData data = null;
@@ -71,6 +71,13 @@ public abstract class CursorPhotoSource extends PhotoSource {
return data;
}
+ @Override
+ protected void donePaging(ImageData current) {
+ if (current.cursor != null && !current.cursor.isClosed()) {
+ current.cursor.close();
+ }
+ }
+
protected abstract void openCursor(ImageData data);
protected abstract void findPosition(ImageData data);
protected abstract ImageData unpackImageData(Cursor cursor, ImageData data);