The YesGraph SDK is written in a modular architecture, making it fully extensible. A few examples of using SDK components are provided below:

Contact Services

updateContactsFromPhone uploads your contacts to the YesGraph /address-book endpoint and returns a ranked list of contacts in the callback.

yesGraphApplication.updateContactsFromPhone(new Handler.Callback() {
  @Override
  public boolean handleMessage(Message msg) {
    if(msg.what == Constants.RESULT_OK)
    {
      //handle the response that is represented as a ContactsList and is ready to use in a RecyclerView or any other way
      ContactList contactList = (ContactList)msg.obj;
    }
    else
    {
      if(msg.obj instanceof JSONObject)
      {
        //handle the JSON error object
        JSONObject jsonObject = (JSONObject) msg.obj;
      } 
      else
      {
        //handle the error that is not in JSON format
      }
    }
    return false;
  }
});

getContactsFromCache retrieves the cached version of the contacts list.

We recommend you use a local cache for the ranked contacts, and display the ranked contact list after the first getContactsFromApi call. This way, your users will have a faster experience without too many API requests. You can call getContactsFromApi once per day to refresh the ranked addressbook on the phone.

yesGraphApplication.getContactsFromCache();

updateSuggestionsSeen sends the list of suggested contacts to the YesGraph /suggested-seen endpoint. Do not send the entire address-book.

Boost your Performance with Suggested Seen

It is recommended that every time the suggestions list is shown, you send the shown suggestions to the YesGraph API via the updateSuggestionsSeen method, so we can improve our rankings.

ArrayList<RankedContact> rankedContacts = new ArrayList<>();
//add here your suggestions that were seen by the user
        
yesGraphApplication.updateSuggestionsSeen(rankedContacts, new Handler.Callback() {
  @Override
  public boolean handleMessage(Message msg) {
    return false;
  }
});

inviteSentForUsers tells the YesGraph API who was contacted by hitting the /invites-sent endpoint after the user sends an invite.

Boost your Performance with Invites Sent

It is recommended that every time your user sends an invite, you send the their invites to the YesGraph API via inviteSentForUsers so we can improve our rankings.

ArrayList<Contact> contacts = new ArrayList<>();
//add here the invited contacts        

yesGraphApplication.inviteSentForUsers(contacts, new Handler.Callback() 
{
  @Override
  public boolean handleMessage(Message msg) {
    return false;
  }
});

configureWithTimeoutConnection and configureWithTimeoutRead let you set how many milliseconds the SDK will wait for a response from the server before timing out when making an HTTP request. This applies to all requests including the client-key from your server and the address-book endpoint on the YesGraph server.

yesGraphApplication.configureWithTimeoutConnection(20000);
yesGraphApplication.configureWithTimeoutRead(20000);

Creating a Share Service

The YesGraph Android SDK provides multiple share services. It is possible to use each of them without using the YesGraph SDK Share Sheet UI.

The services that are currently provided:

  • Facebook
  • Twitter
  • YesGraph Invite Service (SMS or email invites to address-book contacts)

All services inherit from BasicShareService class.

To use a specific share service, all you have to do is to instantiate it and add it to the array list on the YesGraph application class.

ArrayList<Object> shareservices = yesGraphApplication.getShareServices();
MyShareService myShareService=new MyShareService(this);
shareservices.add(myShareService);

Retrieving a Share Service

If you used the Convenience API to initialize your share sheet, you might be having trouble finding the specific share service to customize it’s properties. YesGraph stores all services in getShareServices getter, which is an array of ArrayList objects. To retrieve the service you are looking for, loop through the array and pull out the service you need by checking its class.

The example below finds ContactShareService.

ArrayList<Object> shareservices = yesGraphApplication.getShareServices();
        
for(Object shareService : shareservices)
{
  if(shareService instanceof ContactShareService)
  {

  }
  else
  {

  }
}

Creating a Custom Share Service

While YesGraph SDK provides a few sharing services out of the box, it still might be needed to create your own specific sharing service. To do this, you need to subclass the BasicShareService class, which is an abstract implementation of a share service.

BasicShareService has a few properties that you need to set.

public class MyShareService extends BasicShareService {
    public MyShareService(final Context context)
    {
        super.setContext(context);
        super.setIcon(context.getResources().getDrawable(com.yesgraph.android.R.drawable.icon));
        super.setColor(Color.parseColor("#444444"));
        super.setTitle("Yesgraph");
        super.setRunnable(new Runnable() {
            @Override
            public void run() {
                try {
                    Intent intent = new Intent(context, ContactsActivity.class);
                    context.startActivity(intent);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}

Adding Sharing Services to YesGraph Share Sheet

The YesGraph Share Sheet is fully extensible. Once you have concrete instances of BasicShareService classes, just add them to the Share Sheet.

ArrayList<Object> shareservices = yesGraphApplication.getShareServices();
MyShareService myShareService=new MyShareService(this);
shareservices.add(myShareService);

Disabling Native Messaging Sheets

The ContactShareService class displays a contact list to the user. The user can select multiple email and phone contacts to invite.

By default the Contact Share Service will display the native messaging sheets. If you are using a custom messaging or emailing framework, you might want to disable the native messaging sheets. You can do this using the setCustomSmsIntent and setCustomEmailIntent methods.

Intent myShareIntentForSMS = new Intent(this, MyShareSMSActivity.class);
yesGraphApplication.setCustomSmsIntent(myShareIntentForSMS);

Intent myShareIntentForEmail = new Intent(this, MyShareEmailActivity.class);
yesGraphApplication.setCustomEmailIntent(myShareIntentForEmail);