Add a conversation to your app

Add a conversation container

  1. Create your VFArticleMetadata object.
VFArticleMetadata articleMetadata = new VFArticleMetadata(new URL(""), "STORY TITLE", "STORY_DESC", new URL("STORY_PICTURE_URL"));
val articleMetadata = VFArticleMetadata(URL(""), "STORY TITLE", "STORY_DESC", new URL("STORY_PICTURE_URL"));
  1. Create your VFSettings object.
VFColors colors = new VFColors(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary), ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryLight), Color.WHITE);
VFSettings vfSettings = new VFSettings(colors);
val colors = VFColors(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary), ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryLight), Color.WHITE);
val vfSettings = VFSettings(colors);
  1. Implement the VFLoginInterface interface.
@Override
public void startLogin() {
    Intent intent = new Intent(getApplicationContext(), LoginActivity.class);
    startActivity(intent);
}
override fun startLogin() {
    val intent = Intent(applicationContext, LoginActivity::class.java)
    startActivity(intent)
}
  1. Add the PreviewCommentsFragment into your content .
VFPreviewCommentsFragment previewCommentsFragment = VFPreviewCommentsFragment.newInstance(getApplication(), articleViewModel.getStory().getContainerId(), articleMetadata, this, vfSettings, 10, VFSortType.mostLiked);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.article_comments_container, previewCommentsFragment);
ft.commitAllowingStateLoss();

previewCommentsFragment.setActionCallback(this);
val previewCommentsFragment = VFPreviewCommentsFragment.newInstance(
    application,
    articleViewModel!!.story.containerId,
    articleMetadata,
    this,
    vfSettings,
  	10,
		VFSortType.mostLiked
)
val ft = supportFragmentManager.beginTransaction()
ft.replace(R.id.article_comments_container, previewCommentsFragment)
ft.commitAllowingStateLoss()
  1. Listen to the PreviewCommentsFragment action callback .
@Override
public void onNewAction(VFActionType actionType, VFActionData action) {
    if (actionType == VFActionType.writeNewCommentPressed) {
        Intent intent = new Intent(getApplicationContext(), NewCommentActivity.class);
        intent.putExtra(IntentKeys.INTENT_CONTAINER_ID, articleViewModel.getStory().getContainerId());
        intent.putExtra(IntentKeys.INTENT_STORY_LINK, articleViewModel.getStory().getLink());
        intent.putExtra(IntentKeys.INTENT_STORY_TITLE, articleViewModel.getStory().getTitle());
        intent.putExtra(IntentKeys.INTENT_NEW_COMMENT_ACTION, action.getNewCommentAction().type.toString());
        if (action.getNewCommentAction().content != null) {
            intent.putExtra(IntentKeys.INTENT_NEW_COMMENT_CONTENT, action.getNewCommentAction().content.toString());
        }
        intent.putExtra(IntentKeys.INTENT_STORY_DESC, articleViewModel.getStory().getDescription());
        intent.putExtra(IntentKeys.INTENT_STORY_PICTUREURL, articleViewModel.getStory().getPictureUrl());
        startActivity(intent);
    } else if (actionType == VFActionType.openProfilePressed) {
        Intent intent = new Intent(getApplicationContext(), ProfileActivity.class);
        intent.putExtra(IntentKeys.INTENT_USER_UUID, action.getOpenProfileAction().userUUID.toString());
        if (action.getOpenProfileAction().presentationType != null) {
            intent.putExtra(IntentKeys.INTENT_USER_PRESENTATION_TYPE, action.getOpenProfileAction().presentationType.toString());
        }
        startActivity(intent);
    }
}
override fun onNewAction(actionType: VFActionType, action: VFActionData) {
    if (actionType == VFActionType.writeNewCommentPressed) {
        val intent = Intent(applicationContext, NewCommentActivity::class.java)
        intent.putExtra(IntentKeys.INTENT_CONTAINER_ID, articleViewModel!!.story.containerId)
        intent.putExtra(IntentKeys.INTENT_STORY_LINK, articleViewModel!!.story.link)
        intent.putExtra(IntentKeys.INTENT_STORY_TITLE, articleViewModel!!.story.title)
        intent.putExtra(
            IntentKeys.INTENT_NEW_COMMENT_ACTION,
            action.newCommentAction.type.toString()
        )
        if (action.newCommentAction.content != null) {
            intent.putExtra(
                IntentKeys.INTENT_NEW_COMMENT_CONTENT,
                action.newCommentAction.content.toString()
            )
        }
        intent.putExtra(IntentKeys.INTENT_STORY_DESC, articleViewModel!!.story.description)
        intent.putExtra(IntentKeys.INTENT_STORY_PICTUREURL, articleViewModel!!.story.pictureUrl)
        startActivity(intent)
    } else if (actionType == VFActionType.openProfilePressed) {
        val intent = Intent(applicationContext, ProfileActivity::class.java)
        intent.putExtra(
            IntentKeys.INTENT_USER_UUID,
            action.openProfileAction.userUUID.toString()
        )
        if (action.openProfileAction.presentationType != null) {
            intent.putExtra(
                IntentKeys.INTENT_USER_PRESENTATION_TYPE,
                action.openProfileAction.presentationType.toString()
            )
        }
        startActivity(intent)
    }
}

Type a new comment

  1. Create your VFArticleMetadata object.
URL storyUrl = new URL(getIntent().getStringExtra(IntentKeys.INTENT_STORY_LINK));
URL pictureUrl = new URL(getIntent().getStringExtra(IntentKeys.INTENT_STORY_PICTUREURL));
VFArticleMetadata articleMetadata = new VFArticleMetadata(storyUrl, getIntent().getStringExtra(IntentKeys.INTENT_STORY_TITLE), getIntent().getStringExtra(IntentKeys.INTENT_STORY_DESC), pictureUrl);
  1. Create your VFSettings object.
VFColors colors = new VFColors(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary), ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryLight), Color.WHITE);
VFSettings vfSettings = new VFSettings(colors);
val colors = VFColors(
    ContextCompat.getColor(applicationContext, R.color.colorPrimary),
    ContextCompat.getColor(
        applicationContext, R.color.colorPrimaryLight
    ),
    Color.WHITE
)
val vfSettings = VFSettings(colors)
  1. Create the VFNewCommentAction object.
VFNewCommentAction newCommentAction = null;

String newCommentActionType = getIntent().getStringExtra(IntentKeys.INTENT_NEW_COMMENT_ACTION);

if (newCommentActionType.equals(VFNewCommentAction.VFNewCommentActionType.create.toString())) {
    newCommentAction = new VFNewCommentAction(VFNewCommentAction.VFNewCommentActionType.create);
} else if (newCommentActionType.equals(VFNewCommentAction.VFNewCommentActionType.reply.toString())) {
    newCommentAction = new VFNewCommentAction(VFNewCommentAction.VFNewCommentActionType.reply);
} else if (newCommentActionType.equals(VFNewCommentAction.VFNewCommentActionType.edit.toString())) {
    newCommentAction = new VFNewCommentAction(VFNewCommentAction.VFNewCommentActionType.edit);
}

if (getIntent().getStringExtra(IntentKeys.INTENT_NEW_COMMENT_CONTENT) != null) {
    newCommentAction.content = UUID.fromString(getIntent().getStringExtra(IntentKeys.INTENT_NEW_COMMENT_CONTENT));
}
var newCommentAction: VFNewCommentAction ? = null
val newCommentActionType = intent.getStringExtra(IntentKeys.INTENT_NEW_COMMENT_ACTION)
if (newCommentActionType == VFNewCommentAction.VFNewCommentActionType.create.toString()) {
    newCommentAction = VFNewCommentAction(VFNewCommentAction.VFNewCommentActionType.create)
} else if (newCommentActionType == VFNewCommentAction.VFNewCommentActionType.reply.toString()) {
    newCommentAction = VFNewCommentAction(VFNewCommentAction.VFNewCommentActionType.reply)
} else if (newCommentActionType == VFNewCommentAction.VFNewCommentActionType.edit.toString()) {
    newCommentAction = VFNewCommentAction(VFNewCommentAction.VFNewCommentActionType.edit)
}
if (intent.getStringExtra(IntentKeys.INTENT_NEW_COMMENT_CONTENT) != null) {
    newCommentAction!!.content =
        UUID.fromString(intent.getStringExtra(IntentKeys.INTENT_NEW_COMMENT_CONTENT))
}
  1. Add the NewCommentFragment into your content .
VFNewCommentFragment newCommentFragment = VFNewCommentFragment.newInstance(getApplication(), newCommentAction, getIntent().getStringExtra(IntentKeys.INTENT_CONTAINER_ID), articleMetadata, this, vfSettings);
newCommentFragment.setActionCallback(this);
newCommentFragment.setCustomUICallback(this);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.new_comment_container, newCommentFragment);
ft.commit();
val newCommentFragment = VFNewCommentFragment.newInstance(
    application, newCommentAction, intent.getStringExtra(IntentKeys.INTENT_CONTAINER_ID), articleMetadata, this, vfSettings
)
newCommentFragment.setActionCallback(this)
newCommentFragment.setCustomUICallback(this)
val ft = supportFragmentManager.beginTransaction()
ft.replace(R.id.new_comment_container, newCommentFragment)
ft.commit()
  1. Listen to the NewCommentFragment action callback .
@Override
public void onNewAction(VFActionType actionType, VFActionData action) {
    if (actionType == VFActionType.closeNewCommentPressed) {
        onBackPressed();
    }
}
override fun onNewAction(actionType: VFActionType, action: VFActionData) {
    if (actionType == VFActionType.closeProfilePressed) {
        onBackPressed()
    }
}

Open a profile

  1. Create your VFSettings object.
VFColors colors = new VFColors(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary), ContextCompat.getColor(getApplicationContext(), R.color.colorPrimaryLight), Color.WHITE);
VFSettings vfSettings = new VFSettings(colors);
val colors = VFColors(
    ContextCompat.getColor(applicationContext, R.color.colorPrimary),
    ContextCompat.getColor(
        applicationContext, R.color.colorPrimaryLight
    ),
    Color.WHITE
)
val vfSettings = VFSettings(colors)
  1. Create the VFProfilePresentationType object.
VFProfilePresentationType presentationType = VFProfilePresentationType.profile;
if (getIntent().getStringExtra(IntentKeys.INTENT_USER_PRESENTATION_TYPE) != null) {
    String presentationTypeString = getIntent().getStringExtra(IntentKeys.INTENT_USER_PRESENTATION_TYPE);
    if (presentationTypeString.equals(VFProfilePresentationType.profile.toString())) {
        presentationType = VFProfilePresentationType.profile;
    } else if (presentationTypeString.equals(VFProfilePresentationType.feed.toString())) {
        presentationType = VFProfilePresentationType.feed;
    }
}
var presentationType = VFProfilePresentationType.profile
if (intent.getStringExtra(IntentKeys.INTENT_USER_PRESENTATION_TYPE) != null) {
    val presentationTypeString =
        intent.getStringExtra(IntentKeys.INTENT_USER_PRESENTATION_TYPE)
    if (presentationTypeString == VFProfilePresentationType.profile.toString()) {
        presentationType = VFProfilePresentationType.profile
    } else if (presentationTypeString == VFProfilePresentationType.feed.toString()) {
        presentationType = VFProfilePresentationType.feed
    }
}
  1. Add the ProfileFragment into your content .
VFProfileFragment profileFragment = VFProfileFragment.newInstance(getApplication(), UUID.fromString(getIntent().getStringExtra(IntentKeys.INTENT_USER_UUID)), presentationType, this, vfSettings);
profileFragment.setActionCallback(this);
profileFragment.setCustomUICallback(this);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.profile_container, profileFragment);
ft.commit();
val profileFragment = VFProfileFragment.newInstance(
    application, UUID.fromString(
        intent.getStringExtra(IntentKeys.INTENT_USER_UUID)
    ), presentationType, this, vfSettings
)
profileFragment.setActionCallback(this)
profileFragment.setCustomUICallback(this)
val ft = supportFragmentManager.beginTransaction()
ft.replace(R.id.profile_container, profileFragment)
ft.commit()
  1. Listen to the ProfileFragment action callback .
@Override
public void onNewAction(VFActionType actionType, VFActionData action) {
    if (actionType == VFActionType.closeProfilePressed) {
        onBackPressed();
    }
}
override fun onNewAction(actionType: VFActionType, action: VFActionData) {
    if (actionType == VFActionType.closeNewCommentPressed) {
        onBackPressed()
    }
}

Implement the VFLayoutInterface (Optional)

The fragment content height will change depending on the amount of content present on the container. Listen to height changes by implementing the VFLayoutInterface and update the container view height accordingly.

@Override
public void containerHeightUpdated(VFFragment fragment, int height) {

}
fun containerHeightUpdated(fragment: VFFragment, height: Int ) {

}