1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-24 02:12:15 -05:00

Remove more of the old messagepassing ui update code in favor of 'runonuithread'

This commit is contained in:
Jesse Vincent 2010-01-09 21:47:10 +00:00
parent e0b98cac21
commit 512177cded

View File

@ -66,140 +66,103 @@ public class FolderList extends K9ListActivity
private int mUnreadMessageCount = 0;
class FolderListHandler extends Handler
{
private static final int MSG_PROGRESS = 2;
private static final int MSG_DATA_CHANGED = 3;
private static final int MSG_FOLDER_LOADING = 7;
private static final int MSG_ACCOUNT_SIZE_CHANGED = 20;
private static final int MSG_WORKING_ACCOUNT = 21;
private static final int MSG_NEW_FOLDERS = 22;
private static final int MSG_SET_TITLE = 23;
@Override
public void handleMessage(android.os.Message msg)
public void refreshTitle()
{
switch (msg.what)
runOnUiThread(new Runnable()
{
case MSG_SET_TITLE:
{
this.setViewTitle();
break;
}
case MSG_NEW_FOLDERS:
ArrayList<FolderInfoHolder> newFolders = (ArrayList<FolderInfoHolder>)msg.obj;
mAdapter.mFolders.clear();
mAdapter.mFolders.addAll(newFolders);
mHandler.dataChanged();
break;
case MSG_PROGRESS:
setProgressBarIndeterminateVisibility(msg.arg1 != 0);
break;
case MSG_DATA_CHANGED:
mAdapter.notifyDataSetChanged();
break;
case MSG_FOLDER_LOADING:
{
FolderInfoHolder folder = mAdapter.getFolder((String) msg.obj);
if (folder != null)
{
folder.loading = msg.arg1 != 0;
}
break;
}
case MSG_ACCOUNT_SIZE_CHANGED:
{
Long[] sizes = (Long[])msg.obj;
String toastText = getString(R.string.account_size_changed, mAccount.getDescription(), SizeFormatter.formatSize(getApplication(), sizes[0]), SizeFormatter.formatSize(getApplication(), sizes[1]));
Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG);
toast.show();
break;
}
case MSG_WORKING_ACCOUNT:
{
int res = msg.arg1;
String toastText = getString(res, mAccount.getDescription());
Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_SHORT);
toast.show();
break;
}
default:
super.handleMessage(msg);
}
}
private void setViewTitle()
public void run()
{
String dispString = mAdapter.mListener.formatHeader(FolderList.this, getString(R.string.folder_list_title, mAccount.getDescription()), mUnreadMessageCount);
setTitle(dispString);
setTitle(dispString);
}
public void refreshTitle()
{
android.os.Message msg = new android.os.Message();
msg.what = MSG_SET_TITLE;
sendMessage(msg);
});
}
public void newFolders(ArrayList<FolderInfoHolder> newFolders)
public void newFolders(final ArrayList<FolderInfoHolder> newFolders)
{
android.os.Message msg = new android.os.Message();
msg.obj = newFolders;
msg.what = MSG_NEW_FOLDERS;
sendMessage(msg);
runOnUiThread(new Runnable()
{
public void run()
{
mAdapter.mFolders.clear();
mAdapter.mFolders.addAll(newFolders);
mHandler.dataChanged();
}
});
}
public void workingAccount(int res)
public void workingAccount(final int res)
{
android.os.Message msg = new android.os.Message();
msg.what = MSG_WORKING_ACCOUNT;
msg.arg1 = res;
sendMessage(msg);
runOnUiThread(new Runnable()
{
public void run()
{
String toastText = getString(res, mAccount.getDescription());
Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_SHORT);
toast.show();
}
});
}
public void accountSizeChanged(long oldSize, long newSize)
public void accountSizeChanged(final long oldSize, final long newSize)
{
android.os.Message msg = new android.os.Message();
msg.what = MSG_ACCOUNT_SIZE_CHANGED;
msg.obj = new Long[] { oldSize, newSize };
sendMessage(msg);
runOnUiThread(new Runnable()
{
public void run()
{
String toastText = getString(R.string.account_size_changed, mAccount.getDescription(), SizeFormatter.formatSize(getApplication(), oldSize), SizeFormatter.formatSize(getApplication(), newSize));
Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG);
toast.show();
}
});
}
public void folderLoading(String folder, boolean loading)
public void folderLoading(final String folder, final boolean loading)
{
android.os.Message msg = new android.os.Message();
msg.what = MSG_FOLDER_LOADING;
msg.arg1 = loading ? 1 : 0;
msg.obj = folder;
sendMessage(msg);
runOnUiThread(new Runnable()
{
public void run()
{
FolderInfoHolder folderHolder = mAdapter.getFolder(folder);
if (folderHolder != null)
{
folderHolder.loading = loading;
}
public void progress(boolean progress)
}
});
}
public void progress(final boolean progress)
{
android.os.Message msg = new android.os.Message();
msg.what = MSG_PROGRESS;
msg.arg1 = progress ? 1 : 0;
sendMessage(msg);
runOnUiThread(new Runnable()
{
public void run()
{
setProgressBarIndeterminateVisibility(progress);
}
});
}
public void dataChanged()
{
sendEmptyMessage(MSG_DATA_CHANGED);
runOnUiThread(new Runnable()
{
public void run()
{
mAdapter.notifyDataSetChanged();
}
});
}
}