Skip to content

Commit 2ba4f67

Browse files
Android UI Kit v2.1.11
1 parent c3be1e3 commit 2ba4f67

File tree

12 files changed

+127
-64
lines changed

12 files changed

+127
-64
lines changed

.idea/gradle.xml

Lines changed: 4 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
# Android Java Chat UI Kit
1111

12+
CometChat Java UI Kit is a collection of custom UI Components designed to build text chat and voice/video callings features in your application.
13+
The UI Kit is developed to keep developers in mind and aims to reduce development efforts significantly<br/><br/>
14+
1215
[![Platform](https://img.shields.io/badge/Platform-Android-brightgreen.svg)](#)
1316
[![Platform](https://img.shields.io/badge/Language-Java-yellowgreen.svg)](#)
1417
![GitHub repo size](https://img.shields.io/github/repo-size/cometchat-pro/android-java-chat-ui-kit)
@@ -18,9 +21,6 @@
1821

1922
<img align="center" src="https://files.readme.io/49d88c3-UI_Kit__2.png"/>
2023

21-
The UI Kit library is collection of custom UI Components and UI Screens design to build chat application within few minutes. UI kit is designed to avoid boilerplate code for building UI,it has three different ways to build a chat application with fully customizable UI. It will help developers to build a chat application within using various UI Components.
22-
<br/><br/>
23-
2424
<hr/>
2525

2626
## Prerequisites :star:
@@ -70,7 +70,7 @@ allprojects {
7070

7171
```groovy
7272
dependencies {
73-
implementation 'com.cometchat:pro-android-chat-sdk:2.1.7-beta3'
73+
implementation 'com.cometchat:pro-android-chat-sdk:2.2.0'
7474
}
7575
```
7676

@@ -104,6 +104,10 @@ The init() method initializes the settings required for CometChat. We suggest ca
104104
<table><td>
105105

106106
```java
107+
import com.cometchat.pro.core.AppSettings;
108+
import com.cometchat.pro.core.CometChat;
109+
import com.cometchat.pro.exceptions.CometChatException;
110+
107111
String appID = "APP_ID"; // Replace with your App ID
108112
String region = "REGION"; // Replace with your App Region ("eu" or "us")
109113

@@ -132,6 +136,9 @@ Once you have created the user successfully, you will need to log the user into
132136
<table><td>
133137

134138
```java
139+
import com.cometchat.pro.core.CometChat;
140+
import com.cometchat.pro.exceptions.CometChatException;
141+
135142
String UID = "user1"; // Replace with the UID of the user to login
136143
String authKey = "AUTH_KEY"; // Replace with your App Auth Key
137144

@@ -260,7 +267,9 @@ To use CometChat UI user has to launch `CometChatUI` class. Add the following co
260267
<table><td>
261268

262269
```java
263-
startActivity(new Intent(YourActivity.this,CometChatUI.class))
270+
import com.cometchat.pro.uikit.ui_components.cometchat_ui.CometChatUI;
271+
272+
startActivity(new Intent(YourActivity.this,CometChatUI.class));
264273
```
265274

266275
</td></table>

uikit/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,6 @@ dependencies {
9090
implementation 'com.google.android.gms:play-services-location:17.0.0'
9191
implementation 'com.google.android.gms:play-services-maps:17.0.0'
9292
//cometchat
93-
compileOnly 'com.cometchat:pro-android-chat-sdk:2.1.7-beta3'
93+
compileOnly 'com.cometchat:pro-android-chat-sdk:2.2.0'
9494
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.4.0'
9595
}

uikit/src/main/java/com/cometchat/pro/uikit/ui_components/calls/call_manager/CometChatStartCallActivity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ protected void onCreate(Bundle savedInstanceState) {
6464
callSettings = new CallSettings.CallSettingsBuilder(this,mainView)
6565
.setSessionId(sessionID)
6666
.build();
67-
Log.e("onStartActivity ", SettingsRepo.getSettings().getWEBRTCHost());
67+
Log.e( "startCallActivity: ",sessionID+" "+type);
6868
CometChat.startCall(callSettings, new CometChat.OngoingCallListener() {
6969
@Override
7070
public void onUserJoined(User user) {
@@ -102,7 +102,7 @@ public void onSuccess(Call call) {
102102

103103
@Override
104104
public void onError(CometChatException e) {
105-
Toast.makeText(CometChatStartCallActivity.this, "Error:" + e.getCode(), Toast.LENGTH_SHORT).show();
105+
Toast.makeText(CometChatStartCallActivity.this, "Error:" + e.getCode()+" "+e.getMessage(), Toast.LENGTH_SHORT).show();
106106
}
107107
});
108108
} else {

uikit/src/main/java/com/cometchat/pro/uikit/ui_components/chats/CometChatConversationList.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public class CometChatConversationList extends Fragment implements TextWatcher {
6161

6262
private ConversationsRequest conversationsRequest; //Uses to fetch Conversations.
6363

64+
private String conversationListType = null;
65+
6466
private static OnItemClickListener events;
6567

6668
private EditText searchEdit; //Uses to perform search operations.
@@ -146,6 +148,10 @@ private void checkDarkMode() {
146148
}
147149
}
148150

151+
152+
public void setConversationListType(String conversationListType) {
153+
this.conversationListType = conversationListType;
154+
}
149155
/**
150156
* This method is used to retrieve list of conversations you have done.
151157
* For more detail please visit our official documentation {@link "https://prodocs.cometchat.com/docs/android-messaging-retrieve-conversations" }
@@ -156,6 +162,9 @@ private void makeConversationList() {
156162

157163
if (conversationsRequest == null) {
158164
conversationsRequest = new ConversationsRequest.ConversationsRequestBuilder().setLimit(50).build();
165+
if (conversationListType!=null)
166+
conversationsRequest = new ConversationsRequest.ConversationsRequestBuilder()
167+
.setConversationType(conversationListType).setLimit(50).build();
159168
}
160169
conversationsRequest.fetchNext(new CometChat.CallbackListener<List<Conversation>>() {
161170
@Override

uikit/src/main/java/com/cometchat/pro/uikit/ui_components/groups/create_group/CometChatCreateGroup.java

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
import com.cometchat.pro.uikit.ui_resources.constants.UIKitConstants;
3131
import com.cometchat.pro.uikit.ui_resources.utils.Utils;
3232

33+
import static com.cometchat.pro.uikit.ui_resources.utils.Utils.generateRandomString;
34+
3335
/**
3436
* Purpose - CometChatCreateGroup class is a fragment used to create a group. User just need to enter
3537
* group name. All other information like guid, groupIcon are set by this class.
@@ -175,37 +177,10 @@ private void checkDarkMode() {
175177
etGroupCnfPassword.setTextColor(getResources().getColor(R.color.primaryTextColor));
176178
}
177179
}
178-
179-
/**
180-
* This method is used to create group when called from layout. It uses <code>Random.nextInt()</code>
181-
* to generate random number to use with group id and group icon. Any Random number between 10 to
182-
* 1000 are choosen.
183-
*
184-
*/
185-
186-
public static String generateRandomString(int length) {
187-
if (length < 1) throw new IllegalArgumentException();
188-
StringBuilder sb = new StringBuilder(length);
189-
for (int i = 0; i < length; i++) {
190-
// 0-62 (exclusive), random returns 0-61
191-
SecureRandom random = new SecureRandom();
192-
String CHAR_LOWER = "abcdefghijklmnopqrstuvwxyz";
193-
String CHAR_UPPER = CHAR_LOWER.toUpperCase();
194-
String NUMBER = "0123456789";
195-
String DATA_FOR_RANDOM_STRING = CHAR_LOWER + CHAR_UPPER + NUMBER;
196-
int rndCharAt = random.nextInt(DATA_FOR_RANDOM_STRING.length());
197-
char rndChar = DATA_FOR_RANDOM_STRING.charAt(rndCharAt);
198-
// debug
199-
System.out.format("%d\t:\t%c%n", rndCharAt, rndChar);
200-
sb.append(rndChar);
201-
}
202-
return sb.toString();
203-
}
204-
205180
private void createGroup() {
206181
if (!etGroupName.getText().toString().isEmpty()) {
207182
if(groupType.equals(com.cometchat.pro.constants.CometChatConstants.GROUP_TYPE_PUBLIC) || groupType.equals(com.cometchat.pro.constants.CometChatConstants.GROUP_TYPE_PRIVATE)) {
208-
Group group = new Group("group" + generateRandomString(95), etGroupName.getText().toString(), groupType, "");
183+
Group group = new Group("group" + generateRandomString(25), etGroupName.getText().toString(), groupType, "");
209184
createGroup(group);
210185
}
211186
else if (groupType.equals(com.cometchat.pro.constants.CometChatConstants.GROUP_TYPE_PASSWORD)) {
@@ -214,7 +189,7 @@ else if (groupType.equals(com.cometchat.pro.constants.CometChatConstants.GROUP_T
214189
else if (etGroupCnfPassword.getText().toString().isEmpty())
215190
etGroupCnfPassword.setError(getResources().getString(R.string.fill_this_field));
216191
else if(etGroupPassword.getText().toString().equals(etGroupCnfPassword.getText().toString())) {
217-
Group group = new Group("group" + generateRandomString(95), etGroupName.getText().toString(), groupType, etGroupPassword.getText().toString());
192+
Group group = new Group("group" + generateRandomString(25), etGroupName.getText().toString(), groupType, etGroupPassword.getText().toString());
218193
createGroup(group);
219194
}
220195
else

uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/CometChatMessageList.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,12 @@ private void checkOnGoingCall() {
558558
@Override
559559
public void onClick(View v) {
560560
onGoingCallView.setVisibility(View.GONE);
561-
CallUtils.joinOnGoingCall(context,CometChat.getActiveCall());
561+
if (CometChat.getActiveCall()!=null)
562+
CallUtils.joinOnGoingCall(context,CometChat.getActiveCall());
563+
else {
564+
Toast.makeText(context,getString(R.string.call_ended),Toast.LENGTH_LONG).show();
565+
onGoingCallView.setVisibility(View.GONE);
566+
}
562567
}
563568
});
564569
}
@@ -842,7 +847,7 @@ else if (option2Text.getText().toString().trim().isEmpty())
842847
jsonObject.put("options", optionJson);
843848
jsonObject.put("receiver", Id);
844849
jsonObject.put("receiverType", type);
845-
CometChat.callExtension("polls", "POST", "/v1/create",
850+
CometChat.callExtension("polls", "POST", "/v2/create",
846851
jsonObject, new CometChat.CallbackListener<JSONObject>() {
847852
@Override
848853
public void onSuccess(JSONObject jsonObject) {
@@ -952,7 +957,8 @@ private void sendCustomMessage(String customType, JSONObject customData) {
952957
@Override
953958
public void onSuccess(CustomMessage customMessage) {
954959
if (customType.equalsIgnoreCase(UIKitConstants.IntentStrings.GROUP_CALL))
955-
CallUtils.startDirectCall(context,Utils.getDirectCallData(customMessage));
960+
if (CometChat.getActiveCall()==null)
961+
CallUtils.startDirectCall(context,Utils.getDirectCallData(customMessage));
956962

957963
if (messageAdapter != null) {
958964
messageAdapter.addMessage(customMessage);

uikit/src/main/java/com/cometchat/pro/uikit/ui_components/messages/message_list/MessageAdapter.java

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import com.cometchat.pro.models.TextMessage;
5454
import com.cometchat.pro.models.User;
5555

56+
import com.cometchat.pro.uikit.ui_components.users.user_details.CometChatUserDetailScreenActivity;
5657
import com.cometchat.pro.uikit.ui_resources.utils.pattern_utils.PatternUtils;
5758
import com.cometchat.pro.uikit.ui_settings.UISettings;
5859
import com.google.android.material.button.MaterialButton;
@@ -669,26 +670,31 @@ private void setPollsData(PollMessageViewHolder viewHolder, int i) {
669670
@Override
670671
public void onClick(View v) {
671672
try {
672-
JSONObject jsonObject = new JSONObject();
673-
jsonObject.put("vote",finalK+1);
674-
jsonObject.put("id",baseMessage.getId());
675-
CometChat.callExtension("polls", "POST", "/v1/vote",
676-
jsonObject,new CometChat.CallbackListener<JSONObject>() {
677-
@Override
678-
public void onSuccess(JSONObject jsonObject) {
679-
// Voted successfully
680-
viewHolder.loadingProgress.setVisibility(View.VISIBLE);
681-
viewHolder.totalCount.setText("0 Votes");
682-
Log.e(TAG, "onSuccess: "+jsonObject.toString());
683-
Toast.makeText(context,"Voted Success",Toast.LENGTH_LONG).show();
684-
}
685-
686-
@Override
687-
public void onError(CometChatException e) {
688-
// Some error occured
689-
Log.e(TAG, "onErrorExtension: "+e.getMessage()+"\n"+e.getCode());
690-
}
691-
});
673+
String pollsId=null;
674+
if (jsonObject.has("id"))
675+
pollsId = jsonObject.getString("id");
676+
else
677+
pollsId = baseMessage.getId()+"";
678+
JSONObject pollsJsonObject = new JSONObject();
679+
pollsJsonObject.put("vote",finalK+1);
680+
pollsJsonObject.put("id", pollsId);
681+
CometChat.callExtension("polls", "POST", "/v2/vote",
682+
pollsJsonObject, new CometChat.CallbackListener<JSONObject>() {
683+
@Override
684+
public void onSuccess(JSONObject jsonObject) {
685+
// Voted successfully
686+
viewHolder.loadingProgress.setVisibility(View.VISIBLE);
687+
viewHolder.totalCount.setText("0 Votes");
688+
Log.e(TAG, "onSuccess: " + jsonObject.toString());
689+
Toast.makeText(context, "Voted Success", Toast.LENGTH_LONG).show();
690+
}
691+
692+
@Override
693+
public void onError(CometChatException e) {
694+
// Some error occured
695+
Log.e(TAG, "onErrorExtension: " + e.getMessage() + "\n" + e.getCode());
696+
}
697+
});
692698
} catch (Exception e) {
693699
Log.e(TAG, "onError: "+e.getMessage());
694700
}
@@ -758,7 +764,24 @@ else if (baseMessage.getReceiverType().equals(com.cometchat.pro.constants.CometC
758764
@Override
759765
public void onClick(View v) {
760766
if (((CustomMessage)baseMessage).getCustomData()!=null) {
761-
CallUtils.startDirectCall(context, Utils.getDirectCallData(baseMessage));
767+
if (CometChat.getActiveCall()==null)
768+
CallUtils.startDirectCall(context, Utils.getDirectCallData(baseMessage));
769+
else {
770+
AlertDialog.Builder alert = new AlertDialog.Builder(context);
771+
alert.setTitle(context.getResources().getString(R.string.ongoing_call))
772+
.setMessage(context.getResources().getString(R.string.ongoing_call_message))
773+
.setPositiveButton(context.getResources().getString(R.string.join), new DialogInterface.OnClickListener() {
774+
@Override
775+
public void onClick(DialogInterface dialog, int which) {
776+
CallUtils.joinOnGoingCall(context,CometChat.getActiveCall());
777+
}
778+
}).setNegativeButton(context.getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
779+
@Override
780+
public void onClick(DialogInterface dialog, int which) {
781+
dialog.dismiss();
782+
}
783+
}).create().show();
784+
}
762785
}
763786
}
764787
});

uikit/src/main/java/com/cometchat/pro/uikit/ui_components/shared/cometchatAvatar/CometChatAvatar.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ public void setInitials(@NonNull String name) {
393393
setImageDrawable(drawable);
394394
}
395395

396+
public float getBorderWidth() {
397+
return borderWidth;
398+
}
396399
public Drawable getDrawable()
397400
{
398401
return drawable;

uikit/src/main/java/com/cometchat/pro/uikit/ui_components/shared/cometchatConversations/CometChatConversationsAdapter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,8 @@ public void update(Conversation conversation) {
299299
if (filterConversationList.contains(conversation)) {
300300
Conversation oldConversation = filterConversationList.get(filterConversationList.indexOf(conversation));
301301
filterConversationList.remove(oldConversation);
302-
conversation.setUnreadMessageCount(oldConversation.getUnreadMessageCount() + 1);
302+
if (conversation.getLastMessage().getCategory().equalsIgnoreCase(CometChatConstants.CATEGORY_MESSAGE))
303+
conversation.setUnreadMessageCount(oldConversation.getUnreadMessageCount() + 1);
303304
filterConversationList.add(0, conversation);
304305
} else {
305306
filterConversationList.add(0, conversation);

0 commit comments

Comments
 (0)