Skip to content

Commit

Permalink
Android UI Kit v2.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
darshanbhanushali committed Jan 6, 2021
1 parent 4481d95 commit 8aa6e62
Show file tree
Hide file tree
Showing 21 changed files with 311 additions and 30 deletions.
11 changes: 11 additions & 0 deletions uikit/src/main/java/adapter/MessageAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2046,6 +2046,17 @@ public boolean onLongClick(View view) {
if (CometChat.isExtensionEnabled("data-masking"))
message = Extensions.checkDataMasking(baseMessage);

if (baseMessage.getMetadata()!=null && baseMessage.getMetadata().has("values")) {
try {
if (Extensions.isMessageTranslated(baseMessage.getMetadata().getJSONObject("values"), ((TextMessage) baseMessage).getText())) {
String translatedMessage = Extensions.getTranslatedMessage(baseMessage);
message = message + "\n(" + translatedMessage + ")";
}
} catch (JSONException e) {
Toast.makeText(context, context.getString(R.string.no_translation_available), Toast.LENGTH_SHORT).show();
}
}

viewHolder.txtMessage.setText(message);
viewHolder.txtMessage.setTypeface(fontUtils.getTypeFace(FontUtils.robotoRegular));

Expand Down
12 changes: 12 additions & 0 deletions uikit/src/main/java/adapter/ThreadAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Expand Down Expand Up @@ -859,6 +860,17 @@ public void onClick(DialogInterface dialog, int which) {
else if (CometChat.isExtensionEnabled("data-masking"))
message = Extensions.checkDataMasking(baseMessage);

if (baseMessage.getMetadata()!=null && baseMessage.getMetadata().has("values")) {
try {
if (Extensions.isMessageTranslated(baseMessage.getMetadata().getJSONObject("values"), ((TextMessage) baseMessage).getText())) {
String translatedMessage = Extensions.getTranslatedMessage(baseMessage);
message = message + "\n(" + translatedMessage + ")";
}
} catch (JSONException e) {
Toast.makeText(context, context.getString(R.string.no_translation_available), Toast.LENGTH_SHORT).show();
}
}

viewHolder.txtMessage.setText(message);
viewHolder.txtMessage.setTypeface(fontUtils.getTypeFace(FontUtils.robotoRegular));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,4 +339,8 @@ public static void enableCollaborativeWhiteBoard(boolean enableWhiteBoardSharing
public static void enableCollaborativeWriteBoard(boolean enableWriteBoardSharing) {
UISettings.sendWriteBoard = enableWriteBoardSharing;
}

public static void enableMessageTranslation(boolean enableMessageTranslation) {
UISettings.allowMessageTranslation = enableMessageTranslation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public UISettings() {}
protected static boolean hideCallNotification = false;
protected static boolean liveReaction = true;
protected static boolean allowReactionOnMessage = true;
protected static boolean allowMessageTranslation = true;
protected static int emailColor = R.color.primaryTextColor;
protected static int phoneColor = R.color.purple;
protected static int urlColor = R.color.dark_blue;
Expand Down Expand Up @@ -256,4 +257,6 @@ public static boolean isWhiteBoardVisible() {
public static boolean isWriteBoardVisible() {
return sendWriteBoard;
}

public static boolean isTranslationAllowed() { return allowMessageTranslation; }
}
60 changes: 57 additions & 3 deletions uikit/src/main/java/screen/messagelist/CometChatMessageScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;

Expand Down Expand Up @@ -2303,6 +2304,7 @@ public void setLongMessageClick(List<BaseMessage> baseMessagesList) {
boolean deleteVisible = UISettings.isEnableDeleteMessage();
boolean forwardVisible = UISettings.isEnableShareCopyForward();
boolean reactionVisible = UISettings.isReactionVisible();
boolean translateVisible = UISettings.isTranslationAllowed();
List<BaseMessage> textMessageList = new ArrayList<>();
List<BaseMessage> mediaMessageList = new ArrayList<>();
List<BaseMessage> locationMessageList = new ArrayList<>();
Expand Down Expand Up @@ -2332,6 +2334,7 @@ public void setLongMessageClick(List<BaseMessage> baseMessagesList) {
}
}
if (textMessageList.size() == 1) {
translateVisible = UISettings.isTranslationAllowed();
BaseMessage basemessage = textMessageList.get(0);
if (basemessage != null && basemessage.getSender() != null) {
if (!(basemessage instanceof Action) && basemessage.getDeletedAt() == 0) {
Expand All @@ -2356,6 +2359,7 @@ public void setLongMessageClick(List<BaseMessage> baseMessagesList) {
}

if (mediaMessageList.size() == 1) {
translateVisible = false;
BaseMessage basemessage = mediaMessageList.get(0);
if (basemessage != null && basemessage.getSender() != null) {
if (!(basemessage instanceof Action) && basemessage.getDeletedAt() == 0) {
Expand All @@ -2380,6 +2384,7 @@ public void setLongMessageClick(List<BaseMessage> baseMessagesList) {
}
}
if (locationMessageList.size() == 1){
translateVisible = false;
BaseMessage basemessage = locationMessageList.get(0);
if (basemessage != null && basemessage.getSender() != null) {
if (!(basemessage instanceof Action) && basemessage.getDeletedAt() == 0) {
Expand Down Expand Up @@ -2408,6 +2413,7 @@ public void setLongMessageClick(List<BaseMessage> baseMessagesList) {
}
if (pollsMessageList.size() == 1){
forwardVisible = false;
translateVisible = false;
copyVisible = false;
editVisible = false;
shareVisible = false;
Expand Down Expand Up @@ -2436,8 +2442,9 @@ public void setLongMessageClick(List<BaseMessage> baseMessagesList) {
forwardVisible = false;
copyVisible = false;
editVisible = false;
translateVisible = false;
shareVisible = false;
replyVisible = UISettings.isStickerVisible();
replyVisible = UISettings.isEnableReplyToMessage();
BaseMessage basemessage = stickerMessageList.get(0);
if (basemessage!=null && basemessage.getSender()!=null) {
if (basemessage.getDeletedAt() == 0) {
Expand All @@ -2461,9 +2468,10 @@ public void setLongMessageClick(List<BaseMessage> baseMessagesList) {
if (whiteBoardMessageList.size()==1) {
forwardVisible = false;
copyVisible = false;
translateVisible = false;
editVisible = false;
shareVisible = false;
replyVisible = UISettings.isStickerVisible();
replyVisible = UISettings.isEnableReplyToMessage();
BaseMessage basemessage = whiteBoardMessageList.get(0);
if (basemessage!=null && basemessage.getSender()!=null) {
if (basemessage.getDeletedAt() == 0) {
Expand All @@ -2489,8 +2497,9 @@ public void setLongMessageClick(List<BaseMessage> baseMessagesList) {
forwardVisible = false;
copyVisible = false;
editVisible = false;
translateVisible = false;
shareVisible = false;
replyVisible = UISettings.isStickerVisible();
replyVisible = UISettings.isEnableReplyToMessage();
BaseMessage basemessage = writeBoardMessageList.get(0);
if (basemessage!=null && basemessage.getSender()!=null) {
if (basemessage.getDeletedAt() == 0) {
Expand Down Expand Up @@ -2522,6 +2531,7 @@ public void setLongMessageClick(List<BaseMessage> baseMessagesList) {
bundle.putBoolean("deleteVisible",deleteVisible);
bundle.putBoolean("replyVisible",replyVisible);
bundle.putBoolean("forwardVisible",forwardVisible);
bundle.putBoolean("translateVisible",translateVisible);
if (CometChat.isExtensionEnabled("reactions"))
bundle.putBoolean("isReactionVisible",reactionVisible);
if (baseMessage.getReceiverType().equals(CometChatConstants.RECEIVER_TYPE_GROUP) &&
Expand Down Expand Up @@ -2658,6 +2668,50 @@ public void onEmojiClicked(Reaction emojicon) {
sendReaction(reaction);
}
}

@Override
public void onTranslateMessageClick() {
try {
String localeLanguage = Locale.getDefault().getLanguage();
JSONObject body = new JSONObject();
JSONArray languages = new JSONArray();
languages.put(localeLanguage);
body.put("msgId", baseMessage.getId());
body.put("languages", languages);
body.put("text", ((TextMessage)baseMessage).getText());

CometChat.callExtension("message-translation", "POST", "/v2/translate", body,
new CometChat.CallbackListener<JSONObject>() {
@Override
public void onSuccess(JSONObject jsonObject) {
if (Extensions.isMessageTranslated(jsonObject,((TextMessage)baseMessage).getText())) {
if (baseMessage.getMetadata()!=null) {
JSONObject meta = baseMessage.getMetadata();
try {
meta.accumulate("values",jsonObject);
baseMessage.setMetadata(meta);
updateMessage(baseMessage);
} catch (JSONException e) {
e.printStackTrace();
}
} else {
baseMessage.setMetadata(jsonObject);
updateMessage(baseMessage);
}
} else {
Snackbar.make(rvChatListView,context.getString(R.string.no_translation_available),Snackbar.LENGTH_LONG).show();
}
}

@Override
public void onError(CometChatException e) {
Toast.makeText(context,e.getCode(),Toast.LENGTH_LONG).show();
}
});
} catch (Exception e) {
Toast.makeText(context,e.getMessage(),Toast.LENGTH_LONG).show();
}
}
});
}

Expand Down
38 changes: 19 additions & 19 deletions uikit/src/main/java/screen/messagelist/MessageActionFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class MessageActionFragment extends BottomSheetDialogFragment {
private TextView copyMessage;
private TextView messageInfo;
private TextView shareMessage;
private TextView translateMessage;


private LinearLayout reactionsList;
Expand All @@ -50,6 +51,7 @@ public class MessageActionFragment extends BottomSheetDialogFragment {
private boolean isReplyVisible;
private boolean isMessageInfoVisible;
private boolean isReactionsVisible;
private boolean isTranslateVisible;

private MessageActionListener messageActionListener;

Expand All @@ -74,6 +76,7 @@ private void fetchArguments() {
isShareVisible = getArguments().getBoolean("shareVisible");
isMessageInfoVisible = getArguments().getBoolean("messageInfoVisible");
isReactionsVisible = getArguments().getBoolean("isReactionVisible");
isTranslateVisible = getArguments().getBoolean("translateVisible");
type = getArguments().getString("type");
}
}
Expand Down Expand Up @@ -135,25 +138,7 @@ public void onClick(View view) {
}
});

// reactionsList.addOnItemTouchListener(new RecyclerTouchListener(getContext(), reactionsList, new ClickListener() {
// @Override
// public void onClick(View var1, int var2) {
// Reaction reaction = (Reaction)var1.getTag(R.string.reaction);
// if (messageActionListener != null)
// messageActionListener.onReactionClick(reaction);
// dismiss();
// }
// }));
// showReactionDialog = view.findViewById(R.id.show_reaction_dialog);
// showReactionDialog.setVisibility(View.GONE);
// showReactionDialog.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View view) {
// if (messageActionListener!=null)
// messageActionListener.onReactionClick(new Reaction("add_emoji",0));
// dismiss();
// }
// });
translateMessage = view.findViewById(R.id.translate_message);
threadMessage = view.findViewById(R.id.start_thread);
editMessage = view.findViewById(R.id.edit_message);
replyMessage = view.findViewById(R.id.reply_message);
Expand All @@ -163,6 +148,11 @@ public void onClick(View view) {
shareMessage = view.findViewById(R.id.share_message);
messageInfo = view.findViewById(R.id.message_info);

if (isTranslateVisible)
translateMessage.setVisibility(View.VISIBLE);
else
translateMessage.setVisibility(View.GONE);

if (isReactionsVisible)
reactionsList.setVisibility(View.VISIBLE);
else
Expand Down Expand Up @@ -204,6 +194,14 @@ public void onClick(View view) {
threadMessage.setVisibility(View.GONE);
}

translateMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (messageActionListener!=null)
messageActionListener.onTranslateMessageClick();
dismiss();
}
});
threadMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down Expand Up @@ -289,6 +287,8 @@ public interface MessageActionListener {
void onMessageInfoClick();

void onReactionClick(Reaction reaction);

void onTranslateMessageClick();
}

@Override
Expand Down
Loading

0 comments on commit 8aa6e62

Please sign in to comment.