Skip to content

Commit

Permalink
Merge pull request #153 from jinfengf/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
jinfengf authored May 23, 2019
2 parents 671d65b + 51e0a15 commit 5a86c5f
Show file tree
Hide file tree
Showing 62 changed files with 1,033 additions and 1,876 deletions.
3 changes: 2 additions & 1 deletion chatapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,6 @@ dependencies {
implementation 'cn.jiguang.sdk:jmessage:2.9.0' // 此处以J
implementation 'cn.jiguang.sdk:jcore:2.0.0'
implementation 'org.greenrobot:eventbus:3.1.1'
implementation 'in.srain.cube:ptr-load-more:1.0.6'
implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-26'
implementation 'com.github.mtotschnig:StickyListHeaders:2.7.1'
}
6 changes: 6 additions & 0 deletions chatapp/src/main/java/jiguang/chat/activity/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public void initTitle(boolean returnBtn, boolean titleLeftDesc, String titleLeft
mReturn_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm.isActive() && getCurrentFocus() != null) {
if (getCurrentFocus().getWindowToken() != null) {
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
finish();
}
});
Expand Down
89 changes: 80 additions & 9 deletions chatapp/src/main/java/jiguang/chat/activity/ChatActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@

import java.io.File;
import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -43,6 +45,7 @@
import cn.jpush.im.android.api.ChatRoomManager;
import cn.jpush.im.android.api.JMessageClient;
import cn.jpush.im.android.api.callback.GetGroupInfoCallback;
import cn.jpush.im.android.api.callback.GetUserInfoListCallback;
import cn.jpush.im.android.api.callback.RequestCallback;
import cn.jpush.im.android.api.content.EventNotificationContent;
import cn.jpush.im.android.api.content.FileContent;
Expand All @@ -53,6 +56,7 @@
import cn.jpush.im.android.api.enums.ConversationType;
import cn.jpush.im.android.api.enums.MessageDirect;
import cn.jpush.im.android.api.event.ChatRoomMessageEvent;
import cn.jpush.im.android.api.event.ChatRoomNotificationEvent;
import cn.jpush.im.android.api.event.CommandNotificationEvent;
import cn.jpush.im.android.api.event.MessageEvent;
import cn.jpush.im.android.api.event.MessageReceiptStatusChangeEvent;
Expand Down Expand Up @@ -526,6 +530,9 @@ public void onBackPressed() {
private void returnBtn() {
mConv.resetUnreadCount();
dismissSoftInput();
if (mChatAdapter != null) {
mChatAdapter.stopMediaPlayer();
}
JMessageClient.exitConversation();
//发送保存为草稿事件到会话列表
EventBus.getDefault().post(new Event.Builder().setType(EventType.draft)
Expand Down Expand Up @@ -673,16 +680,18 @@ protected void onPause() {
@Override
protected void onResume() {
String targetId = getIntent().getStringExtra(TARGET_ID);
if (!mIsSingle) {
if (mIsSingle) {
if (null != targetId) {
String appKey = getIntent().getStringExtra(TARGET_APP_KEY);
JMessageClient.enterSingleConversation(targetId, appKey);
}
} else if (!isChatRoom) {
long groupId = getIntent().getLongExtra(GROUP_ID, 0);
if (groupId != 0) {
JGApplication.isAtMe.put(groupId, false);
JGApplication.isAtall.put(groupId, false);
JMessageClient.enterGroupConversation(groupId);
}
} else if (null != targetId) {
String appKey = getIntent().getStringExtra(TARGET_APP_KEY);
JMessageClient.enterSingleConversation(targetId, appKey);
}

//历史消息中删除后返回到聊天界面刷新界面
Expand All @@ -695,7 +704,9 @@ protected void onResume() {
mChatAdapter.notifyDataSetChanged();
//发送名片返回聊天界面刷新信息
if (SharePreferenceManager.getIsOpen()) {
initData();
if (!isChatRoom) {
initData();
}
SharePreferenceManager.setIsOpen(false);
}
super.onResume();
Expand Down Expand Up @@ -730,6 +741,49 @@ public void onEventMainThread(ChatRoomMessageEvent event) {
mChatAdapter.addMsgListToList(messages);
}

public void onEventMainThread(ChatRoomNotificationEvent event) {
try {
Constructor constructor = EventNotificationContent.class.getDeclaredConstructor();
constructor.setAccessible(true);
List<Message> messages = new ArrayList<>();
switch (event.getType()) {
case add_chatroom_admin:
case del_chatroom_admin:
event.getTargetUserInfoList(new GetUserInfoListCallback() {
@Override
public void gotResult(int i, String s, List<UserInfo> list) {
if (i == 0) {
for (UserInfo userInfo : list) {
try {
EventNotificationContent content = (EventNotificationContent) constructor.newInstance();
Field field = content.getClass().getSuperclass().getDeclaredField("contentType");
field.setAccessible(true);
field.set(content, ContentType.eventNotification);
String user = userInfo.getUserID() == JMessageClient.getMyInfo().getUserID()
? "你" : TextUtils.isEmpty(userInfo.getNickname()) ? userInfo.getUserName() : userInfo.getNickname();
String result = event.getType() == ChatRoomNotificationEvent.Type.add_chatroom_admin ? "被设置成管理员" : "被取消管理员";
content.setStringExtra("msg", user + result);
if (mConv != null) {
messages.add(mConv.createSendMessage(content));
}
} catch (Exception e) {
e.printStackTrace();
}
}
if (messages.size() > 0) {
mChatAdapter.addMsgListToList(messages);
}
}
}
});
break;
default:
}
} catch (Exception e) {
e.printStackTrace();
}
}

public void onEvent(MessageEvent event) {
final Message message = event.getMessage();

Expand Down Expand Up @@ -873,6 +927,9 @@ private void refreshGroupNum() {

@Override
public void onContentLongClick(final int position, View view) {
if (isChatRoom) {
return;
}
final Message msg = mChatAdapter.getMessage(position);

if (msg == null) {
Expand Down Expand Up @@ -1147,10 +1204,10 @@ public void onEventMainThread(ImageEvent event) {
break;
case JGApplication.BUSINESS_CARD:
intent = new Intent(mContext, FriendListActivity.class);
intent.putExtra("isSingle", mIsSingle);
intent.putExtra("userId", mTargetId);
intent.putExtra("groupId", mGroupId);
startActivity(intent);
intent.putExtra(JGApplication.CONV_TYPE, mConv.getType());
intent.putExtra(JGApplication.TARGET_ID, mTargetId);
intent.putExtra(JGApplication.TARGET_APP_KEY, mTargetAppKey);;
startActivityForResult(intent, JGApplication.REQUEST_CODE_FRIEND_LIST);
break;
case JGApplication.TACK_VIDEO:
case JGApplication.TACK_VOICE:
Expand All @@ -1173,6 +1230,20 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
case RequestCode.PICK_IMAGE://4
onPickImageActivityResult(requestCode, data);
break;
case JGApplication.REQUEST_CODE_FRIEND_LIST:
// 发送名片成功后,聊天室需要添加消息
if (resultCode == RESULT_OK && isChatRoom) {
String msgJson = data.getStringExtra(JGApplication.MSG_JSON);
if (msgJson != null) {
Message msg = Message.fromJson(msgJson);
if (msg != null) {
mChatAdapter.addMsgToList(msg);
mChatAdapter.notifyDataSetChanged();
}
}
}
break;

}

switch (resultCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public void onClick(View v) {
};
exitDialog = DialogCreator.createBaseDialogWithTitle(ChatRoomInfoActivity.this, "确定退出聊天室", listener);
exitDialog.show();
break;
default:
break;
}
Expand Down Expand Up @@ -129,6 +130,9 @@ private void initData() {
mTvChatRoomDesc = (TextView) findViewById(R.id.tv_chatRoomDesc);
mTvChatRoomOwner = (TextView) findViewById(R.id.tv_chatRoomOwner);
mGvChatRoomKeeper = (NoScrollGridView) findViewById(R.id.grid_chatRommKeeper);
mGvChatRoomKeeper.setClickable(false);
mGvChatRoomKeeper.setPressed(false);
mGvChatRoomKeeper.setEnabled(false);
roomId = getIntent().getLongExtra("chatRoomId", 0);
findViewById(R.id.ll_chat_room_name).setOnClickListener(this);
findViewById(R.id.ll_chat_room_desc).setOnClickListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void gotResult(int i, String s, List<UserInfo> userInfos) {
}
mAdapter = new ChatRoomKeeperListAdapter(ChatRoomKeeperActivity.this, mShowKeeperList, roomID, isOwner);
mLvKeeper.setAdapter(mAdapter);
mLvKeeper.setOnItemClickListener(mAdapter);
loadingDialog.dismiss();
} else {
loadingDialog.dismiss();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import jiguang.chat.utils.keyboard.widget.EmoticonsEditText;
import jiguang.chat.utils.pinyin.UserComparator;
import jiguang.chat.utils.sidebar.SideBar;
import jiguang.chat.view.listview.StickyListHeadersListView;
import se.emilsjolander.stickylistheaders.StickyListHeadersListView;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import jiguang.chat.utils.keyboard.utils.EmoticonsKeyboardUtils;
import jiguang.chat.utils.pinyin.PinyinComparator;
import jiguang.chat.utils.sidebar.SideBar;
import jiguang.chat.view.listview.StickyListHeadersListView;
import se.emilsjolander.stickylistheaders.StickyListHeadersListView;


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import cn.jpush.im.android.api.JMessageClient;
import cn.jpush.im.android.api.content.TextContent;
import cn.jpush.im.android.api.enums.ConversationType;
import cn.jpush.im.android.api.model.Conversation;
import cn.jpush.im.android.api.model.Message;
import cn.jpush.im.android.api.options.MessageSendingOptions;
Expand Down Expand Up @@ -64,7 +65,7 @@ private void initView() {
private void initData() {
List<Conversation> conversationList = JMessageClient.getConversationList();
for (Conversation conv : conversationList) {
if (!conv.getTargetId().equals("feedback_Android")) {
if (!conv.getTargetId().equals("feedback_Android") && conv.getType() != ConversationType.chatroom) {
forwardList.add(conv);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,22 @@

import cn.jpush.im.android.api.JMessageClient;
import cn.jpush.im.android.api.content.TextContent;
import cn.jpush.im.android.api.enums.ConversationType;
import cn.jpush.im.android.api.model.Conversation;
import cn.jpush.im.android.api.model.Message;
import cn.jpush.im.android.api.options.MessageSendingOptions;
import cn.jpush.im.api.BasicCallback;
import jiguang.chat.R;
import jiguang.chat.adapter.FriendListAdapter;
import jiguang.chat.application.JGApplication;
import jiguang.chat.database.FriendEntry;
import jiguang.chat.database.UserEntry;
import jiguang.chat.utils.DialogCreator;
import jiguang.chat.utils.HandleResponseCode;
import jiguang.chat.utils.SharePreferenceManager;
import jiguang.chat.utils.pinyin.PinyinComparator;
import jiguang.chat.utils.sidebar.SideBar;
import jiguang.chat.view.listview.StickyListHeadersListView;
import se.emilsjolander.stickylistheaders.StickyListHeadersListView;

/**
* Created by ${chenyn} on 2017/9/21.
Expand Down Expand Up @@ -87,10 +89,26 @@ public void onClick(View v) {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Object itemAtPosition = parent.getItemAtPosition(position);
FriendEntry friendEntry = (FriendEntry) itemAtPosition;
if (getIntent().getBooleanExtra("isSingle", false)) {
setBusinessCard(friendEntry, JMessageClient.getSingleConversation(getIntent().getStringExtra("userId")));
} else {
setBusinessCard(friendEntry, JMessageClient.getGroupConversation(getIntent().getLongExtra("groupId", 0)));
ConversationType convType = (ConversationType) getIntent().getSerializableExtra(JGApplication.CONV_TYPE);
String targetId = getIntent().getStringExtra(JGApplication.TARGET_ID);
String targetAppKey = getIntent().getStringExtra(JGApplication.TARGET_APP_KEY);
Conversation conv = null;
if (convType != null) {
switch (convType) {
case single:
conv = JMessageClient.getSingleConversation(targetId, targetAppKey);
break;
case group:
conv = JMessageClient.getGroupConversation(Long.valueOf(targetId));
break;
case chatroom:
conv = JMessageClient.getChatRoomConversation(Long.valueOf(targetId));
break;
default:
}
}
if (conv != null) {
setBusinessCard(friendEntry, conv);
}
}
});
Expand Down Expand Up @@ -133,6 +151,9 @@ public void gotResult(int i, String s) {
if (i == 0) {
SharePreferenceManager.setIsOpen(true);
Toast.makeText(FriendListActivity.this, "发送成功", Toast.LENGTH_SHORT).show();
Intent intent = new Intent();
intent.putExtra(JGApplication.MSG_JSON, textMessage.toJson());
FriendListActivity.this.setResult(RESULT_OK, intent);
finish();
} else {
HandleResponseCode.onHandle(FriendListActivity.this, i, false);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import jiguang.chat.application.JGApplication;
import jiguang.chat.utils.GroupMemberListComparator;
import jiguang.chat.utils.sidebar.SideBar;
import jiguang.chat.view.listview.StickyListHeadersListView;
import se.emilsjolander.stickylistheaders.StickyListHeadersListView;

/**
* Created by ${chenyn} on 2017/11/3.
Expand Down
Loading

0 comments on commit 5a86c5f

Please sign in to comment.