Search in sources :

Example 1 with CallRecord

use of com.voipgrid.vialer.api.models.CallRecord in project vialer-android by VoIPGRID.

the class CallRecordAdapter method onClick.

@Override
public void onClick(View view) {
    // Get the position of the list item the buttons is clicked for.
    View parentRow = (View) view.getParent();
    ListView listView = (ListView) parentRow.getParent();
    final int position = listView.getPositionForView(parentRow);
    // Get the call record.
    CallRecord callRecord = getItem(position);
    String direction = callRecord.getDirection();
    String numberToCall = null;
    // Determine direction and the number we need to call.
    if (direction.equals(CallRecord.DIRECTION_OUTBOUND)) {
        numberToCall = callRecord.getDialedNumber();
    } else if (direction.equals(CallRecord.DIRECTION_INBOUND)) {
        numberToCall = callRecord.getCaller();
    }
    if (numberToCall != null && !mCallAlreadySetup) {
        mCallAlreadySetup = true;
        new DialHelper(mActivity, new JsonStorage(mActivity), ConnectivityHelper.get(mActivity), new AnalyticsHelper(((AnalyticsApplication) mActivity.getApplication()).getDefaultTracker())).callNumber(numberToCall, "");
        PreferenceManager.getDefaultSharedPreferences(mActivity).edit().putString(DialerActivity.LAST_DIALED, numberToCall).apply();
    }
}
Also used : ListView(android.widget.ListView) DialHelper(com.voipgrid.vialer.util.DialHelper) JsonStorage(com.voipgrid.vialer.util.JsonStorage) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) CallRecord(com.voipgrid.vialer.api.models.CallRecord) AnalyticsHelper(com.voipgrid.vialer.analytics.AnalyticsHelper)

Example 2 with CallRecord

use of com.voipgrid.vialer.api.models.CallRecord in project vialer-android by VoIPGRID.

the class CallRecordAdapter method getView.

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder viewHolder;
    // Get the call record.
    CallRecord callRecord = getItem(position);
    String name = null;
    String number = "";
    // Default resource for direction.
    int resource = 0;
    if (callRecord != null) {
        // Get the direction from the call record.
        String direction = callRecord.getDirection();
        // Set the drawable resource.
        if (direction.equals(CallRecord.DIRECTION_OUTBOUND)) {
            number = callRecord.getDialedNumber();
            resource = R.drawable.ic_outgoing;
        } else if (direction.equals(CallRecord.DIRECTION_INBOUND)) {
            number = callRecord.getCaller();
            if (callRecord.getDuration() == 0) {
                resource = R.drawable.ic_incoming_missed;
            } else {
                resource = R.drawable.ic_incoming;
            }
        }
        // Get possible name or null.
        if (ContactsPermission.hasPermission(mActivity)) {
            name = getContactNameForNumber(number);
        }
    }
    if (convertView == null) {
        // Inflate the layout.
        LayoutInflater inflater = mActivity.getLayoutInflater();
        convertView = inflater.inflate(R.layout.list_item_call_record, parent, false);
    }
    String firstLetterOfName = name != null ? name.substring(0, 1) : "";
    Bitmap bitmapImage = IconHelper.getCallerIconBitmap(firstLetterOfName, Color.BLUE);
    View photoView = convertView.findViewById(R.id.text_view_contact_icon);
    ((CircleImageView) photoView).setImageBitmap(bitmapImage);
    // Set up the ViewHolder.
    viewHolder = new ViewHolder();
    viewHolder.title = (TextView) convertView.findViewById(R.id.text_view_contact_name);
    viewHolder.information = (TextView) convertView.findViewById(R.id.text_view_contact_information);
    ImageButton callButton = (ImageButton) convertView.findViewById(R.id.call_record_call_button);
    // Store the holder with the view.
    convertView.setTag(viewHolder);
    if (callRecord != null) {
        // Set name or number as text.
        if (number != null && PhoneNumberUtils.isAnonymousNumber(callRecord.getCaller())) {
            viewHolder.title.setText(convertView.getContext().getString(R.string.supressed_number));
            // Make call button invisible.
            callButton.setVisibility(View.GONE);
        } else if (name != null) {
            viewHolder.title.setText(name);
            callButton.setOnClickListener(this);
            callButton.setVisibility(View.VISIBLE);
        } else {
            viewHolder.title.setText(number);
            callButton.setOnClickListener(this);
            callButton.setVisibility(View.VISIBLE);
        }
        // Set the compound drawable to the view.
        viewHolder.information.setCompoundDrawablesWithIntrinsicBounds(resource, 0, 0, 0);
        // Format the date.
        SimpleDateFormat dateFormat = new SimpleDateFormat(CallRecord.DATE_FORMAT);
        Date date = null;
        try {
            date = dateFormat.parse(callRecord.getCallDate());
        } catch (ParseException e) {
            e.printStackTrace();
        }
        // Set the call record date information to the view.
        viewHolder.information.setText(DateUtils.getRelativeDateTimeString(mActivity, date.getTime(), DateUtils.SECOND_IN_MILLIS, DateUtils.YEAR_IN_MILLIS, DateUtils.FORMAT_ABBREV_TIME));
    }
    return convertView;
}
Also used : CircleImageView(de.hdodenhof.circleimageview.CircleImageView) Bitmap(android.graphics.Bitmap) ImageButton(android.widget.ImageButton) LayoutInflater(android.view.LayoutInflater) ParseException(java.text.ParseException) CircleImageView(de.hdodenhof.circleimageview.CircleImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) SimpleDateFormat(java.text.SimpleDateFormat) CallRecord(com.voipgrid.vialer.api.models.CallRecord) Date(java.util.Date)

Aggregations

View (android.view.View)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 CallRecord (com.voipgrid.vialer.api.models.CallRecord)2 CircleImageView (de.hdodenhof.circleimageview.CircleImageView)2 Bitmap (android.graphics.Bitmap)1 LayoutInflater (android.view.LayoutInflater)1 ImageButton (android.widget.ImageButton)1 AnalyticsHelper (com.voipgrid.vialer.analytics.AnalyticsHelper)1 DialHelper (com.voipgrid.vialer.util.DialHelper)1 JsonStorage (com.voipgrid.vialer.util.JsonStorage)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1