mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 17:43:06 +02:00
Add make track public in sharing dialog.
This commit is contained in:
@@ -21,14 +21,23 @@ limitations under the License.
|
||||
android:layout_width="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:padding="8dp" >
|
||||
<TextView
|
||||
android:text="@string/share_track_emails_label"
|
||||
style="@style/EditLabel" />
|
||||
<MultiAutoCompleteTextView
|
||||
android:hint="@string/share_track_add_emails_hint"
|
||||
android:completionThreshold="1"
|
||||
android:id="@+id/add_emails"
|
||||
android:hint="@string/share_track_emails_hint"
|
||||
android:id="@+id/share_track_emails"
|
||||
android:imeOptions="actionDone"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:singleLine="false" >
|
||||
</MultiAutoCompleteTextView>
|
||||
<CheckBox
|
||||
android:id="@+id/share_track_public"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginTop="16dp"
|
||||
android:text="@string/share_track_public"
|
||||
style="@style/TextMedium" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
@@ -2000,26 +2000,29 @@ limitations under the License.
|
||||
</string>
|
||||
|
||||
<!-- Share Track -->
|
||||
<string name="share_track_add_emails_title"
|
||||
translation_description="The dialog title for entering email addresses for sharing a track
|
||||
with.">
|
||||
Share track with
|
||||
</string>
|
||||
<string name="share_track_add_emails_hint"
|
||||
translation_description="The hint in the auto complete text box for entering email addresses.">
|
||||
Enter email addresses
|
||||
</string>
|
||||
<string name="share_track_drive_confirm_message"
|
||||
<string name="share_track_confirm_message"
|
||||
translation_description="The confirmation message when sharing a track via Google Drive with
|
||||
friends.">
|
||||
This will upload your track to Google Drive so you can share the file with friends. The file
|
||||
will be private and only those you have shared with will have access.
|
||||
This will upload your track to Google Drive so you can share the file with friends.
|
||||
</string>
|
||||
<string name="share_track_emails_hint"
|
||||
translation_description="The hint for the auto complete text box for entering email addresses.">
|
||||
Email addresses
|
||||
</string>
|
||||
<string name="share_track_emails_label"
|
||||
translation_description="The label for the auto complete text box for entering email
|
||||
addresses.">
|
||||
Invite to view:
|
||||
</string>
|
||||
<string name="share_track_picker_title"
|
||||
translation_description="When sharing a track with friends, the title on the picker to ask the
|
||||
user to select an application.">
|
||||
Select an application
|
||||
</string>
|
||||
<string name="share_track_public"
|
||||
translation_description="The checkbox to make a track public and share its url.">
|
||||
Make public & share URL
|
||||
</string>
|
||||
<string name="share_track_share_file"
|
||||
translation_description="After saving a track to the external storage, the button on the result
|
||||
dialog to share the saved track file with friends.">
|
||||
@@ -2046,10 +2049,19 @@ limitations under the License.
|
||||
%2$s: track description.">
|
||||
I think you might be interested in this track:\n\n%1$s\n\n%2$s
|
||||
</string>
|
||||
<string name="share_track_share_url_title"
|
||||
translation_description="The dialog title asking the user to select an application for sharing
|
||||
an URL.">
|
||||
Share URL using:
|
||||
</string>
|
||||
<string name="share_track_subject"
|
||||
translation_description="When sharing a track with friends, the subject line.">
|
||||
I would like to share a track with you
|
||||
</string>
|
||||
<string name="share_track_title"
|
||||
translation_description="The dialog title to share a track.">
|
||||
Share track
|
||||
</string>
|
||||
|
||||
<!-- Stats -->
|
||||
<string name="stats_average_moving_pace"
|
||||
|
||||
@@ -16,16 +16,15 @@
|
||||
|
||||
package com.google.android.apps.mytracks;
|
||||
|
||||
import com.google.android.apps.mytracks.fragments.AddEmailsDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.AddEmailsDialogFragment.AddEmailsCaller;
|
||||
import com.google.android.apps.mytracks.fragments.CheckPermissionFragment;
|
||||
import com.google.android.apps.mytracks.fragments.CheckPermissionFragment.CheckPermissionCaller;
|
||||
import com.google.android.apps.mytracks.fragments.ChooseAccountDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.ChooseAccountDialogFragment.ChooseAccountCaller;
|
||||
import com.google.android.apps.mytracks.fragments.ChooseActivityDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.ConfirmDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.ConfirmDialogFragment.ConfirmCaller;
|
||||
import com.google.android.apps.mytracks.fragments.InstallEarthDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.ShareTrackDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.ShareTrackDialogFragment.ShareTrackCaller;
|
||||
import com.google.android.apps.mytracks.io.drive.SendDriveActivity;
|
||||
import com.google.android.apps.mytracks.io.file.SaveActivity;
|
||||
import com.google.android.apps.mytracks.io.file.TrackFileFormat;
|
||||
@@ -66,7 +65,7 @@ import java.io.IOException;
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActivity implements
|
||||
ChooseAccountCaller, CheckPermissionCaller, AddEmailsCaller, ConfirmCaller {
|
||||
ChooseAccountCaller, CheckPermissionCaller, ShareTrackCaller, ConfirmCaller {
|
||||
|
||||
private static final String TAG = AbstractMyTracksActivity.class.getSimpleName();
|
||||
private static final String SEND_REQUEST_KEY = "send_request_key";
|
||||
@@ -182,13 +181,12 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddEmailsDone(String emails) {
|
||||
if (emails != null && !emails.equals("")) {
|
||||
sendRequest.setDriveShareEmails(emails);
|
||||
Intent intent = IntentUtils.newIntent(this, SendDriveActivity.class)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
|
||||
startActivity(intent);
|
||||
}
|
||||
public void onShareTrackDone(String emails, boolean makePublic) {
|
||||
sendRequest.setDriveShareEmails(emails);
|
||||
sendRequest.setDriveSharePublic(makePublic);
|
||||
Intent intent = IntentUtils.newIntent(this, SendDriveActivity.class)
|
||||
.putExtra(SendRequest.SEND_REQUEST_KEY, sendRequest);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void onDrivePermissionSuccess() {
|
||||
@@ -260,15 +258,11 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv
|
||||
* <p>
|
||||
* isSendDrive and isDriveEnableSync -> enable sync
|
||||
* <p>
|
||||
* isSendDrive and isDriveShare -> show {@link AddEmailsDialogFragment}
|
||||
* isSendDrive and isDriveShare -> show {@link ShareTrackDialogFragment}
|
||||
* <p>
|
||||
* isSendDrive -> start {@link SendDriveActivity}
|
||||
* <p>
|
||||
* isSendMaps and isMapShare -> show {@link ChooseActivityDialogFragment}
|
||||
* <p>
|
||||
* isSendMaps and isMapsExistingMap -> start {@link ChooseMapActivity}
|
||||
* <p>
|
||||
* isSendMaps and !isMapsExistingMap -> {@link SendMapsActivity}
|
||||
* isSendMaps -> start {@link SendMapsActivity}
|
||||
* <p>
|
||||
* isSendFusionTables -> start {@link SendFusionTablesActivity}
|
||||
* <p>
|
||||
@@ -292,8 +286,8 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv
|
||||
SyncUtils.enableSync(sendRequest.getAccount());
|
||||
return;
|
||||
} else if (sendRequest.isDriveShare()) {
|
||||
AddEmailsDialogFragment.newInstance(sendRequest.getTrackId())
|
||||
.show(getSupportFragmentManager(), AddEmailsDialogFragment.ADD_EMAILS_DIALOG_TAG);
|
||||
ShareTrackDialogFragment.newInstance(sendRequest.getTrackId())
|
||||
.show(getSupportFragmentManager(), ShareTrackDialogFragment.SHARE_TRACK_DIALOG_TAG);
|
||||
return;
|
||||
} else {
|
||||
next = SendDriveActivity.class;
|
||||
@@ -344,7 +338,7 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv
|
||||
protected void confirmShare(long trackId) {
|
||||
ConfirmDialogFragment.newInstance(R.string.confirm_share_drive_key,
|
||||
PreferencesUtils.CONFIRM_SHARE_DRIVE_DEFAULT,
|
||||
getString(R.string.share_track_drive_confirm_message), new long[] { trackId })
|
||||
getString(R.string.share_track_confirm_message), new long[] { trackId })
|
||||
.show(getSupportFragmentManager(), ConfirmDialogFragment.CONFIRM_DIALOG_TAG);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -124,7 +124,7 @@ public class ChooseActivityDialogFragment extends DialogFragment {
|
||||
caller.onChooseActivityDone(
|
||||
activityInfo.applicationInfo.packageName, activityInfo.name);
|
||||
}
|
||||
}).setTitle(R.string.share_track_picker_title).create();
|
||||
}).setTitle(R.string.share_track_share_url_title).create();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+25
-18
@@ -30,64 +30,69 @@ import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.widget.SimpleCursorAdapter;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.FilterQueryProvider;
|
||||
import android.widget.MultiAutoCompleteTextView;
|
||||
|
||||
/**
|
||||
* A DialogFragment to add emails.
|
||||
* A DialogFragment to share a track.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class AddEmailsDialogFragment extends DialogFragment {
|
||||
public class ShareTrackDialogFragment extends DialogFragment {
|
||||
|
||||
/**
|
||||
* Interface for caller of this dialog fragment.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public interface AddEmailsCaller {
|
||||
public interface ShareTrackCaller {
|
||||
|
||||
/**
|
||||
* Called when add emails is done.
|
||||
* Called when share track is done.
|
||||
*
|
||||
* @param emails the added emails
|
||||
* @param makePublic true to make the track public
|
||||
*/
|
||||
public void onAddEmailsDone(String emails);
|
||||
public void onShareTrackDone(String emails, boolean makePublic);
|
||||
}
|
||||
|
||||
public static final String ADD_EMAILS_DIALOG_TAG = "addEmailsDialog";
|
||||
public static final String SHARE_TRACK_DIALOG_TAG = "shareTrackDialog";
|
||||
|
||||
private static final String KEY_TRACK_ID = "trackId";
|
||||
|
||||
public static AddEmailsDialogFragment newInstance(long trackId) {
|
||||
public static ShareTrackDialogFragment newInstance(long trackId) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(KEY_TRACK_ID, trackId);
|
||||
|
||||
AddEmailsDialogFragment addPeopleDialogFragment = new AddEmailsDialogFragment();
|
||||
addPeopleDialogFragment.setArguments(bundle);
|
||||
return addPeopleDialogFragment;
|
||||
ShareTrackDialogFragment shareleTrackDialogFragment = new ShareTrackDialogFragment();
|
||||
shareleTrackDialogFragment.setArguments(bundle);
|
||||
return shareleTrackDialogFragment;
|
||||
}
|
||||
|
||||
private AddEmailsCaller caller;
|
||||
private ShareTrackCaller caller;
|
||||
private FragmentActivity fragmentActivity;
|
||||
private MultiAutoCompleteTextView multiAutoCompleteTextView;
|
||||
|
||||
private CheckBox checkBox;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
try {
|
||||
caller = (AddEmailsCaller) activity;
|
||||
caller = (ShareTrackCaller) activity;
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException(
|
||||
activity.toString() + " must implement " + AddEmailsCaller.class.getSimpleName());
|
||||
activity.toString() + " must implement " + ShareTrackCaller.class.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
fragmentActivity = getActivity();
|
||||
View view = fragmentActivity.getLayoutInflater().inflate(R.layout.add_emails, null);
|
||||
multiAutoCompleteTextView = (MultiAutoCompleteTextView) view.findViewById(R.id.add_emails);
|
||||
View view = fragmentActivity.getLayoutInflater().inflate(R.layout.share_track, null);
|
||||
|
||||
multiAutoCompleteTextView = (MultiAutoCompleteTextView) view.findViewById(
|
||||
R.id.share_track_emails);
|
||||
multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
|
||||
|
||||
SimpleCursorAdapter adapter = new SimpleCursorAdapter(fragmentActivity,
|
||||
@@ -109,15 +114,17 @@ public class AddEmailsDialogFragment extends DialogFragment {
|
||||
});
|
||||
multiAutoCompleteTextView.setAdapter(adapter);
|
||||
|
||||
checkBox = (CheckBox) view.findViewById(R.id.share_track_public);
|
||||
|
||||
return new AlertDialog.Builder(fragmentActivity).setNegativeButton(
|
||||
R.string.generic_cancel, null)
|
||||
.setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String acl = multiAutoCompleteTextView.getText().toString();
|
||||
caller.onAddEmailsDone(acl);
|
||||
caller.onShareTrackDone(acl, checkBox.isChecked());
|
||||
}
|
||||
}).setTitle(R.string.share_track_add_emails_title).setView(view).create();
|
||||
}).setTitle(R.string.share_track_title).setView(view).create();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,8 +37,8 @@ public class SendDriveActivity extends AbstractSendActivity {
|
||||
|
||||
@Override
|
||||
protected AbstractSendAsyncTask createAsyncTask() {
|
||||
return new SendDriveAsyncTask(
|
||||
this, sendRequest.getTrackId(), sendRequest.getAccount(), sendRequest.getDriveShareEmails());
|
||||
return new SendDriveAsyncTask(this, sendRequest.getTrackId(), sendRequest.getAccount(),
|
||||
sendRequest.getDriveShareEmails(), sendRequest.isDriveSharePublic());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,6 +28,7 @@ import com.google.api.client.googleapis.extensions.android.gms.auth.UserRecovera
|
||||
import com.google.api.services.drive.Drive;
|
||||
import com.google.api.services.drive.model.File;
|
||||
import com.google.api.services.drive.model.Permission;
|
||||
import com.google.api.services.drive.model.PermissionList;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.content.Context;
|
||||
@@ -44,10 +45,12 @@ public class SendDriveAsyncTask extends AbstractSendAsyncTask {
|
||||
private final long trackId;
|
||||
private final Account account;
|
||||
private final String[] acl;
|
||||
private final boolean isPublic;
|
||||
private final Context context;
|
||||
private final MyTracksProviderUtils myTracksProviderUtils;
|
||||
|
||||
public SendDriveAsyncTask(SendDriveActivity activity, long trackId, Account account, String acl) {
|
||||
public SendDriveAsyncTask(
|
||||
SendDriveActivity activity, long trackId, Account account, String acl, boolean isPublic) {
|
||||
super(activity);
|
||||
this.trackId = trackId;
|
||||
this.account = account;
|
||||
@@ -56,7 +59,8 @@ public class SendDriveAsyncTask extends AbstractSendAsyncTask {
|
||||
} else {
|
||||
this.acl = null;
|
||||
}
|
||||
|
||||
this.isPublic = isPublic;
|
||||
|
||||
context = activity.getApplicationContext();
|
||||
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(context);
|
||||
}
|
||||
@@ -91,18 +95,18 @@ public class SendDriveAsyncTask extends AbstractSendAsyncTask {
|
||||
File driveFile = drive.files().get(driveId).execute();
|
||||
if (SyncUtils.isValid(driveFile, folderId) && SyncUtils.updateDriveFile(
|
||||
drive, driveFile, context, myTracksProviderUtils, track, false)) {
|
||||
addPermission(drive, driveId);
|
||||
addPermission(drive, driveFile);
|
||||
return true;
|
||||
}
|
||||
SyncUtils.updateTrackWithDriveFileInfo(myTracksProviderUtils, track, null);
|
||||
}
|
||||
|
||||
String id = SyncUtils.insertDriveFile(
|
||||
File file = SyncUtils.insertDriveFile(
|
||||
drive, folderId, context, myTracksProviderUtils, track, false);
|
||||
if (id == null) {
|
||||
if (file == null) {
|
||||
return false;
|
||||
}
|
||||
addPermission(drive, id);
|
||||
addPermission(drive, file);
|
||||
return true;
|
||||
} catch (UserRecoverableAuthException e) {
|
||||
SendToGoogleUtils.sendNotification(
|
||||
@@ -128,16 +132,38 @@ public class SendDriveAsyncTask extends AbstractSendAsyncTask {
|
||||
* @param drive the drive
|
||||
* @param driveId the drive id
|
||||
*/
|
||||
private void addPermission(Drive drive, String driveId) throws IOException {
|
||||
private void addPermission(Drive drive, File file) throws IOException {
|
||||
if (isPublic) {
|
||||
boolean hasPublic = false;
|
||||
PermissionList permissionList = drive.permissions().list(file.getId()).execute();
|
||||
for (Permission permission : permissionList.getItems()) {
|
||||
String role = permission.getRole();
|
||||
if (role.equals("reader") || role.equals("writer")) {
|
||||
if (permission.getType().equals("anyone")) {
|
||||
hasPublic = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!hasPublic) {
|
||||
Permission permission = new Permission();
|
||||
permission.setRole("reader");
|
||||
permission.setType("anyone");
|
||||
permission.setValue("");
|
||||
drive.permissions().insert(file.getId(), permission).execute();
|
||||
}
|
||||
shareUrl = file.getAlternateLink();
|
||||
}
|
||||
|
||||
if (acl != null) {
|
||||
for (String email : acl) {
|
||||
email = email.trim();
|
||||
if (!email.equals("")) {
|
||||
Permission permission = new Permission();
|
||||
permission.setValue(email);
|
||||
permission.setType("user");
|
||||
permission.setRole("reader");
|
||||
drive.permissions().insert(driveId, permission).execute();
|
||||
permission.setType("user");
|
||||
permission.setValue(email);
|
||||
drive.permissions().insert(file.getId(), permission).execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -214,8 +214,9 @@ public class SendFusionTablesAsyncTask extends AbstractSendAsyncTask {
|
||||
}
|
||||
Drive drive = SyncUtils.getDriveService(driveCredential);
|
||||
Permission permission = new Permission();
|
||||
permission.setType("anyone");
|
||||
permission.setRole("reader");
|
||||
permission.setType("anyone");
|
||||
permission.setValue("");
|
||||
drive.permissions().insert(tableId, permission).execute();
|
||||
return true;
|
||||
}
|
||||
|
||||
+2
-1
@@ -90,7 +90,8 @@ public abstract class AbstractSendActivity extends Activity {
|
||||
*
|
||||
* @param success true if the AsyncTask is successful
|
||||
*/
|
||||
public void onAsyncTaskCompleted(boolean success) {
|
||||
public void onAsyncTaskCompleted(boolean success, String shareUrl) {
|
||||
sendRequest.setShareUrl(shareUrl);
|
||||
startNextActivity(success, false);
|
||||
}
|
||||
|
||||
|
||||
+13
-7
@@ -20,7 +20,7 @@ import android.os.AsyncTask;
|
||||
|
||||
/**
|
||||
* The abstract class for AsyncTasks sending a track to Google.
|
||||
*
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public abstract class AbstractSendAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
||||
@@ -35,6 +35,11 @@ public abstract class AbstractSendAsyncTask extends AsyncTask<Void, Integer, Boo
|
||||
*/
|
||||
private boolean success;
|
||||
|
||||
/**
|
||||
* The share url from the AsyncTask.
|
||||
*/
|
||||
protected String shareUrl;
|
||||
|
||||
/**
|
||||
* True if the AsyncTask has completed.
|
||||
*/
|
||||
@@ -47,25 +52,26 @@ public abstract class AbstractSendAsyncTask extends AsyncTask<Void, Integer, Boo
|
||||
|
||||
/**
|
||||
* Creates an AsyncTask.
|
||||
*
|
||||
*
|
||||
* @param activity the activity currently associated with this AsyncTask
|
||||
*/
|
||||
public AbstractSendAsyncTask(AbstractSendActivity activity) {
|
||||
this.activity = activity;
|
||||
success = false;
|
||||
shareUrl = null;
|
||||
completed = false;
|
||||
canRetry = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current activity associated with this AyncTask.
|
||||
*
|
||||
*
|
||||
* @param activity the current activity, can be null
|
||||
*/
|
||||
public void setActivity(AbstractSendActivity activity) {
|
||||
this.activity = activity;
|
||||
if (completed && activity != null) {
|
||||
activity.onAsyncTaskCompleted(success);
|
||||
activity.onAsyncTaskCompleted(success, shareUrl);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,14 +104,14 @@ public abstract class AbstractSendAsyncTask extends AsyncTask<Void, Integer, Boo
|
||||
saveResult();
|
||||
}
|
||||
if (activity != null) {
|
||||
activity.onAsyncTaskCompleted(success);
|
||||
activity.onAsyncTaskCompleted(success, shareUrl);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retries the task. First, invalidates the auth token. If can retry, invokes
|
||||
* {@link #performTask()}. Returns false if cannot retry.
|
||||
*
|
||||
*
|
||||
* @return the result of the retry.
|
||||
*/
|
||||
protected boolean retryTask() {
|
||||
@@ -133,7 +139,7 @@ public abstract class AbstractSendAsyncTask extends AsyncTask<Void, Integer, Boo
|
||||
|
||||
/**
|
||||
* Performs the AsyncTask.
|
||||
*
|
||||
*
|
||||
* @return true if success
|
||||
*/
|
||||
protected abstract boolean performTask();
|
||||
|
||||
@@ -36,9 +36,10 @@ public class SendRequest implements Parcelable {
|
||||
private boolean sendFusionTables = false;
|
||||
private boolean sendSpreadsheets = false;
|
||||
|
||||
private boolean driveEnableSync = false;
|
||||
private boolean driveShare = false;
|
||||
private String driveShareEmails = null;
|
||||
private boolean driveEnableSync = false; // to enable Drive sync
|
||||
private boolean driveShare = false; // to enable Drive share
|
||||
private String driveShareEmails = null; // share with emails
|
||||
private boolean driveSharePublic = false; // share as public
|
||||
|
||||
private Account account = null;
|
||||
|
||||
@@ -46,6 +47,7 @@ public class SendRequest implements Parcelable {
|
||||
private boolean mapsSuccess = false;
|
||||
private boolean spreadsheetsSuccess = false;
|
||||
private boolean fusionTablesSuccess = false;
|
||||
private String shareUrl = null;
|
||||
|
||||
/**
|
||||
* Creates a new send request.
|
||||
@@ -116,6 +118,14 @@ public class SendRequest implements Parcelable {
|
||||
this.driveShareEmails = driveShareEmails;
|
||||
}
|
||||
|
||||
public boolean isDriveSharePublic() {
|
||||
return driveSharePublic;
|
||||
}
|
||||
|
||||
public void setDriveSharePublic(boolean driveSharePublic) {
|
||||
this.driveSharePublic = driveSharePublic;
|
||||
}
|
||||
|
||||
public Account getAccount() {
|
||||
return account;
|
||||
}
|
||||
@@ -156,6 +166,14 @@ public class SendRequest implements Parcelable {
|
||||
this.spreadsheetsSuccess = spreadsheetsSuccess;
|
||||
}
|
||||
|
||||
public String getShareUrl() {
|
||||
return shareUrl;
|
||||
}
|
||||
|
||||
public void setShareUrl(String shareUrl) {
|
||||
this.shareUrl = shareUrl;
|
||||
}
|
||||
|
||||
private SendRequest(Parcel in) {
|
||||
trackId = in.readLong();
|
||||
sendDrive = in.readByte() == 1;
|
||||
@@ -165,11 +183,13 @@ public class SendRequest implements Parcelable {
|
||||
driveEnableSync = in.readByte() == 1;
|
||||
driveShare = in.readByte() == 1;
|
||||
driveShareEmails = in.readString();
|
||||
driveSharePublic = in.readByte() == 1;
|
||||
account = in.readParcelable(null);
|
||||
driveSuccess = in.readByte() == 1;
|
||||
mapsSuccess = in.readByte() == 1;
|
||||
fusionTablesSuccess = in.readByte() == 1;
|
||||
spreadsheetsSuccess = in.readByte() == 1;
|
||||
shareUrl = in.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -184,14 +204,16 @@ public class SendRequest implements Parcelable {
|
||||
out.writeByte((byte) (sendMaps ? 1 : 0));
|
||||
out.writeByte((byte) (sendFusionTables ? 1 : 0));
|
||||
out.writeByte((byte) (sendSpreadsheets ? 1 : 0));
|
||||
out.writeByte((byte) (driveEnableSync ? 1 : 0));
|
||||
out.writeByte((byte) (driveEnableSync ? 1 : 0));
|
||||
out.writeByte((byte) (driveShare ? 1 : 0));
|
||||
out.writeString(driveShareEmails);
|
||||
out.writeByte((byte) (driveSharePublic ? 1 : 0));
|
||||
out.writeParcelable(account, 0);
|
||||
out.writeByte((byte) (driveSuccess ? 1 : 0));
|
||||
out.writeByte((byte) (mapsSuccess ? 1 : 0));
|
||||
out.writeByte((byte) (fusionTablesSuccess ? 1 : 0));
|
||||
out.writeByte((byte) (spreadsheetsSuccess ? 1 : 0));
|
||||
out.writeString(shareUrl);
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<SendRequest>
|
||||
|
||||
+7
-1
@@ -60,7 +60,7 @@ public class UploadResultActivity extends FragmentActivity implements ChooseActi
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
sendRequest = getIntent().getParcelableExtra(SendRequest.SEND_REQUEST_KEY);
|
||||
shareUrl = null;
|
||||
shareUrl = sendRequest.getShareUrl();
|
||||
|
||||
Track track = MyTracksProviderUtils.Factory.get(this).getTrack(sendRequest.getTrackId());
|
||||
if (track == null) {
|
||||
@@ -69,6 +69,12 @@ public class UploadResultActivity extends FragmentActivity implements ChooseActi
|
||||
return;
|
||||
}
|
||||
|
||||
if (sendRequest.isDriveSuccess() && shareUrl != null) {
|
||||
new ChooseActivityDialogFragment().show(
|
||||
getSupportFragmentManager(), ChooseActivityDialogFragment.CHOOSE_ACTIVITY_DIALOG_TAG);
|
||||
return;
|
||||
}
|
||||
|
||||
if (sendRequest.isSendMaps() && sendRequest.isMapsSuccess()) {
|
||||
shareUrl = SendMapsUtils.getMapUrl(track);
|
||||
}
|
||||
|
||||
@@ -262,9 +262,9 @@ public class SyncUtils {
|
||||
* @param myTracksProviderUtils the myTracksProviderUtils
|
||||
* @param track the track
|
||||
* @param canRetry true if can retry
|
||||
* @return the added drive file id or null.
|
||||
* @return the added drive file or null.
|
||||
*/
|
||||
public static String insertDriveFile(Drive drive, String folderId, Context context,
|
||||
public static File insertDriveFile(Drive drive, String folderId, Context context,
|
||||
MyTracksProviderUtils myTracksProviderUtils, Track track, boolean canRetry)
|
||||
throws IOException {
|
||||
java.io.File file = getFile(context, myTracksProviderUtils, track);
|
||||
@@ -281,7 +281,7 @@ public class SyncUtils {
|
||||
return null;
|
||||
}
|
||||
SyncUtils.updateTrackWithDriveFileInfo(myTracksProviderUtils, track, uploadedFile);
|
||||
return uploadedFile.getId();
|
||||
return uploadedFile;
|
||||
} finally {
|
||||
file.delete();
|
||||
}
|
||||
|
||||
+20
-1
@@ -32,6 +32,7 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
private final static String ACCOUNTNAME = "testAccount1";
|
||||
private final static String ACCOUNTYPE = "testType1";
|
||||
private final static String DRIVE_SHARE_EMAILS = "foo@foo.com";
|
||||
private final static String SHARE_URL = "url@url.com";
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@@ -128,12 +129,14 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeString(DRIVE_SHARE_EMAILS);
|
||||
parcel.writeByte((byte) 1);
|
||||
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
|
||||
parcel.writeParcelable(account, 0);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeString(SHARE_URL);
|
||||
parcel.setDataPosition(0);
|
||||
sendRequest = SendRequest.CREATOR.createFromParcel(parcel);
|
||||
assertEquals(2, sendRequest.getTrackId());
|
||||
@@ -144,11 +147,13 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
assertTrue(sendRequest.isDriveEnableSync());
|
||||
assertTrue(sendRequest.isDriveShare());
|
||||
assertEquals(DRIVE_SHARE_EMAILS, sendRequest.getDriveShareEmails());
|
||||
assertTrue(sendRequest.isDriveSharePublic());
|
||||
assertEquals(account, sendRequest.getAccount());
|
||||
assertTrue(sendRequest.isDriveSuccess());
|
||||
assertTrue(sendRequest.isMapsSuccess());
|
||||
assertTrue(sendRequest.isFusionTablesSuccess());
|
||||
assertTrue(sendRequest.isSpreadsheetsSuccess());
|
||||
assertEquals(SHARE_URL, sendRequest.getShareUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,12 +170,14 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeString(null);
|
||||
parcel.writeByte((byte) 0);
|
||||
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
|
||||
parcel.writeParcelable(account, 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeString(null);
|
||||
parcel.setDataPosition(0);
|
||||
sendRequest = SendRequest.CREATOR.createFromParcel(parcel);
|
||||
assertEquals(4, sendRequest.getTrackId());
|
||||
@@ -181,11 +188,13 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
assertFalse(sendRequest.isDriveEnableSync());
|
||||
assertFalse(sendRequest.isDriveShare());
|
||||
assertNull(sendRequest.getDriveShareEmails());
|
||||
assertFalse(sendRequest.isDriveSharePublic());
|
||||
assertEquals(account, sendRequest.getAccount());
|
||||
assertFalse(sendRequest.isDriveSuccess());
|
||||
assertFalse(sendRequest.isMapsSuccess());
|
||||
assertFalse(sendRequest.isFusionTablesSuccess());
|
||||
assertFalse(sendRequest.isSpreadsheetsSuccess());
|
||||
assertNull(sendRequest.getShareUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -202,14 +211,16 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
boolean sendMaps = parcel.readByte() == 1;
|
||||
boolean sendFusionTables = parcel.readByte() == 1;
|
||||
boolean sendSpreadsheets = parcel.readByte() == 1;
|
||||
boolean driveEnableSync = parcel.readByte() == 1;
|
||||
boolean driveEnableSync = parcel.readByte() == 1;
|
||||
boolean driveShare = parcel.readByte() == 1;
|
||||
String dirveShareEmails = parcel.readString();
|
||||
boolean driveSharePublic = parcel.readByte() == 1;
|
||||
Parcelable account = parcel.readParcelable(null);
|
||||
boolean driveSuccess = parcel.readByte() == 1;
|
||||
boolean mapsSuccess = parcel.readByte() == 1;
|
||||
boolean fusionTablesSuccess = parcel.readByte() == 1;
|
||||
boolean spreadsheetsSuccess = parcel.readByte() == 1;
|
||||
String shareUrl = parcel.readString();
|
||||
assertEquals(1, trackId);
|
||||
assertFalse(sendDrive);
|
||||
assertFalse(sendMaps);
|
||||
@@ -218,11 +229,13 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
assertFalse(driveEnableSync);
|
||||
assertFalse(driveShare);
|
||||
assertNull(dirveShareEmails);
|
||||
assertFalse(driveSharePublic);
|
||||
assertNull(account);
|
||||
assertFalse(driveSuccess);
|
||||
assertFalse(mapsSuccess);
|
||||
assertFalse(fusionTablesSuccess);
|
||||
assertFalse(spreadsheetsSuccess);
|
||||
assertNull(shareUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -237,12 +250,14 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
sendRequest.setDriveEnableSync(true);
|
||||
sendRequest.setDriveShare(true);
|
||||
sendRequest.setDriveShareEmails(DRIVE_SHARE_EMAILS);
|
||||
sendRequest.setDriveSharePublic(true);
|
||||
Account accountNew = new Account(ACCOUNTNAME + "2", ACCOUNTYPE + "2");
|
||||
sendRequest.setAccount(accountNew);
|
||||
sendRequest.setMapsSuccess(true);
|
||||
sendRequest.setDriveSuccess(true);
|
||||
sendRequest.setFusionTablesSuccess(true);
|
||||
sendRequest.setSpreadsheetsSuccess(true);
|
||||
sendRequest.setShareUrl(SHARE_URL);
|
||||
Parcel parcel = Parcel.obtain();
|
||||
parcel.setDataPosition(0);
|
||||
sendRequest.writeToParcel(parcel, 1);
|
||||
@@ -255,11 +270,13 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
boolean driveEnableSync = parcel.readByte() == 1;
|
||||
boolean driveShare = parcel.readByte() == 1;
|
||||
String driveShareEmails = parcel.readString();
|
||||
boolean driveSharePublic = parcel.readByte() == 1;
|
||||
Parcelable account = parcel.readParcelable(null);
|
||||
boolean driveSuccess = parcel.readByte() == 1;
|
||||
boolean mapsSuccess = parcel.readByte() == 1;
|
||||
boolean fusionTablesSuccess = parcel.readByte() == 1;
|
||||
boolean spreadsheetsSuccess = parcel.readByte() == 1;
|
||||
String shareUrl = parcel.readString();
|
||||
assertEquals(4, trackId);
|
||||
assertTrue(sendDrive);
|
||||
assertTrue(sendMaps);
|
||||
@@ -268,10 +285,12 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
assertTrue(driveEnableSync);
|
||||
assertTrue(driveShare);
|
||||
assertEquals(DRIVE_SHARE_EMAILS, driveShareEmails);
|
||||
assertTrue(driveSharePublic);
|
||||
assertEquals(accountNew, account);
|
||||
assertTrue(driveSuccess);
|
||||
assertTrue(mapsSuccess);
|
||||
assertTrue(fusionTablesSuccess);
|
||||
assertTrue(spreadsheetsSuccess);
|
||||
assertEquals(SHARE_URL, shareUrl);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user