<commit_before>
package com.fsck.k9.activity;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.view.*;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.*;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import com.fsck.k9.*;
import com.fsck.k9.activity.setup.AccountSettings;
import com.fsck.k9.activity.setup.AccountSetupBasics;
import com.fsck.k9.activity.setup.Prefs;
import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.store.LocalStore;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class Accounts extends K9ListActivity implements OnItemClickListener, OnClickListener
{
    private static final int DIALOG_REMOVE_ACCOUNT = 1;
    private ConcurrentHashMap<String, Integer> unreadMessageCounts = new ConcurrentHashMap<String, Integer>();

    private ConcurrentHashMap<Account, String> pendingWork = new ConcurrentHashMap<Account, String>();

    private Account mSelectedContextAccount;
    private int mUnreadMessageCount = 0;

    private AccountsHandler mHandler = new AccountsHandler();
    private AccountsAdapter mAdapter;

    private class AccountSizeChangedHolder
    {
        Account account;
        long oldSize;
        long newSize;
    }

    class AccountsHandler extends Handler
    {
        private static final int DATA_CHANGED = 1;
        private static final int MSG_ACCOUNT_SIZE_CHANGED = 2;
        private static final int MSG_WORKING_ACCOUNT = 3;
        private static final int MSG_PROGRESS = 4;
        private static final int MSG_DEFINITE_PROGRESS = 6;
        private static final int MSG_SET_TITLE = 7;

        public void handleMessage(android.os.Message msg)
        {
            switch (msg.what)
            {
                case MSG_SET_TITLE:
                {
                    this.setViewTitle();
                    break;
                }

                case DATA_CHANGED:
                    if (mAdapter != null)
                    {
                        mAdapter.notifyDataSetChanged();
                    }
                    break;
                case MSG_WORKING_ACCOUNT:
                {
                    Account account = (Account)msg.obj;
                    int res = msg.arg1;
                    String toastText = getString(res, account.getDescription());

                    Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_SHORT);
                    toast.show();
                    break;
                }
                case MSG_ACCOUNT_SIZE_CHANGED:
                {
                    AccountSizeChangedHolder holder = (AccountSizeChangedHolder)msg.obj;
                    Account account = holder.account;
                    Long oldSize = holder.oldSize;
                    Long newSize = holder.newSize;
                    String toastText = getString(R.string.account_size_changed, account.getDescription(),
                                                 SizeFormatter.formatSize(getApplication(), oldSize), SizeFormatter.formatSize(getApplication(), newSize));;

                    Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG);
                    toast.show();
                    break;
                }
                case MSG_PROGRESS:
                    setProgressBarIndeterminateVisibility(msg.arg1 != 0);
                    //setProgressBarVisibility(msg.arg1 != 0);
                    break;
                case MSG_DEFINITE_PROGRESS:
                    getWindow().setFeatureInt(Window.FEATURE_PROGRESS, msg.arg1);
                    break;
                default:
                    super.handleMessage(msg);
            }
        }
        private void setViewTitle()
        {
            String dispString = mListener.formatHeader(Accounts.this, getString(R.string.accounts_title), mUnreadMessageCount);

            setTitle(dispString);
        }
        public void refreshTitle()
        {
            android.os.Message msg = new android.os.Message();
            msg.what = MSG_SET_TITLE;
            sendMessage(msg);
        }

        public void dataChanged()
        {
            sendEmptyMessage(DATA_CHANGED);
        }

        public void workingAccount(Account account, int res)
        {
            android.os.Message msg = new android.os.Message();
            msg.what = MSG_WORKING_ACCOUNT;
            msg.obj = account;
            msg.arg1 = res;

            sendMessage(msg);
        }

        public void accountSizeChanged(Account account, long oldSize, long newSize)
        {
            android.os.Message msg = new android.os.Message();
            msg.what = MSG_ACCOUNT_SIZE_CHANGED;
            AccountSizeChangedHolder holder = new AccountSizeChangedHolder();
            holder.account = account;
            holder.oldSize = oldSize;
            holder.newSize = newSize;
            msg.obj = holder;
            sendMessage(msg);
        }

        public void progress(boolean progress)
        {
            android.os.Message msg = new android.os.Message();
            msg.what = MSG_PROGRESS;
            msg.arg1 = progress ? 1 : 0;
            sendMessage(msg);
        }
        public void progress(int progress)
        {
            android.os.Message msg = new android.os.Message();
            msg.what = MSG_DEFINITE_PROGRESS;
            msg.arg1 = progress ;
            sendMessage(msg);
        }
    }

    ActivityListener mListener = new ActivityListener()
    {
        @Override
        public void accountStatusChanged(Account account, int unreadMessageCount)
        {
            Integer oldUnreadMessageCountInteger = unreadMessageCounts.get(account.getUuid());
            int oldUnreadMessageCount = 0;
            if (oldUnreadMessageCountInteger != null)
            {
                oldUnreadMessageCount = oldUnreadMessageCountInteger;
            }

            unreadMessageCounts.put(account.getUuid(), unreadMessageCount);
            mUnreadMessageCount += unreadMessageCount - oldUnreadMessageCount;
            mHandler.dataChanged();
            pendingWork.remove(account);


            if (pendingWork.isEmpty())
            {
                mHandler.progress(Window.PROGRESS_END);
                mHandler.refreshTitle();
            }
            else
            {
                int level = (Window.PROGRESS_END / mAdapter.getCount()) * (mAdapter.getCount() - pendingWork.size()) ;
                mHandler.progress(level);
            }<commit_msg>Switch from old, scary message passing to more modern "run on ui thread" for Accounts.java<commit_after>
package com.fsck.k9.activity;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.view.*;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.*;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import com.fsck.k9.*;
import com.fsck.k9.activity.setup.AccountSettings;
import com.fsck.k9.activity.setup.AccountSetupBasics;
import com.fsck.k9.activity.setup.Prefs;
import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.store.LocalStore;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class Accounts extends K9ListActivity implements OnItemClickListener, OnClickListener
{
    private static final int DIALOG_REMOVE_ACCOUNT = 1;
    private ConcurrentHashMap<String, Integer> unreadMessageCounts = new ConcurrentHashMap<String, Integer>();

    private ConcurrentHashMap<Account, String> pendingWork = new ConcurrentHashMap<Account, String>();

    private Account mSelectedContextAccount;
    private int mUnreadMessageCount = 0;

    private AccountsHandler mHandler = new AccountsHandler();
    private AccountsAdapter mAdapter;

    class AccountsHandler extends Handler
    {
        private void setViewTitle()
        {
            String dispString = mListener.formatHeader(Accounts.this, getString(R.string.accounts_title), mUnreadMessageCount);

            setTitle(dispString);
        }
        public void refreshTitle()
        {
            runOnUiThread(new Runnable()
            {
                public void run()
                {
                    setViewTitle();
                }
            });
        }

        public void dataChanged()
        {
            runOnUiThread(new Runnable()
            {
                public void run()
                {
                    if (mAdapter != null)
                    {
                        mAdapter.notifyDataSetChanged();
                    }
                }
            });
        }

        public void workingAccount(final Account account, final int res)
        {
            runOnUiThread(new Runnable()
            {
                public void run()
                {
                    String toastText = getString(res, account.getDescription());

                    Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_SHORT);
                    toast.show();
                }
            });
        }

        public void accountSizeChanged(final Account account, final long oldSize, final long newSize)
        {
            runOnUiThread(new Runnable()
            {
                public void run()
                {
                    String toastText = getString(R.string.account_size_changed, account.getDescription(),
                                                 SizeFormatter.formatSize(getApplication(), oldSize), SizeFormatter.formatSize(getApplication(), newSize));;

                    Toast toast = Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG);
                    toast.show();
                }
            });
        }

        public void progress(final boolean progress)
        {
            runOnUiThread(new Runnable()
            {
                public void run()
                {
                    setProgressBarIndeterminateVisibility(progress);
                }
            });
        }
        public void progress(final int progress)
        {
            runOnUiThread(new Runnable()
            {
                public void run()
                {
                    getWindow().setFeatureInt(Window.FEATURE_PROGRESS, progress);
                }
            });
        }
    }

    ActivityListener mListener = new ActivityListener()
    {
        @Override
        public void accountStatusChanged(Account account, int unreadMessageCount)
        {
            Integer oldUnreadMessageCountInteger = unreadMessageCounts.get(account.getUuid());
            int oldUnreadMessageCount = 0;
            if (oldUnreadMessageCountInteger != null)
            {
                oldUnreadMessageCount = oldUnreadMessageCountInteger;
            }

            unreadMessageCounts.put(account.getUuid(), unreadMessageCount);
            mUnreadMessageCount += unreadMessageCount - oldUnreadMessageCount;
            mHandler.dataChanged();
            pendingWork.remove(account);


            if (pendingWork.isEmpty())
            {
                mHandler.progress(Window.PROGRESS_END);
                mHandler.refreshTitle();
            }
            else
            {
                int level = (Window.PROGRESS_END / mAdapter.getCount()) * (mAdapter.getCount() - pendingWork.size()) ;
                mHandler.progress(level);
            }
{'fraction_non_alphanumeric': 0.08064649813510154, 'fraction_numerical': 0.003232490675507667, 'mean_word_length': 1.8673954372623573, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5700327', 'n_tokens_mistral': 3099, 'n_tokens_neox': 2954, 'n_words': 617}