Skip to main content

Android-UGC

UGC Editor

A library with UGC Editor that works with InAppStory library.

Requirements

The minimum SDK version is 21 (Android 5.0).

Version compatibility

UGC SDK versionInAppStory SDK version
1.4.01.18.0 - 1.20.x
1.3.01.17.0+
1.2.21.16.2+
1.2.11.16.1
1.2.01.16.0
1.1.0 - 1.1.21.15.0-rc1
1.0.71.12.4
1.0.61.12.0-rc7
1.0.51.12.0-rc3+
1.0.41.12.0-rc2
1.0.0 - 1.0.21.9.1 - 1.11.1

The library is intended for Phone and Tablet projects (not intended for Android TV or Android Wear applications).

Adding to the project

Add jitpack maven repo to the root build.gradle in the repositories section :

allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}

In the project build.gradle (app level) in the dependencies section add dependency to InAppStory library:

implementation("com.github.inappstory:android-sdk:$inappstory_version") {
transitive=true
}

And then add dependency to UGC library (Latest release version is 1.2.2):

implementation("com.github.inappstory:ugc-android-sdk:$ugc_version") {
transitive=true
exclude group: 'com.github.inappstory', module: 'android-sdk' //exclude to prevent libraries overriding
}

Initialization and Editor Usage

  1. Initialize InAppStory SDK
  2. In AppearanceManager (in global or for StoriesList) you need to set csHasUgc as true.
  3. For StoriesList set click callback from UGC item with setOnUGCItemClick(callback: OnUGCItemClick). In callback you can open Editor with method from UGCInAppStoryManager.openEditor(ctx: Context, ugcInitData: HashMap<String, Any?>? = null)

For example:

appearanceManager.csHasUgc(true);
storiesList.setAppearanceManager(appearanceManager)
storiesList.setOnUGCItemClick {
UGCInAppStoryManager.openEditor(context)
}
storiesList.loadStories()

If you want to force close editor, you can use method UGCInAppStoryManager.closeEditor(closeCallback: () -> Unit) //closeCallback has empty body by default For example:

UGCInAppStoryManager.closeEditor {
Log.e(TAG, "Close editor")
}

UgcStoriesList

Initialization

Starting from version 1.12.x was added UgcStoriesList class to view UGC stories. It can be used like any View class. For example - via xml.


<com.inappstory.sdk.stories.ui.ugclist.UgcStoriesList android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/ugc_stories_list" />

Or via code:

fun addUGCStoriesList(parentView: ViewGroup, context: Context) {
val ugcStoriesList = UgcStoriesList(context)
parentView.addView(ugcStoriesList)
}

Methods

After SDK initialization you can load stories in UgcStoriesList with one of next methods

fun loadUGCStories(ugcStoriesList: UgcStoriesList) {
//use if you want load to show ugc stories without any filter
ugcStoriesList.loadStories();
}

fun loadUGCStories(ugcStoriesList: UgcStoriesList, stringFilter: String) {
//use if you want to pass filter as json string
ugcStoriesList.loadStories(stringFilter);
}

fun loadUGCStories(ugcStoriesList: UgcStoriesList, mapFilter: HashMap<String, Any?>) {
//use if you want to pass filter as HashMap
ugcStoriesList.loadStories(mapFilter);
}

This method also can be used to reload list (for example in PtR case)

warning

This method can generate DataException if SDK was not initialized. Strictly recommend to catch DataException for additional info.

UgcStoriesList is extends androidx.recyclerview.widget.RecyclerView. If necessary, you can use all the methods that are in the RecyclerView (setting the layoutManager, getting the adapter, etc.).

Customization and Callbacks

UgcStoriesList has same ways of customization and same callbacks as usual StoriesList. For more information you can read this (Customization) and this (Callbacks)

Ugc cell (simple customization)

If you don't use cells customization, you can set parametes for UGC editor cell with this method:

fun setUGCListItemSimpleAppearance(
appearanceManager: AppearanceManager,
ugcListItemSimpleAppearance: UGCListItemSimpleAppearance
) {
appearanceManager
.csUGCListItemSimpleAppearance(ugcListItemSimpleAppearance);
}


class UGCListItemSimpleAppearance(
iconColor: Int? = null, //uses for tint icon image
backgroundColor: Int? = Color("#0C62F3"),
iconMargin: Int? = Sizes.dpToPx(16, context),
iconId: Int? = R.drawable.ic_new_ugc, //icon from SDK
)

UGCListItemSimpleAppearance parameters can be set through Builder pattern

val appearance = UGCListItemSimpleAppearance()
.csIconColor(Color.RED)
.csBackgroundColor(Color.WHITE)

Loader

In version 1.2.0 added interfaceIUgcReaderLoaderView. You can use it to substitute your own loader instead of the default one on the ugc editor screen.

fun setCustomLoader() {
UGCInAppStoryManager.csUgcReaderLoaderView(
object : IUGCReaderLoaderView {
override fun getView(context: Context): View {
TODO("Not yet implemented")
}

override fun setIndeterminate(indeterminate: Boolean) {
TODO("Not yet implemented")
}

override fun setProgress(progress: Int, max: Int) {
TODO("Not yet implemented")
}
}
)
}
warning

Current version of UgcStoriesList does not support favorites, like/dislike and share features. Relevant settings in AppearanceManager (csHasFavorite, csHasShare, csHasLike and csFavoriteListItemInterface) will not affect the ugc stories list.