Commit 02d6dcc9 authored by sheteng's avatar sheteng

连接超时错误码

parent 7df562e2
...@@ -58,9 +58,11 @@ public class FirstFragment extends Fragment { ...@@ -58,9 +58,11 @@ public class FirstFragment extends Fragment {
} }
@Override @Override
public void onSocketDisconnection() { public void onSocketDisconnection(int code) {
refreshLogView("disconnect");
} }
}); });
CCIMClient.getInstance().registerMessageListener(new OnPushMsgListener() { CCIMClient.getInstance().registerMessageListener(new OnPushMsgListener() {
......
...@@ -25,8 +25,8 @@ public class LoginViewModel extends ViewModel { ...@@ -25,8 +25,8 @@ public class LoginViewModel extends ViewModel {
public MutableLiveData<Collection<Contact>> contactList = new MutableLiveData<>(); public MutableLiveData<Collection<Contact>> contactList = new MutableLiveData<>();
public MutableLiveData<Collection<ContactGroup>> contactGroupList = new MutableLiveData<>(); public MutableLiveData<Collection<ContactGroup>> contactGroupList = new MutableLiveData<>();
public MutableLiveData<Collection<Dialog>> dialogList = new MutableLiveData<>(); public MutableLiveData<Collection<Dialog>> dialogList = new MutableLiveData<>();
public MutableLiveData<List<MessageContent>> privateMsgList = new MutableLiveData<>(); public MutableLiveData<MessageContent> privateMsgList = new MutableLiveData<>();
public MutableLiveData<List<MessageContent>> channelMsgList = new MutableLiveData<>(); public MutableLiveData<MessageContent> channelMsgList = new MutableLiveData<>();
public MutableLiveData<List<Long>> channelList = new MutableLiveData<>(); public MutableLiveData<List<Long>> channelList = new MutableLiveData<>();
...@@ -42,14 +42,17 @@ public class LoginViewModel extends ViewModel { ...@@ -42,14 +42,17 @@ public class LoginViewModel extends ViewModel {
CCIMClient.getInstance().initSDK(context, appKey, username, extData, id, ts, sign, new OnConnectListener() { CCIMClient.getInstance().initSDK(context, appKey, username, extData, id, ts, sign, new OnConnectListener() {
@Override @Override
public void onSocketConnection() { public void onSocketConnection() {
System.out.println("onSocketConnection");
loginState.postValue(true); loginState.postValue(true);
} }
@Override @Override
public void onSocketDisconnection() { public void onSocketDisconnection(int code) {
System.out.println("onSocketDisconnection");
//重连 //重连
login(context, appKey, appsecret, username, userId, ip, port); login(context, appKey, appsecret, username, userId, ip, port);
} }
}); });
} }
...@@ -89,42 +92,22 @@ public class LoginViewModel extends ViewModel { ...@@ -89,42 +92,22 @@ public class LoginViewModel extends ViewModel {
} }
public void addPrivateMsg(MessageContent res) { public void addPrivateMsg(MessageContent res) {
List<MessageContent> value = privateMsgList.getValue(); privateMsgList.postValue(res);
if (value == null) {
value = new ArrayList<>();
}
value.add(res);
privateMsgList.postValue(value);
} }
public void addPrivateMsg(List<MessageContent> res) { public void addPrivateMsg(List<MessageContent> res) {
List<MessageContent> value = privateMsgList.getValue();
if (value == null) {
value = new ArrayList<>();
}
for (MessageContent re : res) { for (MessageContent re : res) {
value.add(re); privateMsgList.postValue(re);
} }
privateMsgList.postValue(value);
} }
public void addChannelMsg(MessageContent res) { public void addChannelMsg(MessageContent res) {
List<MessageContent> value = channelMsgList.getValue(); channelMsgList.postValue(res);
if (value == null) {
value = new ArrayList<>();
}
value.add(res);
channelMsgList.postValue(value);
} }
public void addChannelMsg(List<MessageContent> res) { public void addChannelMsg(List<MessageContent> res) {
List<MessageContent> value = channelMsgList.getValue();
if (value == null) {
value = new ArrayList<>();
}
for (MessageContent re : res) { for (MessageContent re : res) {
value.add(re); channelMsgList.postValue(re);
} }
channelMsgList.postValue(value);
} }
} }
\ No newline at end of file
...@@ -48,18 +48,15 @@ public class ConnectFragment extends Fragment { ...@@ -48,18 +48,15 @@ public class ConnectFragment extends Fragment {
Contact contact = (Contact) getArguments().getSerializable("contact"); Contact contact = (Contact) getArguments().getSerializable("contact");
loginViewModel.privateMsgList.observe(getViewLifecycleOwner(), new Observer<List<MessageContent>>() { loginViewModel.privateMsgList.observe(getViewLifecycleOwner(), new Observer<MessageContent>() {
@Override @Override
public void onChanged(List<MessageContent> messageContents) { public void onChanged(MessageContent messageContent) {
list.clear(); if (messageContent.getSenderUserId().equals(contact.getContactUserId()) || messageContent.getReciveUserId().equals(contact.getContactUserId())) {
for (MessageContent messageContent : messageContents) {
if ((contact.getContactUserId().equals(messageContent.getSenderUserId()) || contact.getContactUserId().equals(messageContent.getReciveUserId()))) {
list.add(messageContent); list.add(messageContent);
}
}
privaetMsgAdapter.refreshData(); privaetMsgAdapter.refreshData();
binding.msgList.setSelection(privaetMsgAdapter.getCount() - 1); binding.msgList.setSelection(privaetMsgAdapter.getCount() - 1);
} }
}
}); });
binding.sendBtn.setOnClickListener(new View.OnClickListener() { binding.sendBtn.setOnClickListener(new View.OnClickListener() {
...@@ -117,11 +114,12 @@ public class ConnectFragment extends Fragment { ...@@ -117,11 +114,12 @@ public class ConnectFragment extends Fragment {
return false; return false;
} }
}); });
CCIMClient.getInstance().getPrivateMessage(contact.getContactUserId(), new ResultEventCallback<List<MessageContent>>() { CCIMClient.getInstance().getPrivateMessage(contact.getContactUserId(), new ResultEventCallback<List<MessageContent>>() {
@Override @Override
public void onSuccess(List<MessageContent> messageContents) { public void onSuccess(List<MessageContent> messageContents) {
loginViewModel.addPrivateMsg(messageContents); list.addAll(messageContents);
privaetMsgAdapter.refreshData();
binding.msgList.setSelection(privaetMsgAdapter.getCount() - 1);
} }
@Override @Override
......
...@@ -46,18 +46,15 @@ public class ConnectChannelFragment extends Fragment { ...@@ -46,18 +46,15 @@ public class ConnectChannelFragment extends Fragment {
long channelId = getArguments().getLong("channelId"); long channelId = getArguments().getLong("channelId");
loginViewModel.channelMsgList.observe(getViewLifecycleOwner(), new Observer<List<MessageContent>>() { loginViewModel.channelMsgList.observe(getViewLifecycleOwner(), new Observer<MessageContent>() {
@Override @Override
public void onChanged(List<MessageContent> messageContents) { public void onChanged(MessageContent messageContent) {
list.clear(); if (messageContent.getChannelId().equals(channelId)) {
for (MessageContent messageContent : messageContents) {
if (messageContent.getChannelId() == channelId) {
list.add(messageContent); list.add(messageContent);
}
}
channelMsgAdapter.refreshData(); channelMsgAdapter.refreshData();
binding.msgList.setSelection(channelMsgAdapter.getCount() - 1); binding.msgList.setSelection(channelMsgAdapter.getCount() - 1);
} }
}
}); });
binding.sendBtn.setOnClickListener(new View.OnClickListener() { binding.sendBtn.setOnClickListener(new View.OnClickListener() {
...@@ -71,6 +68,7 @@ public class ConnectChannelFragment extends Fragment { ...@@ -71,6 +68,7 @@ public class ConnectChannelFragment extends Fragment {
loginViewModel.addChannelMsg(messageContent); loginViewModel.addChannelMsg(messageContent);
ToastUtil.show(getContext(), "send Success"); ToastUtil.show(getContext(), "send Success");
} }
@Override @Override
public void onFailed(int errorCode) { public void onFailed(int errorCode) {
ToastUtil.show(getContext(), "send onFailed :" + errorCode); ToastUtil.show(getContext(), "send onFailed :" + errorCode);
...@@ -82,7 +80,9 @@ public class ConnectChannelFragment extends Fragment { ...@@ -82,7 +80,9 @@ public class ConnectChannelFragment extends Fragment {
CCIMClient.getInstance().getChannelMessage(channelId, new ResultEventCallback<List<MessageContent>>() { CCIMClient.getInstance().getChannelMessage(channelId, new ResultEventCallback<List<MessageContent>>() {
@Override @Override
public void onSuccess(List<MessageContent> messageContents) { public void onSuccess(List<MessageContent> messageContents) {
loginViewModel.addChannelMsg(messageContents); list.addAll(messageContents);
channelMsgAdapter.refreshData();
binding.msgList.setSelection(channelMsgAdapter.getCount() - 1);
} }
@Override @Override
...@@ -95,7 +95,7 @@ public class ConnectChannelFragment extends Fragment { ...@@ -95,7 +95,7 @@ public class ConnectChannelFragment extends Fragment {
@Override @Override
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getAction() == MotionEvent.ACTION_UP) {
CCIMClient.getInstance().stopAndSendChannelAudioMessage(channelId, new ResultEventCallback<MessageContent>(){ CCIMClient.getInstance().stopAndSendChannelAudioMessage(channelId, new ResultEventCallback<MessageContent>() {
@Override @Override
public void onSuccess(MessageContent message) { public void onSuccess(MessageContent message) {
binding.sendEdit.setText(""); binding.sendEdit.setText("");
...@@ -105,7 +105,7 @@ public class ConnectChannelFragment extends Fragment { ...@@ -105,7 +105,7 @@ public class ConnectChannelFragment extends Fragment {
@Override @Override
public void onFailed(int errorCode) { public void onFailed(int errorCode) {
ToastUtil.show(getContext(), "send onFailed :" + errorCode ); ToastUtil.show(getContext(), "send onFailed :" + errorCode);
} }
}); });
} }
......
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:hint="ip" android:hint="ip"
android:text="10.4.5.134" android:text="106.15.237.67"
android:imeActionLabel="@string/action_sign_in_short" android:imeActionLabel="@string/action_sign_in_short"
android:imeOptions="actionDone" android:imeOptions="actionDone"
android:selectAllOnFocus="true" android:selectAllOnFocus="true"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment