Merge pull request #354 from uberspot/master

Multiselect: Create 'select all' in public and secret keylist
This commit is contained in:
Dominik Schürmann 2014-03-06 19:36:31 +01:00
commit 28e4a75e7e
10 changed files with 28 additions and 12 deletions

View File

@ -144,8 +144,6 @@ public class KeyListPublicFragment extends Fragment implements SearchView.OnQuer
mStickyList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); mStickyList.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
mStickyList.getWrappedList().setMultiChoiceModeListener(new MultiChoiceModeListener() { mStickyList.getWrappedList().setMultiChoiceModeListener(new MultiChoiceModeListener() {
private int count = 0;
@Override @Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) { public boolean onCreateActionMode(ActionMode mode, Menu menu) {
android.view.MenuInflater inflater = getActivity().getMenuInflater(); android.view.MenuInflater inflater = getActivity().getMenuInflater();
@ -179,13 +177,20 @@ public class KeyListPublicFragment extends Fragment implements SearchView.OnQuer
showDeleteKeyDialog(mode, ids); showDeleteKeyDialog(mode, ids);
break; break;
} }
case R.id.menu_key_list_public_multi_select_all: {
//Select all
int localCount = mStickyList.getCount();
for(int k = 0; k < localCount; k++) {
mStickyList.setItemChecked(k, true);
}
break;
}
} }
return true; return true;
} }
@Override @Override
public void onDestroyActionMode(ActionMode mode) { public void onDestroyActionMode(ActionMode mode) {
count = 0;
mAdapter.clearSelection(); mAdapter.clearSelection();
} }
@ -193,13 +198,11 @@ public class KeyListPublicFragment extends Fragment implements SearchView.OnQuer
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
boolean checked) { boolean checked) {
if (checked) { if (checked) {
count++;
mAdapter.setNewSelection(position, checked); mAdapter.setNewSelection(position, checked);
} else { } else {
count--;
mAdapter.removeSelection(position); mAdapter.removeSelection(position);
} }
int count = mAdapter.getCurrentCheckedPosition().size();
String keysSelected = getResources().getQuantityString( String keysSelected = getResources().getQuantityString(
R.plurals.key_list_selected_keys, count, count); R.plurals.key_list_selected_keys, count, count);
mode.setTitle(keysSelected); mode.setTitle(keysSelected);

View File

@ -82,8 +82,6 @@ public class KeyListSecretFragment extends ListFragment implements
getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
getListView().setMultiChoiceModeListener(new MultiChoiceModeListener() { getListView().setMultiChoiceModeListener(new MultiChoiceModeListener() {
private int count = 0;
@Override @Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) { public boolean onCreateActionMode(ActionMode mode, Menu menu) {
android.view.MenuInflater inflater = getActivity().getMenuInflater(); android.view.MenuInflater inflater = getActivity().getMenuInflater();
@ -113,13 +111,20 @@ public class KeyListSecretFragment extends ListFragment implements
showDeleteKeyDialog(mode, ids); showDeleteKeyDialog(mode, ids);
break; break;
} }
case R.id.menu_key_list_public_multi_select_all: {
//Select all
int localCount = getListView().getCount();
for(int k = 0; k < localCount; k++) {
getListView().setItemChecked(k, true);
}
break;
}
} }
return true; return true;
} }
@Override @Override
public void onDestroyActionMode(ActionMode mode) { public void onDestroyActionMode(ActionMode mode) {
count = 0;
mAdapter.clearSelection(); mAdapter.clearSelection();
} }
@ -127,13 +132,12 @@ public class KeyListSecretFragment extends ListFragment implements
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, public void onItemCheckedStateChanged(ActionMode mode, int position, long id,
boolean checked) { boolean checked) {
if (checked) { if (checked) {
count++;
mAdapter.setNewSelection(position, checked); mAdapter.setNewSelection(position, checked);
} else { } else {
count--;
mAdapter.removeSelection(position); mAdapter.removeSelection(position);
} }
int count = getListView().getCheckedItemCount();
String keysSelected = getResources().getQuantityString( String keysSelected = getResources().getQuantityString(
R.plurals.key_list_selected_keys, count, count); R.plurals.key_list_selected_keys, count, count);
mode.setTitle(keysSelected); mode.setTitle(keysSelected);

View File

@ -223,7 +223,7 @@ public class KeyListPublicAdapter extends CursorAdapter implements StickyListHea
*/ */
// default color // default color
v.setBackgroundColor(Color.TRANSPARENT); v.setBackgroundColor(Color.TRANSPARENT);
if (mSelection.get(position) != null) { if (mSelection.get(position) != null && mSelection.get(position).booleanValue()) {
// this is a selected position, change color! // this is a selected position, change color!
v.setBackgroundColor(parent.getResources().getColor(R.color.emphasis)); v.setBackgroundColor(parent.getResources().getColor(R.color.emphasis));
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 507 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 351 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 563 B

View File

@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_key_list_public_multi_select_all"
android:icon="@drawable/ic_action_select_all"
android:title="@string/menu_select_all" />
<item <item
android:id="@+id/menu_key_list_public_multi_encrypt" android:id="@+id/menu_key_list_public_multi_encrypt"
android:icon="@drawable/ic_action_secure" android:icon="@drawable/ic_action_secure"

View File

@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"> <menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_key_list_public_multi_select_all"
android:icon="@drawable/ic_action_select_all"
android:title="@string/menu_select_all" />
<item <item
android:id="@+id/menu_key_list_public_multi_delete" android:id="@+id/menu_key_list_public_multi_delete"
android:icon="@drawable/ic_action_discard" android:icon="@drawable/ic_action_discard"

View File

@ -96,6 +96,7 @@
<string name="menu_beam_preferences">Beam settings</string> <string name="menu_beam_preferences">Beam settings</string>
<string name="menu_key_edit_cancel">Cancel</string> <string name="menu_key_edit_cancel">Cancel</string>
<string name="menu_encrypt_to">Encrypt to…</string> <string name="menu_encrypt_to">Encrypt to…</string>
<string name="menu_select_all">Select all</string>
<!-- label --> <!-- label -->
<string name="label_sign">Sign</string> <string name="label_sign">Sign</string>