forked from upstream-mirrors/OpenTracks
Update the contextual action menu to not show edit option
for "Shared with me" tracks and markers. Also not show the delete option for markers from "Shared with me" tracks.
This commit is contained in:
@@ -22,7 +22,7 @@ package com.google.android.apps.mytracks;
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
public interface ContextualActionModeCallback {
|
||||
|
||||
|
||||
/**
|
||||
* Invoked when an item is selected.
|
||||
*
|
||||
@@ -31,4 +31,20 @@ public interface ContextualActionModeCallback {
|
||||
* @param id the id of the selected row, if available
|
||||
*/
|
||||
public boolean onClick(int itemId, int position, long id);
|
||||
|
||||
/**
|
||||
* True if the item in the selected row can be edited.
|
||||
*
|
||||
* @param position the position of the selected row
|
||||
* @param id the id of the selected row
|
||||
*/
|
||||
public boolean canEdit(int position, long id);
|
||||
|
||||
/**
|
||||
* True if the item in the selected row can be deleted.
|
||||
*
|
||||
* @param position the position of the selected row
|
||||
* @param id the id of the selected row
|
||||
*/
|
||||
public boolean canDelete(int position, long id);
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.google.android.apps.mytracks;
|
||||
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.content.Waypoint.WaypointType;
|
||||
import com.google.android.apps.mytracks.content.WaypointsColumns;
|
||||
import com.google.android.apps.mytracks.fragments.DeleteOneMarkerDialogFragment;
|
||||
@@ -71,6 +72,18 @@ public class MarkerListActivity extends AbstractMyTracksActivity {
|
||||
public boolean onClick(int itemId, int position, long id) {
|
||||
return handleContextItem(itemId, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEdit(int position, long id) {
|
||||
Track track = myTracksProviderUtils.getTrack(trackId);
|
||||
return !track.isSharedWithMe();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDelete(int poistion, long id) {
|
||||
Track track = myTracksProviderUtils.getTrack(trackId);
|
||||
return !track.isSharedWithMe();
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
@@ -104,6 +117,7 @@ public class MarkerListActivity extends AbstractMyTracksActivity {
|
||||
}
|
||||
};
|
||||
|
||||
private MyTracksProviderUtils myTracksProviderUtils;
|
||||
private SharedPreferences sharedPreferences;
|
||||
|
||||
private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
||||
@@ -120,6 +134,7 @@ public class MarkerListActivity extends AbstractMyTracksActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this);
|
||||
sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L);
|
||||
if (trackId == -1L) {
|
||||
@@ -167,8 +182,7 @@ public class MarkerListActivity extends AbstractMyTracksActivity {
|
||||
ApiAdapterFactory.getApiAdapter()
|
||||
.configureListViewContextualMenu(this, listView, contextualActionModeCallback);
|
||||
|
||||
final long firstWaypointId = MyTracksProviderUtils.Factory.get(this)
|
||||
.getFirstWaypointId(trackId);
|
||||
final long firstWaypointId = myTracksProviderUtils.getFirstWaypointId(trackId);
|
||||
getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() {
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
|
||||
|
||||
@@ -128,11 +128,32 @@ public class SearchListActivity extends AbstractMyTracksActivity implements Dele
|
||||
public boolean onClick(int itemId, int position, long id) {
|
||||
return handleContextItem(itemId, position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEdit(int position, long id) {
|
||||
Map<String, Object> item = arrayAdapter.getItem(position);
|
||||
Long trackId = (Long) item.get(TRACK_ID_FIELD);
|
||||
Track track = myTracksProviderUtils.getTrack(trackId);
|
||||
return !track.isSharedWithMe();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDelete(int position, long id) {
|
||||
Map<String, Object> item = arrayAdapter.getItem(position);
|
||||
Long trackId = (Long) item.get(TRACK_ID_FIELD);
|
||||
Long markerId = (Long) item.get(MARKER_ID_FIELD);
|
||||
if (markerId != null) {
|
||||
Track track = myTracksProviderUtils.getTrack(trackId);
|
||||
return !track.isSharedWithMe();
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private MyTracksProviderUtils myTracksProviderUtils;
|
||||
private SharedPreferences sharedPreferences;
|
||||
private TrackRecordingServiceConnection trackRecordingServiceConnection;
|
||||
private MyTracksProviderUtils myTracksProviderUtils;
|
||||
private SearchEngine searchEngine;
|
||||
private SearchRecentSuggestions searchRecentSuggestions;
|
||||
private MyTracksLocationManager myTracksLocationManager;
|
||||
@@ -151,9 +172,9 @@ public class SearchListActivity extends AbstractMyTracksActivity implements Dele
|
||||
super.onCreate(savedInstanceState);
|
||||
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
||||
|
||||
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this);
|
||||
sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, null);
|
||||
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this);
|
||||
searchEngine = new SearchEngine(myTracksProviderUtils);
|
||||
searchRecentSuggestions = SearchEngineProvider.newHelper(this);
|
||||
myTracksLocationManager = new MyTracksLocationManager(this);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.google.android.apps.mytracks;
|
||||
|
||||
import com.google.android.apps.mytracks.content.MyTracksProviderUtils;
|
||||
import com.google.android.apps.mytracks.content.Track;
|
||||
import com.google.android.apps.mytracks.content.TrackDataHub;
|
||||
import com.google.android.apps.mytracks.content.TrackDataListener;
|
||||
@@ -194,6 +195,17 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac
|
||||
public boolean onClick(int itemId, int position, long id) {
|
||||
return handleContextItem(itemId, id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEdit(int position, long id) {
|
||||
Track track = myTracksProviderUtils.getTrack(id);
|
||||
return !track.isSharedWithMe();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDelete(int position, long id) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
private final OnClickListener recordListener = new OnClickListener() {
|
||||
@@ -316,6 +328,7 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac
|
||||
};
|
||||
|
||||
// The following are set in onCreate
|
||||
private MyTracksProviderUtils myTracksProviderUtils;
|
||||
private SharedPreferences sharedPreferences;
|
||||
private TrackRecordingServiceConnection trackRecordingServiceConnection;
|
||||
private TrackController trackController;
|
||||
@@ -347,6 +360,7 @@ public class TrackListActivity extends FragmentActivity implements DeleteOneTrac
|
||||
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
||||
setContentView(R.layout.track_list);
|
||||
|
||||
myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this);
|
||||
sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(
|
||||
|
||||
@@ -73,8 +73,12 @@ public class Api11Adapter extends Api10Adapter {
|
||||
}
|
||||
@Override
|
||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||
// Return false to indicate no change.
|
||||
return false;
|
||||
menu.findItem(R.id.list_context_menu_edit)
|
||||
.setVisible(contextualActionModeCallback.canEdit(position, id));
|
||||
menu.findItem(R.id.list_context_menu_delete)
|
||||
.setVisible(contextualActionModeCallback.canDelete(position, id));
|
||||
// Return true to indicate change
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void onDestroyActionMode(ActionMode mode) {
|
||||
|
||||
Reference in New Issue
Block a user