The Referrals kit allows the user to share a code to potential new users they invite and in turn, incur some benefits or rewards.
On this page:
Overview
To include the Referral kit, open the Gradle Scripts | build.gradle (Module: app)
and add the following to the
dependencies section:
implementation 'com.cheetahdigital.android:referral:<version>'
The Referrals kit contains two features: Submit Referral Code and Share Referral Code.
Submit Referral Code enables users to enter the referral code.
Share Referral Code displays the user’s referral code which they can share to others.
On the other hand, Referrals Activity is an Activity
that shows both of these features in a ViewPager
.
Launching the Referral Activities
-
Add the Activities in
AndroidManifest.xml
:<activity android:name="com.cheetahdigital.sdk.pager.ReferralsActivity" android:label="@string/referrals" /> <activity android:name="com.cheetahdigital.referral.ui.referral.ShareReferralActivity"> <intent-filter> <action android:name="${applicationId}.SHARE_REFERRALS" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> <activity android:name="com.cheetahdigital.referral.ui.submitreferral.SubmitReferralActivity"> <intent-filter> <action android:name="${applicationId}.SUBMIT_REFERRALS" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity>
-
Launch the corresponding Referrals Activity from your parent Activity (let’s assume it’s
MainActivity
for this example):startActivity(new Intent(Actions.Referrals.getReferralsAction(MainActivity.this))); startActivity(new Intent(Actions.Referrals.getShareReferralsAction(MainActivity.this))); startActivity(new Intent(Actions.Referrals.getSubmitReferralsAction(MainActivity.this)));
-
Override the following in your applications’s
strings.xml
to customize the texts displayed:<string name="referral_subject">Referral Subject"</string> <string name="referral_body" formatted="false"> "Insert Referral Body Here" Referral Code: %s \n\n Get the app here: \n iOS: %s \n Android: %s \n</string> <string name="referral_ios_link">https://itunes.apple.com/us/app</string> <string name="referral_android_link">https://play.google.com/</string>
-
This will be the result of the body when the refferal code is shared:
Theme Customization
The Kits leverage on Android’s built-in support for Styles and Themes. Overriding the Styles and Themes of the app will also change the corresponding Views used in this kit.
Layout Customization
Customizing Layouts via XML
You can customize the layouts of the different screens in the Referrals kit by copying the layout XML’s and overriding as desired. To read more about style-able layout XMLs, please visit the Layout Customization via XML document. The XML’s used are:
fragment_referral_code_generate.xml
- layout for the Share Referral screenactivity_share_referrals.xml
- layout for the Share Referral Activity which just acts as container for the Fragment that usesfragment_referral_code_generate
fragment_referral_submit_code.xml
- layout for the Submit Referral screenactivity_submit_referrals.xml
- layout for the Submit Referral Screen which just acts as container for the Fragment that usesfragment_referral_submit_code
fragment_referrals_page.xml
- layout for the Fragment which displays both of Referrals screens in aViewPager
activity_referrals
- layout for the Referrals Activity which just contains the Fragment that usesfragment_referrals_page
Customizing Layouts via Code
There are certain cases that you may want to use a highly-customized layout for an Activity/Fragment. To read more about this, please visit the Layout Customization via Code document. The classes used for the Referrals kit are:
ShareReferralActivity
andReferralCodeFragment
for sharing the referral screenSubmitReferralActivity
andSubmitReferralCodeFragment
for submitting the referral screenReferralsActivity
andReferralsPagerFragment
for displaying both the sharing and submitting referrals screen in aViewPager
.
Customizing Handlers
There are certain cases that you may want to change the default behavior of an Activity/Fragment. You can achieve that by extending the Activity/Fragment that you want to customize and overriding as necessary.
Handlers may occur in different places:
- Adapters - for lists
- Member variables inside Activities or Fragments
- Member variables inside custom Widgets - for stand-alone custom Widgets
To start with, you may look at the classes mentioned in Customizing Layouts via Code.
Fully Custom UI
If changing the layout does not suffice for your app, you may also do a full customization. You can use the following methods from the ReferralAPI
class:
Query Referral Code
getReferralCodes(ReferralParams referralParams, boolean clearCache,
ListenerModel<BaseModel<List<ReferralCode>>, List<ReferralCode>> listener)
, and also the following method from the ProfileAPI
class:
Submit Referral Code
submitReferralCode(ProfileParams parameters, Listener<SuccessResponse> listener)