FastComments.com

Android 앱에 댓글 추가하기


이것은 FastComments의 공식 Android 라이브러리입니다.

Android용 FastComments 댓글 위젯

저장소

GitHub에서 보기


기능 Internal Link


  • 🔄 실시간 업데이트를 통한 라이브 댓글
  • 📱 네이티브 Android UI 구성 요소
  • 🧵 답글을 포함한 스레드형 토론
  • 👤 보안 SSO 인증
  • 👍 사용자 지정 가능한 스타일의 투표 시스템
  • 🔔 사용자 알림 및 접속 상태
  • 🔍 댓글 중재 기능
  • 📱 소셜 피드 통합
  • ♾️ 무한 스크롤 페이지 매김
  • 🎨 포괄적인 테마

요구 사항 Internal Link

  • Android SDK 26+ (Android 8.0 Oreo 이상)
  • Java 8+

설치 Internal Link

앱의 build.gradle.kts 파일에 FastComments SDK를 추가하세요:

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

프로젝트의 settings.gradle.kts 파일에 Repsy 리포지토리가 포함되어 있는지 확인하세요:

dependencyResolutionManagement {
    repositories {
        maven {
            url = uri("https://repo.repsy.io/mvn/winrid/fastcomments")
        }
        // 다른 리포지토리...
    }
}

기본 사용법 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";

// 피드 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();
    }
});

// Load the feed
feedView.load();

라이브 채팅 연동 Internal Link

앱에 실시간 채팅 인터페이스를 추가하세요:

// 레이아웃 XML에 LiveChatView 추가
// <com.fastcomments.sdk.LiveChatView
//     android:id="@+id/liveChatView"
//     android:layout_width="match_parent"
//     android:layout_height="match_parent" />

// Create a configuration for the 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)

// 라이브 채팅 뷰 설정
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 클래스에서 다양한 구성 옵션을 제공합니다:

OptionDescription
tenantIdFastComments 계정 ID
urlId현재 페이지를 나타내는 ID
sso인증을 위한 SSO 토큰
allowAnon익명 댓글 허용
voteStyleUpDown 또는 Heart 투표 스타일
hideAvatars사용자 아바타 숨기기
hasDarkBackground다크 모드 여부
customCSS사용자 정의 CSS 스타일
enableInfiniteScrolling무한 스크롤 페이징 활성화
readonly댓글 작성 비활성화(댓글 표시)
disableVoting투표 기능 비활성화
disableLiveCommenting실시간 업데이트 비활성화

포괄적인 테마 커스터마이징 Internal Link

FastComments SDK의 모든 버튼 및 UI 요소는 테마 설정이 가능합니다. 앱 브랜딩을 완전히 제어하려면 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)

빠른 색상 재정의

간단한 브랜딩을 위해 colors.xml의 색상 리소스를 오버라이드하세요:

<!-- 앱의 res/values/colors.xml에서 -->
<resources>
    <!-- 모든 주요 UI 요소 변경 -->
    <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

메모리 누수 방지

Activity 또는 Fragment에서 FastComments 뷰를 사용할 때 메모리 누수를 방지하려면, 더 이상 뷰가 필요하지 않을 때 항상 cleanup()을 호출하세요:

액티비티에서:

@Override
protected void onDestroy() {
    super.onDestroy();
    // 메모리 누수를 방지하기 위해 FastComments 뷰를 정리합니다
    if (feedView != null) {
        feedView.cleanup();
    }
    if (commentsView != null) {
        commentsView.cleanup();
    }
}

프래그먼트에서:

@Override
public void onDestroyView() {
    super.onDestroyView();
    // 프래그먼트 뷰가 파괴될 때 FastComments 뷰를 정리합니다
    if (feedView != null) {
        feedView.cleanup();
        feedView = null;
    }
}

@Override
public void onDestroy() {
    super.onDestroy();
    // 프래그먼트가 파괴될 때 추가 정리 수행
    if (feedSDK != null) {
        feedSDK.cleanup();
        feedSDK = null;
    }
}

프래그먼트를 전환할 때:

// FastComments 뷰를 포함한 프래그먼트를 교체 또는 제거하기 전에
Fragment currentFragment = getSupportFragmentManager().findFragmentById(R.id.container);
if (currentFragment instanceof YourFragmentWithFeedView) {
    ((YourFragmentWithFeedView) currentFragment).cleanupFeedView();
}

// Then proceed with fragment transaction
getSupportFragmentManager().beginTransaction()
    .replace(R.id.container, newFragment)
    .commit();

중요: 메모리 누수를 방지하려면 항상 cleanup() 메서드를 호출하세요. 특히 다음과 같은 경우:

  • 액티비티가 종료될 때
  • 프래그먼트 뷰가 파괴될 때
  • 프래그먼트 간 전환 시
  • FastComments 컴포넌트를 포함한 화면에서 이동할 때

도움을 원하시나요?

Android 라이브러리와 관련하여 문제가 발생하거나 질문이 있는 경우, 다음을 이용하세요:

기여

기여는 환영합니다! 기여 지침은 GitHub 저장소에서 확인하세요.