syncslides: Upgrade to Vanadium 0.8

Also fix a couple of places where I wasn't checking for errors on the
VIterable.

Change-Id: Id2872cac16cb3662ce38b023dfd6c5a4b4cc0ff2
diff --git a/android/app/build.gradle b/android/app/build.gradle
index 920690c..a507a38 100644
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -1,5 +1,6 @@
 buildscript {
     repositories {
+        jcenter()
         mavenCentral()
     }
 
@@ -8,7 +9,7 @@
         classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
         // We are going to define a custom VDL service. The Vanadium
         // Gradle plugin makes that easier, so let's use that.
-        classpath 'io.v:gradle-plugin:0.1'
+        classpath 'io.v:gradle-plugin:1.3'
         // Retrolambda saves a ton on boilerplate.
         classpath 'me.tatarka:gradle-retrolambda:3.2.4'
     }
@@ -53,7 +54,7 @@
     compile 'com.android.support:design:23.1.0'
     compile 'com.android.support:recyclerview-v7:23.0.1'
     compile 'com.android.support:cardview-v7:23.0.1'
-    compile 'io.v:vanadium-android:0.2'
+    compile 'io.v:vanadium-android:0.8'
 }
 
 vdl {
diff --git a/android/app/src/main/java/io/v/syncslides/db/DeckWatcher.java b/android/app/src/main/java/io/v/syncslides/db/DeckWatcher.java
index f3bc39f..4f74905 100644
--- a/android/app/src/main/java/io/v/syncslides/db/DeckWatcher.java
+++ b/android/app/src/main/java/io/v/syncslides/db/DeckWatcher.java
@@ -12,6 +12,7 @@
 import io.v.impl.google.naming.NamingUtil;
 import io.v.syncslides.model.Deck;
 import io.v.syncslides.model.DeckImpl;
+import io.v.v23.InputChannels;
 import io.v.v23.VIterable;
 import io.v.v23.context.VContext;
 import io.v.v23.services.watch.ResumeMarker;
@@ -42,8 +43,8 @@
         try {
             BatchDatabase batch = sync(mDB.beginBatch(context, null));
             ResumeMarker resumeMarker = sync(batch.getResumeMarker(context));
-            DatabaseCore.QueryResults results = sync(batch.exec(context,
-                    "SELECT k, v FROM Decks WHERE Type(v) like \"%VDeck\""));
+            VIterable<List<VdlAny>> results = InputChannels.asIterable(sync(batch.exec(
+                    context, "SELECT k, v FROM Decks WHERE Type(v) like \"%VDeck\"")));
             for (List<VdlAny> row : results) {
                 if (row.size() != 2) {
                     throw new VException("Wrong number of columns: " + row.size());
@@ -57,7 +58,7 @@
                 throw results.error();
             }
 
-            VIterable<WatchChange> changes = sync(mDB.watch(
+            VIterable<WatchChange> changes = InputChannels.asIterable(mDB.watch(
                     context, SyncbaseDB.DECKS_TABLE, "", resumeMarker));
             for (WatchChange change : changes) {
                 final String key = change.getRowName();
diff --git a/android/app/src/main/java/io/v/syncslides/db/SlideNumberWatcher.java b/android/app/src/main/java/io/v/syncslides/db/SlideNumberWatcher.java
index 15d3e10..1ed2f5b 100644
--- a/android/app/src/main/java/io/v/syncslides/db/SlideNumberWatcher.java
+++ b/android/app/src/main/java/io/v/syncslides/db/SlideNumberWatcher.java
@@ -16,6 +16,7 @@
 
 import io.v.impl.google.naming.NamingUtil;
 import io.v.syncslides.model.Session;
+import io.v.v23.InputChannels;
 import io.v.v23.VIterable;
 import io.v.v23.context.CancelableVContext;
 import io.v.v23.context.VContext;
@@ -133,9 +134,9 @@
                 mHandler.post(() -> currentSlideChanged(slide));
             }
             ResumeMarker marker = sync(batch.getResumeMarker(mCurrentContext));
-            VIterable<WatchChange> changes =
-                    sync(mDb.watch(mCurrentContext, SyncbaseDB.PRESENTATIONS_TABLE,
-                            rowKey, marker));
+
+            VIterable<WatchChange> changes = InputChannels.asIterable(
+                    mDb.watch(mCurrentContext, SyncbaseDB.PRESENTATIONS_TABLE, rowKey, marker));
             for (WatchChange change : changes) {
                 String key = change.getRowName();
                 Log.i(TAG, "Found CurrentSlide change " + key);
@@ -148,6 +149,9 @@
                     mHandler.post(() -> currentSlideChanged(slide));
                 }
             }
+            if (changes.error() != null) {
+                throw changes.error();
+            }
         } catch (final VException e) {
             mHandler.post(() -> notifyError(e));
         }
@@ -163,7 +167,8 @@
             mHandler.post(() -> localSlideChanged(vSession.getLocalSlide()));
             ResumeMarker marker = sync(batch.getResumeMarker(mCurrentContext));
             VIterable<WatchChange> changes =
-                    sync(mDb.watch(mCurrentContext, SyncbaseDB.UI_TABLE, mSessionId, marker));
+                    InputChannels.asIterable(mDb.watch(
+                            mCurrentContext, SyncbaseDB.UI_TABLE, mSessionId, marker));
             for (WatchChange change : changes) {
                 String key = change.getRowName();
                 Log.i(TAG, "Found local slide change " + key);
@@ -176,7 +181,10 @@
                     mHandler.post(() -> localSlideChanged(vSession1.getLocalSlide()));
                 }
             }
-        } catch (final VException e) {
+            if (changes.error() != null) {
+                throw changes.error();
+            }
+         } catch (final VException e) {
             mHandler.post(() -> notifyError(e));
         }
     }
diff --git a/android/app/src/main/java/io/v/syncslides/db/SlideWatcher.java b/android/app/src/main/java/io/v/syncslides/db/SlideWatcher.java
index 30d0aa2..2913dec 100644
--- a/android/app/src/main/java/io/v/syncslides/db/SlideWatcher.java
+++ b/android/app/src/main/java/io/v/syncslides/db/SlideWatcher.java
@@ -11,6 +11,7 @@
 import io.v.impl.google.naming.NamingUtil;
 import io.v.syncslides.model.Slide;
 import io.v.syncslides.model.SlideImpl;
+import io.v.v23.InputChannels;
 import io.v.v23.VIterable;
 import io.v.v23.context.VContext;
 import io.v.v23.services.watch.ResumeMarker;
@@ -72,7 +73,8 @@
         Table notesTable = batch.getTable(SyncbaseDB.NOTES_TABLE);
         String query = "SELECT k, v FROM Decks WHERE Type(v) LIKE \"%VSlide\" " +
                 "AND k LIKE \"" + NamingUtil.join(mDeckId, "slides") + "%\"";
-        DatabaseCore.QueryResults results = sync(batch.exec(context, query));
+        VIterable<List<VdlAny>> results = InputChannels.asIterable(
+                sync(batch.exec(context, query)));
         for (List<VdlAny> row : results) {
             if (row.size() != 2) {
                 throw new VException("Wrong number of columns: " + row.size());
@@ -84,13 +86,16 @@
             Slide newSlide = new DBSlide(key, slide, notes);
             listener.onPut(newSlide);
         }
+        if (results.error() != null) {
+            throw results.error();
+        }
     }
 
     private void watchSlideChanges(VContext context, Listener<Slide> listener,
                                    ResumeMarker watchMarker) throws VException {
         Table notesTable = mDb.getTable(SyncbaseDB.NOTES_TABLE);
-        VIterable<WatchChange> changes =
-                sync(mDb.watch(context, SyncbaseDB.DECKS_TABLE, mDeckId, watchMarker));
+        VIterable<WatchChange> changes = InputChannels.asIterable(
+                mDb.watch(context, SyncbaseDB.DECKS_TABLE, mDeckId, watchMarker));
         for (WatchChange change : changes) {
             String key = change.getRowName();
             if (isDeckKey(key)) {
@@ -121,8 +126,8 @@
     private void watchNoteChanges(VContext context, Listener<Slide> listener,
                                   ResumeMarker watchMarker) throws VException {
         Table decksTable = mDb.getTable(SyncbaseDB.DECKS_TABLE);
-        VIterable<WatchChange> changes =
-                sync(mDb.watch(context, SyncbaseDB.NOTES_TABLE, mDeckId, watchMarker));
+        VIterable<WatchChange> changes = InputChannels.asIterable(
+                mDb.watch(context, SyncbaseDB.NOTES_TABLE, mDeckId, watchMarker));
         for (WatchChange change : changes) {
             String key = change.getRowName();
             if (!SyncbaseDB.isSlideKey(key)) {
diff --git a/android/app/src/main/java/io/v/syncslides/db/SyncbaseDB.java b/android/app/src/main/java/io/v/syncslides/db/SyncbaseDB.java
index 4b314e7..a319459 100644
--- a/android/app/src/main/java/io/v/syncslides/db/SyncbaseDB.java
+++ b/android/app/src/main/java/io/v/syncslides/db/SyncbaseDB.java
@@ -223,7 +223,7 @@
         String key = slideRowKey(prefix, idx);
         Log.i(TAG, "Adding slide " + key);
         BlobWriter writer = sync(mDB.writeBlob(mVContext, null));
-        try (OutputStream out = sync(writer.stream(mVContext))) {
+        try (OutputStream out = writer.stream(mVContext)) {
             out.write(slide.getImageData());
         } catch (IOException e) {
             throw new VException("Couldn't write slide: " + key + ": " + e.getMessage());