tt程序分析(一)
// 这个地方跳转一定要快
@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()函数。
// 跳转到聊天页面
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();
}
并且,程序能够正常显示发送内容。
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);
}
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();
}
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();
}
tt程序分析(一)的更多相关文章
- APM程序分析-AC_WPNav.cpp
		
APM程序分析 主程序在ArduCopter.cpp的loop()函数. /// advance_wp_target_along_track - move target location along ...
 - 对Java数组中去除重复项程序分析
		
我作为一个Java菜鸟,只会用简单的办法来处理这个问题.如果有大神看到,请略过,感激不尽! 所以首先先分析这道题目:数组中重复的数据进行删除,并且要让数组里的数据按原来的顺序排列,中间不能留空. 既然 ...
 - (IOS)BaiduFM 程序分析
		
本文主要分享下楼主在学习Swift编程过程中,对GitHub上的一个开源app BaiduFM的研究心得. 项目地址:https://github.com/belm/BaiduFM-Swift 一.项 ...
 - Linux程序分析工具:ldd和nm
		
ldd和nm是Linux下两个非常实用的程序分析工具.其中,ldd是用来分析程序运行时需要依赖的动态链接库的工具,nm是用来查看指定程序中的符号表信息的工具. 1 ldd 格式:ldd [option ...
 - 二进制程序分析工具Pin在Windows系统中的安装和使用方法
		
这篇日志其实很弱智,也是因为换了新电脑,实验环境不全(当然,做这个实验我是在虚拟机里,因为接下来想拿些恶意代码的数据),所以这里记录一下在Windows下怎么安装和使用Pin这个程序分析领域最常用的工 ...
 - C#程序分析
		
一.程序及问题 阅读下面程序,请回答如下问题: 问题1:这个程序要找的是符合什么条件的数? 问题2:这样的数存在么?符合这一条件的最小的数是什么? 问题3:在电脑上运行这一程序,你估计多长时间才能输出 ...
 - linux程序分析工具
		
ldd和nm是Linux下两个非常实用的程序分析工具.ldd是用来分析程序运行时需要依赖的动态链接库的工具,nm是用来查看指定程序中的符号表信息的工具,objdump用来查看源代码与汇编代码,-d只查 ...
 - Codeforces 718A Efim and Strange Grade 程序分析
		
Codeforces 718A Efim and Strange Grade 程序分析 jerry的程序 using namespace std; typedef long long ll; stri ...
 - 代码实现:判断101-200之间有多少个素数(质数),并输出所有素数。  程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除,则表明此数不是素数,反之是素数。
		
package com.loaderman.Coding; /* 判断101-200之间有多少个素数(质数),并输出所有素数. 程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能 ...
 
随机推荐
- idea编译报错:未结束的字符串文字;非法的表达式;未结束的字符串字面值
			
在idea的Settings中,找到File Encodings,将IDE Encoding 改为UTF-8 要多试几次,清除缓存什么的,具体原因不知道,不过经常第一次修改不能成功.
 - Android实现GIF图片解码与播放
			
Android实现GIF图片解码与播放 如何在Android中播放GIF图片呢?如果直接按以前的方法,分解图片,可能相对比较麻烦. 今天给大伙介绍一种新的方式,构造自己的Android图片解码帮助类, ...
 - linux系统定时重启tomcat
			
#touch auto-start.sh [root@Linux opt]# echo $LANGen_US.UTF-8 #vim auto-start.sh #!/bin/sh export LAN ...
 - java面向对象_接口
			
java接口 interface,是一个抽象类型,是抽象方法的集合,接口通常以interface来声明.一个类通过继承接口的方式,从而来继承接口的抽象方法. 接口并不是类,编写接口的方式和类很相似,但 ...
 - 篇一:eclipse创建maven工程
			
一.概览 maven创建的项目主要分为三类:war(网页工程).jar(Java工程).pom(父工程); war:网页工程,包含webapp,用于view层 jar:Java工程,用于提供方法.se ...
 - 利用未文档化API:RtlGetNtVersionNumbers 获取系统版本号
			
问题一:Windows SDK 8.1版本中的VersionHelper.h文件当中没有IsWindows10ORGreater,所以当你用IsWindows8Point1ORGreater判断出版本 ...
 - hdu_5711_Ingress(TSP+贪心)
			
题目连接:hdu5711 这题是 HDU 女生赛最后一题,TSP+贪心,确实不好想,看了wkc巨巨的题解,然后再做的 题解传送门:Ingress #include<cstdio> #inc ...
 - Django: 之数据库完美解析
			
Python的web矿建有Django.Tornado.Flask等多种,Django相较与其他WEB框架其优势为:大而全,框架本身集成了ORM.模型绑定,模版引擎.缓存.Session等诸多功能. ...
 - MapReduce常见算法
			
1.单词计数 2.数据去重 3.排序 4.Top K(求数据中的最大值) 5.选择 6.投影 7.分组 8.多表连接 9.单表关联
 - 第15章 I/O(输入/输出)
			
在变量.数组和对象中存储的数据是暂时存在的,程序结束后它们就会丢失.为了能够永久地保存创建的数据,需要将其保存在磁盘文件中,这样就可以在其它程序中使用它们.Java的I/O技术可以将数据保存到文本文件 ...