FastComments.com

FastComments Android Library


ื–ื•ื”ื™ ืกืคืจื™ื™ืช Android ื”ืจืฉืžื™ืช ืฉืœ FastComments.

ื•ื•ื™ื“ื’'ื˜ื™ื ืฉืœ ืชื’ื•ื‘ื•ืช ืฉืœ FastComments ืขื‘ื•ืจ Android

ืžืื’ืจ

ืฆืคื” ื‘-GitHub


ืชื›ื•ื ื•ืช Internal Link

  • ๐Ÿ”„ ืชื’ื•ื‘ื•ืช ื—ื™ื•ืช ืขื ืขื“ื›ื•ื ื™ื ื‘ื–ืžืŸ ืืžืช
  • ๐Ÿ“ฑ ืจื›ื™ื‘ื™ ืžืžืฉืง ืžืฉืชืžืฉ ืžืงื•ืจื™ื™ื ืœ-Android
  • ๐Ÿงต ื“ื™ื•ื ื™ื ืžืฉืจืฉืจื™ื ืขื ืชื’ื•ื‘ื•ืช
  • ๐Ÿ‘ค ืื™ืžื•ืช SSO ืžืื•ื‘ื˜ื—
  • ๐Ÿ‘ ืžืขืจื›ืช ื”ืฆื‘ืขื” ืขื ืกื’ื ื•ื ื•ืช ื ื™ืชื ื™ื ืœื”ืชืืžื” ืื™ืฉื™ืช
  • ๐Ÿ”” ื”ืชืจืื•ืช ืžืฉืชืžืฉ ื•ื ื•ื›ื—ื•ืช
  • ๐Ÿ” ื™ื›ื•ืœื•ืช ืžื•ื“ืจืฆื™ื” ืฉืœ ืชื’ื•ื‘ื•ืช
  • ๐Ÿ“ฑ ืื™ื ื˜ื’ืจืฆื™ื” ืขื ืคื™ื“ ื—ื‘ืจืชื™
  • โ™พ๏ธ ื’ืœื™ืœื” ืื™ื ืกื•ืคื™ืช
  • ๐ŸŽจ ืชืžื™ื›ื” ื‘ืขืจื›ื•ืช ื ื•ืฉื ืžืงื™ืคื•ืช

ื“ืจื™ืฉื•ืช Internal Link

  • Android SDK 26+ (Android 8.0 Oreo ืื• ืžืื•ื—ืจ ื™ื•ืชืจ)
  • Java 8+

ื”ืชืงื ื” Internal Link

ื”ื•ืกืฃ ืืช ื”โ€‘FastComments SDK ืœืงื•ื‘ืฅ build.gradle.kts ืฉืœ ื”ืืคืœื™ืงืฆื™ื” ืฉืœืš:

dependencies {
    implementation("com.fastcomments:sdk:0.0.1")
}

ื•ื“ื ืฉื™ืฉ ืœืš ืืช ืžืื’ืจ Repsy ื‘ืงื•ื‘ืฅ settings.gradle.kts ืฉืœ ื”ืคืจื•ื™ืงื˜ ืฉืœืš:

dependencyResolutionManagement {
    repositories {
        maven {
            url = uri("https://repo.repsy.io/mvn/winrid/fastcomments")
        }
        // other repositories...
    }
}

ืฉื™ืžื•ืฉ ื‘ืกื™ืกื™ Internal Link

1. ื”ื•ืกืฃ FastCommentsView ืœืคืจื™ืกื” ืฉืœืš

<com.fastcomments.sdk.FastCommentsView
    android:id="@+id/commentsView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

2. ืืชื—ื•ืœ ื•ืงื•ื ืคื™ื’ื•ืจืฆื™ื” ืฉืœ ื”โ€‘SDK

// ืงื‘ืข ืืช ืชืฆื•ืจืช ื”โ€‘SDK
val config = CommentWidgetConfig(
    "your-tenant-id", 
    "page-url-id", 
    "Page Title", 
    "yourdomain.com", 
    "Site Name"
)

// ืืคืฉืจื•ื™ื•ืช ืงื•ื ืคื™ื’ื•ืจืฆื™ื” ื ื•ืกืคื•ืช
config.voteStyle = VoteStyle.UpDown // ืื• VoteStyle.Heart
config.enableInfiniteScrolling = true
config.hasDarkBackground = true // ืขื‘ื•ืจ ืชืžื™ื›ื” ื‘ืžืฆื‘ ื›ื”ื”

// ืืชื—ืœ ืืช ื”โ€‘SDK
val sdk = FastCommentsSDK(config)

// ืžืฆื ืืช ืชืฆื•ื’ืช ื”ืชื’ื•ื‘ื•ืช ื‘ืคืจื™ืกื” ืฉืœืš
val commentsView = findViewById<FastCommentsView>(R.id.commentsView)

// ื”ื’ื“ืจ ืืช ืžื•ืคืข ื”โ€‘SDK ืœืชืฆื•ื’ื”
commentsView.setSDK(sdk)

// ื˜ืขืŸ ืชื’ื•ื‘ื•ืช
commentsView.load()

ืื™ืžื•ืช SSO ืžืื•ื‘ื˜ื— Internal Link

ื”ื˜ืžืขืช ืื™ืžื•ืช ืžืื•ื‘ื˜ื— ืขื‘ื•ืจ ื”ืžืฉืชืžืฉื™ื ืฉืœืš:

// ืฆื•ืจ ื ืชื•ื ื™ ืžืฉืชืžืฉ (ืžื•ืžืœืฅ ืœื‘ืฆืข ื–ืืช ื‘ืฉืจืช ืฉืœืš)
val userData = SecureSSOUserData(
    "user-id",
    "user@example.com",
    "User Name",
    "https://path-to-avatar.jpg"
)

// ื™ืฆื™ืจืช ืืกื™ืžื•ืŸ SSO (ื™ืฉ ืœื‘ืฆืข ื–ืืช ื‘ืฆื“ ื”ืฉืจืช!)
val sso = FastCommentsSSO.createSecure("YOUR_API_KEY", userData)
val token = sso.prepareToSend()

// ื”ื•ืกืฃ ืœืงื•ื ืคื™ื’
config.sso = token

ืฉื™ืœื•ื‘ ืคื™ื“ Internal Link

ื”ืฆื’ ืคื™ื“ ื‘ืกื’ื ื•ืŸ ืจืฉืช ื—ื‘ืจืชื™ืช ืขื ืชื’ื•ื‘ื•ืช:

// ื”ื’ื“ืจ ืืช ื”-SDK
CommentWidgetConfig config = new CommentWidgetConfig();
config.tenantId = "your-tenant-id";
config.urlId = "page-url-id";

// ืืชื—ืœ ืืช Feed SDK
FastCommentsFeedSDK feedSDK = new FastCommentsFeedSDK(config);

// ื”ื’ื“ืจ ืืช ืชืฆื•ื’ืช ื”ืคื™ื“
FastCommentsFeedView feedView = findViewById(R.id.feedView);
feedView.setSDK(feedSDK);

// ื”ื’ื“ืจ ืžืื–ื™ืŸ ืœืื™ื ื˜ืจืืงืฆื™ื•ืช
feedView.setFeedViewInteractionListener(new FastCommentsFeedView.OnFeedViewInteractionListener() {
    @Override
    public void onFeedLoaded(List<FeedPost> posts) {
        // ื”ืคื™ื“ ื”ื•ื˜ืขืŸ ื‘ื”ืฆืœื—ื”
    }

    @Override
    public void onFeedError(String errorMessage) {
        // ื˜ืคืœ ื‘ืฉื’ื™ืื•ืช
    }

    @Override
    public void onPostSelected(FeedPost post) {
        // ื”ืžืฉืชืžืฉ ื‘ื—ืจ ืคื•ืกื˜
    }

    @Override
    public void onCommentsRequested(FeedPost post) {
        // ื”ืฆื’ ืชื’ื•ื‘ื•ืช ืขื‘ื•ืจ ื”ืคื•ืกื˜
        CommentsDialog dialog = new CommentsDialog(context, post, feedSDK);
        dialog.show();
    }
});

// ื˜ืขืŸ ืืช ื”ืคื™ื“
feedView.load();

ืฉื™ืœื•ื‘ ืฆ'ืื˜ ื—ื™ Internal Link


ื”ื•ืกืฃ ืžืžืฉืง ืฆ'ืื˜ ื‘ื–ืžืŸ ืืžืช ืœืืคืœื™ืงืฆื™ื” ืฉืœืš:

// ื”ื•ืกืฃ ืืช LiveChatView ืœ-XML ืฉืœ ื”ืคืจื™ืกื” ืฉืœืš
// <com.fastcomments.sdk.LiveChatView
//     android:id="@+id/liveChatView"
//     android:layout_width="match_parent"
//     android:layout_height="match_parent" />

// ืฆื•ืจ ืชืฆื•ืจื” ืขื‘ื•ืจ ื”-SDK
val config = CommentWidgetConfig().apply {
    tenantId = "your-tenant-id"
    urlId = "chat-room-identifier" 
    pageTitle = "Chat Room Name"
}
LiveChatView.setupLiveChatConfig(config)

// ืื•ืคืฆื™ื•ื ืœื™: ื”ื•ืกืฃ ืื™ืžื•ืช ืžืฉืชืžืฉ
val userData = SimpleSSOUserData(
    "User Name",
    "user@example.com",
    "https://path-to-avatar.jpg"
)
val sso = FastCommentsSSO(userData)
config.sso = sso.prepareToSend()

// ืืชื—ืœ ืืช ื”-SDK
val sdk = FastCommentsSDK().configure(config)

// ื”ื’ื“ืจ ืืช LiveChatView
val liveChatView = findViewById<LiveChatView>(R.id.liveChatView)
liveChatView.setSDK(sdk)
liveChatView.load()

// ืืœ ืชืฉื›ื— ืœื˜ืคืœ ื‘ืžื—ื–ื•ืจ ื”ื—ื™ื™ื
override fun onResume() {
    super.onResume()
    sdk.refreshLiveEvents()
}

override fun onDestroy() {
    super.onDestroy()
    sdk.cleanup()
}

ืคืจื•ื™ืงื˜ื™ื ืœื“ื•ื’ืžื” Internal Link

ืขื™ื™ืŸ ื‘ืžื™ืžื•ืฉื™ ื”ื“ืžื• ื”ื‘ืื™ื:

ืืคืฉืจื•ื™ื•ืช ืชืฆื•ืจื” Internal Link


ื”-SDK ืžืกืคืง ืžื’ื•ื•ืŸ ืืคืฉืจื•ื™ื•ืช ืชืฆื•ืจื” ื“ืจืš ื”ืžื—ืœืงื” CommentWidgetConfig:

ืืคืฉืจื•ืช ืชื™ืื•ืจ
tenantId ืžื–ื”ื” ื”ื—ืฉื‘ื•ืŸ ืฉืœืš ื‘-FastComments
urlId ืžื–ื”ื” ื”ืžื™ื™ืฆื’ ืืช ื”ื“ืฃ ื”ื ื•ื›ื—ื™
sso ืืกื™ืžื•ืŸ SSO ืœืื™ืžื•ืช
allowAnon ืืคืฉืจ ืคืจืกื•ื ืชื’ื•ื‘ื•ืช ืื ื•ื ื™ืžื™ื•ืช
voteStyle ืกื’ื ื•ืŸ ื”ืฆื‘ืขื” โ€” UpDown ืื• Heart
hideAvatars ื”ืกืชืจืช ืื•ื•ื˜ืจื™ื ืฉืœ ืžืฉืชืžืฉื™ื
hasDarkBackground ืžืฆื™ื™ืŸ ืžืฆื‘ ื›ื”ื”
customCSS ืกื’ื ื•ื ื•ืช CSS ืžื•ืชืืžื™ื ืื™ืฉื™ืช
enableInfiniteScrolling ื”ืคืขืœืช ื’ืœื™ืœื” ืื™ื ืกื•ืคื™ืช
readonly ืžื ื™ืขืช ืคืจืกื•ื ืชื’ื•ื‘ื•ืช ืืš ื”ืฆื’ืช ืชื’ื•ื‘ื•ืช ืงื™ื™ืžื•ืช
disableVoting ื”ืฉื‘ืชืช ืคื•ื ืงืฆื™ื™ืช ื”ื”ืฆื‘ืขื”
disableLiveCommenting ื”ืฉื‘ืชืช ืขื“ื›ื•ื ื™ื ื‘ื–ืžืŸ ืืžืช
---

ื”ืชืืžื” ืžืงื™ืคื” ืฉืœ ืขืจื›ืช ื”ื ื•ืฉื Internal Link

ื›ืœ ื”ื›ืคืชื•ืจื™ื ื•ืืœืžื ื˜ื™ื ื‘ืžืžืฉืง ื”ืžืฉืชืžืฉ ื‘ืขืจื›ืช ื”ืคื™ืชื•ื— ืฉืœ FastComments ื ื™ืชื ื™ื ืœืขื™ืฆื•ื‘. ื”ืฉืชืžืฉ ื‘- FastCommentsTheme.Builder ืœืฉืœื™ื˜ื” ืžืœืื” ื‘ืžื™ืชื•ื’ ืฉืœ ื”ืืคืœื™ืงืฆื™ื” ืฉืœืš.

ืขื™ืฆื•ื‘ ืชื›ื ื•ืชื™ (ืžื•ืžืœืฅ)

val theme = FastCommentsTheme.Builder()
    // ื›ืคืชื•ืจื™ ืคืขื•ืœื”: ืฉืœื™ื—ื”, ื”ืฆื‘ืขื”, ืชืคืจื™ื˜, ื›ืคืชื•ืจื™ ืœื™ื™ืง/ืฉื™ืชื•ืฃ
    .setActionButtonColor(Color.parseColor("#FF1976D2"))

    // ื›ืคืชื•ืจื™ ืชื’ื•ื‘ื”: ื›ืคืชื•ืจื™ ืžืขื ื” ืœื”ืขืจื•ืช  
    .setReplyButtonColor(Color.parseColor("#FF4CAF50"))

    // ื›ืคืชื•ืจื™ ื”ื—ืœืคื”: ื›ืคืชื•ืจื™ ื”ืฆื’/ื”ืกืชืจ ืชื’ื•ื‘ื•ืช
    .setToggleRepliesButtonColor(Color.parseColor("#FFFF5722"))

    // ื›ืคืชื•ืจื™ ื˜ืขื™ื ืช ืขื•ื“: ื›ืคืชื•ืจื™ ืขื™ืžื•ื“
    .setLoadMoreButtonTextColor(Color.parseColor("#FF9C27B0"))

    .setPrimaryColor(Color.parseColor("#FF6200EE"))
    .setLinkColor(Color.parseColor("#FF1976D2"))
    .setDialogHeaderBackgroundColor(Color.parseColor("#FF333333"))
    .build()

// ื”ื—ืœืช ื”ืขื™ืฆื•ื‘
sdk.setTheme(theme)

ื”ื—ืœืคื” ืžื”ื™ืจื” ืฉืœ ืฆื‘ืขื™ื

Override color resources in your colors.xml for simple branding:

<!-- ื‘ืงื•ื‘ืฅ res/values/colors.xml ืฉืœ ื”ืืคืœื™ืงืฆื™ื” ืฉืœืš -->
<resources>
    <!-- ืฉื ื” ืืช ื›ืœ ืจื›ื™ื‘ื™ ื”ืžืžืฉืง ื”ืจืืฉื™ื™ื -->
    <color name="primary">#FF1976D2</color>

    <!-- ืื• ื”ืชืื ืกื•ื’ื™ ื›ืคืชื•ืจื™ื ืกืคืฆื™ืคื™ื™ื -->
    <color name="fastcomments_action_button_color">#FF1976D2</color>
    <color name="fastcomments_reply_button_color">#FF4CAF50</color>
    <color name="fastcomments_toggle_replies_button_color">#FFFF5722</color>
    <color name="fastcomments_load_more_button_text_color">#FF9C27B0</color>
</resources>

ื›ื™ืกื•ื™ ื›ืคืชื•ืจื™ื ืžืขื•ืฆื‘ื™ื

ื›ืœ ื›ืคืชื•ืจ ื‘-SDK ืชื•ืžืš ื‘ืขื™ืฆื•ื‘:

  • ื›ืคืชื•ืจื™ ืฉืœื™ื—ื”, ื›ืคืชื•ืจื™ ื”ืฆื‘ืขื”, ื›ืคืชื•ืจื™ ืชืคืจื™ื˜, ื›ืคืชื•ืจื™ ืชื’ื•ื‘ื”
  • ื›ืคืชื•ืจื™ ื”ืฆื’/ื”ืกืชืจ ืชื’ื•ื‘ื•ืช, ื›ืคืชื•ืจื™ 'ื˜ืขื•ืŸ ืขื•ื“'
  • ื›ืคืชื•ืจื™ ืคืขื•ืœื” ื‘ืคื™ื“ (ืœื™ื™ืง, ืชื’ื•ื‘ื”, ืฉื™ืชื•ืฃ)
  • ื›ืคืชื•ืจื™ ื“ื™ืืœื•ื’ (ืฉืœื—, ื‘ื˜ืœ, ืฉืžื•ืจ)
  • ื›ืคืชื•ืจื™ ืžืฉื™ืžื•ืช ื“ื™ื ืžื™ื™ื ื‘ืคื•ืกื˜ื™ื ืฉืœ ื”ืคื™ื“

ืœืชื™ืขื•ื“ ืžืคื•ืจื˜ ืขืœ ืขืจื›ื•ืช ืขื™ืฆื•ื‘, ืจืื• ืืช THEMING.md.

ื ื™ื”ื•ืœ ื–ื™ื›ืจื•ืŸ Internal Link

ืžื ื™ืขืช ื“ืœื™ืคื•ืช ื–ื™ื›ืจื•ืŸ

ื›ื“ื™ ืœืžื ื•ืข ื“ืœื™ืคื•ืช ื–ื™ื›ืจื•ืŸ ื‘ืขืช ืฉื™ืžื•ืฉ ื‘ึพFastComments views ื‘ึพActivities ืื• Fragments, ืชืžื™ื“ ืงืจืื• ืœึพcleanup() ื›ืืฉืจ ื”ืชืฆื•ื’ื” ื›ื‘ืจ ืœื ื ื“ืจืฉืช:

ื‘ึพActivities:

@Override
protected void onDestroy() {
    super.onDestroy();
    // ื ืงื” ืชืฆื•ื’ื•ืช FastComments ื›ื“ื™ ืœืžื ื•ืข ื“ืœื™ืคื•ืช ื–ื™ื›ืจื•ืŸ
    if (feedView != null) {
        feedView.cleanup();
    }
    if (commentsView != null) {
        commentsView.cleanup();
    }
}

ื‘ึพFragments:

@Override
public void onDestroyView() {
    super.onDestroyView();
    // ื ืงื” ืชืฆื•ื’ื•ืช FastComments ื›ืืฉืจ ืชืฆื•ื’ืช ื”ึพFragment ื ื”ืจืกืช
    if (feedView != null) {
        feedView.cleanup();
        feedView = null;
    }
}

@Override
public void onDestroy() {
    super.onDestroy();
    // ื ื™ืงื•ื™ ื ื•ืกืฃ ื›ืืฉืจ ื”ึพFragment ื ื”ืจืก
    if (feedSDK != null) {
        feedSDK.cleanup();
        feedSDK = null;
    }
}

ื‘ืขืช ื”ื—ืœืคืช Fragments:

// ืœืคื ื™ ื”ื—ืœืคื” ืื• ื”ืกืจื” ืฉืœ fragment ื”ืžื›ื™ืœ ืชืฆื•ื’ื•ืช FastComments
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.container);
if (currentFragment instanceof YourFragmentWithFeedView) {
    ((YourFragmentWithFeedView) currentFragment).cleanupFeedView();
}

// ื•ืื– ื”ืžืฉื™ื›ื• ื‘ืขืกืงืช ื”ึพfragment
getSupportFragmentManager().beginTransaction()
    .replace(R.id.container, newFragment)
    .commit();

ื—ืฉื•ื‘: ืชืžื™ื“ ืงืจืื• ืœืฉื™ื˜ื•ืช cleanup() ื›ื“ื™ ืœืžื ื•ืข ื“ืœื™ืคื•ืช ื–ื™ื›ืจื•ืŸ, ื‘ืžื™ื•ื—ื“ ื›ืืฉืจ:

  • ื”ึพActivities ื ื”ืจืกื•ืช
  • ืชืฆื•ื’ื•ืช ื”ึพFragment ื ื”ืจืกื•ืช
  • ื”ื—ืœืคื” ื‘ื™ืŸ Fragments
  • ื ื™ื•ื•ื˜ ื”ื—ื•ืฆื” ืžืžืกื›ื™ื ื”ืžื›ื™ืœื™ื ืจื›ื™ื‘ื™ FastComments

ื–ืงื•ืงื™ื ืœืขื–ืจื”?

ืื ืืชื ื ืชืงืœื™ื ื‘ื‘ืขื™ื•ืช ืื• ื™ืฉ ืœื›ื ืฉืืœื•ืช ืœื’ื‘ื™ ืกืคืจื™ื™ืช Android, ืื ื:

ืชืจื•ืžื•ืช

ืชืจื•ืžื•ืช ืžืชืงื‘ืœื•ืช ื‘ื‘ืจื›ื”! ืื ื ื‘ืงืจื• ื‘-ืžืื’ืจ GitHub ืœื”ื ื—ื™ื•ืช ืœืชืจื•ืžื”.