forked from upstream-mirrors/OpenTracks
inline choose account in share trak dialog
This commit is contained in:
@@ -0,0 +1,25 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:id="@android:id/text1"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:padding="8dp"
|
||||||
|
android:singleLine="true"
|
||||||
|
style="@style/TextSmall" />
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
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.
|
||||||
|
-->
|
||||||
|
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:id="@android:id/text1"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:singleLine="true"
|
||||||
|
style="@style/TextSmall" />
|
||||||
@@ -20,7 +20,7 @@ limitations under the License.
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:padding="8dp">
|
android:padding="8dp" >
|
||||||
<CheckBox
|
<CheckBox
|
||||||
android:id="@+id/share_track_public"
|
android:id="@+id/share_track_public"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
@@ -43,5 +43,11 @@ limitations under the License.
|
|||||||
android:singleLine="false"
|
android:singleLine="false"
|
||||||
android:visibility="gone" >
|
android:visibility="gone" >
|
||||||
</MultiAutoCompleteTextView>
|
</MultiAutoCompleteTextView>
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/share_track_account"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:layout_marginTop="24dp"
|
||||||
|
android:layout_width="wrap_content" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
@@ -68,6 +68,7 @@ limitations under the License.
|
|||||||
<string name="google_account_key">googleAccount</string>
|
<string name="google_account_key">googleAccount</string>
|
||||||
<string name="recording_track_id_key">recordingTrackId</string>
|
<string name="recording_track_id_key">recordingTrackId</string>
|
||||||
<string name="recording_track_paused_key">recordingTrackPaused</string>
|
<string name="recording_track_paused_key">recordingTrackPaused</string>
|
||||||
|
<string name="share_track_account_key">shareTrackAccountKey</string>
|
||||||
<string name="weight_key">weight</string>
|
<string name="weight_key">weight</string>
|
||||||
<!-- Keys for non-persisted preferences. Sorted alphabetically. DO NOT TRANSLATE. -->
|
<!-- Keys for non-persisted preferences. Sorted alphabetically. DO NOT TRANSLATE. -->
|
||||||
<string name="settings_advanced_key">settingsAdvanced</string>
|
<string name="settings_advanced_key">settingsAdvanced</string>
|
||||||
|
|||||||
@@ -2050,7 +2050,7 @@ limitations under the License.
|
|||||||
</string>
|
</string>
|
||||||
<string name="share_track_title"
|
<string name="share_track_title"
|
||||||
translation_description="The dialog title to share a track.">
|
translation_description="The dialog title to share a track.">
|
||||||
Share track via Google Drive
|
Share on Google Drive
|
||||||
</string>
|
</string>
|
||||||
|
|
||||||
<!-- Stats -->
|
<!-- Stats -->
|
||||||
|
|||||||
@@ -158,11 +158,18 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv
|
|||||||
*/
|
*/
|
||||||
protected void shareTrack(long trackId) {
|
protected void shareTrack(long trackId) {
|
||||||
AnalyticsUtils.sendPageViews(this, AnalyticsUtils.ACTION_SHARE_DRIVE);
|
AnalyticsUtils.sendPageViews(this, AnalyticsUtils.ACTION_SHARE_DRIVE);
|
||||||
SendRequest newRequest;
|
sendRequest = new SendRequest(trackId);
|
||||||
newRequest = new SendRequest(trackId);
|
sendRequest.setSendDrive(true);
|
||||||
newRequest.setSendDrive(true);
|
ShareTrackDialogFragment.newInstance(sendRequest.getTrackId())
|
||||||
newRequest.setDriveShare(true);
|
.show(getSupportFragmentManager(), ShareTrackDialogFragment.SHARE_TRACK_DIALOG_TAG);
|
||||||
sendToGoogle(newRequest);
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onShareTrackDone(boolean makePublic, String emails, Account account) {
|
||||||
|
sendRequest.setDriveSharePublic(makePublic);
|
||||||
|
sendRequest.setDriveShareEmails(emails);
|
||||||
|
sendRequest.setAccount(account);
|
||||||
|
onConfirmSyncDone(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -312,8 +319,6 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv
|
|||||||
* <p>
|
* <p>
|
||||||
* isSendDrive and isDriveEnableSync -> enable sync
|
* isSendDrive and isDriveEnableSync -> enable sync
|
||||||
* <p>
|
* <p>
|
||||||
* isSendDrive and isDriveShare -> show {@link ShareTrackDialogFragment}
|
|
||||||
* <p>
|
|
||||||
* isSendDrive -> start {@link SendDriveActivity}
|
* isSendDrive -> start {@link SendDriveActivity}
|
||||||
* <p>
|
* <p>
|
||||||
* isSendMaps -> start {@link SendMapsActivity}
|
* isSendMaps -> start {@link SendMapsActivity}
|
||||||
@@ -339,10 +344,6 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv
|
|||||||
// Enable sync for account
|
// Enable sync for account
|
||||||
SyncUtils.enableSync(sendRequest.getAccount());
|
SyncUtils.enableSync(sendRequest.getAccount());
|
||||||
return;
|
return;
|
||||||
} else if (sendRequest.isDriveShare()) {
|
|
||||||
ShareTrackDialogFragment.newInstance(sendRequest.getTrackId())
|
|
||||||
.show(getSupportFragmentManager(), ShareTrackDialogFragment.SHARE_TRACK_DIALOG_TAG);
|
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
next = SendDriveActivity.class;
|
next = SendDriveActivity.class;
|
||||||
}
|
}
|
||||||
@@ -367,15 +368,6 @@ public abstract class AbstractSendToGoogleActivity extends AbstractMyTracksActiv
|
|||||||
Toast.makeText(this, R.string.send_google_no_account_permission, Toast.LENGTH_LONG).show();
|
Toast.makeText(this, R.string.send_google_no_account_permission, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete tracks.
|
* Delete tracks.
|
||||||
*
|
*
|
||||||
|
|||||||
+76
-25
@@ -16,9 +16,12 @@
|
|||||||
|
|
||||||
package com.google.android.apps.mytracks.fragments;
|
package com.google.android.apps.mytracks.fragments;
|
||||||
|
|
||||||
|
import com.google.android.apps.mytracks.Constants;
|
||||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.maps.mytracks.R;
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
|
import android.accounts.Account;
|
||||||
|
import android.accounts.AccountManager;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
@@ -30,11 +33,13 @@ import android.provider.ContactsContract;
|
|||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.widget.SimpleCursorAdapter;
|
import android.support.v4.widget.SimpleCursorAdapter;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
import android.widget.FilterQueryProvider;
|
import android.widget.FilterQueryProvider;
|
||||||
import android.widget.MultiAutoCompleteTextView;
|
import android.widget.MultiAutoCompleteTextView;
|
||||||
|
import android.widget.Spinner;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -54,10 +59,11 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
/**
|
/**
|
||||||
* Called when share track is done.
|
* Called when share track is done.
|
||||||
*
|
*
|
||||||
* @param emails the added emails
|
|
||||||
* @param makePublic true to make the track public
|
* @param makePublic true to make the track public
|
||||||
|
* @param emails the emails to share the track with
|
||||||
|
* @param account the google drive account
|
||||||
*/
|
*/
|
||||||
public void onShareTrackDone(String emails, boolean makePublic);
|
public void onShareTrackDone(boolean makePublic, String emails, Account account);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final String SHARE_TRACK_DIALOG_TAG = "shareTrackDialog";
|
public static final String SHARE_TRACK_DIALOG_TAG = "shareTrackDialog";
|
||||||
@@ -75,9 +81,13 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
|
|
||||||
private ShareTrackCaller caller;
|
private ShareTrackCaller caller;
|
||||||
private FragmentActivity fragmentActivity;
|
private FragmentActivity fragmentActivity;
|
||||||
private MultiAutoCompleteTextView multiAutoCompleteTextView;
|
private Account[] accounts;
|
||||||
|
|
||||||
|
// UI elements
|
||||||
private CheckBox publicCheckBox;
|
private CheckBox publicCheckBox;
|
||||||
private CheckBox inviteCheckBox;
|
private CheckBox inviteCheckBox;
|
||||||
|
private MultiAutoCompleteTextView multiAutoCompleteTextView;
|
||||||
|
private Spinner accountSpinner;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
@@ -93,14 +103,41 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
@Override
|
@Override
|
||||||
protected Dialog createDialog() {
|
protected Dialog createDialog() {
|
||||||
fragmentActivity = getActivity();
|
fragmentActivity = getActivity();
|
||||||
|
accounts = AccountManager.get(fragmentActivity).getAccountsByType(Constants.ACCOUNT_TYPE);
|
||||||
|
|
||||||
|
if (accounts.length == 0) {
|
||||||
|
return new AlertDialog.Builder(fragmentActivity).setMessage(
|
||||||
|
R.string.send_google_no_account_message).setTitle(R.string.send_google_no_account_title)
|
||||||
|
.setPositiveButton(R.string.generic_ok, null).create();
|
||||||
|
}
|
||||||
|
|
||||||
View view = fragmentActivity.getLayoutInflater().inflate(R.layout.share_track, null);
|
View view = fragmentActivity.getLayoutInflater().inflate(R.layout.share_track, null);
|
||||||
|
|
||||||
|
// Setup publicCheckBox
|
||||||
|
publicCheckBox = (CheckBox) view.findViewById(R.id.share_track_public);
|
||||||
|
publicCheckBox.setChecked(PreferencesUtils.getBoolean(
|
||||||
|
fragmentActivity, R.string.share_track_public_key,
|
||||||
|
PreferencesUtils.SHARE_TRACK_PUBLIC_DEFAULT));
|
||||||
|
|
||||||
|
// Setup inviteCheckBox
|
||||||
|
inviteCheckBox = (CheckBox) view.findViewById(R.id.share_track_invite);
|
||||||
|
inviteCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
multiAutoCompleteTextView.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
inviteCheckBox.setChecked(PreferencesUtils.getBoolean(
|
||||||
|
fragmentActivity, R.string.share_track_invite_key,
|
||||||
|
PreferencesUtils.SHARE_TRACK_INVITE_DEFAULT));
|
||||||
|
|
||||||
|
// Setup multiAutoCompleteTextView
|
||||||
multiAutoCompleteTextView = (MultiAutoCompleteTextView) view.findViewById(
|
multiAutoCompleteTextView = (MultiAutoCompleteTextView) view.findViewById(
|
||||||
R.id.share_track_emails);
|
R.id.share_track_emails);
|
||||||
multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
|
multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
|
||||||
|
|
||||||
SimpleCursorAdapter adapter = new SimpleCursorAdapter(fragmentActivity,
|
SimpleCursorAdapter adapter = new SimpleCursorAdapter(fragmentActivity,
|
||||||
R.layout.add_emails_item, getCursor(fragmentActivity, null), new String[] {
|
R.layout.add_emails_item, getAutoCompleteCursor(null), new String[] {
|
||||||
ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Email.DATA },
|
ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Email.DATA },
|
||||||
new int[] { android.R.id.text1, android.R.id.text2 }, 0);
|
new int[] { android.R.id.text1, android.R.id.text2 }, 0);
|
||||||
adapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() {
|
adapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter() {
|
||||||
@@ -113,26 +150,14 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
adapter.setFilterQueryProvider(new FilterQueryProvider() {
|
adapter.setFilterQueryProvider(new FilterQueryProvider() {
|
||||||
@Override
|
@Override
|
||||||
public Cursor runQuery(CharSequence constraint) {
|
public Cursor runQuery(CharSequence constraint) {
|
||||||
return getCursor(fragmentActivity, constraint);
|
return getAutoCompleteCursor(constraint);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
multiAutoCompleteTextView.setAdapter(adapter);
|
multiAutoCompleteTextView.setAdapter(adapter);
|
||||||
|
|
||||||
publicCheckBox = (CheckBox) view.findViewById(R.id.share_track_public);
|
// Setup accountSpinner
|
||||||
publicCheckBox.setChecked(PreferencesUtils.getBoolean(
|
accountSpinner = (Spinner) view.findViewById(R.id.share_track_account);
|
||||||
fragmentActivity, R.string.share_track_public_key,
|
setupAccountSpinner(accountSpinner);
|
||||||
PreferencesUtils.SHARE_TRACK_PUBLIC_DEFAULT));
|
|
||||||
|
|
||||||
inviteCheckBox = (CheckBox) view.findViewById(R.id.share_track_invite);
|
|
||||||
inviteCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
|
||||||
@Override
|
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
|
||||||
multiAutoCompleteTextView.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
inviteCheckBox.setChecked(PreferencesUtils.getBoolean(
|
|
||||||
fragmentActivity, R.string.share_track_invite_key,
|
|
||||||
PreferencesUtils.SHARE_TRACK_INVITE_DEFAULT));
|
|
||||||
|
|
||||||
return new AlertDialog.Builder(fragmentActivity).setNegativeButton(
|
return new AlertDialog.Builder(fragmentActivity).setNegativeButton(
|
||||||
R.string.generic_cancel, null)
|
R.string.generic_cancel, null)
|
||||||
@@ -150,22 +175,26 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
.show();
|
.show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Account account = accounts.length > 1 ? accounts[accountSpinner
|
||||||
|
.getSelectedItemPosition()]
|
||||||
|
: accounts[0];
|
||||||
PreferencesUtils.setBoolean(
|
PreferencesUtils.setBoolean(
|
||||||
fragmentActivity, R.string.share_track_public_key, publicCheckBox.isChecked());
|
fragmentActivity, R.string.share_track_public_key, publicCheckBox.isChecked());
|
||||||
PreferencesUtils.setBoolean(
|
PreferencesUtils.setBoolean(
|
||||||
fragmentActivity, R.string.share_track_invite_key, inviteCheckBox.isChecked());
|
fragmentActivity, R.string.share_track_invite_key, inviteCheckBox.isChecked());
|
||||||
caller.onShareTrackDone(acl, publicCheckBox.isChecked());
|
PreferencesUtils.setString(
|
||||||
|
fragmentActivity, R.string.share_track_account_key, account.name);
|
||||||
|
caller.onShareTrackDone(publicCheckBox.isChecked(), acl, account);
|
||||||
}
|
}
|
||||||
}).setTitle(R.string.share_track_title).setView(view).create();
|
}).setTitle(R.string.share_track_title).setView(view).create();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the cursor
|
* Gets the auto complete cursor.
|
||||||
*
|
*
|
||||||
* @param activity the activity
|
|
||||||
* @param constraint the constraint
|
* @param constraint the constraint
|
||||||
*/
|
*/
|
||||||
private Cursor getCursor(Activity activity, CharSequence constraint) {
|
private Cursor getAutoCompleteCursor(CharSequence constraint) {
|
||||||
String order = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
|
String order = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
|
||||||
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";
|
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";
|
||||||
if (constraint != null) {
|
if (constraint != null) {
|
||||||
@@ -176,6 +205,28 @@ public class ShareTrackDialogFragment extends AbstractMyTracksDialogFragment {
|
|||||||
String[] projection = new String[] { ContactsContract.Contacts._ID,
|
String[] projection = new String[] { ContactsContract.Contacts._ID,
|
||||||
ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Email.DATA };
|
ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.CommonDataKinds.Email.DATA };
|
||||||
Uri uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI;
|
Uri uri = ContactsContract.CommonDataKinds.Email.CONTENT_URI;
|
||||||
return activity.getContentResolver().query(uri, projection, selection, null, order);
|
return fragmentActivity.getContentResolver().query(uri, projection, selection, null, order);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setupAccountSpinner(Spinner spinner) {
|
||||||
|
boolean hasMultiple = accounts.length > 1;
|
||||||
|
spinner.setVisibility(hasMultiple ? View.VISIBLE : View.GONE);
|
||||||
|
if (hasMultiple) {
|
||||||
|
String shareTrackAccount = PreferencesUtils.getString(fragmentActivity,
|
||||||
|
R.string.share_track_account_key, PreferencesUtils.SHARE_TRACK_ACCOUNT_DEFAULT);
|
||||||
|
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
|
||||||
|
fragmentActivity, R.layout.account_spinner_item);
|
||||||
|
int selection = 0;
|
||||||
|
for (int i = 0; i < accounts.length; i++) {
|
||||||
|
String name = accounts[i].name;
|
||||||
|
adapter.add(name);
|
||||||
|
if (name.equals(shareTrackAccount)) {
|
||||||
|
selection = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
adapter.setDropDownViewResource(R.layout.account_spinner_dropdown_item);
|
||||||
|
spinner.setAdapter(adapter);
|
||||||
|
spinner.setSelection(selection);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,6 +59,7 @@ public class PreferenceBackupHelper {
|
|||||||
doNotBackup.add(context.getString(R.string.google_account_key));
|
doNotBackup.add(context.getString(R.string.google_account_key));
|
||||||
doNotBackup.add(context.getString(R.string.recording_track_id_key));
|
doNotBackup.add(context.getString(R.string.recording_track_id_key));
|
||||||
doNotBackup.add(context.getString(R.string.recording_track_paused_key));
|
doNotBackup.add(context.getString(R.string.recording_track_paused_key));
|
||||||
|
doNotBackup.add(context.getString(R.string.share_track_account_key));
|
||||||
doNotBackup.add(context.getString(R.string.weight_key));
|
doNotBackup.add(context.getString(R.string.weight_key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,10 @@ import com.google.android.apps.mytracks.content.Track;
|
|||||||
import com.google.android.apps.mytracks.io.sendtogoogle.AbstractSendAsyncTask;
|
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.sendtogoogle.SendToGoogleUtils;
|
||||||
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
import com.google.android.apps.mytracks.io.sync.SyncUtils;
|
||||||
|
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||||
import com.google.android.gms.auth.GoogleAuthException;
|
import com.google.android.gms.auth.GoogleAuthException;
|
||||||
import com.google.android.gms.auth.UserRecoverableAuthException;
|
import com.google.android.gms.auth.UserRecoverableAuthException;
|
||||||
|
import com.google.android.maps.mytracks.R;
|
||||||
import com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential;
|
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.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException;
|
||||||
import com.google.api.services.drive.Drive;
|
import com.google.api.services.drive.Drive;
|
||||||
@@ -88,7 +90,10 @@ public class SendDriveAsyncTask extends AbstractSendAsyncTask {
|
|||||||
|
|
||||||
Track track = myTracksProviderUtils.getTrack(trackId);
|
Track track = myTracksProviderUtils.getTrack(trackId);
|
||||||
String driveId = track.getDriveId();
|
String driveId = track.getDriveId();
|
||||||
if (driveId != null && !driveId.equals("")) {
|
String syncAccount = PreferencesUtils.getString(
|
||||||
|
context, R.string.google_account_key, PreferencesUtils.GOOGLE_ACCOUNT_DEFAULT);
|
||||||
|
boolean sameAccount = account.name.equals(syncAccount);
|
||||||
|
if (sameAccount && driveId != null && !driveId.equals("")) {
|
||||||
File driveFile = drive.files().get(driveId).execute();
|
File driveFile = drive.files().get(driveId).execute();
|
||||||
if (driveFile != null && updateDriveFile(drive, driveFile, folderId, track)) {
|
if (driveFile != null && updateDriveFile(drive, driveFile, folderId, track)) {
|
||||||
addPermission(drive, driveFile);
|
addPermission(drive, driveFile);
|
||||||
@@ -101,7 +106,7 @@ public class SendDriveAsyncTask extends AbstractSendAsyncTask {
|
|||||||
|
|
||||||
// insert new drive file
|
// insert new drive file
|
||||||
File file = SyncUtils.insertDriveFile(
|
File file = SyncUtils.insertDriveFile(
|
||||||
drive, folderId, context, myTracksProviderUtils, track, false);
|
drive, folderId, context, myTracksProviderUtils, track, false, sameAccount);
|
||||||
if (file == null) {
|
if (file == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,9 +38,8 @@ public class SendRequest implements Parcelable {
|
|||||||
|
|
||||||
private boolean driveSync = false; // to enable Drive sync
|
private boolean driveSync = false; // to enable Drive sync
|
||||||
private boolean driveSyncConfirm = false;
|
private boolean driveSyncConfirm = false;
|
||||||
private boolean driveShare = false; // to enable Drive share
|
|
||||||
private String driveShareEmails = null; // for driveShare, emails to share
|
|
||||||
private boolean driveSharePublic = false; // for driveShare, share as public
|
private boolean driveSharePublic = false; // for driveShare, share as public
|
||||||
|
private String driveShareEmails = null; // for driveShare, emails to share
|
||||||
|
|
||||||
private Account account = null;
|
private Account account = null;
|
||||||
|
|
||||||
@@ -111,22 +110,6 @@ public class SendRequest implements Parcelable {
|
|||||||
this.driveSyncConfirm = driveSyncConfirm;
|
this.driveSyncConfirm = driveSyncConfirm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDriveShare() {
|
|
||||||
return driveShare;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDriveShare(boolean driveShare) {
|
|
||||||
this.driveShare = driveShare;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDriveShareEmails() {
|
|
||||||
return driveShareEmails;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDriveShareEmails(String driveShareEmails) {
|
|
||||||
this.driveShareEmails = driveShareEmails;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isDriveSharePublic() {
|
public boolean isDriveSharePublic() {
|
||||||
return driveSharePublic;
|
return driveSharePublic;
|
||||||
}
|
}
|
||||||
@@ -134,6 +117,14 @@ public class SendRequest implements Parcelable {
|
|||||||
public void setDriveSharePublic(boolean driveSharePublic) {
|
public void setDriveSharePublic(boolean driveSharePublic) {
|
||||||
this.driveSharePublic = driveSharePublic;
|
this.driveSharePublic = driveSharePublic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDriveShareEmails() {
|
||||||
|
return driveShareEmails;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDriveShareEmails(String driveShareEmails) {
|
||||||
|
this.driveShareEmails = driveShareEmails;
|
||||||
|
}
|
||||||
|
|
||||||
public Account getAccount() {
|
public Account getAccount() {
|
||||||
return account;
|
return account;
|
||||||
@@ -191,9 +182,8 @@ public class SendRequest implements Parcelable {
|
|||||||
sendSpreadsheets = in.readByte() == 1;
|
sendSpreadsheets = in.readByte() == 1;
|
||||||
driveSync = in.readByte() == 1;
|
driveSync = in.readByte() == 1;
|
||||||
driveSyncConfirm = in.readByte() == 1;
|
driveSyncConfirm = in.readByte() == 1;
|
||||||
driveShare = in.readByte() == 1;
|
|
||||||
driveShareEmails = in.readString();
|
|
||||||
driveSharePublic = in.readByte() == 1;
|
driveSharePublic = in.readByte() == 1;
|
||||||
|
driveShareEmails = in.readString();
|
||||||
account = in.readParcelable(null);
|
account = in.readParcelable(null);
|
||||||
driveSuccess = in.readByte() == 1;
|
driveSuccess = in.readByte() == 1;
|
||||||
mapsSuccess = in.readByte() == 1;
|
mapsSuccess = in.readByte() == 1;
|
||||||
@@ -216,9 +206,8 @@ public class SendRequest implements Parcelable {
|
|||||||
out.writeByte((byte) (sendSpreadsheets ? 1 : 0));
|
out.writeByte((byte) (sendSpreadsheets ? 1 : 0));
|
||||||
out.writeByte((byte) (driveSync ? 1 : 0));
|
out.writeByte((byte) (driveSync ? 1 : 0));
|
||||||
out.writeByte((byte) (driveSyncConfirm ? 1 : 0));
|
out.writeByte((byte) (driveSyncConfirm ? 1 : 0));
|
||||||
out.writeByte((byte) (driveShare ? 1 : 0));
|
|
||||||
out.writeString(driveShareEmails);
|
|
||||||
out.writeByte((byte) (driveSharePublic ? 1 : 0));
|
out.writeByte((byte) (driveSharePublic ? 1 : 0));
|
||||||
|
out.writeString(driveShareEmails);
|
||||||
out.writeParcelable(account, 0);
|
out.writeParcelable(account, 0);
|
||||||
out.writeByte((byte) (driveSuccess ? 1 : 0));
|
out.writeByte((byte) (driveSuccess ? 1 : 0));
|
||||||
out.writeByte((byte) (mapsSuccess ? 1 : 0));
|
out.writeByte((byte) (mapsSuccess ? 1 : 0));
|
||||||
|
|||||||
@@ -365,7 +365,8 @@ public class SyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// If not successful, the next sync will retry again
|
// If not successful, the next sync will retry again
|
||||||
SyncUtils.insertDriveFile(drive, folderId, context, myTracksProviderUtils, track, true);
|
SyncUtils.insertDriveFile(
|
||||||
|
drive, folderId, context, myTracksProviderUtils, track, true, true);
|
||||||
} while (cursor.moveToNext());
|
} while (cursor.moveToNext());
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@@ -298,10 +298,11 @@ public class SyncUtils {
|
|||||||
* @param myTracksProviderUtils the myTracksProviderUtils
|
* @param myTracksProviderUtils the myTracksProviderUtils
|
||||||
* @param track the track
|
* @param track the track
|
||||||
* @param canRetry true if can retry
|
* @param canRetry true if can retry
|
||||||
|
* @param updateTrack true to update track
|
||||||
* @return the added drive file or null.
|
* @return the added drive file or null.
|
||||||
*/
|
*/
|
||||||
public static File insertDriveFile(Drive drive, String folderId, Context context,
|
public static File insertDriveFile(Drive drive, String folderId, Context context,
|
||||||
MyTracksProviderUtils myTracksProviderUtils, Track track, boolean canRetry)
|
MyTracksProviderUtils myTracksProviderUtils, Track track, boolean canRetry, boolean updateTrack)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
java.io.File file = null;
|
java.io.File file = null;
|
||||||
try {
|
try {
|
||||||
@@ -318,7 +319,9 @@ public class SyncUtils {
|
|||||||
Log.e(TAG, "Unable to add Drive file. Uploaded file is null for track " + track.getName());
|
Log.e(TAG, "Unable to add Drive file. Uploaded file is null for track " + track.getName());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
SyncUtils.updateTrack(myTracksProviderUtils, track, uploadedFile);
|
if (updateTrack) {
|
||||||
|
SyncUtils.updateTrack(myTracksProviderUtils, track, uploadedFile);
|
||||||
|
}
|
||||||
return uploadedFile;
|
return uploadedFile;
|
||||||
} finally {
|
} finally {
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ public class PreferencesUtils {
|
|||||||
public static final String SENSOR_TYPE_DEFAULT = "NONE";
|
public static final String SENSOR_TYPE_DEFAULT = "NONE";
|
||||||
|
|
||||||
// Share track
|
// Share track
|
||||||
|
public static final String SHARE_TRACK_ACCOUNT_DEFAULT = "";
|
||||||
public static final boolean SHARE_TRACK_INVITE_DEFAULT = false;
|
public static final boolean SHARE_TRACK_INVITE_DEFAULT = false;
|
||||||
public static final boolean SHARE_TRACK_PUBLIC_DEFAULT = false;
|
public static final boolean SHARE_TRACK_PUBLIC_DEFAULT = false;
|
||||||
|
|
||||||
|
|||||||
+7
-16
@@ -130,7 +130,6 @@ 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.writeString(DRIVE_SHARE_EMAILS);
|
||||||
parcel.writeByte((byte) 1);
|
|
||||||
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
|
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
|
||||||
parcel.writeParcelable(account, 0);
|
parcel.writeParcelable(account, 0);
|
||||||
parcel.writeByte((byte) 1);
|
parcel.writeByte((byte) 1);
|
||||||
@@ -147,9 +146,8 @@ public class SendRequestTest extends AndroidTestCase {
|
|||||||
assertTrue(sendRequest.isSendSpreadsheets());
|
assertTrue(sendRequest.isSendSpreadsheets());
|
||||||
assertTrue(sendRequest.isDriveSync());
|
assertTrue(sendRequest.isDriveSync());
|
||||||
assertTrue(sendRequest.isDriveSyncConfirm());
|
assertTrue(sendRequest.isDriveSyncConfirm());
|
||||||
assertTrue(sendRequest.isDriveShare());
|
|
||||||
assertEquals(DRIVE_SHARE_EMAILS, sendRequest.getDriveShareEmails());
|
|
||||||
assertTrue(sendRequest.isDriveSharePublic());
|
assertTrue(sendRequest.isDriveSharePublic());
|
||||||
|
assertEquals(DRIVE_SHARE_EMAILS, sendRequest.getDriveShareEmails());
|
||||||
assertEquals(account, sendRequest.getAccount());
|
assertEquals(account, sendRequest.getAccount());
|
||||||
assertTrue(sendRequest.isDriveSuccess());
|
assertTrue(sendRequest.isDriveSuccess());
|
||||||
assertTrue(sendRequest.isMapsSuccess());
|
assertTrue(sendRequest.isMapsSuccess());
|
||||||
@@ -173,7 +171,6 @@ 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.writeString(null);
|
||||||
parcel.writeByte((byte) 0);
|
|
||||||
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
|
Account account = new Account(ACCOUNTNAME, ACCOUNTYPE);
|
||||||
parcel.writeParcelable(account, 0);
|
parcel.writeParcelable(account, 0);
|
||||||
parcel.writeByte((byte) 0);
|
parcel.writeByte((byte) 0);
|
||||||
@@ -190,9 +187,8 @@ public class SendRequestTest extends AndroidTestCase {
|
|||||||
assertFalse(sendRequest.isSendSpreadsheets());
|
assertFalse(sendRequest.isSendSpreadsheets());
|
||||||
assertFalse(sendRequest.isDriveSync());
|
assertFalse(sendRequest.isDriveSync());
|
||||||
assertFalse(sendRequest.isDriveSyncConfirm());
|
assertFalse(sendRequest.isDriveSyncConfirm());
|
||||||
assertFalse(sendRequest.isDriveShare());
|
|
||||||
assertNull(sendRequest.getDriveShareEmails());
|
|
||||||
assertFalse(sendRequest.isDriveSharePublic());
|
assertFalse(sendRequest.isDriveSharePublic());
|
||||||
|
assertNull(sendRequest.getDriveShareEmails());
|
||||||
assertEquals(account, sendRequest.getAccount());
|
assertEquals(account, sendRequest.getAccount());
|
||||||
assertFalse(sendRequest.isDriveSuccess());
|
assertFalse(sendRequest.isDriveSuccess());
|
||||||
assertFalse(sendRequest.isMapsSuccess());
|
assertFalse(sendRequest.isMapsSuccess());
|
||||||
@@ -217,9 +213,8 @@ public class SendRequestTest extends AndroidTestCase {
|
|||||||
boolean sendSpreadsheets = parcel.readByte() == 1;
|
boolean sendSpreadsheets = parcel.readByte() == 1;
|
||||||
boolean driveSync = parcel.readByte() == 1;
|
boolean driveSync = parcel.readByte() == 1;
|
||||||
boolean driveSyncConfirm = parcel.readByte() == 1;
|
boolean driveSyncConfirm = parcel.readByte() == 1;
|
||||||
boolean driveShare = parcel.readByte() == 1;
|
|
||||||
String dirveShareEmails = parcel.readString();
|
|
||||||
boolean driveSharePublic = parcel.readByte() == 1;
|
boolean driveSharePublic = parcel.readByte() == 1;
|
||||||
|
String dirveShareEmails = parcel.readString();
|
||||||
Parcelable account = parcel.readParcelable(null);
|
Parcelable account = parcel.readParcelable(null);
|
||||||
boolean driveSuccess = parcel.readByte() == 1;
|
boolean driveSuccess = parcel.readByte() == 1;
|
||||||
boolean mapsSuccess = parcel.readByte() == 1;
|
boolean mapsSuccess = parcel.readByte() == 1;
|
||||||
@@ -233,9 +228,8 @@ public class SendRequestTest extends AndroidTestCase {
|
|||||||
assertFalse(sendSpreadsheets);
|
assertFalse(sendSpreadsheets);
|
||||||
assertFalse(driveSync);
|
assertFalse(driveSync);
|
||||||
assertFalse(driveSyncConfirm);
|
assertFalse(driveSyncConfirm);
|
||||||
assertFalse(driveShare);
|
|
||||||
assertNull(dirveShareEmails);
|
|
||||||
assertFalse(driveSharePublic);
|
assertFalse(driveSharePublic);
|
||||||
|
assertNull(dirveShareEmails);
|
||||||
assertNull(account);
|
assertNull(account);
|
||||||
assertFalse(driveSuccess);
|
assertFalse(driveSuccess);
|
||||||
assertFalse(mapsSuccess);
|
assertFalse(mapsSuccess);
|
||||||
@@ -255,9 +249,8 @@ public class SendRequestTest extends AndroidTestCase {
|
|||||||
sendRequest.setSendSpreadsheets(true);
|
sendRequest.setSendSpreadsheets(true);
|
||||||
sendRequest.setDriveSync(true);
|
sendRequest.setDriveSync(true);
|
||||||
sendRequest.setDriveSyncConfirm(true);
|
sendRequest.setDriveSyncConfirm(true);
|
||||||
sendRequest.setDriveShare(true);
|
|
||||||
sendRequest.setDriveShareEmails(DRIVE_SHARE_EMAILS);
|
|
||||||
sendRequest.setDriveSharePublic(true);
|
sendRequest.setDriveSharePublic(true);
|
||||||
|
sendRequest.setDriveShareEmails(DRIVE_SHARE_EMAILS);
|
||||||
Account accountNew = new Account(ACCOUNTNAME + "2", ACCOUNTYPE + "2");
|
Account accountNew = new Account(ACCOUNTNAME + "2", ACCOUNTYPE + "2");
|
||||||
sendRequest.setAccount(accountNew);
|
sendRequest.setAccount(accountNew);
|
||||||
sendRequest.setMapsSuccess(true);
|
sendRequest.setMapsSuccess(true);
|
||||||
@@ -276,9 +269,8 @@ public class SendRequestTest extends AndroidTestCase {
|
|||||||
boolean sendSpreadsheets = parcel.readByte() == 1;
|
boolean sendSpreadsheets = parcel.readByte() == 1;
|
||||||
boolean driveSync = parcel.readByte() == 1;
|
boolean driveSync = parcel.readByte() == 1;
|
||||||
boolean driveSyncConfirm = parcel.readByte() == 1;
|
boolean driveSyncConfirm = parcel.readByte() == 1;
|
||||||
boolean driveShare = parcel.readByte() == 1;
|
|
||||||
String driveShareEmails = parcel.readString();
|
|
||||||
boolean driveSharePublic = parcel.readByte() == 1;
|
boolean driveSharePublic = parcel.readByte() == 1;
|
||||||
|
String driveShareEmails = parcel.readString();
|
||||||
Parcelable account = parcel.readParcelable(null);
|
Parcelable account = parcel.readParcelable(null);
|
||||||
boolean driveSuccess = parcel.readByte() == 1;
|
boolean driveSuccess = parcel.readByte() == 1;
|
||||||
boolean mapsSuccess = parcel.readByte() == 1;
|
boolean mapsSuccess = parcel.readByte() == 1;
|
||||||
@@ -292,9 +284,8 @@ public class SendRequestTest extends AndroidTestCase {
|
|||||||
assertTrue(sendSpreadsheets);
|
assertTrue(sendSpreadsheets);
|
||||||
assertTrue(driveSync);
|
assertTrue(driveSync);
|
||||||
assertTrue(driveSyncConfirm);
|
assertTrue(driveSyncConfirm);
|
||||||
assertTrue(driveShare);
|
|
||||||
assertEquals(DRIVE_SHARE_EMAILS, driveShareEmails);
|
|
||||||
assertTrue(driveSharePublic);
|
assertTrue(driveSharePublic);
|
||||||
|
assertEquals(DRIVE_SHARE_EMAILS, driveShareEmails);
|
||||||
assertEquals(accountNew, account);
|
assertEquals(accountNew, account);
|
||||||
assertTrue(driveSuccess);
|
assertTrue(driveSuccess);
|
||||||
assertTrue(mapsSuccess);
|
assertTrue(mapsSuccess);
|
||||||
|
|||||||
Reference in New Issue
Block a user