<commit_before>package de.measite.contactmerger.ui;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicLong;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ContentProviderClient;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Typeface;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.Website;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import de.measite.contactmerger.R;
import de.measite.contactmerger.contacts.Contact;
import de.measite.contactmerger.contacts.ContactDataMapper;
import de.measite.contactmerger.contacts.ImMetadata;
import de.measite.contactmerger.contacts.Metadata;
import de.measite.contactmerger.contacts.NicknameMetadata;
import de.measite.contactmerger.contacts.PhotoMetadata;
import de.measite.contactmerger.contacts.RawContact;
import de.measite.contactmerger.ui.model.MergeContact;
import de.measite.contactmerger.ui.model.ModelIO;
import de.measite.contactmerger.ui.model.ModelSavePool;
import de.measite.contactmerger.ui.model.RootContact;
import de.measite.contactmerger.util.ShiftedExpireLRU;

public class MergeListAdapter extends BaseAdapter implements OnClickListener {

    protected static final String TAG = "ContactMerger/MergeListAdapter";
    protected Thread transform;
    protected ArrayList<MergeContact> model;
    protected ContentProviderClient provider;
    protected LayoutInflater layoutInflater;
    protected ContactDataMapper contactMapper;
    protected Activity activity;
    protected Typeface font;
    protected File modelFile;
    protected File tmpModelFile;
    protected long timestamp;
    protected static AtomicLong generation = new AtomicLong();

    public MergeListAdapter(Activity activity) {
        super();
        model = new ArrayList<MergeContact>();

        this.activity = activity;

        if (model.size() == 0) update();

        provider =
            activity.getContentResolver().acquireContentProviderClient(
                ContactsContract.AUTHORITY_URI);
        contactMapper = new ContactDataMapper(provider);
        contactMapper.setCache(new ShiftedExpireLRU(5 * 60 * 1000, 100));
        layoutInflater = activity.getLayoutInflater();
        font = Typeface.createFromAsset(
                    activity.getAssets(), "fontawesome-webfont.ttf" );
    }

    public synchronized void update() {
        File path = activity.getDatabasePath("contactsgraph");
        modelFile = new File(path, "model.kryo.gz");
        long lastModified = modelFile.lastModified();
        tmpModelFile = new File(path, "model-tmp-" + lastModified + ".kryo.gz");

        try {
            if (!tmpModelFile.exists()) {
                for (File f : path.listFiles()) {
                    if (f.getName().startsWith("model-tmp-")) f.delete();
                }
                this.model = ModelIO.load(modelFile);
            } else {
                this.model = ModelIO.load(tmpModelFile);
            }
            notifyDataSetChanged();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public int getCount() {
        return (model == null) ? 0 : model.size();
    }

    @Override
    public Object getItem(int position) {<commit_msg>Fix timestamp file<commit_after>package de.measite.contactmerger.ui;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicLong;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ContentProviderClient;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Typeface;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.ContactsContract.CommonDataKinds.Email;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.Website;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import de.measite.contactmerger.R;
import de.measite.contactmerger.contacts.Contact;
import de.measite.contactmerger.contacts.ContactDataMapper;
import de.measite.contactmerger.contacts.ImMetadata;
import de.measite.contactmerger.contacts.Metadata;
import de.measite.contactmerger.contacts.NicknameMetadata;
import de.measite.contactmerger.contacts.PhotoMetadata;
import de.measite.contactmerger.contacts.RawContact;
import de.measite.contactmerger.ui.model.MergeContact;
import de.measite.contactmerger.ui.model.ModelIO;
import de.measite.contactmerger.ui.model.ModelSavePool;
import de.measite.contactmerger.ui.model.RootContact;
import de.measite.contactmerger.util.ShiftedExpireLRU;

public class MergeListAdapter extends BaseAdapter implements OnClickListener {

    protected static final String TAG = "ContactMerger/MergeListAdapter";
    protected Thread transform;
    protected ArrayList<MergeContact> model;
    protected ContentProviderClient provider;
    protected LayoutInflater layoutInflater;
    protected ContactDataMapper contactMapper;
    protected Activity activity;
    protected Typeface font;
    protected File modelFile;
    protected File tmpModelFile;
    protected long timestamp;
    protected static AtomicLong generation = new AtomicLong();

    public MergeListAdapter(Activity activity) {
        super();
        model = new ArrayList<MergeContact>();

        this.activity = activity;

        if (model.size() == 0) update();

        provider =
            activity.getContentResolver().acquireContentProviderClient(
                ContactsContract.AUTHORITY_URI);
        contactMapper = new ContactDataMapper(provider);
        contactMapper.setCache(new ShiftedExpireLRU(5 * 60 * 1000, 100));
        layoutInflater = activity.getLayoutInflater();
        font = Typeface.createFromAsset(
                    activity.getAssets(), "fontawesome-webfont.ttf" );
    }

    public synchronized void update() {
        File path = activity.getDatabasePath("contactsgraph");
        modelFile = new File(path, "model.kryo.gz");
        timestamp = modelFile.lastModified();
        tmpModelFile = new File(path, "model-tmp-" + timestamp + ".kryo.gz");

        try {
            if (!tmpModelFile.exists()) {
                for (File f : path.listFiles()) {
                    if (f.getName().startsWith("model-tmp-")) f.delete();
                }
                this.model = ModelIO.load(modelFile);
                ModelSavePool.getInstance().update(activity, timestamp, generation.getAndIncrement(), (ArrayList<MergeContact>)model.clone());
            } else {
                this.model = ModelIO.load(tmpModelFile);
            }
            notifyDataSetChanged();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public int getCount() {
        return (model == null) ? 0 : model.size();
    }

    @Override
    public Object getItem(int position) {
{'fraction_non_alphanumeric': 0.09652650822669104, 'fraction_numerical': 0.0029250457038391227, 'mean_word_length': 3.6466591166477915, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '6642606', 'n_tokens_mistral': 2296, 'n_tokens_neox': 2180, 'n_words': 451}