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();
}
}
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;
}
Aggregations