Skip to content

Commit 25386a1

Browse files
committed
comment toolbar
1 parent 5273381 commit 25386a1

File tree

16 files changed

+1388
-8
lines changed

16 files changed

+1388
-8
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package com.fastcomments
2+
3+
import android.os.Bundle
4+
import androidx.appcompat.app.AppCompatActivity
5+
import com.fastcomments.core.CommentWidgetConfig
6+
import com.fastcomments.core.VoteStyle
7+
import com.fastcomments.core.sso.FastCommentsSSO
8+
import com.fastcomments.core.sso.SimpleSSOUserData
9+
import com.fastcomments.sdk.FastCommentsSDK
10+
import com.fastcomments.sdk.FastCommentsView
11+
import com.fastcomments.sdk.examples.CodeFormattingToolbarButton
12+
import com.fastcomments.sdk.examples.EmojiPickerToolbarButton
13+
import com.fastcomments.sdk.examples.GifPickerToolbarButton
14+
import com.fastcomments.sdk.examples.MentionToolbarButton
15+
16+
/**
17+
* Activity that showcases the FastComments toolbar functionality for prospective developers.
18+
*
19+
* This example demonstrates:
20+
* - How to enable the comment input toolbar
21+
* - How to configure default formatting buttons (bold, italic, link, code)
22+
* - How to add custom toolbar buttons (emoji picker, GIF picker, mention, custom code formatter)
23+
* - Both global SDK configuration and per-instance customization
24+
* - Best practices for toolbar implementation
25+
*/
26+
class ToolbarShowcaseActivity : AppCompatActivity() {
27+
28+
private lateinit var commentsView: FastCommentsView
29+
30+
override fun onCreate(savedInstanceState: Bundle?) {
31+
super.onCreate(savedInstanceState)
32+
setContentView(R.layout.activity_main)
33+
34+
// 1. Basic FastComments configuration (same as SimpleSSOExampleActivity)
35+
val config = CommentWidgetConfig(
36+
"demo",
37+
"toolbar-showcase", // Different URL slug to avoid comment conflicts
38+
"https://fastcomments.com/toolbar-demo",
39+
"fastcomments.com",
40+
"Toolbar Demo"
41+
)
42+
43+
// Optional: Configure vote style
44+
config.voteStyle = VoteStyle.Heart
45+
46+
// 2. Set up SSO with example user data
47+
val userData = SimpleSSOUserData(
48+
"Toolbar Demo User",
49+
50+
"https://staticm.fastcomments.com/1639362726066-DSC_0841.JPG"
51+
)
52+
val sso = FastCommentsSSO(userData)
53+
config.sso = sso.prepareToSend()
54+
55+
// 3. Create SDK instance
56+
val sdk = FastCommentsSDK(config)
57+
58+
// 4. TOOLBAR CONFIGURATION - This is the main showcase feature
59+
configureFastCommentsToolbar(sdk)
60+
61+
// 5. Set up the comments view
62+
commentsView = findViewById(R.id.commentsView)
63+
commentsView.setSDK(sdk)
64+
commentsView.load()
65+
66+
// 6. Optional: Demonstrate per-instance toolbar customization
67+
demonstrateInstanceCustomization()
68+
}
69+
70+
/**
71+
* Configures the FastComments toolbar with various buttons and features.
72+
* This demonstrates the main toolbar functionality that developers will use.
73+
*/
74+
private fun configureFastCommentsToolbar(sdk: FastCommentsSDK) {
75+
// Enable the comment input toolbar globally for all comment inputs
76+
sdk.setCommentToolbarEnabled(true)
77+
78+
// Enable default formatting buttons (bold, italic, link)
79+
// These provide basic text formatting functionality out of the box
80+
sdk.setDefaultFormattingButtonsEnabled(true)
81+
82+
// Add custom toolbar buttons that will appear on all comment inputs
83+
// These demonstrate how to extend the toolbar with custom functionality
84+
85+
// 1. Emoji Picker - Provides a grid of common emojis
86+
sdk.addGlobalCustomToolbarButton(EmojiPickerToolbarButton())
87+
88+
// 2. GIF Picker - Demonstrates file/media selection (simulated for demo)
89+
sdk.addGlobalCustomToolbarButton(GifPickerToolbarButton())
90+
91+
// 3. Mention Button - Shows how to implement @mention functionality
92+
sdk.addGlobalCustomToolbarButton(MentionToolbarButton())
93+
94+
// 4. Code Formatter - Custom button that we created for this showcase
95+
// Demonstrates wrapping text in code tags with both click and long-click handlers
96+
sdk.addGlobalCustomToolbarButton(CodeFormattingToolbarButton())
97+
98+
// Note: You can also remove buttons dynamically:
99+
// sdk.removeGlobalCustomToolbarButton("button_id")
100+
// sdk.clearGlobalCustomToolbarButtons()
101+
}
102+
103+
/**
104+
* Demonstrates additional per-instance customization options.
105+
* This shows how individual comment input instances can have different toolbar configurations.
106+
*/
107+
private fun demonstrateInstanceCustomization() {
108+
// You can customize toolbar settings for specific comment input instances
109+
// after the SDK has been set. This is useful for different contexts within your app.
110+
111+
// Example of per-instance customization (commented out for this demo):
112+
/*
113+
// Get access to the bottom comment input view
114+
val bottomInputView = commentsView.getBottomCommentInputView()
115+
116+
// Override global settings for this specific instance
117+
bottomInputView?.let { inputView ->
118+
// Add an instance-specific button
119+
inputView.addCustomToolbarButton(SomeCustomButton())
120+
121+
// Or disable default formatting for this instance only
122+
inputView.setDefaultFormattingEnabled(false)
123+
124+
// Or hide the toolbar entirely for this instance
125+
inputView.setToolbarVisible(false)
126+
}
127+
*/
128+
}
129+
130+
companion object {
131+
private const val TAG = "ToolbarShowcase"
132+
}
133+
}

libraries/sdk/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ dependencies {
5858
implementation("com.github.chrisbanes:PhotoView:2.3.0")
5959

6060
testImplementation(libs.junit)
61+
testImplementation("org.mockito:mockito-core:5.8.0")
62+
testImplementation("org.robolectric:robolectric:4.11.1")
6163
androidTestImplementation(libs.androidx.junit)
6264
androidTestImplementation(libs.androidx.espresso.core)
6365
}

0 commit comments

Comments
 (0)