<commit_before>/**
 * 
 */
package info.guardianproject.otr.app.im.app;

import java.util.ArrayList;
import java.util.List;

import info.guardianproject.otr.app.im.IImConnection;
import info.guardianproject.otr.app.im.engine.ImConnection;
import info.guardianproject.otr.app.im.provider.Imps;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.RemoteException;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class AccountAdapter extends CursorAdapter {
    private LayoutInflater mInflater;
    private int mResId;
    private Cursor mStashCursor;
    private AsyncTask<Void, Void, List<AccountSetting>> mBindTask;
    private Listener mListener;

    public AccountAdapter(Activity context,
            LayoutInflater.Factory factory, int resId) {
        super(context, null, 0);
        mInflater = LayoutInflater.from(context).cloneInContext(context);
        mInflater.setFactory(factory);
        mResId = resId;
    }
    
    public void setListener(Listener listener) {
        this.mListener = listener;
    }
    
    @Override
    public Cursor swapCursor(Cursor newCursor) {
        if(mBindTask != null) {
            mBindTask.cancel(false);
            mBindTask = null ;
        }
        mStashCursor = newCursor;
        
        if (mStashCursor != null) {
            // Delay swapping in the cursor until we get the extra info
            List<AccountInfo> accountInfoList = getAccountInfoList(mStashCursor) ;
            runBindTask((Activity)mContext, accountInfoList);
        }
        return super.swapCursor(mStashCursor);
    };
    
    /**
     * @param mStashCursor
     * @return
     */
    private List<AccountInfo> getAccountInfoList(Cursor cursor) {
        List<AccountInfo> aiList = new ArrayList<AccountInfo>();
        cursor.moveToPosition(-1);
        while( cursor.moveToNext() ) {
            aiList.add( getAccountInfo(cursor));
        }
        return aiList;
    }

    static class AccountInfo {<commit_msg>make sure we close this cursor<commit_after>/**
 * 
 */
package info.guardianproject.otr.app.im.app;

import java.util.ArrayList;
import java.util.List;

import info.guardianproject.otr.app.im.IImConnection;
import info.guardianproject.otr.app.im.engine.ImConnection;
import info.guardianproject.otr.app.im.provider.Imps;
import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.RemoteException;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class AccountAdapter extends CursorAdapter {
    private LayoutInflater mInflater;
    private int mResId;
    private Cursor mStashCursor;
    private AsyncTask<Void, Void, List<AccountSetting>> mBindTask;
    private Listener mListener;

    public AccountAdapter(Activity context,
            LayoutInflater.Factory factory, int resId) {
        super(context, null, 0);
        mInflater = LayoutInflater.from(context).cloneInContext(context);
        mInflater.setFactory(factory);
        mResId = resId;
    }
    
    public void setListener(Listener listener) {
        this.mListener = listener;
    }
    
    @Override
    public Cursor swapCursor(Cursor newCursor) {
        if(mBindTask != null) {
            mBindTask.cancel(false);
            mBindTask = null ;
        }
        
        if (mStashCursor != null && (!mStashCursor.isClosed()))
                mStashCursor.close();
        
        mStashCursor = newCursor;
        
        if (mStashCursor != null) {
            // Delay swapping in the cursor until we get the extra info
            List<AccountInfo> accountInfoList = getAccountInfoList(mStashCursor) ;
            runBindTask((Activity)mContext, accountInfoList);
        }
        return super.swapCursor(mStashCursor);
    };
    
    /**
     * @param mStashCursor
     * @return
     */
    private List<AccountInfo> getAccountInfoList(Cursor cursor) {
        List<AccountInfo> aiList = new ArrayList<AccountInfo>();
        cursor.moveToPosition(-1);
        while( cursor.moveToNext() ) {
            aiList.add( getAccountInfo(cursor));
        }
        return aiList;
    }

    static class AccountInfo {
{'fraction_non_alphanumeric': 0.09457398125953367, 'fraction_numerical': 0.0013074743952930922, 'mean_word_length': 2.919726729291204, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7587800', 'n_tokens_mistral': 1329, 'n_tokens_neox': 1290, 'n_words': 274}