mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-27 19:52:17 -05:00
Cleanups to our MessageList item select/deselect code.
Fixes bugs where the action mode wouldn't trigger if the first item was checked with the checkbox
This commit is contained in:
parent
77bc346ef9
commit
b5d887728a
@ -669,7 +669,7 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
|
|||||||
|
|
||||||
MessageInfoHolder message = (MessageInfoHolder) mAdapter.getItem(position);
|
MessageInfoHolder message = (MessageInfoHolder) mAdapter.getItem(position);
|
||||||
if (mSelectedCount > 0) {
|
if (mSelectedCount > 0) {
|
||||||
handleContextRelatedClick(position);
|
toggleMessageSelect(position);
|
||||||
} else {
|
} else {
|
||||||
onOpenMessage(message);
|
onOpenMessage(message);
|
||||||
}
|
}
|
||||||
@ -700,7 +700,8 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
|
|||||||
@Override
|
@Override
|
||||||
public boolean onItemLongClick(AdapterView<?> parent, View view,
|
public boolean onItemLongClick(AdapterView<?> parent, View view,
|
||||||
int position, long id) {
|
int position, long id) {
|
||||||
return handleContextRelatedClick(position);
|
toggleMessageSelect(position);
|
||||||
|
return true;
|
||||||
}});
|
}});
|
||||||
|
|
||||||
// Correcting for screen rotation when in ActionMode
|
// Correcting for screen rotation when in ActionMode
|
||||||
@ -2288,24 +2289,12 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
|
|||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
if (position != -1) {
|
if (position != -1) {
|
||||||
MessageInfoHolder message = (MessageInfoHolder) mAdapter.getItem(position);
|
MessageInfoHolder message = (MessageInfoHolder) mAdapter.getItem(position);
|
||||||
if (message.selected != isChecked) {
|
toggleMessageSelect(message);
|
||||||
if (isChecked) {
|
if (!mCheckboxes) {
|
||||||
mSelectedCount++;
|
selected.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||||
} else if (mSelectedCount > 0) {
|
|
||||||
mSelectedCount--;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// We must set the flag before showing the buttons as the
|
|
||||||
// buttons text depends on what is selected.
|
|
||||||
message.selected = isChecked;
|
|
||||||
if (!mCheckboxes) {
|
|
||||||
if (isChecked) {
|
|
||||||
selected.setVisibility(View.VISIBLE);
|
|
||||||
} else {
|
|
||||||
selected.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2399,7 +2388,23 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
|
|||||||
mAdapter.notifyDataSetChanged();
|
mAdapter.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void toggleMessageSelect(int position){
|
||||||
|
MessageInfoHolder holder = (MessageInfoHolder) mAdapter.getItem(position);
|
||||||
|
toggleMessageSelect(holder);
|
||||||
|
}
|
||||||
|
|
||||||
private void toggleMessageSelect(final MessageInfoHolder holder){
|
private void toggleMessageSelect(final MessageInfoHolder holder){
|
||||||
|
if (mActionMode != null) {
|
||||||
|
if (mSelectedCount == 1 && holder.selected) {
|
||||||
|
mActionMode.finish();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mActionMode = MessageList.this.startActionMode(mActionModeCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (holder.selected) {
|
if (holder.selected) {
|
||||||
holder.selected = false;
|
holder.selected = false;
|
||||||
mSelectedCount -= 1;
|
mSelectedCount -= 1;
|
||||||
@ -2720,25 +2725,6 @@ public class MessageList extends K9ListActivity implements OnItemClickListener {
|
|||||||
return account;
|
return account;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean handleContextRelatedClick(int position){
|
|
||||||
MessageInfoHolder holder = (MessageInfoHolder) mAdapter.getItem(position);
|
|
||||||
if (mActionMode != null) {
|
|
||||||
if (mSelectedCount > 1) {
|
|
||||||
toggleMessageSelect(holder);
|
|
||||||
} else {
|
|
||||||
if (holder.selected) {
|
|
||||||
mActionMode.finish();
|
|
||||||
} else {
|
|
||||||
toggleMessageSelect(holder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mActionMode = MessageList.this.startActionMode(mActionModeCallback);
|
|
||||||
toggleMessageSelect(holder);
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
|
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user