Code cleanup: rename to ConfirmSyncDialogFragment

This commit is contained in:
Jimmy Shih
2013-06-24 10:57:29 -07:00
parent 636ffbf39a
commit 27cea61edb
4 changed files with 54 additions and 38 deletions
+14 -14
View File
@@ -556,19 +556,6 @@ limitations under the License.
Segment Segment
</string> </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.">
This will allow you to view your tracks in Google Drive and view the 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 --> <!-- Eula -->
<string name="eula_accept" <string name="eula_accept"
translation_description="In the 'Terms of Service' dialog, the button to accept."> translation_description="In the 'Terms of Service' dialog, the button to accept.">
@@ -2176,7 +2163,20 @@ limitations under the License.
translation_description="In the 'Stats' page, the total time."> translation_description="In the 'Stats' page, the total time.">
Total time Total time
</string> </string>
<!-- Sync -->
<string name="sync_enable_message"
translation_description="The dialog message asking the user if he wants to enable sync with
Google Drive.">
This will allow you to view your tracks in Google Drive and view the tracks shared with you. All
tracks synced to Google Drive will be private by default.
</string>
<string name="sync_enable_title"
translation_description="The dialog title asking the user if he wants to enable sync with Google
Drive.">
Sync with Google Drive?
</string>
<!-- Track --> <!-- Track -->
<string name="track_name_format" <string name="track_name_format"
translation_description="When creating a new track, the string format to name the track. translation_description="When creating a new track, the string format to name the track.
@@ -19,10 +19,10 @@ package com.google.android.apps.mytracks;
import com.google.android.apps.mytracks.content.MyTracksProviderUtils; import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
import com.google.android.apps.mytracks.content.Track; import com.google.android.apps.mytracks.content.Track;
import com.google.android.apps.mytracks.content.TracksColumns; import com.google.android.apps.mytracks.content.TracksColumns;
import com.google.android.apps.mytracks.fragments.ConfirmSyncDialogFragment;
import com.google.android.apps.mytracks.fragments.ConfirmSyncDialogFragment.ConfirmSyncCaller;
import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment; import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment;
import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment.DeleteTrackCaller; import com.google.android.apps.mytracks.fragments.DeleteTrackDialogFragment.DeleteTrackCaller;
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;
import com.google.android.apps.mytracks.fragments.EulaDialogFragment.EulaCaller; import com.google.android.apps.mytracks.fragments.EulaDialogFragment.EulaCaller;
import com.google.android.apps.mytracks.fragments.FileTypeDialogFragment; import com.google.android.apps.mytracks.fragments.FileTypeDialogFragment;
@@ -93,7 +93,7 @@ import java.util.Locale;
* @author Leif Hendrik Wilden * @author Leif Hendrik Wilden
*/ */
public class TrackListActivity extends AbstractSendToGoogleActivity public class TrackListActivity extends AbstractSendToGoogleActivity
implements EulaCaller, EnableSyncCaller, DeleteTrackCaller, FileTypeCaller { implements EulaCaller, ConfirmSyncCaller, DeleteTrackCaller, FileTypeCaller {
private static final String TAG = TrackListActivity.class.getSimpleName(); private static final String TAG = TrackListActivity.class.getSimpleName();
private static final int GOOGLE_PLAY_SERVICES_REQUEST_CODE = 0; private static final int GOOGLE_PLAY_SERVICES_REQUEST_CODE = 0;
@@ -693,16 +693,17 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
private void showEnableSync() { private void showEnableSync() {
if (EulaUtils.getShowEnableSync(this)) { if (EulaUtils.getShowEnableSync(this)) {
Fragment fragment = getSupportFragmentManager() Fragment fragment = getSupportFragmentManager()
.findFragmentByTag(EnableSyncDialogFragment.ENABLE_SYNC_DIALOG_TAG); .findFragmentByTag(ConfirmSyncDialogFragment.CONFIRM_SYNC_DIALOG_TAG);
if (fragment == null) { if (fragment == null) {
new EnableSyncDialogFragment().show( ConfirmSyncDialogFragment.newInstance(
getSupportFragmentManager(), EnableSyncDialogFragment.ENABLE_SYNC_DIALOG_TAG); R.string.sync_enable_title, getString(R.string.sync_enable_message))
.show(getSupportFragmentManager(), ConfirmSyncDialogFragment.CONFIRM_SYNC_DIALOG_TAG);
} }
} }
} }
@Override @Override
public void onEnableSyncDone(boolean enable) { public void onConfirmSyncDone(boolean enable) {
EulaUtils.setShowEnableSync(this); EulaUtils.setShowEnableSync(this);
if (enable) { if (enable) {
SendRequest sendRequest = new SendRequest(-1L); SendRequest sendRequest = new SendRequest(-1L);
@@ -29,38 +29,51 @@ import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity; import android.support.v4.app.FragmentActivity;
/** /**
* A DialogFrament to enable sync. * A DialogFrament to confirm sync to Google Drive.
* *
* @author Jimmy Shih * @author Jimmy Shih
*/ */
public class EnableSyncDialogFragment extends DialogFragment { public class ConfirmSyncDialogFragment extends DialogFragment {
/** /**
* Interface for caller of this dialog fragment. * Interface for caller of this dialog fragment.
* *
* @author Jimmy Shih * @author Jimmy Shih
*/ */
public interface EnableSyncCaller { public interface ConfirmSyncCaller {
/** /**
* Called when enable sync is done. * Called when confirm sync is done.
*/ */
public void onEnableSyncDone(boolean enable); public void onConfirmSyncDone(boolean enable);
} }
public static final String ENABLE_SYNC_DIALOG_TAG = "enableSyncDialog"; public static final String CONFIRM_SYNC_DIALOG_TAG = "confirmSyncDialog";
private EnableSyncCaller caller; private static final String KEY_TITLE_ID = "titleId";
private static final String KEY_MESSAGE = "message";
private ConfirmSyncCaller caller;
private FragmentActivity fragmentActivity; private FragmentActivity fragmentActivity;
public static ConfirmSyncDialogFragment newInstance(int titleId, String message) {
Bundle bundle = new Bundle();
bundle.putInt(KEY_TITLE_ID, titleId);
bundle.putString(KEY_MESSAGE, message);
ConfirmSyncDialogFragment confirmSyncDialogFragment = new ConfirmSyncDialogFragment();
confirmSyncDialogFragment.setArguments(bundle);
return confirmSyncDialogFragment;
}
@Override @Override
public void onAttach(Activity activity) { public void onAttach(Activity activity) {
super.onAttach(activity); super.onAttach(activity);
try { try {
caller = (EnableSyncCaller) activity; caller = (ConfirmSyncCaller) activity;
} catch (ClassCastException e) { } catch (ClassCastException e) {
throw new ClassCastException( throw new ClassCastException(
activity.toString() + " must implement " + EnableSyncCaller.class.getSimpleName()); activity.toString() + " must implement " + ConfirmSyncCaller.class.getSimpleName());
} }
} }
@@ -71,29 +84,31 @@ public class EnableSyncDialogFragment extends DialogFragment {
if (PreferencesUtils.getBoolean( if (PreferencesUtils.getBoolean(
fragmentActivity, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT)) { fragmentActivity, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT)) {
dismiss(); dismiss();
caller.onEnableSyncDone(false); caller.onConfirmSyncDone(false);
return; return;
} }
} }
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(fragmentActivity).setMessage(R.string.enable_sync_message) int titleId = getArguments().getInt(KEY_TITLE_ID);
String message = getArguments().getString(KEY_MESSAGE);
return new AlertDialog.Builder(fragmentActivity).setMessage(message)
.setNegativeButton(R.string.generic_no, new OnClickListener() { .setNegativeButton(R.string.generic_no, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
caller.onEnableSyncDone(false); caller.onConfirmSyncDone(false);
} }
}).setPositiveButton(R.string.generic_yes, new OnClickListener() { }).setPositiveButton(R.string.generic_yes, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
caller.onEnableSyncDone(true); caller.onConfirmSyncDone(true);
} }
}).setTitle(R.string.enable_sync_title).create(); }).setTitle(titleId).create();
} }
@Override @Override
public void onCancel(DialogInterface arg0) { public void onCancel(DialogInterface arg0) {
caller.onEnableSyncDone(false); caller.onConfirmSyncDone(false);
} }
} }
@@ -340,7 +340,7 @@ public class EndToEndTestUtils {
if ((getButtonOnScreen(activityMytracks.getString(R.string.eula_accept), false, false) != null)) { if ((getButtonOnScreen(activityMytracks.getString(R.string.eula_accept), false, false) != null)) {
getButtonOnScreen(activityMytracks.getString(R.string.eula_accept), true, true); getButtonOnScreen(activityMytracks.getString(R.string.eula_accept), true, true);
} }
if (SOLO.waitForText(activityMytracks.getString(R.string.enable_sync_title))) { if (SOLO.waitForText(activityMytracks.getString(R.string.sync_enable_title))) {
// Click for Sync with Google Drive(Don't enable sync as default). // Click for Sync with Google Drive(Don't enable sync as default).
getButtonOnScreen(activityMytracks.getString(R.string.generic_no), true, true); getButtonOnScreen(activityMytracks.getString(R.string.generic_no), true, true);
instrumentation.waitForIdleSync(); instrumentation.waitForIdleSync();