forked from upstream-mirrors/OpenTracks
Handle the case a Shared with me track can be trashed.
This commit is contained in:
@@ -149,12 +149,12 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
// Get all the KML files in the "My Drive:/My Tracks" folder
|
// Get all the KML files in the "My Drive:/My Tracks" folder
|
||||||
Files.List myTracksFolderRequest = drive.files()
|
Files.List myTracksFolderRequest = drive.files()
|
||||||
.list().setQ(String.format(Locale.US, SyncUtils.MY_TRACKS_FOLDER_FILES_QUERY, folderId));
|
.list().setQ(String.format(Locale.US, SyncUtils.MY_TRACKS_FOLDER_FILES_QUERY, folderId));
|
||||||
Map<String, File> myTracksFolderMap = getFiles(myTracksFolderRequest);
|
Map<String, File> myTracksFolderMap = getFiles(myTracksFolderRequest, true);
|
||||||
|
|
||||||
// Get all the KML files in the "Shared with me:/" folder
|
// Get all the KML files in the "Shared with me:/" folder
|
||||||
Files.List sharedWithMeRequest = drive.files()
|
Files.List sharedWithMeRequest = drive.files()
|
||||||
.list().setQ(SyncUtils.SHARED_WITH_ME_FILES_QUERY);
|
.list().setQ(SyncUtils.SHARED_WITH_ME_FILES_QUERY);
|
||||||
Map<String, File> sharedWithMeMap = getFiles(sharedWithMeRequest);
|
Map<String, File> sharedWithMeMap = getFiles(sharedWithMeRequest, false);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
insertNewDriveFiles(myTracksFolderMap.values());
|
insertNewDriveFiles(myTracksFolderMap.values());
|
||||||
@@ -324,14 +324,19 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
* Gets all the files from a request.
|
* Gets all the files from a request.
|
||||||
*
|
*
|
||||||
* @param request the request
|
* @param request the request
|
||||||
|
* @param excludeSharedWithMe true to exclude shared with me files
|
||||||
* @return a map of file id to file
|
* @return a map of file id to file
|
||||||
*/
|
*/
|
||||||
private Map<String, File> getFiles(Files.List request) throws IOException {
|
private Map<String, File> getFiles(Files.List request, boolean excludeSharedWithMe)
|
||||||
|
throws IOException {
|
||||||
Map<String, File> idToFileMap = new HashMap<String, File>();
|
Map<String, File> idToFileMap = new HashMap<String, File>();
|
||||||
do {
|
do {
|
||||||
FileList files = request.execute();
|
FileList files = request.execute();
|
||||||
|
|
||||||
for (File file : files.getItems()) {
|
for (File file : files.getItems()) {
|
||||||
|
if (excludeSharedWithMe && file.getSharedWithMeDate() != null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
idToFileMap.put(file.getId(), file);
|
idToFileMap.put(file.getId(), file);
|
||||||
}
|
}
|
||||||
request.setPageToken(files.getNextPageToken());
|
request.setPageToken(files.getNextPageToken());
|
||||||
@@ -359,14 +364,12 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
changes.put(change.getFileId(), null);
|
changes.put(change.getFileId(), null);
|
||||||
} else {
|
} else {
|
||||||
File file = change.getFile();
|
File file = change.getFile();
|
||||||
if (SyncUtils.isInFolder(file, folderId)) {
|
if (SyncUtils.isInFolder(file, folderId) || SyncUtils.isSharedWithMe(file)) {
|
||||||
if (file.getLabels().getTrashed()) {
|
if (file.getLabels().getTrashed()) {
|
||||||
changes.put(change.getFileId(), null);
|
changes.put(change.getFileId(), null);
|
||||||
} else {
|
} else {
|
||||||
changes.put(change.getFileId(), file);
|
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
|
// if trashed, ignore
|
||||||
} else if (SyncUtils.isSharedWithMe(driveFile)) {
|
} 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) {
|
} catch (UserRecoverableAuthIOException e) {
|
||||||
throw e;
|
throw e;
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ public class SyncUtils {
|
|||||||
|
|
||||||
// Get shared with me KML files
|
// Get shared with me KML files
|
||||||
public static final String SHARED_WITH_ME_FILES_QUERY = "sharedWithMe and mimeType = '"
|
public static final String SHARED_WITH_ME_FILES_QUERY = "sharedWithMe and mimeType = '"
|
||||||
+ KML_MIME_TYPE + "'";
|
+ KML_MIME_TYPE + "' and trashed = false";
|
||||||
|
|
||||||
// Folder mime type
|
// Folder mime type
|
||||||
private static final String FOLDER_MIME_TYPE = "application/vnd.google-apps.folder";
|
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));
|
.list().setQ(String.format(Locale.US, MY_TRACKS_FOLDER_QUERY, folderName));
|
||||||
FileList result = list.execute();
|
FileList result = list.execute();
|
||||||
for (File file : result.getItems()) {
|
for (File file : result.getItems()) {
|
||||||
if (file.getTitle().equals(folderName)) {
|
if (file.getSharedWithMeDate() == null && file.getTitle().equals(folderName)) {
|
||||||
return file.getId();
|
return file.getId();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user