Cheetah CES Docs Portal

Navigation
Home
GitHub
Email
Corporate Site


Newsfeed

« Back to Kits References

A Newsfeed serves as a channel for brands to interact with their members. Members can post updates and allow other members to like, comment on, and share their posts.


On this page:

Overview

To include the Newsfeed kit, open the Gradle Scripts | build.gradle (Module: app) and add the following to the dependencies section:

   implementation 'com.cheetahdigital.android:newsfeed:<version>'

The Newsfeed kit follows the Master / Detail navigation flow. The details view displays the list of comments and a view for adding comments:

The kit also has a page for composing a new post:

Launching the Newsfeed Activities

Assuming that the Newsfeed kit will be launched from a MainActivity, you can follow the succeeding steps to launch the NewsfeedListActivity from a Button’s OnClickListener:

  1. Add the following Newsfeed Activities to the AndroidManifest.xml.
    • NewsfeedListActivity
    • NewsfeedDetailsActivity
    • NewsfeedPostActivity
    • NewsfeedAttachmentsActivity
    • NewsVideoActivity
    • MembersActivity
    <!-- Newsfeed -->
        <activity
            android:name="com.cheetahdigital.newsfeed.ui.list.NewsfeedListActivity"
            android:parentActivityName="com.cheetahdigital.sdk.MainActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="${applicationId}.NEWSFEED_LIST" />
    
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.cheetahdigital.newsfeed.ui.details.NewsfeedDetailsActivity"
            android:parentActivityName="com.cheetahdigital.newsfeed.ui.list.NewsfeedListActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="${applicationId}.NEWSFEED_DETAILS" />
    
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.cheetahdigital.newsfeed.ui.list.FeedsListActivity"
            android:parentActivityName="com.cheetahdigital.sdk.MainActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="${applicationId}.FEED_LIST" />
    
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.cheetahdigital.newsfeed.ui.post.NewsfeedPostActivity"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="adjustResize">
            <intent-filter>
                <action android:name="${applicationId}.NEWSFEED_POST" />
    
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.cheetahdigital.newsfeed.ui.attachments.NewsfeedAttachmentsActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="${applicationId}.NEWSFEED_ATTACHMENTS" />
    
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.cheetahdigital.newsfeed.ui.attachments.NewsVideoActivity"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="${applicationId}.NEWSFEED_VIDEO" />
    
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    
  2. You need to declare the camera and write external storage in your AndroidManifest.xml. This is for selecting an image or video to upload in the Newsfeed.

    <uses-permission android:name="android.permission.CAMERA"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    
  3. On your activity, add a Button to launch the Starting Activity - NewsfeedListActivity:

    mButton.setOnClickListener(new View.OnClickListener() {
       @Override
       public void onClick(View v) {
           startActivity(new Intent(Actions.Newsfeed.getListAction(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

You can customize the layouts of the different screens in the Newsfeed kit by copying the layout XML’s and overriding as desired. To read more about this, please visit the Layout Customization via XML document. The XML’s used are:

  • fragment_newsfeed_list.xml - layout for displaying the list of newsfeed items
  • activity_newsfeed_list.xml - layout of Activity that will display the Fragment that uses fragment_newsfeed_list.xml
  • activity_news_details_list.xml - layout of a newsfeed item details page
  • activity_newsfeed_video.xml - layout of a newsfeed item details page specifically for videos
  • list_item_news.xml - layout of a newsfeed item in a list
  • list_item_comment.xml - layout of a comment of a newsfeed item
  • news_attachment_image.xml - layout for displaying a newsfeed attachment
  • news_feed_post_activity.xml - layout for the new post Activity
  • social_widget.xml - the bottom part of a newsfeed post (for like, share, flag actions)
  • social_widget_comments.xml - the bottom part of a comment (for like, share, flag actions)
  • view_share_widget.xml - the layout that pops up when a user wants to share a URL

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 Newsfeed kit are:

  • NewsfeedListActivity and NewsfeedListFragment for displaying the newsfeed list
  • NewsfeedDetailsActivity for displaying one newsfeed item and its corresponding comments
  • NewsfeedAttachmentsActivity for displaying the attachments of a newsfeed item
  • NewsfeedPostActivity for when the user wants to create a new post
  • NewsfeedVideoActivity for displaying a video newsfeed item

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, along with:

  • NewsfeedDetailsAdapter for displaying the comments in the newsfeed item details page
  • AttachmentPagerAdapter for displaying the list of attachments of a newsfeed item
  • FlagDialogFragment for when the user wants to flag a newfeed item
  • SocialWidget for the part of a newsfeed item where the user likes, comments, or shares
  • ViewShareUrlWidget for when the user wants to share a URL post

Fully Custom UI

If changing the layout does not suffice for your case, you can always do a full customization. The following are the methods you can use from the NewsfeedAPI class:

Querying Newsfeed Data

getFeeds(NewsfeedParams queryParams, boolean clearCache, ListenerModel<BaseModel<Feeds>, Feeds> listener)

getNewsfeed(NewsfeedParams queryParams, boolean clearCache, ListenerModel<BaseModel<Newsfeed>, Newsfeed> listener)

getPost(NewsfeedParams queryParams, boolean clearCache, ListenerModel<BaseModel<Post>, Post> listener)

Deleting News Post

deletePost(NewsfeedParams queryParams, ListenerModel<BaseModel<Post>, Post> listener) {

Like/Unlike a Post

likePost(NewsfeedParams queryParams, Listener<SuccessResponse> listener)

unLikePost(NewsfeedParams queryParams, Listener<SuccessResponse> listener)

Adding a New Post

addPost(NewsfeedParams queryParams, NewsfeedFields fieldParams, List<MultipartBody.Part> attachments, ListenerModel<BaseModel<NewPost>, NewPost> listener)

Querying Comments Data

getComments(NewsfeedParams queryParams, boolean clearCache, ListenerModel<BaseModel<Comments>, Comments> listener)

Adding a Comment

addComment(NewsfeedParams queryParams, NewsfeedFields fieldParams, Listener<SuccessResponse> listener) {

Like/Unlike a Comment

likeComment(NewsfeedParams queryParams, Listener<SuccessResponse> listener)

unlikeComment(NewsfeedParams queryParams, Listener<SuccessResponse> listener)

Deleting a Comment

deleteComment(NewsfeedParams queryParams, ListenerModel<BaseModel<DeletedComment>, DeletedComment> listener) {

Querying Flags

getFlags(NewsfeedParams queryParams, boolean clearCache, ListenerModel<BaseModel<List<Flag>>, List<Flag>> listener) {

Flag/Unflag a Post

flagPost(NewsfeedParams queryParams, NewsfeedFields fieldParams, Listener<SuccessResponse> callback)

unflagPost(NewsfeedParams queryParams, Listener<SuccessResponse> callback)

Flag/Unflag a Comment

flagComment(NewsfeedParams queryParams, NewsfeedFields fieldParams, Listener<SuccessResponse> callback)

unflagComment(NewsfeedParams queryParams, Listener<SuccessResponse> callback)


« Back to Kits References