31
31
import com .cometchat .chatuikit .shared .models .CometChatMessageTemplate ;
32
32
import com .cometchat .chatuikit .shared .resources .utils .Utils ;
33
33
import com .cometchat .chatuikit .shared .viewholders .MessagesViewHolderListener ;
34
- import com .cometchat .chatuikit .shared .views .cometchatmessagebubble .CometChatMessageBubble ;
34
+ import com .cometchat .chatuikit .shared .views .messagebubble .CometChatMessageBubble ;
35
35
36
36
import java .util .HashMap ;
37
37
import java .util .List ;
@@ -50,23 +50,6 @@ public CollaborativeDocumentExtensionDecorator(DataSource dataSource, Collaborat
50
50
this .configuration = configuration ;
51
51
}
52
52
53
- @ Override
54
- public List <String > getDefaultMessageTypes () {
55
- List <String > types = super .getDefaultMessageTypes ();
56
- if (!types .contains (collaborativeDocumentExtensionTypeConstant )) {
57
- types .add (collaborativeDocumentExtensionTypeConstant );
58
- }
59
- return types ;
60
- }
61
-
62
- @ Override
63
- public List <String > getDefaultMessageCategories () {
64
- List <String > categories = super .getDefaultMessageCategories ();
65
- if (!categories .contains (UIKitConstants .MessageCategory .CUSTOM ))
66
- categories .add (UIKitConstants .MessageCategory .CUSTOM );
67
- return categories ;
68
- }
69
-
70
53
@ Override
71
54
public List <CometChatMessageTemplate > getMessageTemplates (AdditionParameter additionParameter ) {
72
55
List <CometChatMessageTemplate > templates = super .getMessageTemplates (additionParameter );
@@ -75,61 +58,62 @@ public List<CometChatMessageTemplate> getMessageTemplates(AdditionParameter addi
75
58
}
76
59
77
60
@ Override
78
- public List <CometChatMessageComposerAction > getAttachmentOptions (Context context , @ Nullable User user , Group group , HashMap <String , String > idMap ) {
61
+ public List <CometChatMessageComposerAction > getAttachmentOptions (Context context ,
62
+ @ Nullable User user ,
63
+ Group group ,
64
+ HashMap <String , String > idMap ) {
79
65
if (!idMap .containsKey (UIKitConstants .MapId .PARENT_MESSAGE_ID )) {
80
66
List <CometChatMessageComposerAction > messageComposerActions = super .getAttachmentOptions (context , user , group , idMap );
81
- messageComposerActions .add (new CometChatMessageComposerAction ().setId (ExtensionConstants .ExtensionType .DOCUMENT ).setTitle (context .getString (R .string .cometchat_collaborative_doc )).setIcon (R .drawable .cometchat_ic_collaborative_document ).setTitleColor (CometChatTheme .getTextColorPrimary (context )).setTitleAppearance (CometChatTheme .getTextAppearanceBodyRegular (context )).setIconTintColor (CometChatTheme .getIconTintHighlight (context )).setBackground (CometChatTheme .getBackgroundColor1 (context )).setOnClick (() -> {
82
- String id , type ;
83
- id = user != null ? user .getUid () : group .getGuid ();
84
- type = user != null ? UIKitConstants .ReceiverType .USER : UIKitConstants .ReceiverType .GROUP ;
85
- Extensions .callWriteBoardExtension (id , type , new ExtensionResponseListener () {
86
- @ Override
87
- public void OnResponseSuccess (Object var ) {
88
- }
89
-
90
- @ Override
91
- public void OnResponseFailed (CometChatException e ) {
92
- showError (context );
93
- }
94
- });
95
- }));
67
+ messageComposerActions .add (new CometChatMessageComposerAction ()
68
+ .setId (ExtensionConstants .ExtensionType .DOCUMENT )
69
+ .setTitle (context .getString (R .string .cometchat_collaborative_doc ))
70
+ .setIcon (R .drawable .cometchat_ic_collaborative_document )
71
+ .setTitleColor (CometChatTheme .getTextColorPrimary (context ))
72
+ .setTitleAppearance (CometChatTheme .getTextAppearanceBodyRegular (context ))
73
+ .setIconTintColor (CometChatTheme .getIconTintHighlight (context ))
74
+ .setBackground (CometChatTheme .getBackgroundColor1 (context ))
75
+ .setOnClick (() -> {
76
+ String id , type ;
77
+ id = user != null ? user .getUid () : group .getGuid ();
78
+ type = user != null ? UIKitConstants .ReceiverType .USER : UIKitConstants .ReceiverType .GROUP ;
79
+ Extensions .callWriteBoardExtension (id , type , new ExtensionResponseListener () {
80
+ @ Override
81
+ public void OnResponseSuccess (Object var ) {
82
+ }
83
+
84
+ @ Override
85
+ public void OnResponseFailed (CometChatException e ) {
86
+ showError (context );
87
+ }
88
+ });
89
+ }));
96
90
return messageComposerActions ;
97
91
} else return super .getAttachmentOptions (context , user , group , idMap );
98
92
}
99
93
100
- private void showError (Context context ) {
101
- String errorMessage = context .getString (R .string .cometchat_something_went_wrong );
102
- Toast .makeText (context , errorMessage , Toast .LENGTH_SHORT ).show ();
94
+ @ Override
95
+ public List <String > getDefaultMessageTypes () {
96
+ List <String > types = super .getDefaultMessageTypes ();
97
+ if (!types .contains (collaborativeDocumentExtensionTypeConstant )) {
98
+ types .add (collaborativeDocumentExtensionTypeConstant );
99
+ }
100
+ return types ;
103
101
}
104
102
105
- public CometChatMessageTemplate getWhiteBoardTemplate (AdditionParameter additionParameter ) {
106
- return new CometChatMessageTemplate ().setCategory (UIKitConstants .MessageCategory .CUSTOM ).setType (collaborativeDocumentExtensionTypeConstant ).setOptions ((context , baseMessage , isLeftAlign ) -> ChatConfigurator .getDataSource ().getCommonOptions (context , baseMessage , isLeftAlign )).setContentView (new MessagesViewHolderListener () {
107
- @ NonNull
108
- @ Override
109
- public View createView (Context context , CometChatMessageBubble messageBubble , UIKitConstants .MessageBubbleAlignment alignment ) {
110
- return CollaborativeUtils .getCollaborativeBubbleView (context , configuration , "Collaborative Document" , "Open document to edit content together." , "Open Document" );
111
- }
112
-
113
- @ Override
114
- public void bindView (Context context , View createdView , @ NonNull BaseMessage message , UIKitConstants .MessageBubbleAlignment alignment , RecyclerView .ViewHolder holder , List <BaseMessage > messageList , int position ) {
115
- CollaborativeUtils .bindWriteBordCollaborativeBubble (context , createdView , CometChatUIKit .getLoggedInUser ().getUid ().equals (message .getSender ().getUid ()) ? additionParameter .getOutgoingCollaborativeBubbleStyle () : additionParameter .getIncomingCollaborativeBubbleStyle (), message , additionParameter );
116
- }
117
- }).setBottomView (new MessagesViewHolderListener () {
118
- @ Override
119
- public View createView (Context context , CometChatMessageBubble messageBubble , UIKitConstants .MessageBubbleAlignment alignment ) {
120
- return CometChatUIKit .getDataSource ().getBottomView (context , messageBubble , alignment );
121
- }
122
-
123
- @ Override
124
- public void bindView (Context context , View createdView , BaseMessage message , UIKitConstants .MessageBubbleAlignment alignment , RecyclerView .ViewHolder holder , List <BaseMessage > messageList , int position ) {
125
- CometChatUIKit .getDataSource ().bindBottomView (context , createdView , message , alignment , holder , messageList , position , additionParameter );
126
- }
127
- });
103
+ @ Override
104
+ public List <String > getDefaultMessageCategories () {
105
+ List <String > categories = super .getDefaultMessageCategories ();
106
+ if (!categories .contains (UIKitConstants .MessageCategory .CUSTOM ))
107
+ categories .add (UIKitConstants .MessageCategory .CUSTOM );
108
+ return categories ;
128
109
}
129
110
130
111
@ Override
131
112
public SpannableString getLastConversationMessage (Context context , Conversation conversation , AdditionParameter additionParameter ) {
132
- if (conversation != null && conversation .getLastMessage () != null && (UIKitConstants .MessageCategory .CUSTOM .equals (conversation .getLastMessage ().getCategory ()) && ExtensionConstants .ExtensionType .DOCUMENT .equalsIgnoreCase (conversation .getLastMessage ().getType ())))
113
+ if (conversation != null && conversation .getLastMessage () != null && (UIKitConstants .MessageCategory .CUSTOM .equals (conversation
114
+ .getLastMessage ()
115
+ .getCategory ()) && ExtensionConstants .ExtensionType .DOCUMENT .equalsIgnoreCase (
116
+ conversation .getLastMessage ().getType ())))
133
117
return SpannableString .valueOf (getLastConversationMessage_ (context , conversation , additionParameter ));
134
118
else return super .getLastConversationMessage (context , conversation , additionParameter );
135
119
}
@@ -157,6 +141,68 @@ public String getLastMessage(Context context, BaseMessage lastMessage) {
157
141
return Utils .getMessagePrefix (lastMessage , context ) + context .getString (R .string .cometchat_document );
158
142
}
159
143
144
+ private void showError (Context context ) {
145
+ String errorMessage = context .getString (R .string .cometchat_something_went_wrong );
146
+ Toast .makeText (context , errorMessage , Toast .LENGTH_SHORT ).show ();
147
+ }
148
+
149
+ public CometChatMessageTemplate getWhiteBoardTemplate (AdditionParameter additionParameter ) {
150
+ return new CometChatMessageTemplate ()
151
+ .setCategory (UIKitConstants .MessageCategory .CUSTOM )
152
+ .setType (collaborativeDocumentExtensionTypeConstant )
153
+ .setOptions ((context , baseMessage , isLeftAlign ) -> ChatConfigurator .getDataSource ().getCommonOptions (context , baseMessage , isLeftAlign ))
154
+ .setContentView (new MessagesViewHolderListener () {
155
+ @ NonNull
156
+ @ Override
157
+ public View createView (Context context , CometChatMessageBubble messageBubble , UIKitConstants .MessageBubbleAlignment alignment ) {
158
+ return CollaborativeUtils .getCollaborativeBubbleView (context ,
159
+ configuration ,
160
+ "Collaborative Document" ,
161
+ "Open document to edit content together." ,
162
+ "Open Document" );
163
+ }
164
+
165
+ @ Override
166
+ public void bindView (Context context ,
167
+ View createdView ,
168
+ @ NonNull BaseMessage message ,
169
+ UIKitConstants .MessageBubbleAlignment alignment ,
170
+ RecyclerView .ViewHolder holder ,
171
+ List <BaseMessage > messageList ,
172
+ int position ) {
173
+ CollaborativeUtils .bindWriteBordCollaborativeBubble (context ,
174
+ createdView ,
175
+ CometChatUIKit
176
+ .getLoggedInUser ()
177
+ .getUid ()
178
+ .equals (message
179
+ .getSender ()
180
+ .getUid ()) ? additionParameter .getOutgoingCollaborativeBubbleStyle () : additionParameter .getIncomingCollaborativeBubbleStyle (),
181
+ message ,
182
+ additionParameter );
183
+ }
184
+ })
185
+ .setBottomView (new MessagesViewHolderListener () {
186
+ @ Override
187
+ public View createView (Context context , CometChatMessageBubble messageBubble , UIKitConstants .MessageBubbleAlignment alignment ) {
188
+ return CometChatUIKit .getDataSource ().getBottomView (context , messageBubble , alignment );
189
+ }
190
+
191
+ @ Override
192
+ public void bindView (Context context ,
193
+ View createdView ,
194
+ BaseMessage message ,
195
+ UIKitConstants .MessageBubbleAlignment alignment ,
196
+ RecyclerView .ViewHolder holder ,
197
+ List <BaseMessage > messageList ,
198
+ int position ) {
199
+ CometChatUIKit
200
+ .getDataSource ()
201
+ .bindBottomView (context , createdView , message , alignment , holder , messageList , position , additionParameter );
202
+ }
203
+ });
204
+ }
205
+
160
206
@ Override
161
207
public String getId () {
162
208
return CollaborativeDocumentExtensionDecorator .class .getSimpleName ();
0 commit comments