forked from upstream-mirrors/OpenTracks
Improve transition after deleting a track or a marker.
This commit is contained in:
+35
-17
@@ -16,23 +16,21 @@
|
||||
|
||||
package com.google.android.apps.mytracks.fragments;
|
||||
|
||||
import com.google.android.apps.mytracks.MarkerListActivity;
|
||||
import com.google.android.apps.mytracks.content.DescriptionGeneratorImpl;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.util.DialogUtils;
|
||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
|
||||
/**
|
||||
* A DialogFragment to delete one marker.
|
||||
*
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public class DeleteOneMarkerDialogFragment extends DialogFragment {
|
||||
@@ -41,6 +39,19 @@ public class DeleteOneMarkerDialogFragment extends DialogFragment {
|
||||
private static final String KEY_MARKER_ID = "markerId";
|
||||
private static final String KEY_TRACK_ID = "trackId";
|
||||
|
||||
/**
|
||||
* Interface for caller of this dialog fragment.
|
||||
*
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public interface DeleteOneMarkerCaller {
|
||||
|
||||
/**
|
||||
* Called when a marker is deleted.
|
||||
*/
|
||||
public void onMarkerDeleted();
|
||||
}
|
||||
|
||||
public static DeleteOneMarkerDialogFragment newInstance(long markerId, long trackId) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putLong(KEY_MARKER_ID, markerId);
|
||||
@@ -51,28 +62,35 @@ public class DeleteOneMarkerDialogFragment extends DialogFragment {
|
||||
return deleteOneMarkerDialogFragment;
|
||||
}
|
||||
|
||||
private FragmentActivity activity;
|
||||
|
||||
private FragmentActivity fragmentActivity;
|
||||
private DeleteOneMarkerCaller caller;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
try {
|
||||
caller = (DeleteOneMarkerCaller) activity;
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException(activity.toString() + " must implement DeleteOneMarkerCaller");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
activity = getActivity();
|
||||
return DialogUtils.createConfirmationDialog(activity,
|
||||
fragmentActivity = getActivity();
|
||||
return DialogUtils.createConfirmationDialog(fragmentActivity,
|
||||
R.string.marker_delete_one_marker_confirm_message, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
@Override
|
||||
public void run() {
|
||||
MyTracksProviderUtils.Factory.get(activity).deleteWaypoint(
|
||||
MyTracksProviderUtils.Factory.get(fragmentActivity).deleteWaypoint(
|
||||
getArguments().getLong(KEY_MARKER_ID),
|
||||
new DescriptionGeneratorImpl(activity));
|
||||
new DescriptionGeneratorImpl(fragmentActivity));
|
||||
caller.onMarkerDeleted();
|
||||
}
|
||||
}).start();
|
||||
Intent intent = IntentUtils.newIntent(activity, MarkerListActivity.class)
|
||||
.putExtra(MarkerListActivity.EXTRA_TRACK_ID, getArguments().getLong(KEY_TRACK_ID));
|
||||
startActivity(intent);
|
||||
// Close the activity since its content can change after delete.
|
||||
activity.finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+22
-20
@@ -16,20 +16,16 @@
|
||||
|
||||
package com.google.android.apps.mytracks.fragments;
|
||||
|
||||
import com.google.android.apps.mytracks.TrackListActivity;
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.services.TrackRecordingServiceConnection;
|
||||
import com.google.android.apps.mytracks.util.DialogUtils;
|
||||
import com.google.android.apps.mytracks.util.IntentUtils;
|
||||
import com.google.android.apps.mytracks.util.PreferencesUtils;
|
||||
import com.google.android.apps.mytracks.util.TrackRecordingServiceConnectionUtils;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
@@ -50,7 +46,16 @@ public class DeleteOneTrackDialogFragment extends DialogFragment {
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public interface DeleteOneTrackCaller {
|
||||
|
||||
/**
|
||||
* Gets the track recording service connection.
|
||||
*/
|
||||
public TrackRecordingServiceConnection getTrackRecordingServiceConnection();
|
||||
|
||||
/**
|
||||
* Called when a track is deleted.
|
||||
*/
|
||||
public void onTrackDeleted();
|
||||
}
|
||||
|
||||
public static DeleteOneTrackDialogFragment newInstance(long trackId) {
|
||||
@@ -62,42 +67,39 @@ public class DeleteOneTrackDialogFragment extends DialogFragment {
|
||||
return deleteOneTrackDialogFragment;
|
||||
}
|
||||
|
||||
private FragmentActivity activity;
|
||||
private FragmentActivity fragmentActivity;
|
||||
private DeleteOneTrackCaller caller;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity anActivity) {
|
||||
super.onAttach(anActivity);
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
try {
|
||||
caller = (DeleteOneTrackCaller) anActivity;
|
||||
caller = (DeleteOneTrackCaller) activity;
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException(anActivity.toString() + " must implement DeleteOneTrackCaller");
|
||||
throw new ClassCastException(activity.toString() + " must implement DeleteOneTrackCaller");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
activity = getActivity();
|
||||
return DialogUtils.createConfirmationDialog(activity,
|
||||
fragmentActivity = getActivity();
|
||||
return DialogUtils.createConfirmationDialog(fragmentActivity,
|
||||
R.string.track_detail_delete_confirm_message, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final long trackId = getArguments().getLong(KEY_TRACK_ID);
|
||||
final Context context = activity;
|
||||
if (trackId == PreferencesUtils.getLong(context, R.string.recording_track_id_key)) {
|
||||
if (trackId
|
||||
== PreferencesUtils.getLong(fragmentActivity, R.string.recording_track_id_key)) {
|
||||
TrackRecordingServiceConnectionUtils.stopRecording(
|
||||
context, caller.getTrackRecordingServiceConnection(), false);
|
||||
fragmentActivity, caller.getTrackRecordingServiceConnection(), false);
|
||||
}
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
@Override
|
||||
public void run() {
|
||||
MyTracksProviderUtils.Factory.get(context).deleteTrack(trackId);
|
||||
MyTracksProviderUtils.Factory.get(fragmentActivity).deleteTrack(trackId);
|
||||
caller.onTrackDeleted();
|
||||
}
|
||||
}).start();
|
||||
Intent intent = IntentUtils.newIntent(context, TrackListActivity.class);
|
||||
startActivity(intent);
|
||||
// Close the activity since its content can change after delete
|
||||
activity.finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user