The Badges kit provides access to badges that are earned / granted to a user. Users can view and show their badges to friends and other members.
On this page:
Overview
The Badges kit follows the Master / Detail
navigation flow. The list is displated using a RecyclerView with items laid out in a grid. The details view displays the details of a Badge.
To include the Badges kit, open the Gradle Scripts | build.gradle (Module: app)
and add the following to the
dependencies section:
implementation 'com.cheetahdigital.android:badges:<version>'
Launching the Badges Activity
Assuming that the Badges kit will be launched
from a MainActivity
, you can follow the succeeding steps to launch the BadgesListActivity
from a Button’s OnClickListener
:
-
Add the
BadgesListActivity
to theAndroidManifest.xml
.<activity android:name="com.cheetahdigital.badges.ui.list.BadgesListActivity" android:screenOrientation="portrait" android:exported="false"> <intent-filter> <action android:name="${applicationId}.BADGES_LIST"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity>
-
In the
MainActivity
, add aButton
that will launch theBadgesListActivity
mButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Launch Badges Activity startActivity(new Intent(Actions.Badges.getBadgesListAction(MainActivity.this))); } });
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
In order to modify the layout of the list, list item, or details screen, you must create a copy of the following and modify as desired:
activity_badges_list.xml
- layout of the Activity that displays the list of badgeslist_item_badge.xml
- layout of each item in the list of badgesfragment_badge_summary.xml
- details layout when a badge in the list is selected
To read more about style-able Layout XMLs, please visit the Layout Customization via XML document.
Customizing Layouts via Code
There are certain cases that you may want to use a highly-customized layout for an Activity. To read more about this, please visit the Layout Customization via Code document. The classes used in the Badges kit are:
BadgesListActivity
andBadgesListFragment
- used to display the list of badges.
Customizing Handlers
In cases where changes in the default behavior of an Activity/Fragment is warranted. Extend the Activity/Fragment that needs to be customized and override 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, look at the classes mentioned in Customizing Layouts via Code, along with BadgesAdapter
, which is used for displaying the list of badges.
Fully Custom UI
If changing the layout does not suffice for the requirements, full customization is always an option. The following are the methods you can use from the BadgesAPI
class:
getBadge(BadgeParams badgeParams, boolean clearCache, ListenerModel<BaseModel<Badge>, Badge> listener)
getBadges(BadgeParams badgeParams, boolean clearCache, ListenerModel<BaseModel<Metadata>, Metadata> listener)
getMemberBadges(BadgeParams badgeParams, boolean clearCache, ListenerModel<BaseModel<Badges>, Badges> listener)