title: Skip duplicated entries on Call Log
body: <p>I'm developing an Android Auto like app, where I want to show the call log using recyclerview and cards.</p>
  
  <p>This is working fine, but the call log is showing all the logs. Lets say that if I have received 3 calls from Peter, I don't want to see 3 entries showing this, with one entry enought. This will be like doing something like "most recent contacts" or something like that.</p>
  
  <p>When using the recyclerview and cards, I've created 3 classes to hold the contacts info: The custom adapter, the contact info, and the custom view holder.</p>
  
  <p>This is the ContactInfo class:</p>
  
  <pre><code>public class ContactInfo {
  
      public int id;
      public String name;
      public String type;
  
      public static final String ID_PREFIX = "ID_";
      public static final String NAME_PREFIX = "Name_";
      public static final String TYPE_PREFIX = "Type_";
  }
  </code></pre>
  
  <p>Then, in the fragment where I show the call log, this is what I do to display the logs:</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
      View view = inflater.inflate(R.layout.phone_layout, container, false);
      ...
      ContactAdapter contactAdapter = new ContactAdapter(DisplayCallLog());        
      ...
      return view;
  }
  
  
  private ArrayList&lt;ContactInfo&gt; DisplayCallLog() {
  
      ArrayList&lt;ContactInfo&gt; data = new ArrayList&lt;ContactInfo&gt;();
      int contactID = 0;
      String contactNumber = null;
      int logType = 0;
      String contactName = null;
      String contactType = null;
      ContactInfo cI;
      int resultLimit = 0;
  
      //Check access to Call Log
      if (ActivityCompat.checkSelfPermission(this.getActivity(), Manifest.permission.READ_CALL_LOG) == PackageManager.PERMISSION_GRANTED) {
  
          //Get phone numbers from call log
          Cursor cursorCallLog = getActivity().getContentResolver().query(CallLog.Calls.CONTENT_URI,
                  null, null, null, CallLog.Calls.DATE + " DESC");
          while (cursorCallLog.moveToNext() &amp;&amp; resultLimit&lt;6) {
              contactNumber = cursorCallLog.getString(cursorCallLog.getColumnIndex(CallLog.Calls.NUMBER));
              //We also get the call type: Incoming, Outgoing, missed
              logType = cursorCallLog.getInt(cursorCallLog.getColumnIndex(CallLog.Calls.TYPE));
              resultLimit++;
  
              //With the phone number we search the ID
              String number = Uri.encode(contactNumber);
              Cursor cursorContactLookup = getActivity().getContentResolver().query(
                      Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
                              number),
                      new String[]{ContactsContract.PhoneLookup.DISPLAY_NAME, ContactsContract.PhoneLookup._ID},
                      null, null, null);
              while (cursorContactLookup.moveToNext()) {
                  contactID = cursorContactLookup
                          .getInt(cursorContactLookup
                                  .getColumnIndexOrThrow(ContactsContract.PhoneLookup._ID));
  
                  //Get the contact name and phone type
                  Cursor cursorContactDetails = getActivity().getContentResolver().query(
                          ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                                  new String[] {
                                          ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
                                          ContactsContract.CommonDataKinds.Phone.TYPE,
                                  },
                                  ContactsContract.Data.CONTACT_ID + "=?",
                                  new String[] {String.valueOf(contactID)}, null);
                  while (cursorContactDetails.moveToNext()) {
                      contactName = cursorContactDetails
                              .getString(cursorContactDetails
                                      .getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
                      int type = cursorContactDetails
                              .getInt(cursorContactDetails
                                      .getColumnIndexOrThrow(ContactsContract.CommonDataKinds.Phone.TYPE));
                      switch (type) {
                          case ContactsContract.CommonDataKinds.Phone.TYPE_HOME:
                              contactType = "Home";
                              break;
                          case ContactsContract.CommonDataKinds.Phone.TYPE_WORK:
                              contactType = "Work";
                              break;
                          case ContactsContract.CommonDataKinds.Phone.TYPE_MOBILE:
                              contactType = "Mobile";
                              break;
                          case ContactsContract.CommonDataKinds.Phone.TYPE_OTHER:
                              contactType = "Other";
                              break;
                      }
  
                      //Call contactinfo class and save into list
                      cI = new ContactInfo();
                      cI.id = contactID;
                      cI.name = contactName;
                      cI.type = contactType;
                      //cI.logType = logType;
  
                      //HERE: CHECK IF LIST DOES NOT CONTAIN CURRENT CONTACT
                      if (!data.contains(cI)) {
                          data.add(cI);
                      }
                  }
                  cursorContactDetails.close();
              }
              cursorContactLookup.close();
          }
          cursorCallLog.close();
      }
      return data;
  }
  </code></pre>
  
  <p>The problem I'm having is that <code>cI</code> shows a string like this: </p>
  
  <pre><code>I/CONTACT_INFO: com.example_infodash.phone.ContactInfo@41c9e198
  </code></pre>
  
  <p>Where the last numbers are allways diferent even if the contact saved is the same. So it never finds the same contact in the list, even if is duplicated.</p>
  
  <p>So my question is, how could I check if the contact saved is already in the list? I guess that the trouble in this case is because of the use of a custom class like ContactInfo.</p>