From 04f83e77d23018d57c3a6241ff12d475310dee26 Mon Sep 17 00:00:00 2001 From: Jimmy Shih Date: Wed, 6 Feb 2013 10:16:49 -0800 Subject: [PATCH] Handle the case a Shared with me track can be trashed. --- .../apps/mytracks/io/sync/SyncAdapter.java | 20 ++++++++++++------- .../apps/mytracks/io/sync/SyncUtils.java | 4 ++-- 2 files changed, 15 insertions(+), 9 deletions(-) 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 3d1c24e10..e4fa9aad1 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 @@ -149,12 +149,12 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter { // Get all the KML files in the "My Drive:/My Tracks" folder Files.List myTracksFolderRequest = drive.files() .list().setQ(String.format(Locale.US, SyncUtils.MY_TRACKS_FOLDER_FILES_QUERY, folderId)); - Map myTracksFolderMap = getFiles(myTracksFolderRequest); + Map myTracksFolderMap = getFiles(myTracksFolderRequest, true); // Get all the KML files in the "Shared with me:/" folder Files.List sharedWithMeRequest = drive.files() .list().setQ(SyncUtils.SHARED_WITH_ME_FILES_QUERY); - Map sharedWithMeMap = getFiles(sharedWithMeRequest); + Map sharedWithMeMap = getFiles(sharedWithMeRequest, false); try { insertNewDriveFiles(myTracksFolderMap.values()); @@ -324,14 +324,19 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter { * Gets all the files from a request. * * @param request the request + * @param excludeSharedWithMe true to exclude shared with me files * @return a map of file id to file */ - private Map getFiles(Files.List request) throws IOException { + private Map getFiles(Files.List request, boolean excludeSharedWithMe) + throws IOException { Map idToFileMap = new HashMap(); do { FileList files = request.execute(); for (File file : files.getItems()) { + if (excludeSharedWithMe && file.getSharedWithMeDate() != null) { + continue; + } idToFileMap.put(file.getId(), file); } request.setPageToken(files.getNextPageToken()); @@ -359,14 +364,12 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter { changes.put(change.getFileId(), null); } else { File file = change.getFile(); - if (SyncUtils.isInFolder(file, folderId)) { + if (SyncUtils.isInFolder(file, folderId) || SyncUtils.isSharedWithMe(file)) { if (file.getLabels().getTrashed()) { changes.put(change.getFileId(), null); } else { changes.put(change.getFileId(), file); } - } else if (SyncUtils.isSharedWithMe(file)) { - changes.put(change.getFileId(), file); } } } @@ -446,7 +449,10 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter { } // if trashed, ignore } else if (SyncUtils.isSharedWithMe(driveFile)) { - drive.files().delete(driveId).execute(); + if (!driveFile.getLabels().getTrashed()) { + drive.files().delete(driveId).execute(); + } + // if trashed, ignore } } catch (UserRecoverableAuthIOException e) { throw e; 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 65c153a78..49109f03c 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 @@ -90,7 +90,7 @@ public class SyncUtils { // Get shared with me KML files public static final String SHARED_WITH_ME_FILES_QUERY = "sharedWithMe and mimeType = '" - + KML_MIME_TYPE + "'"; + + KML_MIME_TYPE + "' and trashed = false"; // Folder mime type private static final String FOLDER_MIME_TYPE = "application/vnd.google-apps.folder"; @@ -265,7 +265,7 @@ public class SyncUtils { .list().setQ(String.format(Locale.US, MY_TRACKS_FOLDER_QUERY, folderName)); FileList result = list.execute(); for (File file : result.getItems()) { - if (file.getTitle().equals(folderName)) { + if (file.getSharedWithMeDate() == null && file.getTitle().equals(folderName)) { return file.getId(); } }