1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 13:12:25 -05:00

Include number of messages in a thread in number of selected messages

Selecting a placeholder message will select all messages in its thread.
This commit is contained in:
cketti 2012-11-02 05:18:24 +01:00
parent 2e1d25118a
commit db3ea36978

View File

@ -1815,14 +1815,22 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
*/ */
private void setSelectionState(boolean selected) { private void setSelectionState(boolean selected) {
if (selected) { if (selected) {
mSelectedCount = mAdapter.getCount(); if (mAdapter.getCount() == 0) {
if (mSelectedCount == 0) {
// Nothing to do if there are no messages // Nothing to do if there are no messages
return; return;
} }
for (int i = 0, end = mSelectedCount; i < end; i++) { mSelectedCount = 0;
for (int i = 0, end = mAdapter.getCount(); i < end; i++) {
mSelected.put(i, true); mSelected.put(i, true);
if (mThreadedList) {
Cursor cursor = (Cursor) mAdapter.getItem(i);
int threadCount = cursor.getInt(THREAD_COUNT_COLUMN);
mSelectedCount += (threadCount > 1) ? threadCount : 1;
} else {
mSelectedCount++;
}
} }
if (mActionMode == null) { if (mActionMode == null) {
@ -1850,10 +1858,23 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
} }
boolean selected = mSelected.get(adapterPosition, false); boolean selected = mSelected.get(adapterPosition, false);
mSelected.put(adapterPosition, !selected); if (!selected) {
mSelected.put(adapterPosition, true);
} else {
mSelected.delete(adapterPosition);
}
int selectedCountDelta = 1;
if (mThreadedList) {
Cursor cursor = (Cursor) mAdapter.getItem(adapterPosition);
int threadCount = cursor.getInt(THREAD_COUNT_COLUMN);
if (threadCount > 1) {
selectedCountDelta = threadCount;
}
}
if (mActionMode != null) { if (mActionMode != null) {
if (mSelectedCount == 1 && selected) { if (mSelectedCount == selectedCountDelta && selected) {
mActionMode.finish(); mActionMode.finish();
mActionMode = null; mActionMode = null;
return; return;
@ -1863,9 +1884,9 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
} }
if (selected) { if (selected) {
mSelectedCount -= 1; mSelectedCount -= selectedCountDelta;
} else { } else {
mSelectedCount += 1; mSelectedCount += selectedCountDelta;
} }
computeBatchDirection(); computeBatchDirection();
@ -1884,7 +1905,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
} }
private void computeSelectAllVisibility() { private void computeSelectAllVisibility() {
mActionModeCallback.showSelectAll(mSelectedCount != mAdapter.getCount()); mActionModeCallback.showSelectAll(mSelected.size() != mAdapter.getCount());
} }
private void computeBatchDirection() { private void computeBatchDirection() {