Skip to content

Commit 24dec15

Browse files
committed
fixing re connection
1 parent 0855e13 commit 24dec15

File tree

5 files changed

+208
-65
lines changed

5 files changed

+208
-65
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.getstream.sdk.chat.adapter;
2+
3+
import android.content.Context;
4+
import android.databinding.DataBindingUtil;
5+
import android.view.LayoutInflater;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
import android.widget.BaseAdapter;
9+
10+
import com.getstream.sdk.chat.R;
11+
import com.getstream.sdk.chat.databinding.ListItemMentionBinding;
12+
import com.getstream.sdk.chat.model.User;
13+
14+
import java.util.List;
15+
16+
public class MentionListItemAdapter extends BaseAdapter {
17+
18+
private final String TAG = MentionListItemAdapter.class.getSimpleName();
19+
private LayoutInflater layoutInflater;
20+
private Context context;
21+
private List<Object> users;
22+
23+
public MentionListItemAdapter(Context context, List users) {
24+
this.context = context;
25+
this.layoutInflater = LayoutInflater.from(context);
26+
this.users = users;
27+
28+
}
29+
30+
@Override
31+
public int getCount() {
32+
return users.size();
33+
}
34+
35+
@Override
36+
public Object getItem(int position) {
37+
return users.get(position);
38+
}
39+
40+
@Override
41+
public long getItemId(int position) {
42+
return position;
43+
}
44+
45+
@Override
46+
public View getView(int position, View convertView, ViewGroup parent) {
47+
ListItemMentionBinding binding;
48+
if (convertView == null) {
49+
convertView = layoutInflater.inflate(R.layout.list_item_command, null);
50+
binding = DataBindingUtil.bind(convertView);
51+
convertView.setTag(binding);
52+
} else {
53+
binding = (ListItemMentionBinding) convertView.getTag();
54+
}
55+
56+
User user = (User) users.get(position);
57+
binding.setUser(user);
58+
59+
return binding.getRoot();
60+
}
61+
}

library/src/main/java/com/getstream/sdk/chat/function/SendFileFunction.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ public void onAnimationStart(Animation animation) {
128128
public void onAnimationEnd(Animation animation) {
129129
view.setVisibility(View.GONE);
130130
view.clearAnimation();
131-
if (view.equals(binding.clSelectPhoto))
132-
binding.tvSelectMediaBack.setVisibility(View.GONE);
131+
if (view.equals(binding.clSelectPhoto) || view.equals(binding.clCommand))
132+
binding.tvInputboxBack.setVisibility(View.GONE);
133133
}
134134

135135
@Override
@@ -235,7 +235,7 @@ private void configSelectAttachView(boolean isMedia, List<Attachment> editAttach
235235

236236
public void onClickSelectMediaViewOpen(View v, List<Attachment> editAttachments) {
237237
initLoadAttachemtView();
238-
binding.tvSelectMediaBack.setVisibility(View.VISIBLE);
238+
binding.tvInputboxBack.setVisibility(View.VISIBLE);
239239
AsyncTask.execute(() -> configSelectAttachView(true, editAttachments));
240240
}
241241

@@ -316,7 +316,7 @@ private void setSelectedMediaAttachmentRecyclerViewAdapter(final List<Attachment
316316

317317
public void onClickSelectFileViewOpen(View v, List<Attachment> editAttachments) {
318318
initLoadAttachemtView();
319-
binding.tvSelectMediaBack.setVisibility(View.VISIBLE);
319+
binding.tvInputboxBack.setVisibility(View.VISIBLE);
320320
AsyncTask.execute(() -> configSelectAttachView(false, editAttachments));
321321
}
322322

@@ -461,6 +461,7 @@ private void convertAttachment(File file, Cursor cursor, boolean isImage) {
461461
private void openCommandView() {
462462
openAnimationView(binding.clCommand);
463463
fadeAnimationView(binding.ivBackAttachment, true);
464+
binding.tvInputboxBack.setVisibility(View.VISIBLE);
464465
}
465466

466467
private void closeCommandView() {
@@ -492,9 +493,8 @@ public void checkCommand(String text) {
492493
}
493494
}
494495

495-
public void onClickCommandViewOpen(boolean isCommand) {
496+
private void onClickCommandViewOpen(boolean isCommand) {
496497
if (isCommand) {
497-
// setGlobalCommands();
498498
setCommands("");
499499
} else {
500500
setMentionUsers("");
@@ -549,4 +549,8 @@ private void setMentionUsers(String string) {
549549
}
550550
}
551551
// endregion
552+
553+
// region Mention
554+
555+
// endregion
552556
}

library/src/main/java/com/getstream/sdk/chat/view/activity/ChatActivity.java

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ private void initReconnection() {
241241
threadBinding.setViewModel(mViewModel);
242242
channel = channelResponse.getChannel();
243243
channelMessages = channelResponse.getMessages();
244+
checkEphemeralMessages();
244245
messageFunction = new MessageFunction(this.channelResponse);
245246
sendFileFunction = new SendFileFunction(this, binding, channelResponse);
246247
checkReadMark();
@@ -249,21 +250,32 @@ private void initReconnection() {
249250
Global.eventFunction.setChannel(this.channel);
250251
}
251252

253+
private void checkEphemeralMessages() {
254+
List<Message> ephemeralMainMessages = Global.getEphemeralMessages(channel.getId(), null);
255+
if (ephemeralMainMessages != null && !ephemeralMainMessages.isEmpty()) {
256+
for (int i = 0; i < ephemeralMainMessages.size(); i++) {
257+
Message message = ephemeralMainMessages.get(i);
258+
if (channelMessages.contains(message)) continue;
259+
channelMessages.add(message);
260+
}
261+
}
262+
}
263+
252264
private boolean lockRVScrollListener = false;
253265

254-
private void getChannel(Channel channel) {
266+
private void getChannel(Channel channel_) {
255267

256268
binding.setShowMainProgressbar(true);
257-
channel.setType(ModelType.channel_messaging);
269+
channel_.setType(ModelType.channel_messaging);
258270
Map<String, Object> messages = new HashMap<>();
259271
messages.put("limit", Constant.DEFAULT_LIMIT);
260272

261273
// Additional Field
262274
Map<String, Object> data = new HashMap<>();
263-
if (channel.getExtraData() != null) {
264-
Set<String> keys = channel.getExtraData().keySet();
275+
if (channel_.getExtraData() != null) {
276+
Set<String> keys = channel_.getExtraData().keySet();
265277
for (String key : keys) {
266-
Object value = channel.getExtraData().get(key);
278+
Object value = channel_.getExtraData().get(key);
267279
if (value != null)
268280
data.put(key, value);
269281
}
@@ -272,21 +284,14 @@ private void getChannel(Channel channel) {
272284

273285
ChannelDetailRequest request = new ChannelDetailRequest(messages, data, true, true);
274286

275-
Global.mRestController.channelDetailWithID(channel.getId(), request, (ChannelResponse response) -> {
287+
Global.mRestController.channelDetailWithID(channel_.getId(), request, (ChannelResponse response) -> {
276288
Log.d(TAG, "Channel Connected");
277289
binding.setShowMainProgressbar(false);
278290
if (!response.getMessages().isEmpty())
279291
Global.setStartDay(response.getMessages(), null);
280292
Global.addChannelResponse(response);
281293
channelResponse = response;
282294
initReconnection();
283-
// Check Ephemeral Messages
284-
List<Message> ephemeralMessages = Global.getEphemeralMessages(channel.getId(), thread_parentMessage.getId());
285-
if (ephemeralMessages != null && !ephemeralMessages.isEmpty()) {
286-
for (int i = 0; i < ephemeralMessages.size(); i++) {
287-
channelMessages.add(ephemeralMessages.get(i));
288-
}
289-
}
290295
setDeliverLastMessage();
291296
configUIs();
292297

@@ -318,17 +323,17 @@ private void configUIs() {
318323
configMessageInputView(); // Message Input box
319324
configMessageRecyclerView(); // Message RecyclerView
320325
// Bottom View
321-
binding.tvNewMessage.setVisibility(View.GONE);
322-
binding.tvNewMessage.setOnClickListener((View v) -> {
323-
scrollPosition = 0;
324-
recyclerView().scrollToPosition(messages().size());
325-
binding.tvNewMessage.setVisibility(View.GONE);
326-
});
326+
// binding.tvNewMessage.setVisibility(View.GONE);
327+
// binding.tvNewMessage.setOnClickListener((View v) -> {
328+
// scrollPosition = 0;
329+
// recyclerView().scrollToPosition(messages().size());
330+
// binding.tvNewMessage.setVisibility(View.GONE);
331+
// });
327332
// File Attachment
328333
configAttachmentUIs();
329334
}
330335

331-
private void configActionBar(){
336+
private void configActionBar() {
332337
try {
333338
getSupportActionBar().hide();
334339
} catch (Exception e) {
@@ -400,7 +405,7 @@ private void configHeaderView() {
400405
binding.tvBack.setOnClickListener((View v) -> finish());
401406
}
402407

403-
private void configMessageInputView(){
408+
private void configMessageInputView() {
404409
binding.setActiveMessageComposer(false);
405410
binding.setActiveMessageSend(false);
406411
binding.setShowLoadMoreProgressbar(false);
@@ -444,7 +449,7 @@ public void onTextChanged(CharSequence s, int start,
444449
binding.tvSend.setOnClickListener(this::sendMessage);
445450
}
446451

447-
private void configMessageRecyclerView(){
452+
private void configMessageRecyclerView() {
448453
mLayoutManager.scrollToPosition(channelMessages.size());
449454
binding.rvMessage.setLayoutManager(mLayoutManager);
450455
setScrollDownHideKeyboard(binding.rvMessage);
@@ -471,7 +476,7 @@ private void configHeaderLastActive(@Nullable Message message) {
471476
}
472477
}
473478

474-
private void configAttachmentUIs(){
479+
private void configAttachmentUIs() {
475480
binding.rvMedia.setLayoutManager(new GridLayoutManager(this, 4, LinearLayoutManager.VERTICAL, false));
476481
binding.rvMedia.hasFixedSize();
477482
binding.rvComposer.setLayoutManager(new GridLayoutManager(this, 1, LinearLayoutManager.HORIZONTAL, false));
@@ -548,9 +553,8 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
548553
Utils.hideSoftKeyboard(ChatActivity.this);
549554
binding.etMessage.clearFocus();
550555
if (currentFirstVisible == 0 && !isNoHistory()) loadMore();
551-
if (currentLastVisible >= messages().size() - 1)
552-
binding.tvNewMessage.setVisibility(View.GONE);
553-
556+
// if (currentLastVisible >= messages().size() - 1)
557+
// binding.tvNewMessage.setVisibility(View.GONE);
554558
}
555559

556560
new Handler().postDelayed(() -> {
@@ -717,7 +721,7 @@ private void editMessage(Message message) {
717721
binding.etMessage.setSelection(binding.etMessage.getText().length());
718722
}
719723
if (message.getAttachments() != null && !message.getAttachments().isEmpty()) {
720-
for (Attachment attachment: message.getAttachments())
724+
for (Attachment attachment : message.getAttachments())
721725
attachment.config.setUploaded(true);
722726

723727
if (message.getAttachments().get(0).getType().equals(ModelType.attach_file)) {
@@ -1130,12 +1134,8 @@ public void onReceive(Context context, Intent intent) {
11301134
Global.setStartDay(channelResponse.getMessages(), null);
11311135
initReconnection();
11321136
// Check Ephemeral Messages
1133-
List<Message> ephemeralMainMessages = Global.getEphemeralMessages(channel.getId(), null);
1134-
if (ephemeralMainMessages != null && !ephemeralMainMessages.isEmpty()) {
1135-
for (int i = 0; i < ephemeralMainMessages.size(); i++) {
1136-
channelMessages.add(ephemeralMainMessages.get(i));
1137-
}
1138-
}
1137+
checkEphemeralMessages();
1138+
11391139
runOnUiThread(() -> {
11401140
setDeliverLastMessage();
11411141
configUIs();
@@ -1240,7 +1240,7 @@ private void newMessageEvent(Message message) {
12401240

12411241
if (message.isIncoming() && !isShowLastMessage) {
12421242
scrollPosition = -1;
1243-
binding.tvNewMessage.setVisibility(View.VISIBLE);
1243+
// binding.tvNewMessage.setVisibility(View.VISIBLE);
12441244
} else {
12451245
scrollPosition = 0;
12461246
}

library/src/main/res/layout/activity_chat.xml

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,22 @@
142142
app:layout_constraintTop_toBottomOf="@+id/header"
143143
tools:listitem="@layout/list_item_message" />
144144

145-
<TextView
146-
android:id="@+id/tv_new_message"
147-
style="@style/text_s"
148-
android:layout_width="wrap_content"
149-
android:layout_height="wrap_content"
150-
android:layout_marginBottom="5dp"
151-
android:background="@drawable/round_action_send"
152-
android:gravity="center"
153-
android:paddingStart="8dp"
154-
android:paddingEnd="8dp"
155-
android:text="New Messages!"
156-
android:textColor="@color/white"
157-
android:visibility="gone"
158-
app:layout_constraintBottom_toTopOf="@+id/ll_composer"
159-
app:layout_constraintEnd_toEndOf="@+id/ll_composer"
160-
app:layout_constraintStart_toStartOf="@+id/ll_composer" />
145+
<!--<TextView-->
146+
<!--android:id="@+id/tv_new_message"-->
147+
<!--style="@style/text_s"-->
148+
<!--android:layout_width="wrap_content"-->
149+
<!--android:layout_height="wrap_content"-->
150+
<!--android:layout_marginBottom="5dp"-->
151+
<!--android:background="@drawable/round_action_send"-->
152+
<!--android:gravity="center"-->
153+
<!--android:paddingStart="8dp"-->
154+
<!--android:paddingEnd="8dp"-->
155+
<!--android:text="New Messages!"-->
156+
<!--android:textColor="@color/white"-->
157+
<!--android:visibility="gone"-->
158+
<!--app:layout_constraintBottom_toTopOf="@+id/ll_composer"-->
159+
<!--app:layout_constraintEnd_toEndOf="@+id/ll_composer"-->
160+
<!--app:layout_constraintStart_toStartOf="@+id/ll_composer" />-->
161161

162162
<include
163163
android:id="@+id/cl_thread"
@@ -404,7 +404,7 @@
404404
android:paddingEnd="20dp"
405405
android:paddingBottom="10dp"
406406
android:visibility="gone"
407-
app:layout_constraintBottom_toBottomOf="parent"
407+
app:layout_constraintBottom_toTopOf="@+id/ll_composer"
408408
app:layout_constraintEnd_toEndOf="parent"
409409
app:layout_constraintStart_toStartOf="parent">
410410

@@ -427,26 +427,38 @@
427427
app:layout_constraintStart_toEndOf="@+id/tv_command_title"
428428
app:layout_constraintTop_toTopOf="@+id/tv_command_title" />
429429

430-
<ListView
431-
android:id="@+id/lv_command"
430+
<FrameLayout
432431
android:layout_width="match_parent"
433432
android:layout_height="wrap_content"
434433
android:layout_marginTop="10dp"
435-
android:layout_marginBottom="80dp"
436-
android:divider="@null"
437434
app:layout_constraintBottom_toBottomOf="parent"
438435
app:layout_constraintEnd_toEndOf="parent"
439436
app:layout_constraintStart_toStartOf="parent"
440-
app:layout_constraintTop_toBottomOf="@+id/tv_command_title"
441-
tools:listitem="@layout/list_item_command" />
437+
app:layout_constraintTop_toBottomOf="@+id/tv_command_title">
438+
439+
<ListView
440+
android:id="@+id/lv_command"
441+
android:layout_width="match_parent"
442+
android:layout_height="wrap_content"
443+
android:divider="@null"
444+
tools:listitem="@layout/list_item_command" />
445+
446+
<ListView
447+
android:id="@+id/lv_mention"
448+
android:layout_width="match_parent"
449+
android:layout_height="wrap_content"
450+
android:divider="@null"
451+
tools:listitem="@layout/list_item_mention" />
452+
</FrameLayout>
453+
442454

443455
</android.support.constraint.ConstraintLayout>
444456

445457
<TextView
446-
android:id="@+id/tv_select_media_back"
458+
android:id="@+id/tv_inputbox_back"
447459
android:layout_width="match_parent"
448460
android:layout_height="0dp"
449-
android:background="@color/white"
461+
android:background="@color/chat_theme"
450462
android:visibility="gone"
451463
app:layout_constraintBottom_toBottomOf="parent"
452464
app:layout_constraintTop_toTopOf="@+id/ll_composer" />

0 commit comments

Comments
 (0)