首先是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. Update Case的用法与execute执行字符串

    摘自于网路:http://www.cnblogs.com/joinger/articles/1297160.html update h_crm_SafetyAccessUser set         ...

  2. Notification使用笔记

    之前在项目中使用了Notification,现分享出来: checkNotification() function checkNotification(){ //判断是否支持Notification ...

  3. sqlserver内存释放

    由于Sql Server对于系统内存的管理策略是有多少占多少,除非系统内存不够用了(大约到剩余内存为4M左右),  Sql Server才会释放一点点内存.所以很多时候,我们会发现运行Sql Serv ...

  4. PHP生成静态页面详解

    PHP生成静态页面详解 看到很多朋友在各个地方发帖问PHP生成静态文章系统的方法,以前曾做过这样一个系统,遂谈些看法,以供各位参考.好了,我们先回顾一些基本的概念. 一,PHP脚本与动态页面. PHP ...

  5. mapreduce 顺序组合

    import java.io.IOException;import java.util.StringTokenizer; import org.apache.hadoop.conf.Configura ...

  6. 2016中国大学生程序设计竞赛 - 网络选拔赛 1011 Lweb and String

    Problem Description Lweb has a string S. Oneday, he decided to transform this string to a new sequen ...

  7. IIS Express允许外部访问(外部调试)

    Visual Studio配合IIS Express为Web开发提供了强劲的调试功能,本文介绍IIS Express如何在调试模式下让局域网的其他设备进行访问,以便进行测试. 1.打开IIS Expr ...

  8. Android如何使用API

    转自:http://www.cnblogs.com/vanezkw/archive/2012/07/03/2574559.html 本文针对Android开发如何使用API文档进行一些经验分享. 1. ...

  9. java工程开发之图形化界面之(第二课)

    上一节主要是讨论小的应用程序,在这里我们将采用一种全新的方式来重新编写它. 在这里我们注重关注JFrame和JOptionPane.这些类提供了在JAVA应用程序使用图形的方法以及在JAVA程序中对I ...

  10. kick_ball

    package com.hereyouare.KickBall; import android.app.Activity; import android.app.AlertDialog; import ...