Skip to content

Commit

Permalink
SyncAdapter.doUploadSync(): Put the user-agent in an annotation param…
Browse files Browse the repository at this point in the history
…eter.

See #11 (comment)
  • Loading branch information
murraycu committed Dec 6, 2014
1 parent 9458b97 commit d025448
Showing 1 changed file with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
*/
public class SyncAdapter extends AbstractThreadedSyncAdapter {
private static final String COUNT_AS_COUNT = "COUNT(*) AS count";
private static final String PARAM_PART_CLASSIFICATION = "classification";
private int mUploadsInProgress = 0;

private boolean mRequestMoreItemsTaskInProgress = false;
Expand Down Expand Up @@ -327,13 +328,6 @@ private boolean doUploadSync(final String itemId, final String subjectId, final
//but that did not allow multiple parameters with the same name, which we need.
final List<NameValuePair> nameValuePairs = new ArrayList<>();

//Help the server know that the classification is from this Android app,
//by reusing the User-Agent string as a parameter value.
//See https://github.com/murraycu/android-galaxyzoo/issues/11
nameValuePairs.add(new BasicNameValuePair("interface",
HttpUtils.USER_AGENT_MURRAYC));

final String PARAM_PART_CLASSIFICATION = "classification";
nameValuePairs.add(new BasicNameValuePair(PARAM_PART_CLASSIFICATION + "[subject_ids][]",
subjectId));

Expand Down Expand Up @@ -369,15 +363,21 @@ private boolean doUploadSync(final String itemId, final String subjectId, final
projection, selection, selectionArgs, orderBy);
}

int max_sequence = 0;
while (c.moveToNext()) {
final int sequence = c.getInt(0);
final String questionId = c.getString(1);
final String answerId = c.getString(2);

//We could instead ORDER BY the sequence but that might be slightly slower and need a index.
if(sequence > max_sequence) {
max_sequence = sequence;
}

//Add the question's answer:
//TODO: Is the string representation of sequence locale-dependent?
final String questionKey =
PARAM_PART_CLASSIFICATION + "[annotations][" + sequence + "][" + questionId + "]";
getAnnotationPart(sequence) + "[" + questionId + "]";
nameValuePairs.add(new BasicNameValuePair(questionKey, answerId));


Expand Down Expand Up @@ -407,9 +407,20 @@ private boolean doUploadSync(final String itemId, final String subjectId, final
c.close();


//Help the server know that the classification is from this Android app,
//by reusing the User-Agent string as a parameter value.
//See https://github.com/murraycu/android-galaxyzoo/issues/11
final String key =
getAnnotationPart(max_sequence + 1 ) + "[interface]";
nameValuePairs.add(new BasicNameValuePair(key, HttpUtils.USER_AGENT_MURRAYC));

return mClient.uploadClassificationSync(authName, authApiKey, nameValuePairs);
}

private static String getAnnotationPart(int sequence) {
return PARAM_PART_CLASSIFICATION + "[annotations][" + sequence + "]";
}

private class UploadTask implements Runnable {
private final String mItemId ;
private final String mSubjectId;
Expand Down

0 comments on commit d025448

Please sign in to comment.