|
|
|
|
@@ -119,11 +119,11 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
|
|
|
|
|
|
|
|
|
public void setPathWithoutVerify(String path) throws UnsupportedEncodingException, InvalidPathException
|
|
|
|
|
{
|
|
|
|
|
Log.d(TAG, "setPath: "+path);
|
|
|
|
|
//Log.d(TAG, "setPath: "+path);
|
|
|
|
|
mAccount = extractAccount(path);
|
|
|
|
|
mAccountLocalPath = path.substring(getProtocolPrefix().length()+encode(mAccount).length()+1);
|
|
|
|
|
Log.d(TAG, " mAccount=" + mAccount);
|
|
|
|
|
Log.d(TAG, " mAccountLocalPath=" + mAccountLocalPath);
|
|
|
|
|
//Log.d(TAG, " mAccount=" + mAccount);
|
|
|
|
|
//Log.d(TAG, " mAccountLocalPath=" + mAccountLocalPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GDrivePath(String parentPath, File fileToAppend) throws UnsupportedEncodingException, FileNotFoundException, IOException, InvalidPathException
|
|
|
|
|
@@ -166,13 +166,13 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
|
|
|
|
for (int i=0;i<parts.length;i++)
|
|
|
|
|
{
|
|
|
|
|
String part = parts[i];
|
|
|
|
|
Log.d(TAG, "parsing part " + part);
|
|
|
|
|
//Log.d(TAG, "parsing part " + part);
|
|
|
|
|
int indexOfSeparator = part.lastIndexOf(NAME_ID_SEP);
|
|
|
|
|
if (indexOfSeparator < 0)
|
|
|
|
|
throw new FileNotFoundException("invalid path " + mAccountLocalPath);
|
|
|
|
|
String id = part.substring(indexOfSeparator+NAME_ID_SEP.length());
|
|
|
|
|
String name = decode(part.substring(0, indexOfSeparator));
|
|
|
|
|
Log.d(TAG, " name=" + name);
|
|
|
|
|
//Log.d(TAG, " name=" + name);
|
|
|
|
|
FileSystemEntryData thisFolder = accountData.mFolderCache.get(id);
|
|
|
|
|
if (thisFolder == null)
|
|
|
|
|
{
|
|
|
|
|
@@ -220,7 +220,7 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
|
|
|
|
for (int i=0;i<parts.length;i++)
|
|
|
|
|
{
|
|
|
|
|
String part = parts[i];
|
|
|
|
|
Log.d(TAG, "parsing part " + part);
|
|
|
|
|
//Log.d(TAG, "parsing part " + part);
|
|
|
|
|
int indexOfSeparator = part.lastIndexOf(NAME_ID_SEP);
|
|
|
|
|
if (indexOfSeparator < 0)
|
|
|
|
|
{
|
|
|
|
|
@@ -295,11 +295,11 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
|
|
|
|
thisFile.parentIds.add(parent.getId());
|
|
|
|
|
}
|
|
|
|
|
mAccountData.get(path.getAccount()).mFolderCache.put(thisFile.id, thisFile);
|
|
|
|
|
try {
|
|
|
|
|
/*try {
|
|
|
|
|
Log.d(TAG, "Added "+path.getFullPath()+" to cache");
|
|
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
return thisFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -336,14 +336,14 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
|
|
|
|
|
|
|
|
|
private File getFileForPath(GDrivePath path, Drive driveService)
|
|
|
|
|
throws IOException, InvalidPathException {
|
|
|
|
|
Log.d(TAG,"getFileForPath... ");
|
|
|
|
|
//Log.d(TAG,"getFileForPath... ");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
//throw new IOException("argh");
|
|
|
|
|
String driveId = path.getGDriveId();
|
|
|
|
|
Log.d(TAG, "id"+driveId);
|
|
|
|
|
//Log.d(TAG, "id"+driveId);
|
|
|
|
|
File file = driveService.files().get(driveId).execute();
|
|
|
|
|
Log.d(TAG,"...done.");
|
|
|
|
|
//Log.d(TAG,"...done.");
|
|
|
|
|
return file;
|
|
|
|
|
}
|
|
|
|
|
catch (IOException e)
|
|
|
|
|
@@ -409,7 +409,7 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
|
|
|
|
{
|
|
|
|
|
File file = getDriveService(parentGdrivePath.getAccount()).files().insert(body).execute();
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "created folder "+newDirName+" in "+parentPath+". id: "+file.getId());
|
|
|
|
|
//Log.d(TAG, "created folder "+newDirName+" in "+parentPath+". id: "+file.getId());
|
|
|
|
|
|
|
|
|
|
//add to cache to avoid network traffic if this folder is accessed (which is likely to happen soon)
|
|
|
|
|
FileSystemEntryData newCacheEntry = new FileSystemEntryData();
|
|
|
|
|
@@ -537,12 +537,12 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Log.d(TAG, "getFileEntry "+filename);
|
|
|
|
|
//Log.d(TAG, "getFileEntry "+filename);
|
|
|
|
|
GDrivePath gdrivePath = new GDrivePath(filename);
|
|
|
|
|
FileEntry res = convertToFileEntry(
|
|
|
|
|
getFileForPath(gdrivePath, getDriveService(gdrivePath.getAccount())),
|
|
|
|
|
filename);
|
|
|
|
|
Log.d(TAG, "getFileEntry res"+res);
|
|
|
|
|
//Log.d(TAG, "getFileEntry res"+res);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
@@ -580,22 +580,22 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
|
|
|
|
|
|
|
|
|
private Drive getDriveService(String accountName)
|
|
|
|
|
{
|
|
|
|
|
Log.d(TAG, "getDriveService "+accountName);
|
|
|
|
|
//Log.d(TAG, "getDriveService "+accountName);
|
|
|
|
|
AccountData accountData = mAccountData.get(accountName);
|
|
|
|
|
Log.d(TAG, "accountData "+accountData);
|
|
|
|
|
//Log.d(TAG, "accountData "+accountData);
|
|
|
|
|
return accountData.drive;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onActivityResult(final JavaFileStorage.FileStorageSetupActivity setupAct, int requestCode, int resultCode, Intent data) {
|
|
|
|
|
Log.d(TAG, "ActivityResult: "+requestCode+"/"+resultCode);
|
|
|
|
|
//Log.d(TAG, "ActivityResult: "+requestCode+"/"+resultCode);
|
|
|
|
|
switch (requestCode) {
|
|
|
|
|
case REQUEST_ACCOUNT_PICKER:
|
|
|
|
|
Log.d(TAG, "ActivityResult: REQUEST_ACCOUNT_PICKER");
|
|
|
|
|
//Log.d(TAG, "ActivityResult: REQUEST_ACCOUNT_PICKER");
|
|
|
|
|
if (resultCode == Activity.RESULT_OK && data != null && data.getExtras() != null) {
|
|
|
|
|
String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
|
|
|
|
|
if (accountName != null) {
|
|
|
|
|
Log.d(TAG, "Initialize Account name="+accountName);
|
|
|
|
|
//Log.d(TAG, "Initialize Account name="+accountName);
|
|
|
|
|
initializeAccountOrPath(setupAct, accountName);
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
@@ -609,10 +609,10 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
|
|
|
|
|
|
|
|
|
case REQUEST_AUTHORIZATION:
|
|
|
|
|
if (resultCode == Activity.RESULT_OK) {
|
|
|
|
|
for (String k: data.getExtras().keySet())
|
|
|
|
|
{
|
|
|
|
|
Log.d(TAG, data.getExtras().get(k).toString());
|
|
|
|
|
}
|
|
|
|
|
//for (String k: data.getExtras().keySet())
|
|
|
|
|
//{
|
|
|
|
|
//Log.d(TAG, data.getExtras().get(k).toString());
|
|
|
|
|
//}
|
|
|
|
|
String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
|
|
|
|
|
if (accountName != null) {
|
|
|
|
|
Log.d(TAG, "Account name="+accountName);
|
|
|
|
|
@@ -669,7 +669,7 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
|
|
|
|
AccountData newAccountData = new AccountData();
|
|
|
|
|
newAccountData.drive = createDriveService(accountName, activity);
|
|
|
|
|
mAccountData.put(accountName, newAccountData);
|
|
|
|
|
Log.d(TAG, "Added account data for " + accountName);
|
|
|
|
|
//Log.d(TAG, "Added account data for " + accountName);
|
|
|
|
|
newAccountData.mFolderCache = buildFoldersCache(accountName);
|
|
|
|
|
|
|
|
|
|
About about = newAccountData.drive.about().get().execute();
|
|
|
|
|
@@ -704,7 +704,7 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
|
|
|
|
}
|
|
|
|
|
} else if ( isCancelled()) {
|
|
|
|
|
// cancel handling here
|
|
|
|
|
Log.d(TAG,"Async Task cancelled!");
|
|
|
|
|
//Log.d(TAG,"Async Task cancelled!");
|
|
|
|
|
|
|
|
|
|
activity.setResult(Activity.RESULT_CANCELED);
|
|
|
|
|
activity.finish();
|
|
|
|
|
@@ -742,12 +742,12 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
|
|
|
|
private HashMap<String,FileSystemEntryData> buildFoldersCache(String accountName) throws IOException {
|
|
|
|
|
|
|
|
|
|
HashMap<String, FileSystemEntryData> folderCache = new HashMap<String, GoogleDriveFileStorage.FileSystemEntryData>();
|
|
|
|
|
Log.d(TAG,"buildFoldersCache");
|
|
|
|
|
//Log.d(TAG,"buildFoldersCache");
|
|
|
|
|
FileList folders=getDriveService(accountName).files().list().setQ("mimeType='"+FOLDER_MIME_TYPE+"' and trashed=false and hidden=false")
|
|
|
|
|
.setFields("items(id,title,parents),nextPageToken")
|
|
|
|
|
.execute();
|
|
|
|
|
for(File fl: folders.getItems()){
|
|
|
|
|
Log.d(TAG,"buildFoldersCache: " + fl.getTitle());
|
|
|
|
|
//Log.d(TAG,"buildFoldersCache: " + fl.getTitle());
|
|
|
|
|
FileSystemEntryData thisFolder = new FileSystemEntryData();
|
|
|
|
|
thisFolder.id = fl.getId();
|
|
|
|
|
thisFolder.displayName = fl.getTitle();
|
|
|
|
|
@@ -759,13 +759,13 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
|
|
|
|
folderCache.put(thisFolder.id, thisFolder);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Log.d(TAG,"that's it!");
|
|
|
|
|
//Log.d(TAG,"that's it!");
|
|
|
|
|
return folderCache;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void finishActivityWithSuccess(FileStorageSetupActivity setupActivity) {
|
|
|
|
|
Log.d("KP2AJ", "Success with authentcating!");
|
|
|
|
|
//Log.d("KP2AJ", "Success with authentcating!");
|
|
|
|
|
Activity activity = (Activity)setupActivity;
|
|
|
|
|
|
|
|
|
|
if (setupActivity.getProcessName().equals(PROCESS_NAME_FILE_USAGE_SETUP))
|
|
|
|
|
@@ -780,13 +780,14 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
|
|
|
|
if (setupActivity.getProcessName().equals(PROCESS_NAME_SELECTFILE))
|
|
|
|
|
{
|
|
|
|
|
Intent data = new Intent();
|
|
|
|
|
if (setupActivity.getState() == null)
|
|
|
|
|
/*if (setupActivity.getState() == null)
|
|
|
|
|
Log.d(TAG, "getState is null");
|
|
|
|
|
else
|
|
|
|
|
if (setupActivity.getState().getString(EXTRA_PATH) == null)
|
|
|
|
|
Log.d(TAG, "setupActivity.getState().getString(EXTRA_PATH) is null");
|
|
|
|
|
else
|
|
|
|
|
Log.d(TAG,setupActivity.getState().getString(EXTRA_PATH));
|
|
|
|
|
*/
|
|
|
|
|
String path = setupActivity.getState().getString(EXTRA_PATH);
|
|
|
|
|
if (path != null)
|
|
|
|
|
data.putExtra(EXTRA_PATH, path);
|
|
|
|
|
@@ -838,7 +839,7 @@ public class GoogleDriveFileStorage implements JavaFileStorage {
|
|
|
|
|
{
|
|
|
|
|
GoogleAccountCredential credential = createCredential(activity);
|
|
|
|
|
|
|
|
|
|
Log.d(TAG, "starting REQUEST_ACCOUNT_PICKER");
|
|
|
|
|
//Log.d(TAG, "starting REQUEST_ACCOUNT_PICKER");
|
|
|
|
|
activity.startActivityForResult(credential.newChooseAccountIntent(), REQUEST_ACCOUNT_PICKER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|