<commit_before>package fr.neamar.kiss.result;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.provider.ContactsContract;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.PopupMenu;
import android.widget.TextView;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import fr.neamar.kiss.KissApplication;
import fr.neamar.kiss.R;
import fr.neamar.kiss.adapter.RecordAdapter;
import fr.neamar.kiss.pojo.ContactsPojo;
import fr.neamar.kiss.searcher.QueryInterface;
import fr.neamar.kiss.ui.ImprovedQuickContactBadge;

public class ContactsResult extends Result {
    private final ContactsPojo contactPojo;
    private final QueryInterface queryInterface;

    public ContactsResult(QueryInterface queryInterface, ContactsPojo contactPojo) {
        super();
        this.pojo = this.contactPojo = contactPojo;
        this.queryInterface = queryInterface;
    }

    @Override
    public View display(Context context, int position, View v) {
        if (v == null)
            v = inflateFromId(context, R.layout.item_contact);

        // Contact name
        TextView contactName = (TextView) v.findViewById(R.id.item_contact_name);
        contactName.setText(enrichText(contactPojo.displayName));

        // Contact phone
        TextView contactPhone = (TextView) v.findViewById(R.id.item_contact_phone);
        contactPhone.setText(contactPojo.phone);

        // Contact photo
        ImprovedQuickContactBadge contactIcon = (ImprovedQuickContactBadge) v
                .findViewById(R.id.item_contact_icon);
        contactIcon.setImageDrawable(getDrawable(context));

        contactIcon.assignContactUri(Uri.withAppendedPath(
                ContactsContract.Contacts.CONTENT_LOOKUP_URI,
                String.valueOf(contactPojo.lookupKey)));
        contactIcon.setExtraOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                recordLaunch(v.getContext());
                queryInterface.launchOccurred(-1, ContactsResult.this);
            }
        });

        // Phone action
        ImageButton phoneButton = (ImageButton) v.findViewById(R.id.item_contact_action_phone);
        // Message action
        ImageButton messageButton = (ImageButton) v.findViewById(R.id.item_contact_action_message);

        PackageManager pm = context.getPackageManager();

        if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
            phoneButton.setVisibility(View.VISIBLE);
            messageButton.setVisibility(View.VISIBLE);
            phoneButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    launchCall(v.getContext());
                }
            });

            messageButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    launchMessaging(v.getContext());
                }
            });

            /*
            Temporary disabled, see https://github.com/Neamar/KISS/issues/540
            if (contactPojo.homeNumber)
                messageButton.setVisibility(View.INVISIBLE);
            else
            */
                messageButton.setVisibility(View.VISIBLE);

        } else {
            phoneButton.setVisibility(View.INVISIBLE);
            messageButton.setVisibility(View.INVISIBLE);
        }

        return v;<commit_msg>Revert "Always display messaging button (see #540)"<commit_after>package fr.neamar.kiss.result;

import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Handler;
import android.provider.ContactsContract;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.PopupMenu;
import android.widget.TextView;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import fr.neamar.kiss.KissApplication;
import fr.neamar.kiss.R;
import fr.neamar.kiss.adapter.RecordAdapter;
import fr.neamar.kiss.pojo.ContactsPojo;
import fr.neamar.kiss.searcher.QueryInterface;
import fr.neamar.kiss.ui.ImprovedQuickContactBadge;

public class ContactsResult extends Result {
    private final ContactsPojo contactPojo;
    private final QueryInterface queryInterface;

    public ContactsResult(QueryInterface queryInterface, ContactsPojo contactPojo) {
        super();
        this.pojo = this.contactPojo = contactPojo;
        this.queryInterface = queryInterface;
    }

    @Override
    public View display(Context context, int position, View v) {
        if (v == null)
            v = inflateFromId(context, R.layout.item_contact);

        // Contact name
        TextView contactName = (TextView) v.findViewById(R.id.item_contact_name);
        contactName.setText(enrichText(contactPojo.displayName));

        // Contact phone
        TextView contactPhone = (TextView) v.findViewById(R.id.item_contact_phone);
        contactPhone.setText(contactPojo.phone);

        // Contact photo
        ImprovedQuickContactBadge contactIcon = (ImprovedQuickContactBadge) v
                .findViewById(R.id.item_contact_icon);
        contactIcon.setImageDrawable(getDrawable(context));

        contactIcon.assignContactUri(Uri.withAppendedPath(
                ContactsContract.Contacts.CONTENT_LOOKUP_URI,
                String.valueOf(contactPojo.lookupKey)));
        contactIcon.setExtraOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                recordLaunch(v.getContext());
                queryInterface.launchOccurred(-1, ContactsResult.this);
            }
        });

        // Phone action
        ImageButton phoneButton = (ImageButton) v.findViewById(R.id.item_contact_action_phone);
        // Message action
        ImageButton messageButton = (ImageButton) v.findViewById(R.id.item_contact_action_message);

        PackageManager pm = context.getPackageManager();

        if (pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
            phoneButton.setVisibility(View.VISIBLE);
            messageButton.setVisibility(View.VISIBLE);
            phoneButton.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    launchCall(v.getContext());
                }
            });

            messageButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    launchMessaging(v.getContext());
                }
            });

            if (contactPojo.homeNumber)
                messageButton.setVisibility(View.INVISIBLE);
            else
                messageButton.setVisibility(View.VISIBLE);

        } else {
            phoneButton.setVisibility(View.INVISIBLE);
            messageButton.setVisibility(View.INVISIBLE);
        }

        return v;
{'fraction_non_alphanumeric': 0.08946110963631537, 'fraction_numerical': 0.0010618529333687285, 'mean_word_length': 2.686399217221135, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '6718148', 'n_tokens_mistral': 2046, 'n_tokens_neox': 1949, 'n_words': 347}