Skip to content

Commit

Permalink
Android UI Kit v2.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
darshanbhanushali committed Sep 29, 2020
1 parent 36e94d8 commit c7627fb
Show file tree
Hide file tree
Showing 36 changed files with 1,598 additions and 90 deletions.
272 changes: 268 additions & 4 deletions uikit/src/main/java/adapter/MessageAdapter.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;

import com.cometchat.pro.core.CometChat;
import com.cometchat.pro.uikit.R;

import java.io.File;
Expand Down Expand Up @@ -88,7 +89,7 @@ public class ComposeBox extends RelativeLayout implements View.OnClickListener {
private Bundle bundle = new Bundle();

public boolean isGalleryVisible = true,isAudioVisible = true,isCameraVisible = true,
isFileVisible = true,isLocationVisible = true;
isFileVisible = true,isLocationVisible = true,isPollVisible = true;

public ComposeBox(Context context) {
super(context);
Expand Down Expand Up @@ -202,6 +203,9 @@ public void onAudioClick() {
public void onLocationClick() {
composeActionListener.onLocationActionClicked();
}

@Override
public void onPollClick() { composeActionListener.onPollActionClicked(); }
});
etComposeBox.addTextChangedListener(new TextWatcher() {
@Override
Expand Down Expand Up @@ -333,6 +337,8 @@ public void onClick(View view) {
bundle.putBoolean("isFileVisible",isFileVisible);
bundle.putBoolean("isAudioVisible",isAudioVisible);
bundle.putBoolean("isLocationVisible",isLocationVisible);
if (CometChat.isExtensionEnabled("polls"))
bundle.putBoolean("isPollsVisible",isPollVisible);
composeBoxActionFragment.setArguments(bundle);
composeBoxActionFragment.show(fm,composeBoxActionFragment.getTag());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ public class ComposeBoxActionFragment extends BottomSheetDialogFragment {
private TextView fileMessage;
private TextView audioMessage;
private TextView locationMessage;
private TextView pollsMessage;

private boolean isGalleryVisible;
private boolean isCameraVisible;
private boolean isAudioVisible;
private boolean isFileVisible;
private boolean isLocationVisible;

private boolean isPollsVisible;

private ComposeBoxActionListener composeBoxActionListener;

Expand All @@ -41,6 +42,7 @@ public void onCreate(Bundle savedInstanceState) {
isFileVisible = getArguments().getBoolean("isFileVisible");
isAudioVisible = getArguments().getBoolean("isAudioVisible");
isLocationVisible = getArguments().getBoolean("isLocationVisible");
isPollsVisible = getArguments().getBoolean("isPollsVisible");
}
}

Expand All @@ -61,12 +63,17 @@ public void onGlobalLayout() {
behavior.setPeekHeight(0);
}
});
pollsMessage = view.findViewById(R.id.polls_message);
galleryMessage = view.findViewById(R.id.gallery_message);
cameraMessage = view.findViewById(R.id.camera_message);
fileMessage = view.findViewById(R.id.file_message);
audioMessage = view.findViewById(R.id.audio_message);
locationMessage = view.findViewById(R.id.location_message);

if (isPollsVisible)
pollsMessage.setVisibility(View.VISIBLE);
else
pollsMessage.setVisibility(View.GONE);
if (isGalleryVisible)
galleryMessage.setVisibility(View.VISIBLE);
else
Expand All @@ -88,6 +95,14 @@ public void onGlobalLayout() {
else
locationMessage.setVisibility(View.GONE);

pollsMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (composeBoxActionListener!=null)
composeBoxActionListener.onPollClick();
dismiss();
}
});
galleryMessage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down Expand Up @@ -143,6 +158,7 @@ public interface ComposeBoxActionListener {
void onFileClick();
void onAudioClick();
void onLocationClick();
void onPollClick();
}

}
14 changes: 13 additions & 1 deletion uikit/src/main/java/constant/StringContract.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ public static class IntentStrings {

public static final String PARENT_BASEMESSAGE = "parent_baseMessage";

public static final String POLL_VOTE_COUNT = "poll_vote_count";

public static String Polls = "extension_poll";

public static String POLL_QUESTION = "poll_question";

public static String POLL_OPTION = "poll_option";

public static String POLL_RESULT = "poll_result";

public static String POLL_ID = "poll_id";

public static final String MEDIA_SIZE = "media_size" ;
}

Expand Down Expand Up @@ -131,6 +143,6 @@ public static class MapUrl{

public static final String MAPS_URL = "https://maps.googleapis.com/maps/api/staticmap?zoom=16&size=380x220&markers=color:red|";

public static final String MAP_ACCESS_KEY = "AIzaSyAa8HeLH2lQMbPeOiMlM9D1VxZ7pbGQq8o";
public static final String MAP_ACCESS_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"; //Replace with your Google API Key
}
}
2 changes: 2 additions & 0 deletions uikit/src/main/java/listeners/ComposeActionListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public abstract class ComposeActionListener {

public void onMoreActionClicked(ImageView moreIcon) {}

public void onPollActionClicked() {}

public void onCameraActionClicked() {}

public void onGalleryActionClicked() {}
Expand Down
62 changes: 60 additions & 2 deletions uikit/src/main/java/screen/CometChatMessageInfoScreenActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import android.content.res.ColorStateList;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
Expand All @@ -16,6 +19,7 @@
import com.cometchat.pro.constants.CometChatConstants;
import com.cometchat.pro.core.CometChat;
import com.cometchat.pro.exceptions.CometChatException;
import com.cometchat.pro.models.Group;
import com.cometchat.pro.models.MessageReceipt;
import com.cometchat.pro.uikit.CometChatReceiptsList;
import com.cometchat.pro.uikit.R;
Expand All @@ -24,9 +28,11 @@
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import constant.StringContract;
import utils.Extensions;
import utils.Utils;

public class CometChatMessageInfoScreenActivity extends AppCompatActivity {
Expand All @@ -37,6 +43,10 @@ public class CometChatMessageInfoScreenActivity extends AppCompatActivity {
private View fileMessage;
private View videoMessage;
private View locationMessage;
private View pollsMessage;

private TextView question;
private LinearLayout optionGroup;

private ImageView ivMap;
private TextView tvPlaceName;
Expand All @@ -58,7 +68,7 @@ public class CometChatMessageInfoScreenActivity extends AppCompatActivity {
private String messageType;
private int messageSize;
private String messageExtension;

private int percentage=0;
private String TAG = "CometChatMessageInfo";

private SwipeRefreshLayout swipeRefreshLayout;
Expand All @@ -73,6 +83,10 @@ protected void onCreate(Bundle savedInstanceState) {
audioMessage = findViewById(R.id.vwAudioMessage);
fileMessage = findViewById(R.id.vwFileMessage);
locationMessage = findViewById(R.id.vwLocationMessage);
pollsMessage = findViewById(R.id.polls_message);
findViewById(R.id.total_votes).setVisibility(View.GONE);
question = findViewById(R.id.tv_question);
optionGroup = findViewById(R.id.options_group);
messageText = findViewById(R.id.go_txt_message);
txtTime = findViewById(R.id.txt_time);
txtTime.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -154,6 +168,9 @@ private void handleIntent() {
message = getIntent().getStringExtra(StringContract.IntentStrings.CUSTOM_MESSAGE);
}

if (getIntent().hasExtra(StringContract.IntentStrings.POLL_RESULT)) {
percentage = getIntent().getIntExtra(StringContract.IntentStrings.POLL_RESULT,0);
}
if (messageType!=null) {
if (messageType.equals(CometChatConstants.MESSAGE_TYPE_TEXT)) {
textMessage.setVisibility(View.VISIBLE);
Expand All @@ -172,7 +189,7 @@ private void handleIntent() {
} else if (messageType.equals(CometChatConstants.MESSAGE_TYPE_AUDIO)) {
audioMessage.setVisibility(View.VISIBLE);
audioFileSize.setText(Utils.getFileSize(messageSize));
} else if (messageType.equals(CometChatConstants.CATEGORY_CUSTOM)) {
} else if (messageType.equals(StringContract.IntentStrings.LOCATION)) {
try {
locationMessage.setVisibility(View.VISIBLE);
JSONObject jsonObject = new JSONObject(message);
Expand All @@ -186,6 +203,47 @@ private void handleIntent() {
} catch (JSONException e) {
e.printStackTrace();
}
} else if (messageType.equals(StringContract.IntentStrings.Polls)) {
pollsMessage.setVisibility(View.VISIBLE);
try {
JSONObject jsonObject = new JSONObject(message);
String questionStr = jsonObject.getString("question");
question.setText(questionStr);
JSONObject options = jsonObject.getJSONObject("options");
for (int i=0;i<options.length();i++) {
LinearLayout linearLayout = new LinearLayout(this);
LinearLayout.LayoutParams layoutParams = new LinearLayout
.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.bottomMargin = (int) Utils.dpToPx(this, 8);
linearLayout.setLayoutParams(layoutParams);

linearLayout.setPadding(8,8,8,8);
linearLayout.setBackground(getResources()
.getDrawable(R.drawable.cc_message_bubble_right));
linearLayout.setBackgroundTintList(ColorStateList.valueOf(getResources()
.getColor(R.color.textColorWhite)));
TextView textViewPercentage = new TextView(this);
TextView textViewOption = new TextView(this);
textViewPercentage.setPadding(16, 4, 0, 4);
textViewOption.setPadding(16, 4, 0, 4);
textViewOption.setTextAppearance(this, R.style.TextAppearance_AppCompat_Medium);
textViewPercentage.setTextAppearance(this, R.style.TextAppearance_AppCompat_Medium);
textViewPercentage.setTextColor(getResources().getColor(R.color.primaryTextColor));
textViewOption.setTextColor(getResources().getColor(R.color.primaryTextColor));
String optionStr = options.getString(String.valueOf(i + 1));
textViewOption.setText(optionStr);
if (percentage>0)
textViewPercentage.setText(percentage + "% ");
if (optionGroup.getChildCount()!=options.length()) {
linearLayout.addView(textViewPercentage);
linearLayout.addView(textViewOption);
optionGroup.addView(linearLayout);
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ public class CometChatMessageListActivity extends AppCompatActivity implements M
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cometchat_message_list);

EmojiCompat.Config config = new BundledEmojiCompatConfig(this);
EmojiCompat.init(config);

if (getIntent()!=null) {
if (getIntent()!=null) {
Bundle bundle = new Bundle();

bundle.putString(StringContract.IntentStrings.AVATAR, getIntent().getStringExtra(StringContract.IntentStrings.AVATAR));
Expand Down Expand Up @@ -135,5 +136,6 @@ protected void onPause() {

public void handleDialogClose(DialogInterface dialog) {
((MessageActionCloseListener)fragment).handleDialogClose(dialog);
dialog.dismiss();
}
}
Loading

0 comments on commit c7627fb

Please sign in to comment.