mirror of
https://codeberg.org/OpenTracksApp/OpenTracks.git
synced 2026-10-03 18:03:06 +02:00
Move select all in multiple select to an action bar item
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.5 KiB |
@@ -40,4 +40,9 @@ limitations under the License.
|
||||
android:id="@+id/list_context_menu_delete"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/menu_delete"/>
|
||||
<item
|
||||
android:icon="@drawable/menu_select_all"
|
||||
android:id="@+id/list_context_menu_select_all"
|
||||
android:showAsAction="ifRoom"
|
||||
android:title="@string/menu_select_all"/>
|
||||
</menu>
|
||||
@@ -953,19 +953,11 @@ limitations under the License.
|
||||
</string>
|
||||
|
||||
<!-- List item -->
|
||||
<string name="list_deselect_all"
|
||||
translation_description="Option to deselect all the items in a list.">
|
||||
Deselect all
|
||||
</string>
|
||||
<string name="list_item_selected"
|
||||
translation_description="Title indicating the number of items selected in a list.
|
||||
%1$d: an integer value. E.g., '2'.">
|
||||
%1$d selected
|
||||
</string>
|
||||
<string name="list_select_all"
|
||||
translation_description="Option to select all the items in a list.">
|
||||
Select all
|
||||
</string>
|
||||
|
||||
<!-- Marker -->
|
||||
<string name="marker_add_error"
|
||||
@@ -1155,6 +1147,12 @@ limitations under the License.
|
||||
Character limit: ~20 (1 line)">
|
||||
Search
|
||||
</string>
|
||||
<string name="menu_select_all"
|
||||
translation_description="In the menu, to select all the items.
|
||||
|
||||
Character limit: ~20 (1 line)">
|
||||
Select all
|
||||
</string>
|
||||
<string name="menu_sensor_state"
|
||||
translation_description="In the menu, to go to the sensor state page.
|
||||
|
||||
@@ -2015,7 +2013,7 @@ limitations under the License.
|
||||
translation_description="When sharing a track, error message indicating that no email addresses
|
||||
is entered.">
|
||||
No email addresses entered.
|
||||
</string>
|
||||
</string>
|
||||
<string name="share_track_no_selection"
|
||||
translation_description="When sharing a track, error message indicating that no option is
|
||||
selected.">
|
||||
|
||||
@@ -31,8 +31,9 @@ public interface ContextualActionModeCallback {
|
||||
* @param menu the menu
|
||||
* @param positions the selected items' positions
|
||||
* @param ids the selected items' ids, if available
|
||||
* @param showSelectAll true to show select all
|
||||
*/
|
||||
public void onPrepare(Menu menu, int[] positions, long[] ids);
|
||||
public void onPrepare(Menu menu, int[] positions, long[] ids, boolean showSelectAll);
|
||||
|
||||
/**
|
||||
* Invoked when items are selected.
|
||||
|
||||
@@ -69,13 +69,19 @@ public class MarkerListActivity extends AbstractMyTracksActivity implements Dele
|
||||
private ContextualActionModeCallback
|
||||
contextualActionModeCallback = new ContextualActionModeCallback() {
|
||||
@Override
|
||||
public void onPrepare(Menu menu, int[] positions, long[] ids) {
|
||||
public void onPrepare(Menu menu, int[] positions, long[] ids, boolean showSelectAll) {
|
||||
menu.findItem(R.id.list_context_menu_play).setVisible(false);
|
||||
menu.findItem(R.id.list_context_menu_share).setVisible(false);
|
||||
menu.findItem(R.id.list_context_menu_show_on_map).setVisible(ids.length == 1);
|
||||
menu.findItem(R.id.list_context_menu_edit)
|
||||
.setVisible(ids.length == 1 && !track.isSharedWithMe());
|
||||
menu.findItem(R.id.list_context_menu_delete).setVisible(!track.isSharedWithMe());
|
||||
/*
|
||||
* Set select all to the same visibility as delete since delete is the
|
||||
* only action that can be applied to multiple markers.
|
||||
*/
|
||||
menu.findItem(R.id.list_context_menu_select_all)
|
||||
.setVisible(showSelectAll && !track.isSharedWithMe());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -125,6 +131,7 @@ public class MarkerListActivity extends AbstractMyTracksActivity implements Dele
|
||||
private ResourceCursorAdapter resourceCursorAdapter;
|
||||
|
||||
// UI elements
|
||||
private ListView listView;
|
||||
private MenuItem insertMarkerMenuItem;
|
||||
private MenuItem searchMenuItem;
|
||||
|
||||
@@ -144,7 +151,7 @@ public class MarkerListActivity extends AbstractMyTracksActivity implements Dele
|
||||
|
||||
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
||||
|
||||
ListView listView = (ListView) findViewById(R.id.marker_list);
|
||||
listView = (ListView) findViewById(R.id.marker_list);
|
||||
listView.setEmptyView(findViewById(R.id.marker_list_empty));
|
||||
listView.setOnItemClickListener(new OnItemClickListener() {
|
||||
@Override
|
||||
@@ -257,9 +264,10 @@ public class MarkerListActivity extends AbstractMyTracksActivity implements Dele
|
||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
getMenuInflater().inflate(R.menu.list_context_menu, menu);
|
||||
|
||||
|
||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
|
||||
contextualActionModeCallback.onPrepare(menu, new int[] {info.position}, new long[] {info.id});
|
||||
contextualActionModeCallback.onPrepare(
|
||||
menu, new int[] { info.position }, new long[] { info.id }, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -299,6 +307,12 @@ public class MarkerListActivity extends AbstractMyTracksActivity implements Dele
|
||||
DeleteMarkerDialogFragment.newInstance(markerIds)
|
||||
.show(getSupportFragmentManager(), DeleteMarkerDialogFragment.DELETE_MARKER_DIALOG_TAG);
|
||||
return true;
|
||||
case R.id.list_context_menu_select_all:
|
||||
int size = listView.getCount();
|
||||
for (int i = 0; i < size; i++) {
|
||||
listView.setItemChecked(i, true);
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
|
||||
return handleContextItem(itemId, positions);
|
||||
}
|
||||
@Override
|
||||
public void onPrepare(Menu menu, int[] positions, long[] ids) {
|
||||
public void onPrepare(Menu menu, int[] positions, long[] ids, boolean showSelectAll) {
|
||||
boolean shareWithMe = true;
|
||||
Long markerId = null;
|
||||
if (positions.length == 1) {
|
||||
@@ -158,6 +158,8 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
|
||||
// Only one item. If marker, cannot be a shareWithMe item. If track, no restriction
|
||||
menu.findItem(R.id.list_context_menu_delete)
|
||||
.setVisible(positions.length == 1 && (markerId == null || !shareWithMe));
|
||||
// Disable select all, no action is available for multiple selection
|
||||
menu.findItem(R.id.list_context_menu_select_all).setVisible(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -296,7 +298,8 @@ public class SearchListActivity extends AbstractSendToGoogleActivity
|
||||
getMenuInflater().inflate(R.menu.list_context_menu, menu);
|
||||
|
||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
|
||||
contextualActionModeCallback.onPrepare(menu, new int[] {info.position}, new long[] {info.id});
|
||||
contextualActionModeCallback.onPrepare(
|
||||
menu, new int[] { info.position }, new long[] { info.id }, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -211,16 +211,18 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
contextualActionModeCallback = new ContextualActionModeCallback() {
|
||||
|
||||
@Override
|
||||
public void onPrepare(Menu menu, int[] positions, long[] ids) {
|
||||
public void onPrepare(Menu menu, int[] positions, long[] ids, boolean showSelectAll) {
|
||||
boolean shareWithMe = true;
|
||||
if (ids.length == 1) {
|
||||
Track track = myTracksProviderUtils.getTrack(ids[0]);
|
||||
shareWithMe = track.isSharedWithMe();
|
||||
}
|
||||
// play is always enabled
|
||||
menu.findItem(R.id.list_context_menu_share).setVisible(!shareWithMe);
|
||||
menu.findItem(R.id.list_context_menu_show_on_map).setVisible(false);
|
||||
menu.findItem(R.id.list_context_menu_edit).setVisible(!shareWithMe);
|
||||
menu.findItem(R.id.list_context_menu_delete).setVisible(true);
|
||||
// delete is always enabled
|
||||
menu.findItem(R.id.list_context_menu_select_all).setVisible(showSelectAll);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -565,7 +567,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
|
||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
|
||||
contextualActionModeCallback.onPrepare(
|
||||
menu, new int[] { info.position }, new long[] { info.id });
|
||||
menu, new int[] { info.position }, new long[] { info.id }, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -770,6 +772,12 @@ public class TrackListActivity extends AbstractSendToGoogleActivity
|
||||
DeleteTrackDialogFragment.newInstance(deleteAll, trackIds)
|
||||
.show(getSupportFragmentManager(), DeleteTrackDialogFragment.DELETE_TRACK_DIALOG_TAG);
|
||||
return true;
|
||||
case R.id.list_context_menu_select_all:
|
||||
int size = listView.getCount();
|
||||
for (int i = 0; i < size; i++) {
|
||||
listView.setItemChecked(i, true);
|
||||
}
|
||||
return false;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -30,16 +30,11 @@ import android.view.ActionMode;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView.MultiChoiceModeListener;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemSelectedListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SearchView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TabWidget;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -74,58 +69,6 @@ public class Api11Adapter extends Api10Adapter {
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||
mode.getMenuInflater().inflate(R.menu.list_context_menu, menu);
|
||||
final Spinner spinner = new Spinner(activity) {
|
||||
@Override
|
||||
public void setSelection(int position) {
|
||||
super.setSelection(position);
|
||||
// Fire event when selecting the same item
|
||||
if (position == getSelectedItemPosition()) {
|
||||
getOnItemSelectedListener()
|
||||
.onItemSelected(this, getSelectedView(), position, getSelectedItemId());
|
||||
}
|
||||
}
|
||||
};
|
||||
ArrayAdapter<StringBuilder> adapter = new ArrayAdapter<StringBuilder>(
|
||||
activity, android.R.layout.simple_spinner_item,
|
||||
new StringBuilder[] { new StringBuilder("") }) {
|
||||
@Override
|
||||
public View getDropDownView(int position, View convertView, ViewGroup parent) {
|
||||
// Display select all/ deselect all
|
||||
View view = super.getDropDownView(position, convertView, parent);
|
||||
TextView textView = (TextView) view;
|
||||
int messageId = listView.getCheckedItemCount() == listView.getCount()
|
||||
? R.string.list_deselect_all
|
||||
: R.string.list_select_all;
|
||||
textView.setText(messageId);
|
||||
return view;
|
||||
};
|
||||
};
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
spinner.setAdapter(adapter);
|
||||
|
||||
// Use a post to prevent the spinner item from firing when first created
|
||||
spinner.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
// Handle select all/ deselect all
|
||||
int size = listView.getCount();
|
||||
boolean allSelected = listView.getCheckedItemCount() == size;
|
||||
for (int i = 0; i < size; i++) {
|
||||
listView.setItemChecked(i, !allSelected);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
// Do nothing
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
mode.setCustomView(spinner);
|
||||
setActionModeTitle(mode);
|
||||
return true;
|
||||
}
|
||||
@@ -133,7 +76,7 @@ public class Api11Adapter extends Api10Adapter {
|
||||
@Override
|
||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||
contextualActionModeCallback.onPrepare(
|
||||
menu, getCheckedPositions(listView), listView.getCheckedItemIds());
|
||||
menu, getCheckedPositions(listView), listView.getCheckedItemIds(), true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -142,18 +85,10 @@ public class Api11Adapter extends Api10Adapter {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void onItemCheckedStateChanged(
|
||||
ActionMode mode, int position, long id, boolean checked) {
|
||||
setActionModeTitle(mode);
|
||||
|
||||
// Update action mode title
|
||||
Spinner spinner = (Spinner) mode.getCustomView();
|
||||
ArrayAdapter<StringBuilder> adapter = (ArrayAdapter<StringBuilder>) spinner.getAdapter();
|
||||
adapter.notifyDataSetChanged();
|
||||
|
||||
// Update contextual action mode items
|
||||
mode.invalidate();
|
||||
}
|
||||
|
||||
@@ -172,12 +107,8 @@ public class Api11Adapter extends Api10Adapter {
|
||||
* @param mode action mode
|
||||
*/
|
||||
private void setActionModeTitle(ActionMode mode) {
|
||||
Spinner spinner = (Spinner) mode.getCustomView();
|
||||
StringBuilder stringBuilder = (StringBuilder) spinner.getSelectedItem();
|
||||
stringBuilder.delete(0, stringBuilder.length());
|
||||
|
||||
int count = listView.getCheckedItemCount();
|
||||
stringBuilder.append(activity.getString(R.string.list_item_selected, count));
|
||||
mode.setTitle(activity.getString(R.string.list_item_selected, count));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user