首先是loginactivity
login成功以后,跳转到mainActivity。
mainActivity中有四个fragment ,
聊天        fragment_chat
通讯录    fragment_contact
发现,    fragment_internal
我的       fragment_my
 
 
在聊天fragment_chat中,设置点击每个item,可以跳转到相应的页面
fragement_chat.java 代码:
// 这个地方跳转一定要快
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) { RecentInfo recentInfo = contactAdapter.getItem(position);
if (recentInfo == null) {
logger.e("recent#null recentInfo -> position:%d", position);
return;
}
IMUIHelper.openChatActivity(getActivity(),recentInfo.getSessionKey());
}

然后分析openChatActivity()函数。

IMUIHelper.java 中代码如下:
// 跳转到聊天页面
public static void openChatActivity(Context ctx, String sessionKey) {
Intent intent = new Intent(ctx, MessageActivity.class);
intent.putExtra(IntentConstant.KEY_SESSION_KEY, sessionKey);
ctx.startActivity(intent);
}

至此,我们跳转到了对话界面。

当点击发送消息按钮的时候代码如下
case R.id.send_message_btn: {
logger.d("message_activity#send btn clicked"); String content = messageEdt.getText().toString();
logger.d("message_activity#chat content:%s", content);
if (content.trim().equals("")) {
Toast.makeText(MessageActivity.this,
getResources().getString(R.string.message_null), Toast.LENGTH_LONG).show();
return;
}
TextMessage textMessage = TextMessage.buildForSend(content, loginUser, peerEntity);
imService.getMessageManager().sendText(textMessage);
messageEdt.setText("");
pushList(textMessage);
scrollToBottomListItem();
}

并且,程序能够正常显示发送内容。

看pushList()函数如下
public void pushList(MessageEntity msg) {
logger.d("chat#pushList msgInfo:%s", msg);
adapter.addItem(msg);
}

查看addItem()函数如下

/**
* ----------------------添加历史消息-----------------
*/
public void addItem(final MessageEntity msg) {
if (msg.getDisplayType() == DBConstant.MSG_TYPE_SINGLE_TEXT) {
if (isMsgGif(msg)) {
msg.setGIfEmo(true);
} else {
msg.setGIfEmo(false);
}
}
int nextTime = msg.getCreated();
if (getCount() > 0) {
Object object = msgObjectList.get(getCount() - 1);
if (object instanceof MessageEntity) {
int preTime = ((MessageEntity) object).getCreated();
boolean needTime = DateUtil.needDisplayTime(preTime, nextTime);
if (needTime) {
Integer in = nextTime;
msgObjectList.add(in);
}
}
} else {
Integer in = msg.getCreated();
msgObjectList.add(in);
}
/**消息的判断*/
if (msg.getDisplayType() == DBConstant.SHOW_MIX_TEXT) {
MixMessage mixMessage = (MixMessage) msg;
msgObjectList.addAll(mixMessage.getMsgList());
} else {
msgObjectList.add(msg);
}
if (msg instanceof ImageMessage) {
ImageMessage.addToImageMessageList((ImageMessage) msg);
}
logger.d("#messageAdapter#addItem");
notifyDataSetChanged(); }

在看scrollToBottomListItem() 函数

/**
* @Description 滑动到列表底部
*/
private void scrollToBottomListItem() {
logger.d("message_activity#scrollToBottomListItem"); // todo eric, why use the last one index + 2 can real scroll to the
// bottom?
ListView lv = lvPTR.getRefreshableView();
if (lv != null) {
lv.setSelection(adapter.getCount() + 1);
}
textView_new_msg_tip.setVisibility(View.GONE);
}
消息添加到msgObjgecList中,并且可以显示。
msgObject的初始化
public void loadHistoryList(final List<MessageEntity> historyList) {
logger.d("#messageAdapter#loadHistoryList");
if (null == historyList || historyList.size() <= 0) {
return;
}
Collections.sort(historyList, new MessageTimeComparator());
ArrayList<Object> chatList = new ArrayList<>();
int preTime = 0;
int nextTime = 0;
for (MessageEntity msg : historyList) {
if (msg.getDisplayType() == DBConstant.MSG_TYPE_SINGLE_TEXT) {
if (isMsgGif(msg)) {
msg.setGIfEmo(true);
} else {
msg.setGIfEmo(false);
}
}
nextTime = msg.getCreated();
boolean needTimeBubble = DateUtil.needDisplayTime(preTime, nextTime);
if (needTimeBubble) {
Integer in = nextTime;
chatList.add(in);
}
preTime = nextTime;
if (msg.getDisplayType() == DBConstant.SHOW_MIX_TEXT) {
MixMessage mixMessage = (MixMessage) msg;
chatList.addAll(mixMessage.getMsgList());
} else {
chatList.add(msg);
}
}
// 如果是历史消息,从头开始加
msgObjectList.addAll(0, chatList);
getImageList();
logger.d("#messageAdapter#addItem");
notifyDataSetChanged();
}
 
在看对对话界面的初始化:
 
在MessageFragment.java
初始化数据:
private void initData() {
historyTimes = 0;
adapter.clearItem();
ImageMessage.clearImageMessageList();
loginUser = imService.getLoginManager().getLoginInfo();
peerEntity = imService.getSessionManager().findPeerEntity(currentSessionKey);
// 头像、历史消息加载、取消通知
setTitleByUser();
reqHistoryMsg();
adapter.setImService(imService, loginUser);
imService.getUnReadMsgManager().readUnreadSession(currentSessionKey);
imService.getNotificationManager().cancelSessionNotifications(currentSessionKey);
}

其中,初始化消息的函数是:reqHistoryMsg();

/**
* 1.初始化请求历史消息
* 2.本地消息不全,也会触发
*/
private void reqHistoryMsg() {
historyTimes++;
List<MessageEntity> msgList = imService.getMessageManager().loadHistoryMsg(historyTimes,currentSessionKey,peerEntity);
pushList(msgList);
scrollToBottomListItem();
}

在看pushList()函数:

public void pushList(List<MessageEntity> entityList) {
logger.d("chat#pushList list:%d", entityList.size());
adapter.loadHistoryList(entityList);
}

在reqHistoryMsg()中加入调试打印出相关信息。

private void reqHistoryMsg() {
historyTimes++;
List<MessageEntity> msgList = imService.getMessageManager().loadHistoryMsg(historyTimes,currentSessionKey,peerEntity);
Log.d("messageActivity","size "+msgList.size()+ " list "+msgList.toString()+"imservice"+imService.toString());
pushList(msgList); scrollToBottomListItem();
}
 
05-12 15:42:41.524: D/messageActivity(26765): 
 
 

tt程序分析(一)的更多相关文章

  1. APM程序分析-AC_WPNav.cpp

    APM程序分析 主程序在ArduCopter.cpp的loop()函数. /// advance_wp_target_along_track - move target location along ...

  2. 对Java数组中去除重复项程序分析

    我作为一个Java菜鸟,只会用简单的办法来处理这个问题.如果有大神看到,请略过,感激不尽! 所以首先先分析这道题目:数组中重复的数据进行删除,并且要让数组里的数据按原来的顺序排列,中间不能留空. 既然 ...

  3. (IOS)BaiduFM 程序分析

    本文主要分享下楼主在学习Swift编程过程中,对GitHub上的一个开源app BaiduFM的研究心得. 项目地址:https://github.com/belm/BaiduFM-Swift 一.项 ...

  4. Linux程序分析工具:ldd和nm

    ldd和nm是Linux下两个非常实用的程序分析工具.其中,ldd是用来分析程序运行时需要依赖的动态链接库的工具,nm是用来查看指定程序中的符号表信息的工具. 1 ldd 格式:ldd [option ...

  5. 二进制程序分析工具Pin在Windows系统中的安装和使用方法

    这篇日志其实很弱智,也是因为换了新电脑,实验环境不全(当然,做这个实验我是在虚拟机里,因为接下来想拿些恶意代码的数据),所以这里记录一下在Windows下怎么安装和使用Pin这个程序分析领域最常用的工 ...

  6. C#程序分析

    一.程序及问题 阅读下面程序,请回答如下问题: 问题1:这个程序要找的是符合什么条件的数? 问题2:这样的数存在么?符合这一条件的最小的数是什么? 问题3:在电脑上运行这一程序,你估计多长时间才能输出 ...

  7. linux程序分析工具

    ldd和nm是Linux下两个非常实用的程序分析工具.ldd是用来分析程序运行时需要依赖的动态链接库的工具,nm是用来查看指定程序中的符号表信息的工具,objdump用来查看源代码与汇编代码,-d只查 ...

  8. Codeforces 718A Efim and Strange Grade 程序分析

    Codeforces 718A Efim and Strange Grade 程序分析 jerry的程序 using namespace std; typedef long long ll; stri ...

  9. 代码实现:判断101-200之间有多少个素数(质数),并输出所有素数。 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。

    package com.loaderman.Coding; /* 判断101-200之间有多少个素数(质数),并输出所有素数. 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能 ...

随机推荐

  1. jsp:usebean 常用注意事项

    bean就是一个Java类,一般来说写这个类应该注意以下几点: 1.必须有包名,不要使用裸类 2.类的第一个名字小写 3.尽量不要使用公共成员变量,使用私有的,通过set.get方法来操作类中的变量 ...

  2. 关于C++ const

    1.Const用途 No. 用途 使用范围 参考代码 1 类型检查 参数传递 void func(const int i){ ... } 2 节省空间,避免不必要的内存分配 代替#define #de ...

  3. iOS 枚举写法

    1.第一种 typedef enum { kPRStateNormal = 0, kPRStatePulling = 1, kPRStateLoading = 2, kPRStateHitTheEnd ...

  4. 最近关于ACM训练与算法的总结

            到了大四以后越来越意识到基础知识的重要性,很多高屋建瓴的观点与想法都是建立在坚实的基础之上的, 招式只有在强劲的内力下才能发挥最大的作用,曾经有段时间我有这样的想法:我们出去以后和其他 ...

  5. Java Concurrent Topics

    To prevent Memory Consistency Errors(MCEs), it is good practice to specify synchronized class specif ...

  6. POJ3321/Apple tree/(DFS序+线段树)

    题目链接 Apple Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9692 Accepted: 3217 Descr ...

  7. Swift POP+MVVM

    Swift2.0中引入了协议扩展的特性,并且建议开发者一切从协议(Protocol)出发,经过几个月的学习探索,博主发现Swift作为一门面向协议编程(POP)的语言非常适合时下火热的MVVM架构.M ...

  8. bootstrap's plugin:sthe usage of carousel

    if we want use the carousel.js,we need quote it in the page. sample code: <div id="myCarouse ...

  9. html dom模型一

    DOM 节点 包含的节点内容: 根据 W3C 的 HTML DOM 标准,HTML 文档中的所有内容都是节点: 整个文档是一个文档节点 每个 HTML 元素是元素节点 HTML 元素内的文本是文本节点 ...

  10. 用cas来实现php的单点登陆

    最近项目中需要做单点登录,客户端包含Java.ruby和PHP,java有几个应用程序,php是discuz+supesite+ucenter,配置步骤如下: 1.cas服务端:下载地址:http:/ ...