mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 17:43:06 +02:00
Change the the return value of SyncUtils.getMyTracksFolder(context, drive) from string to File object.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-1
@@ -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);
|
||||
|
||||
+1
-27
@@ -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<File> 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<File>();
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user