mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-02 09:33:06 +02:00
In the start up flow, ask the user if he wants to enable Google Drive sync.
This commit is contained in:
@@ -556,6 +556,20 @@ limitations under the License.
|
||||
Segment
|
||||
</string>
|
||||
|
||||
<!-- Enable Sync -->
|
||||
<string name="enable_sync_message"
|
||||
translation_description="The dialog message asking the user if he wants to enable sync with
|
||||
Google Drive.">
|
||||
Do you want to sync your tracks with Google Drive? This will allow you to view your tracks in
|
||||
Google Drive, share tracks via Google Drive, and view tracks shared with you. All tracks synced
|
||||
to Google Drive will be private by default.
|
||||
</string>
|
||||
<string name="enable_sync_title"
|
||||
translation_description="The dialog title asking the user if he wants to enable sync with Google
|
||||
Drive.">
|
||||
Sync with Google Drive
|
||||
</string>
|
||||
|
||||
<!-- Eula -->
|
||||
<string name="eula_accept"
|
||||
translation_description="In the 'Terms of Service' dialog, the button to accept.">
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.google.android.apps.mytracks.io.sendtogoogle.SendRequest;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.SendToGoogleUtils;
|
||||
import com.google.android.apps.mytracks.io.sendtogoogle.UploadResultActivity;
|
||||
import com.google.android.apps.mytracks.io.spreadsheets.SendSpreadsheetsActivity;
|
||||
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
@@ -43,6 +44,7 @@ import android.accounts.AccountManagerFuture;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.app.Activity;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
@@ -287,7 +289,19 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv
|
||||
private void startNextActivity() {
|
||||
Class<?> next;
|
||||
if (sendRequest.isSendDrive()) {
|
||||
if (sendRequest.isDriveShare()) {
|
||||
if (sendRequest.isDriveEnableSync()) {
|
||||
PreferencesUtils.setBoolean(this, R.string.drive_sync_key, true);
|
||||
|
||||
// Turn off everything
|
||||
SyncUtils.disableSync(this);
|
||||
|
||||
// Turn on sync
|
||||
ContentResolver.setMasterSyncAutomatically(true);
|
||||
|
||||
// Enable sync for account
|
||||
SyncUtils.enableSync(sendRequest.getAccount());
|
||||
return;
|
||||
} else if (sendRequest.isDriveShare()) {
|
||||
AddEmailsDialogFragment.newInstance(sendRequest.getTrackId())
|
||||
.show(getSupportFragmentManager(), AddEmailsDialogFragment.ADD_EMAILS_DIALOG_TAG);
|
||||
return;
|
||||
|
||||
@@ -28,6 +28,8 @@ import com.google.android.apps.mytracks.fragments.ConfirmDialogFragment.ConfirmC
|
||||
import com.google.android.apps.mytracks.fragments.DeleteAllTrackDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.DeleteOneTrackDialogFragment.DeleteOneTrackCaller;
|
||||
import com.google.android.apps.mytracks.fragments.EnableSyncDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.EnableSyncDialogFragment.EnableSyncCaller;
|
||||
import com.google.android.apps.mytracks.fragments.EulaDialogFragment;
|
||||
import com.google.android.apps.mytracks.fragments.EulaDialogFragment.EulaCaller;
|
||||
import com.google.android.apps.mytracks.fragments.WelcomeDialogFragment;
|
||||
@@ -93,7 +95,7 @@ import java.util.Locale;
|
||||
* @author Leif Hendrik Wilden
|
||||
*/
|
||||
public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
implements EulaCaller, WelcomeCaller, ConfirmCaller, DeleteOneTrackCaller {
|
||||
implements EulaCaller, WelcomeCaller, EnableSyncCaller, ConfirmCaller, DeleteOneTrackCaller {
|
||||
|
||||
private static final String TAG = TrackListActivity.class.getSimpleName();
|
||||
private static final String START_GPS_KEY = "start_gps_key";
|
||||
@@ -720,8 +722,32 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
});
|
||||
if (dialog != null) {
|
||||
dialog.show();
|
||||
return;
|
||||
}
|
||||
}
|
||||
showEnableSync();
|
||||
}
|
||||
|
||||
private void showEnableSync() {
|
||||
if (EulaUtils.getShowEnableSync(this)) {
|
||||
Fragment fragment = getSupportFragmentManager()
|
||||
.findFragmentByTag(EnableSyncDialogFragment.ENABLE_SYNC_DIALOG_TAG);
|
||||
if (fragment == null) {
|
||||
new EnableSyncDialogFragment().show(
|
||||
getSupportFragmentManager(), EnableSyncDialogFragment.ENABLE_SYNC_DIALOG_TAG);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnableSyncDone(boolean enable) {
|
||||
EulaUtils.setShowEnableSync(this);
|
||||
if (enable) {
|
||||
SendRequest sendRequest = new SendRequest(-1L);
|
||||
sendRequest.setSendDrive(true);
|
||||
sendRequest.setDriveEnableSync(true);
|
||||
sendToGoogle(sendRequest);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2013 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
|
||||
package com.google.android.apps.mytracks.fragments;
|
||||
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
||||
/**
|
||||
* A DialogFrament to enable sync.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class EnableSyncDialogFragment extends DialogFragment {
|
||||
|
||||
/**
|
||||
* Interface for caller of this dialog fragment.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public interface EnableSyncCaller {
|
||||
|
||||
/**
|
||||
* Called when enable sync is done.
|
||||
*/
|
||||
public void onEnableSyncDone(boolean enable);
|
||||
}
|
||||
|
||||
public static final String ENABLE_SYNC_DIALOG_TAG = "enableSyncDialog";
|
||||
|
||||
private EnableSyncCaller caller;
|
||||
private FragmentActivity fragmentActivity;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
try {
|
||||
caller = (EnableSyncCaller) activity;
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException(
|
||||
activity.toString() + " must implement " + EnableSyncCaller.class.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
fragmentActivity = getActivity();
|
||||
return new AlertDialog.Builder(fragmentActivity).setNegativeButton(
|
||||
R.string.generic_cancel, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
caller.onEnableSyncDone(false);
|
||||
}
|
||||
}).setPositiveButton(R.string.generic_ok, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
caller.onEnableSyncDone(true);
|
||||
}
|
||||
}).setTitle(R.string.enable_sync_title).setMessage(R.string.enable_sync_message).create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface arg0) {
|
||||
caller.onEnableSyncDone(false);
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,7 @@ 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;
|
||||
|
||||
@@ -97,6 +98,14 @@ public class SendRequest implements Parcelable {
|
||||
this.sendSpreadsheets = sendSpreadsheets;
|
||||
}
|
||||
|
||||
public boolean isDriveEnableSync() {
|
||||
return driveEnableSync;
|
||||
}
|
||||
|
||||
public void setDriveEnableSync(boolean driveEnableSync) {
|
||||
this.driveEnableSync = driveEnableSync;
|
||||
}
|
||||
|
||||
public boolean isDriveShare() {
|
||||
return driveShare;
|
||||
}
|
||||
@@ -199,6 +208,7 @@ public class SendRequest implements Parcelable {
|
||||
sendMaps = in.readByte() == 1;
|
||||
sendFusionTables = in.readByte() == 1;
|
||||
sendSpreadsheets = in.readByte() == 1;
|
||||
driveEnableSync = in.readByte() == 1;
|
||||
driveShare = in.readByte() == 1;
|
||||
driveShareEmails = in.readString();
|
||||
mapsShare = in.readByte() == 1;
|
||||
@@ -225,6 +235,7 @@ 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) (driveShare ? 1 : 0));
|
||||
out.writeString(driveShareEmails);
|
||||
out.writeByte((byte) (mapsShare ? 1 : 0));
|
||||
|
||||
@@ -31,6 +31,7 @@ public class EulaUtils {
|
||||
// Accepting Google mobile terms of service
|
||||
private static final String ACCEPT_EULA_PREFERENCE_KEY = "eula.google_mobile_tos_accepted";
|
||||
private static final String SHOW_WELCOME_PREFERENCE_KEY = "showWelcome";
|
||||
private static final String SHOW_ENABLE_SYNC_PREFERENCE_KEY = "showEnableSync";
|
||||
|
||||
private EulaUtils() {}
|
||||
|
||||
@@ -49,7 +50,15 @@ public class EulaUtils {
|
||||
public static void setShowWelcome(Context context) {
|
||||
setValue(context, SHOW_WELCOME_PREFERENCE_KEY, false);
|
||||
}
|
||||
|
||||
|
||||
public static boolean getShowEnableSync(Context context) {
|
||||
return getValue(context, SHOW_ENABLE_SYNC_PREFERENCE_KEY, true);
|
||||
}
|
||||
|
||||
public static void setShowEnableSync(Context context) {
|
||||
setValue(context, SHOW_ENABLE_SYNC_PREFERENCE_KEY, false);
|
||||
}
|
||||
|
||||
private static boolean getValue(Context context, String key, boolean defaultValue) {
|
||||
SharedPreferences sharedPreferences = context.getSharedPreferences(
|
||||
EULA_PREFERENCE_FILE, Context.MODE_PRIVATE);
|
||||
|
||||
+11
-2
@@ -151,6 +151,7 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeString(DRIVE_SHARE_EMAILS);
|
||||
parcel.writeByte((byte) 1);
|
||||
parcel.writeString("");
|
||||
@@ -170,6 +171,7 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
assertTrue(sendRequest.isSendMaps());
|
||||
assertTrue(sendRequest.isSendFusionTables());
|
||||
assertTrue(sendRequest.isSendSpreadsheets());
|
||||
assertTrue(sendRequest.isDriveEnableSync());
|
||||
assertTrue(sendRequest.isDriveShare());
|
||||
assertEquals(DRIVE_SHARE_EMAILS, sendRequest.getDriveShareEmails());
|
||||
assertTrue(sendRequest.isMapsShare());
|
||||
@@ -196,6 +198,7 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeString(null);
|
||||
parcel.writeByte((byte) 0);
|
||||
parcel.writeString(null);
|
||||
@@ -215,6 +218,7 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
assertFalse(sendRequest.isSendMaps());
|
||||
assertFalse(sendRequest.isSendFusionTables());
|
||||
assertFalse(sendRequest.isSendSpreadsheets());
|
||||
assertFalse(sendRequest.isDriveEnableSync());
|
||||
assertFalse(sendRequest.isDriveShare());
|
||||
assertNull(sendRequest.getDriveShareEmails());
|
||||
assertFalse(sendRequest.isMapsShare());
|
||||
@@ -243,6 +247,7 @@ 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 driveShare = parcel.readByte() == 1;
|
||||
String dirveShareEmails = parcel.readString();
|
||||
boolean mapsShare = parcel.readByte() == 1;
|
||||
@@ -260,6 +265,7 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
assertFalse(sendMaps);
|
||||
assertFalse(sendFusionTables);
|
||||
assertFalse(sendSpreadsheets);
|
||||
assertFalse(driveEnableSync);
|
||||
assertFalse(driveShare);
|
||||
assertNull(dirveShareEmails);
|
||||
assertFalse(mapsShare);
|
||||
@@ -283,6 +289,7 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
sendRequest.setSendMaps(true);
|
||||
sendRequest.setSendFusionTables(true);
|
||||
sendRequest.setSendSpreadsheets(true);
|
||||
sendRequest.setDriveEnableSync(true);
|
||||
sendRequest.setDriveShare(true);
|
||||
sendRequest.setDriveShareEmails(DRIVE_SHARE_EMAILS);
|
||||
sendRequest.setMapsShare(true);
|
||||
@@ -305,7 +312,8 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
boolean sendMaps = parcel.readByte() == 1;
|
||||
boolean sendFusionTables = parcel.readByte() == 1;
|
||||
boolean sendSpreadsheets = parcel.readByte() == 1;
|
||||
boolean shareDrive = parcel.readByte() == 1;
|
||||
boolean driveEnableSync = parcel.readByte() == 1;
|
||||
boolean driveShare = parcel.readByte() == 1;
|
||||
String driveShareEmails = parcel.readString();
|
||||
boolean mapsShare = parcel.readByte() == 1;
|
||||
String mapsSharePackageName = parcel.readString();
|
||||
@@ -322,7 +330,8 @@ public class SendRequestTest extends AndroidTestCase {
|
||||
assertTrue(sendMaps);
|
||||
assertTrue(sendFusionTables);
|
||||
assertTrue(sendSpreadsheets);
|
||||
assertTrue(shareDrive);
|
||||
assertTrue(driveEnableSync);
|
||||
assertTrue(driveShare);
|
||||
assertEquals(DRIVE_SHARE_EMAILS, driveShareEmails);
|
||||
assertTrue(mapsShare);
|
||||
assertEquals(MAPS_SHARE_PACKAGE_NAME, mapsSharePackageName);
|
||||
|
||||
Reference in New Issue
Block a user