Code cleanup

This commit is contained in:
cketti 2012-09-05 03:50:02 +02:00
parent 16ab1b67bc
commit 9c335127e2
1 changed files with 21 additions and 60 deletions

View File

@ -350,37 +350,26 @@ public class MessageList
} }
/** /**
* FIXME * This class is used to run operations that modify UI elements in the UI thread.
*
* <p>We are using convenience methods that add a {@link android.os.Message} instance or a
* {@link Runnable} to the message queue.</p>
*
* <p><strong>Note:</strong> If you add a method to this class make sure you don't accidentally
* perform the operation in the calling thread.</p>
*/ */
class MessageListHandler extends Handler { class MessageListHandler extends Handler {
private static final int ACTION_REMOVE_MESSAGES = 1; private static final int ACTION_REMOVE_MESSAGE = 1;
private static final int ACTION_ADD_MESSAGES = 2; private static final int ACTION_RESET_UNREAD_COUNT = 2;
private static final int ACTION_RESET_UNREAD_COUNT = 3; private static final int ACTION_SORT_MESSAGES = 3;
private static final int ACTION_SORT_MESSAGES = 4; private static final int ACTION_FOLDER_LOADING = 4;
private static final int ACTION_FOLDER_LOADING = 5; private static final int ACTION_REFRESH_TITLE = 5;
private static final int ACTION_REFRESH_TITLE = 6; private static final int ACTION_PROGRESS = 6;
private static final int ACTION_PROGRESS = 7;
private static final int ACTION_REMOVE_MESSAGE = 8;
/** public void removeMessage(MessageReference messageReference) {
* @param messages Never {@code null}. android.os.Message msg = android.os.Message.obtain(this, ACTION_REMOVE_MESSAGE,
*/ messageReference);
public void removeMessages(final List<MessageInfoHolder> messages) {
android.os.Message msg = android.os.Message.obtain(this, ACTION_REMOVE_MESSAGES, messages);
sendMessage(msg);
}
/**
* @param messages Never {@code null}.
*/
public void addMessages(final List<MessageInfoHolder> messages) {
android.os.Message msg = android.os.Message.obtain(this, ACTION_ADD_MESSAGES, messages);
sendMessage(msg);
}
public void resetUnreadCount() {
android.os.Message msg = android.os.Message.obtain(this, ACTION_RESET_UNREAD_COUNT);
sendMessage(msg); sendMessage(msg);
} }
@ -406,15 +395,9 @@ public class MessageList
sendMessage(msg); sendMessage(msg);
} }
public void removeMessage(MessageReference messageReference) {
android.os.Message msg = android.os.Message.obtain(this, ACTION_REMOVE_MESSAGE,
messageReference);
sendMessage(msg);
}
public void changeMessageUid(final MessageReference ref, final String newUid) { public void changeMessageUid(final MessageReference ref, final String newUid) {
// Instead of creating a container to be able to pass both arguments in a Message we // Instead of explicitly creating a container to be able to pass both arguments in a
// post a Runnable to the message queue. // Message we post a Runnable to the message queue.
post(new Runnable() { post(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -437,18 +420,12 @@ public class MessageList
}); });
} }
@SuppressWarnings("unchecked")
@Override @Override
public void handleMessage(android.os.Message msg) { public void handleMessage(android.os.Message msg) {
switch (msg.what) { switch (msg.what) {
case ACTION_REMOVE_MESSAGES: { case ACTION_REMOVE_MESSAGE: {
List<MessageInfoHolder> messages = (List<MessageInfoHolder>) msg.obj; MessageReference messageReference = (MessageReference) msg.obj;
mAdapter.removeMessages(messages); mAdapter.removeMessage(messageReference);
break;
}
case ACTION_ADD_MESSAGES: {
List<MessageInfoHolder> messages = (List<MessageInfoHolder>) msg.obj;
mAdapter.addMessages(messages);
break; break;
} }
case ACTION_RESET_UNREAD_COUNT: { case ACTION_RESET_UNREAD_COUNT: {
@ -474,11 +451,6 @@ public class MessageList
MessageList.this.progress(progress); MessageList.this.progress(progress);
break; break;
} }
case ACTION_REMOVE_MESSAGE: {
MessageReference messageReference = (MessageReference) msg.obj;
mAdapter.removeMessage(messageReference);
break;
}
} }
} }
} }
@ -2297,10 +2269,6 @@ public class MessageList
return -1; return -1;
} }
public Object getItem(long position) {
return getItem((int)position);
}
@Override @Override
public Object getItem(int position) { public Object getItem(int position) {
try { try {
@ -2519,17 +2487,10 @@ public class MessageList
} }
} }
@Override @Override
public boolean hasStableIds() { public boolean hasStableIds() {
return true; return true;
} }
public boolean isItemSelectable(int position) {
return (position < mMessages.size());
}
} }
class MessageViewHolder class MessageViewHolder