diff --git a/app/src/androidTest/java/com/murrayc/galaxyzoo/app/provider/test/ZooniverseClientTest.java b/app/src/androidTest/java/com/murrayc/galaxyzoo/app/provider/test/ZooniverseClientTest.java index d4f6205b..c1f7cf8a 100644 --- a/app/src/androidTest/java/com/murrayc/galaxyzoo/app/provider/test/ZooniverseClientTest.java +++ b/app/src/androidTest/java/com/murrayc/galaxyzoo/app/provider/test/ZooniverseClientTest.java @@ -79,7 +79,7 @@ public void testMoreItems() throws IOException, InterruptedException, Zooniverse final ZooniverseClient client = createZooniverseClient(server); final int COUNT = 10; - final List subjects = client.requestMoreItemsSync(COUNT); + final List subjects = client.requestMoreItemsSync(TEST_GROUP_ID, COUNT); assertNotNull(subjects); assertEquals(COUNT, subjects.size()); @@ -290,7 +290,7 @@ public void testMoreItemsWithBadResponseContent() throws IOException { //Mostly we want to check that it doesn't crash on a bad HTTP response. try { - final List subjects = client.requestMoreItemsSync(5); + final List subjects = client.requestMoreItemsSync(TEST_GROUP_ID, 5); assertTrue((subjects == null) || (subjects.isEmpty())); } catch (final ZooniverseClient.RequestMoreItemsException e) { /* We don't care about the actual cause. @@ -320,7 +320,7 @@ public void testMoreItemsWithBadResponseCode() throws IOException { //Mostly we want to check that it doesn't crash on a bad HTTP response. try { - final List subjects = client.requestMoreItemsSync(5); + final List subjects = client.requestMoreItemsSync(TEST_GROUP_ID, 5); assertTrue((subjects == null) || (subjects.isEmpty())); } catch (final ZooniverseClient.RequestMoreItemsException e) { assertNotNull(e.getMessage()); diff --git a/app/src/androidTest/java/com/murrayc/galaxyzoo/app/provider/test/ZooniverseClientWithRealServerTest.java b/app/src/androidTest/java/com/murrayc/galaxyzoo/app/provider/test/ZooniverseClientWithRealServerTest.java index 241be506..fc8fa2e6 100644 --- a/app/src/androidTest/java/com/murrayc/galaxyzoo/app/provider/test/ZooniverseClientWithRealServerTest.java +++ b/app/src/androidTest/java/com/murrayc/galaxyzoo/app/provider/test/ZooniverseClientWithRealServerTest.java @@ -55,7 +55,7 @@ public void testMoreItems() throws IOException, ZooniverseClient.RequestMoreItem // Do this enough times that we are very likely to excercise all groups: final int count = Config.SUBJECT_GROUPS.size() * 5; for (int i = 0; i < count; ++i) { - final List subjects = client.requestMoreItemsSync(1); + final List subjects = client.requestMoreItemsSync(Config.SUBJECT_GROUP_ID_GAMA_15,1); assertNotNull(subjects); assertTrue(subjects.size() == 1); diff --git a/app/src/main/java/com/murrayc/galaxyzoo/app/provider/ItemsContentProvider.java b/app/src/main/java/com/murrayc/galaxyzoo/app/provider/ItemsContentProvider.java index 368f217d..1b1d7035 100644 --- a/app/src/main/java/com/murrayc/galaxyzoo/app/provider/ItemsContentProvider.java +++ b/app/src/main/java/com/murrayc/galaxyzoo/app/provider/ItemsContentProvider.java @@ -700,7 +700,8 @@ selection, prependToArray(selectionArgs, uriParts.itemId), for(int i = 0; i < 3; i++) { List subjects = null; try { - subjects = mZooniverseClient.requestMoreItemsSync(1); + final String groupId = mZooniverseClient.getGroupIdForNextQuery(); + subjects = mZooniverseClient.requestMoreItemsSync(groupId, 1); } catch (final HttpUtils.NoNetworkException e) { //Return the empty cursor, //and let the caller guess at the cause. diff --git a/app/src/main/java/com/murrayc/galaxyzoo/app/provider/client/ZooniverseClient.java b/app/src/main/java/com/murrayc/galaxyzoo/app/provider/client/ZooniverseClient.java index dfdf87b5..5ff89c92 100644 --- a/app/src/main/java/com/murrayc/galaxyzoo/app/provider/client/ZooniverseClient.java +++ b/app/src/main/java/com/murrayc/galaxyzoo/app/provider/client/ZooniverseClient.java @@ -82,7 +82,7 @@ public static Gson createGson() { * * @return */ - private static String getGroupIdForNextQuery() { + public static String getGroupIdForNextQuery() { //Get a list of only the groups that should be used for new queries. //TODO: Avoid doing this each time? @@ -155,7 +155,7 @@ public LoginUtils.LoginResult loginSync(final String username, final String pass * @param count * @return */ - public List requestMoreItemsSync(int count) throws RequestMoreItemsException { + public List requestMoreItemsSync(final String groupId, int count) throws RequestMoreItemsException { throwIfNoNetwork(); //Avoid suddenly doing too much network and disk IO @@ -167,7 +167,7 @@ public List requestMoreItemsSync(int count) throws RequestMoreItemsExce Response response = null; try { - final Call call = callGetSubjects(count); + final Call call = callGetSubjects(groupId, count); response = call.execute(); } catch (final IOException e) { Log.error("requestMoreItemsSync(): request failed.", e); @@ -286,12 +286,12 @@ public List requestWorkflowSync(final String workflowId) throws Reques return result; } - public void requestMoreItemsAsync(final int count, final Callback callback) { + public void requestMoreItemsAsync(final String groupId, final int count, final Callback callback) { throwIfNoNetwork(); Log.info("requestMoreItemsAsync(): count=" + count); - final Call call = callGetSubjects(count); + final Call call = callGetSubjects(groupId, count); call.enqueue(callback); } @@ -302,8 +302,8 @@ public void requestWorkflowAsync(final String workflowId, final Callback callGetSubjects(final int count) { - return mRetrofitService.getSubjects(getGroupIdForNextQuery(), count); + private Call callGetSubjects(final String groupId, final int count) { + return mRetrofitService.getSubjects(groupId, count); } private Call callGetProject(final String projectSlug) { diff --git a/app/src/main/java/com/murrayc/galaxyzoo/app/syncadapter/SyncAdapter.java b/app/src/main/java/com/murrayc/galaxyzoo/app/syncadapter/SyncAdapter.java index 0ebe3858..0a4c0af5 100644 --- a/app/src/main/java/com/murrayc/galaxyzoo/app/syncadapter/SyncAdapter.java +++ b/app/src/main/java/com/murrayc/galaxyzoo/app/syncadapter/SyncAdapter.java @@ -112,7 +112,7 @@ private void doRegularTasks() { //Do the download first, to avoid the UI having to wait for new subjects to classify. - downloadMinimumSubjectsAsync(); + downloadMinimumSubjectsAsync(ZooniverseClient.getGroupIdForNextQuery()); downloadMissingImages(); //Do less urgent things next: @@ -164,17 +164,17 @@ private ContentResolver getContentResolver() { * * @return Return true if we know for sure that no further downloading is currently necessary. */ - private boolean downloadMinimumSubjectsAsync() { + private boolean downloadMinimumSubjectsAsync(final String groupId) { final int missing = getNotDoneNeededForCache(); if (missing > 0) { - requestMoreItemsAsync(missing); + requestMoreItemsAsync(groupId, missing); return false; } else { return true; //Tell the caller that no action was necessary. } } - private void requestMoreItemsAsync(final int count) { + private void requestMoreItemsAsync(final String groupId, final int count) { if(mRequestMoreItemsTaskInProgress) { //Do just one of these at a time, //to avoid requesting more while we are processing the results from a first one. @@ -188,7 +188,7 @@ private void requestMoreItemsAsync(final int count) { mRequestMoreItemsTaskInProgress = true; try { - mClient.requestMoreItemsAsync(count, + mClient.requestMoreItemsAsync(groupId, count, new Callback() { @Override public void onResponse(final Call call, final retrofit2.Response response) {