When sending to Google Fusion Table, allow either new public tables

or new private tables.
This commit is contained in:
Jimmy Shih
2013-02-08 16:40:44 -08:00
parent ab61869956
commit bc0a2e3404
9 changed files with 85 additions and 15 deletions
@@ -94,7 +94,8 @@ public class ChooseUploadServiceDialogFragment extends DialogFragment {
activity, R.string.send_to_maps_key, PreferencesUtils.SEND_TO_MAPS_DEFAULT));
fusionTablesCheckBox.setChecked(PreferencesUtils.getBoolean(
activity, R.string.send_to_fusion_tables_key,
PreferencesUtils.SEND_TO_FUSION_TABLES_DEFAULT));
PreferencesUtils.SEND_TO_FUSION_TABLES_DEFAULT));
docsCheckBox.setChecked(PreferencesUtils.getBoolean(
activity, R.string.send_to_docs_key, PreferencesUtils.SEND_TO_DOCS_DEFAULT));
@@ -123,7 +124,16 @@ public class ChooseUploadServiceDialogFragment extends DialogFragment {
} else {
newMapRadioButton.setChecked(true);
}
// Update fusion table
boolean defaultTablePublic = PreferencesUtils.getBoolean(activity,
R.string.default_table_public_key,
PreferencesUtils.DEFAULT_TABLE_PUBLIC_DEFAULT);
String text = getString(R.string.send_google_fusion_tables) + "\n"
+ getString(defaultTablePublic ? R.string.send_google_fusion_tables_public
: R.string.send_google_fusion_tables_private);
fusionTablesCheckBox.setText(text);
return new AlertDialog.Builder(activity).setNegativeButton(R.string.generic_cancel, null)
.setPositiveButton(R.string.send_google_send_now, new DialogInterface.OnClickListener() {
@Override
@@ -11,7 +11,9 @@ import com.google.android.apps.mytracks.content.Waypoint;
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
import com.google.android.apps.mytracks.io.sendtogoogle.AbstractSendAsyncTask;
import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils;
import com.google.android.apps.mytracks.io.sync.SyncUtils;
import com.google.android.apps.mytracks.util.LocationUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.gms.auth.GoogleAuthException;
import com.google.android.gms.auth.UserRecoverableAuthException;
import com.google.android.maps.mytracks.R;
@@ -19,6 +21,8 @@ import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
import com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.drive.Drive;
import com.google.api.services.drive.model.Permission;
import com.google.api.services.fusiontables.Fusiontables;
import com.google.api.services.fusiontables.Fusiontables.Query.Sql;
import com.google.api.services.fusiontables.model.Column;
@@ -114,6 +118,10 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
publishProgress(PROGRESS_SET_STYLE);
setStyle(fusiontables, tableId);
setTemplate(fusiontables, tableId);
if (!setPermission(tableId)) {
Log.d(TAG, "Cannot set permission for table " + tableId);
return false;
}
// Upload all the track points plus the start and end markers
publishProgress(PROGRESS_UPLOAD_DATA_MIN);
@@ -189,6 +197,26 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
fusiontables.template().insert(tableId, template).execute();
}
private boolean setPermission(String tableId) throws IOException, GoogleAuthException {
boolean defaultTablePublic = PreferencesUtils.getBoolean(context,
R.string.default_table_public_key,
PreferencesUtils.DEFAULT_TABLE_PUBLIC_DEFAULT);
if (!defaultTablePublic) {
return true;
}
GoogleAccountCredential driveCredential = SendToGoogleUtils.getGoogleAccountCredential(
context, account.name, SendToGoogleUtils.DRIVE_SCOPE);
if (driveCredential == null) {
return false;
}
Drive drive = SyncUtils.getDriveService(driveCredential);
Permission permission = new Permission();
permission.setType("anyone");
permission.setRole("reader");
drive.permissions().insert(tableId, permission).execute();
return true;
}
/**
* Uploads all the points in a track. *
*
@@ -172,7 +172,7 @@ public class AccountChooserActivity extends Activity {
* Checks the Drive permission.
*/
private void checkDrivePermission() {
if (sendRequest.isSendDrive()) {
if (sendRequest.isSendDrive() || sendRequest.isSendFusionTables()) {
SendToGoogleUtils.checkPermissionByActivity(this, sendRequest.getAccount().name,
SendToGoogleUtils.DRIVE_SCOPE, SendToGoogleUtils.DRIVE_PERMISSION_REQUEST_CODE,
driveCallback);
@@ -22,6 +22,7 @@ import com.google.android.apps.mytracks.fragments.ChooseActivityDialogFragment;
import com.google.android.apps.mytracks.io.fusiontables.SendFusionTablesUtils;
import com.google.android.apps.mytracks.io.maps.SendMapsUtils;
import com.google.android.apps.mytracks.util.IntentUtils;
import com.google.android.apps.mytracks.util.PreferencesUtils;
import com.google.android.maps.mytracks.R;
import com.google.common.annotations.VisibleForTesting;
@@ -79,7 +80,12 @@ public class UploadResultActivity extends FragmentActivity {
}
if (shareUrl == null && sendRequest.isSendFusionTables()
&& sendRequest.isFusionTablesSuccess()) {
shareUrl = SendFusionTablesUtils.getMapUrl(track);
boolean defaultTablePublic = PreferencesUtils.getBoolean(this,
R.string.default_table_public_key,
PreferencesUtils.DEFAULT_TABLE_PUBLIC_DEFAULT);
if (defaultTablePublic) {
shareUrl = SendFusionTablesUtils.getMapUrl(track);
}
}
showDialog(DIALOG_RESULT_ID);
}
@@ -56,6 +56,7 @@ public class PreferencesUtils {
public static final String DEFAULT_ACTIVITY_DEFAULT = "";
public static final boolean DEFAULT_MAP_PUBLIC_DEFAULT = false;
public static final boolean DEFAULT_TABLE_PUBLIC_DEFAULT = false;
public static final String DRIVE_DELETED_LIST_DEFAULT = "";
public static final long DRIVE_LARGEST_CHANGE_ID_DEFAULT = -1L;
public static final boolean DRIVE_SYNC_DEFAULT = false;