forked from upstream-mirrors/OpenTracks
Code cleanup: rename to ConfirmSyncDialogFragment
This commit is contained in:
+31
-16
@@ -29,38 +29,51 @@ import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
||||
/**
|
||||
* A DialogFrament to enable sync.
|
||||
* A DialogFrament to confirm sync to Google Drive.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class EnableSyncDialogFragment extends DialogFragment {
|
||||
public class ConfirmSyncDialogFragment extends DialogFragment {
|
||||
|
||||
/**
|
||||
* Interface for caller of this dialog fragment.
|
||||
*
|
||||
* @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;
|
||||
|
||||
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
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
try {
|
||||
caller = (EnableSyncCaller) activity;
|
||||
caller = (ConfirmSyncCaller) activity;
|
||||
} catch (ClassCastException e) {
|
||||
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(
|
||||
fragmentActivity, R.string.drive_sync_key, PreferencesUtils.DRIVE_SYNC_DEFAULT)) {
|
||||
dismiss();
|
||||
caller.onEnableSyncDone(false);
|
||||
caller.onConfirmSyncDone(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
caller.onEnableSyncDone(false);
|
||||
caller.onConfirmSyncDone(false);
|
||||
}
|
||||
}).setPositiveButton(R.string.generic_yes, new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
caller.onEnableSyncDone(true);
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
caller.onConfirmSyncDone(true);
|
||||
}
|
||||
}).setTitle(R.string.enable_sync_title).create();
|
||||
}).setTitle(titleId).create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface arg0) {
|
||||
caller.onEnableSyncDone(false);
|
||||
caller.onConfirmSyncDone(false);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user