diff --git a/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java b/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java index 842d5c07a54a..af1cd05f472c 100644 --- a/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java +++ b/mobile/android/base/java/org/mozilla/gecko/db/BrowserContract.java @@ -512,6 +512,17 @@ public class BrowserContract { public static final String VALUE = "value"; public static final String SYNC_STATUS = "sync_status"; + public enum Key { + // We use a parameter, rather than name(), as defensive coding: we can't let the + // enum name change because we've already stored values into the DB. + SCREENSHOT ("screenshot"); + + private final String dbValue; + + Key(final String dbValue) { this.dbValue = dbValue; } + public String getDbValue() { return dbValue; } + } + public enum SyncStatus { // We use a parameter, rather than ordinal(), as defensive coding: we can't let the // ordinal values change because we've already stored values into the DB. diff --git a/mobile/android/base/java/org/mozilla/gecko/db/LocalUrlAnnotations.java b/mobile/android/base/java/org/mozilla/gecko/db/LocalUrlAnnotations.java index 58e53ad4809c..44159e7a700a 100644 --- a/mobile/android/base/java/org/mozilla/gecko/db/LocalUrlAnnotations.java +++ b/mobile/android/base/java/org/mozilla/gecko/db/LocalUrlAnnotations.java @@ -6,8 +6,13 @@ package org.mozilla.gecko.db; import android.content.ContentResolver; import android.content.ContentValues; +import android.database.Cursor; import android.net.Uri; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import org.json.JSONObject; import org.mozilla.gecko.annotation.RobocopTarget; +import org.mozilla.gecko.db.BrowserContract.UrlAnnotations.Key; public class LocalUrlAnnotations implements UrlAnnotations { private Uri urlAnnotationsTableWithProfile; @@ -28,4 +33,26 @@ public class LocalUrlAnnotations implements UrlAnnotations { values.put(BrowserContract.UrlAnnotations.DATE_MODIFIED, creationTime); cr.insert(urlAnnotationsTableWithProfile, values); } + + private Cursor queryByKey(final ContentResolver cr, @NonNull final Key key, @Nullable final String[] projections, + @Nullable final String sortOrder) { + return cr.query(urlAnnotationsTableWithProfile, + projections, + BrowserContract.UrlAnnotations.KEY + " = ?", new String[] { key.getDbValue() }, + sortOrder); + } + + @Override + public Cursor getScreenshots(ContentResolver cr) { + return queryByKey(cr, + Key.SCREENSHOT, + new String[] { + BrowserContract.UrlAnnotations._ID, + BrowserContract.UrlAnnotations.URL, + BrowserContract.UrlAnnotations.KEY, + BrowserContract.UrlAnnotations.VALUE, + BrowserContract.UrlAnnotations.DATE_CREATED, + }, + BrowserContract.UrlAnnotations.DATE_CREATED + " DESC"); + } } diff --git a/mobile/android/base/java/org/mozilla/gecko/db/StubBrowserDB.java b/mobile/android/base/java/org/mozilla/gecko/db/StubBrowserDB.java index 1056d649bedc..861629e0e830 100644 --- a/mobile/android/base/java/org/mozilla/gecko/db/StubBrowserDB.java +++ b/mobile/android/base/java/org/mozilla/gecko/db/StubBrowserDB.java @@ -153,6 +153,9 @@ class StubTabsAccessor implements TabsAccessor { class StubUrlAnnotations implements UrlAnnotations { @Override public void insertAnnotation(ContentResolver cr, String url, String key, String value) {} + + @Override + public Cursor getScreenshots(ContentResolver cr) { return null; } } /* diff --git a/mobile/android/base/java/org/mozilla/gecko/db/UrlAnnotations.java b/mobile/android/base/java/org/mozilla/gecko/db/UrlAnnotations.java index 907618ed3f01..9148cb4099ad 100644 --- a/mobile/android/base/java/org/mozilla/gecko/db/UrlAnnotations.java +++ b/mobile/android/base/java/org/mozilla/gecko/db/UrlAnnotations.java @@ -5,8 +5,10 @@ package org.mozilla.gecko.db; import android.content.ContentResolver; +import android.database.Cursor; import org.mozilla.gecko.annotation.RobocopTarget; public interface UrlAnnotations { @RobocopTarget void insertAnnotation(ContentResolver cr, String url, String key, String value); + Cursor getScreenshots(ContentResolver cr); }