Skip to content

Commit 5273381

Browse files
authored
Merge pull request #35 from FastComments/tags
Adding Tags
2 parents ffbd0fa + a93fc99 commit 5273381

File tree

11 files changed

+82
-73
lines changed

11 files changed

+82
-73
lines changed

app/src/main/java/com/fastcomments/FeedExampleActivity.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919
import com.fastcomments.sdk.FastCommentsFeedView;
2020
import com.fastcomments.sdk.FeedPostCreateView;
2121
import com.fastcomments.sdk.OnUserClickListener;
22+
import com.fastcomments.sdk.TagSupplier;
2223
import com.fastcomments.sdk.UserClickContext;
2324
import com.fastcomments.sdk.UserClickSource;
2425
import com.fastcomments.sdk.UserInfo;
2526
import com.google.android.material.floatingactionbutton.FloatingActionButton;
2627

28+
import java.util.Arrays;
2729
import java.util.List;
2830

2931
/**
@@ -73,6 +75,12 @@ protected void onCreate(Bundle savedInstanceState) {
7375

7476
// Set the SDK instance for the view
7577
feedView.setSDK(feedSDK);
78+
79+
feedView.setTagSupplier(currentUser -> {
80+
// You can customize the user's experience. Only feed items with the same tags will be returned.
81+
// return null or don't set a supplier to get a "global" feed.
82+
return null;
83+
});
7684

7785
// Create and add the FeedPostCreateView
7886
setupPostCreationView();

libraries/sdk/src/main/java/com/fastcomments/sdk/FastCommentsFeedSDK.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ public class FastCommentsFeedSDK {
8383
private String tenantIdWS;
8484
private String urlIdWS;
8585
private String userIdWS;
86+
private TagSupplier tagSupplier;
8687

8788
/**
8889
* Constructs a FastCommentsFeedSDK instance with the given configuration
@@ -117,6 +118,25 @@ public FastCommentsTheme getTheme() {
117118
return theme;
118119
}
119120

121+
/**
122+
* Set a TagSupplier to provide tags for filtering feed posts.
123+
* The tags returned by the supplier will be used when fetching posts from the API.
124+
*
125+
* @param tagSupplier The TagSupplier implementation, or null to disable tag filtering
126+
*/
127+
public void setTagSupplier(TagSupplier tagSupplier) {
128+
this.tagSupplier = tagSupplier;
129+
}
130+
131+
/**
132+
* Get the current TagSupplier
133+
*
134+
* @return The current TagSupplier or null if not set
135+
*/
136+
public TagSupplier getTagSupplier() {
137+
return tagSupplier;
138+
}
139+
120140
/**
121141
* Set a custom theme for the SDK
122142
*
@@ -304,11 +324,18 @@ public void load(FCCallback<PublicFeedPostsResponse> callback) {
304324
*/
305325
private void loadFeedPosts(FCCallback<PublicFeedPostsResponse> callback) {
306326
try {
327+
// Get tags from TagSupplier if available
328+
List<String> tags = null;
329+
if (tagSupplier != null) {
330+
tags = tagSupplier.getTags(currentUser);
331+
}
332+
307333
api.getFeedPostsPublic(config.tenantId)
308334
.afterId(lastPostId)
309335
.limit(pageSize)
310336
.sso(config.getSSOToken())
311337
.includeUserInfo(lastPostId == null) // only include for initial req
338+
.tags(tags)
312339
.executeAsync(new ApiCallback<GetFeedPostsPublic200Response>() {
313340
@Override
314341
public void onFailure(ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {

libraries/sdk/src/main/java/com/fastcomments/sdk/FastCommentsFeedView.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,18 @@ public void setFeedViewInteractionListener(OnFeedViewInteractionListener listene
421421
public void setOnUserClickListener(OnUserClickListener listener) {
422422
this.userClickListener = listener;
423423
}
424+
425+
/**
426+
* Set a TagSupplier to provide tags for filtering feed posts.
427+
* The tags returned by the supplier will be used when fetching posts from the API.
428+
*
429+
* @param tagSupplier The TagSupplier implementation, or null to disable tag filtering
430+
*/
431+
public void setTagSupplier(TagSupplier tagSupplier) {
432+
if (sdk != null) {
433+
sdk.setTagSupplier(tagSupplier);
434+
}
435+
}
424436

425437
/**
426438
* Flag to track when loading more posts

libraries/sdk/src/main/java/com/fastcomments/sdk/FeedPostCreateView.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,19 @@ private CreateFeedPostParams convertToParams(FeedPost post) {
564564
params.setLinks(post.getLinks());
565565
params.setFromUserId(post.getFromUserId());
566566
params.setFromUserDisplayName(post.getFromUserDisplayName());
567-
params.setTags(post.getTags());
567+
568+
// Use tags from TagSupplier if available, otherwise use post's tags
569+
if (sdk != null && sdk.getTagSupplier() != null) {
570+
List<String> supplierTags = sdk.getTagSupplier().getTags(sdk.getCurrentUser());
571+
if (supplierTags != null && !supplierTags.isEmpty()) {
572+
params.setTags(supplierTags);
573+
} else {
574+
params.setTags(post.getTags());
575+
}
576+
} else {
577+
params.setTags(post.getTags());
578+
}
579+
568580
params.setMeta(post.getMeta());
569581

570582
return params;

libraries/sdk/src/main/java/com/fastcomments/sdk/FeedPostsAdapter.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import com.fastcomments.model.FeedPostLink;
2828
import com.fastcomments.model.FeedPostMediaItem;
2929
import com.fastcomments.model.FeedPostMediaItemAsset;
30-
import com.google.android.material.chip.Chip;
31-
import com.google.android.material.chip.ChipGroup;
3230

3331
import java.time.OffsetDateTime;
3432
import java.time.format.DateTimeFormatter;
@@ -388,7 +386,6 @@ class FeedPostViewHolder extends RecyclerView.ViewHolder {
388386
private final TextView postTimeTextView;
389387
private final TextView contentTextView;
390388
private final ImageView avatarImageView;
391-
private final ChipGroup tagsChipGroup;
392389
private final TextView likeCountTextView;
393390
private final Button commentButton;
394391
private final Button likeButton;
@@ -421,7 +418,6 @@ class FeedPostViewHolder extends RecyclerView.ViewHolder {
421418
postTimeTextView = itemView.findViewById(R.id.postTimeTextView);
422419
contentTextView = itemView.findViewById(R.id.contentTextView);
423420
avatarImageView = itemView.findViewById(R.id.avatarImageView);
424-
tagsChipGroup = itemView.findViewById(R.id.tagsChipGroup);
425421
likeCountTextView = itemView.findViewById(R.id.likeCountTextView);
426422
commentButton = itemView.findViewById(R.id.commentButton);
427423
likeButton = itemView.findViewById(R.id.likeButton);
@@ -555,8 +551,6 @@ void bind(FeedPost post, int position) {
555551
contentTextView.setVisibility(View.GONE);
556552
}
557553

558-
// Set tags if available
559-
setupTags(post);
560554

561555
// Handle like count and comment count display
562556
updateLikeAndCommentCounts(post);
@@ -1167,27 +1161,6 @@ private void bindTaskPost(FeedPost post) {
11671161
}
11681162
}
11691163

1170-
private void setupTags(FeedPost post) {
1171-
tagsChipGroup.removeAllViews();
1172-
1173-
if (post.getTags() != null && !post.getTags().isEmpty()) {
1174-
tagsChipGroup.setVisibility(View.VISIBLE);
1175-
1176-
for (String tag : post.getTags()) {
1177-
Chip chip = new Chip(context);
1178-
chip.setText(tag);
1179-
chip.setClickable(true);
1180-
chip.setCheckable(false);
1181-
chip.setChipBackgroundColorResource(android.R.color.transparent);
1182-
chip.setChipStrokeWidth(1f);
1183-
chip.setChipStrokeColorResource(android.R.color.darker_gray);
1184-
1185-
tagsChipGroup.addView(chip);
1186-
}
1187-
} else {
1188-
tagsChipGroup.setVisibility(View.GONE);
1189-
}
1190-
}
11911164

11921165
/**
11931166
* Get the best quality image URL for full-screen viewing
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.fastcomments.sdk;
2+
3+
import com.fastcomments.model.UserSessionInfo;
4+
5+
import java.util.List;
6+
7+
/**
8+
* Interface for providing tags to filter feed posts.
9+
* The tags returned by this supplier will be used to:
10+
* 1. Filter the feed when fetching posts
11+
* 2. Automatically include when creating new posts
12+
*/
13+
public interface TagSupplier {
14+
/**
15+
* Get the list of tags to use for filtering feed posts.
16+
* This method is called when loading the feed and when creating new posts.
17+
*
18+
* @param currentUser The current authenticated user, or null if not authenticated
19+
* @return List of tags to filter by, or null/empty list for no filtering
20+
*/
21+
List<String> getTags(UserSessionInfo currentUser);
22+
}

libraries/sdk/src/main/res/layout/feed_post_item.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,6 @@
104104
<!-- Links will be added dynamically here -->
105105
</LinearLayout>
106106

107-
<!-- Tags Container -->
108-
<com.google.android.material.chip.ChipGroup
109-
android:id="@+id/tagsChipGroup"
110-
android:layout_width="match_parent"
111-
android:layout_height="wrap_content"
112-
android:layout_marginTop="4dp"
113-
app:chipSpacingHorizontal="4dp"
114-
android:visibility="gone"
115-
tools:visibility="visible" />
116107

117108
<!-- Like Count -->
118109
<TextView

libraries/sdk/src/main/res/layout/feed_post_item_multi_image.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,6 @@
189189
android:paddingEnd="12dp"
190190
android:paddingBottom="2dp">
191191

192-
<!-- Tags Container -->
193-
<com.google.android.material.chip.ChipGroup
194-
android:id="@+id/tagsChipGroup"
195-
android:layout_width="match_parent"
196-
android:layout_height="wrap_content"
197-
android:layout_marginTop="4dp"
198-
app:chipSpacingHorizontal="4dp"
199-
android:visibility="gone"
200-
tools:visibility="visible" />
201192

202193
<!-- Like Count -->
203194
<TextView

libraries/sdk/src/main/res/layout/feed_post_item_single_image.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,6 @@
116116
android:paddingEnd="12dp"
117117
android:paddingBottom="2dp">
118118

119-
<!-- Tags Container -->
120-
<com.google.android.material.chip.ChipGroup
121-
android:id="@+id/tagsChipGroup"
122-
android:layout_width="match_parent"
123-
android:layout_height="wrap_content"
124-
android:layout_marginTop="4dp"
125-
app:chipSpacingHorizontal="4dp"
126-
android:visibility="gone"
127-
tools:visibility="visible" />
128119

129120
<!-- Like Count -->
130121
<TextView

libraries/sdk/src/main/res/layout/feed_post_item_task.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,6 @@
183183
<!-- Regular link buttons will be added dynamically -->
184184
</LinearLayout>
185185

186-
<!-- Tags Container -->
187-
<com.google.android.material.chip.ChipGroup
188-
android:id="@+id/tagsChipGroup"
189-
android:layout_width="match_parent"
190-
android:layout_height="wrap_content"
191-
android:layout_marginTop="4dp"
192-
app:chipSpacingHorizontal="4dp"
193-
android:visibility="gone"
194-
tools:visibility="visible" />
195186

196187
<!-- Like Count -->
197188
<TextView

0 commit comments

Comments
 (0)