From 9d6ba74a6dbc297d4a3eafc897b0f94ec1c23bea Mon Sep 17 00:00:00 2001 From: youtaol Date: Mon, 18 Feb 2013 19:50:21 +0800 Subject: [PATCH] Change the the return value of SyncUtils.getMyTracksFolder(context, drive) from string to File object. --- .../mytracks/io/drive/SendDriveAsyncTask.java | 2 +- .../apps/mytracks/io/sync/SyncAdapter.java | 2 +- .../apps/mytracks/io/sync/SyncUtils.java | 6 ++-- .../sync/SyncMyTracksWithDriveTest.java | 3 +- .../endtoendtest/sync/SyncTestUtils.java | 28 +------------------ 5 files changed, 8 insertions(+), 33 deletions(-) diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/drive/SendDriveAsyncTask.java b/MyTracks/src/com/google/android/apps/mytracks/io/drive/SendDriveAsyncTask.java index 63238f587..70c809d9c 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/drive/SendDriveAsyncTask.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/drive/SendDriveAsyncTask.java @@ -76,7 +76,7 @@ public class SendDriveAsyncTask extends AbstractSendAsyncTask { return false; } Drive drive = SyncUtils.getDriveService(credential); - String folderId = SyncUtils.getMyTracksFolder(context, drive); + String folderId = SyncUtils.getMyTracksFolder(context, drive).getId(); if (folderId == null) { return false; } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncAdapter.java b/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncAdapter.java index fdfc18701..6d4a39024 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncAdapter.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncAdapter.java @@ -113,7 +113,7 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter { driveAccountName = account.name; } - String folderId = SyncUtils.getMyTracksFolder(context, drive); + String folderId = SyncUtils.getMyTracksFolder(context, drive).getId(); if (folderId == null) { return; } diff --git a/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncUtils.java b/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncUtils.java index b3aebd075..f6bd217f4 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/io/sync/SyncUtils.java @@ -153,20 +153,20 @@ public class SyncUtils { * @param context the context * @param drive the drive */ - public static String getMyTracksFolder(Context context, Drive drive) throws IOException { + public static File getMyTracksFolder(Context context, Drive drive) throws IOException { String folderName = context.getString(R.string.my_tracks_app_name); List list = drive.files() .list().setQ(String.format(Locale.US, MY_TRACKS_FOLDER_QUERY, folderName)); FileList result = list.execute(); for (File file : result.getItems()) { if (file.getSharedWithMeDate() == null) { - return file.getId(); + return file; } } File file = new File(); file.setTitle(folderName); file.setMimeType(FOLDER_MIME_TYPE); - return drive.files().insert(file).execute().getId(); + return drive.files().insert(file).execute(); } /** diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncMyTracksWithDriveTest.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncMyTracksWithDriveTest.java index 3b2f1652a..4a402b3b2 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncMyTracksWithDriveTest.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncMyTracksWithDriveTest.java @@ -17,6 +17,7 @@ package com.google.android.apps.mytracks.endtoendtest.sync; import com.google.android.apps.mytracks.TrackListActivity; import com.google.android.apps.mytracks.endtoendtest.EndToEndTestUtils; +import com.google.android.apps.mytracks.io.sync.SyncUtils; import com.google.android.maps.mytracks.R; import com.google.api.services.drive.Drive; import com.google.api.services.drive.model.File; @@ -110,7 +111,7 @@ public class SyncMyTracksWithDriveTest extends ActivityInstrumentationTestCase2< EndToEndTestUtils.activityMytracks.getString(R.string.menu_sync_now), true); instrumentation.waitForIdleSync(); SyncTestUtils.checkFilesNumber(drive); - File folder = SyncTestUtils.getMyTracksFolder(trackListActivity.getApplicationContext(), drive); + File folder = SyncUtils.getMyTracksFolder(trackListActivity.getApplicationContext(), drive); assertNotNull(folder); SyncTestUtils.removeFile(folder, drive); diff --git a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncTestUtils.java b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncTestUtils.java index 4f7041242..9a9f0eb38 100644 --- a/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncTestUtils.java +++ b/MyTracksTest_E2E/src/com/google/android/apps/mytracks/endtoendtest/sync/SyncTestUtils.java @@ -29,11 +29,9 @@ import com.google.api.client.http.GenericUrl; import com.google.api.client.http.HttpResponse; import com.google.api.services.drive.Drive; import com.google.api.services.drive.model.File; -import com.google.api.services.drive.model.FileList; import android.app.Instrumentation; import android.content.Context; -import android.util.Log; import android.widget.CheckBox; import java.io.BufferedReader; @@ -134,7 +132,7 @@ public class SyncTestUtils { * @throws IOException */ public static List getDriveFiles(Context context, Drive drive) throws IOException { - File folder = SyncTestUtils.getMyTracksFolder(context, drive); + File folder = SyncUtils.getMyTracksFolder(context, drive); if (folder == null) { return new ArrayList(); } @@ -320,28 +318,4 @@ public class SyncTestUtils { br.close(); return fileContent; } - - /** - * Gets the MyTracks folder on Google Drive. - * - * @param context context of application - * @param drive a Google Drive object - * @return the MyTracks folder on Google Drive - */ - public static File getMyTracksFolder(Context context, Drive drive) { - try { - String folderName = context.getString(R.string.my_tracks_app_name); - com.google.api.services.drive.Drive.Files.List list = drive.files().list() - .setQ(String.format(Locale.US, SyncUtils.MY_TRACKS_FOLDER_QUERY, folderName)); - FileList result = list.execute(); - for (File file : result.getItems()) { - if (file.getTitle().equals(folderName)) { - return file; - } - } - } catch (IOException e) { - Log.e(EndToEndTestUtils.LOG_TAG, "IOException", e); - } - return null; - } }