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(这个数),如果能 ...
随机推荐
- 不注册COM组件直接调用接口
本文以COM组件AppTest.dll为例,AppTest.dll中提供了ITest接口,在不使用regsvr32命令向系统注册的情况下创建ITest接口并调用. 一.导入组件或类型库: 在C++中使 ...
- 直接用request.setAttribute()会报错,在这之前应该先让request获取ServletActionContext.getRequest();方法 // request.getAttribute同理
正确流程应该是 import javax.servlet.http.HttpServletRequest; HttpServletRequst request = ServletActionConte ...
- php+redis实现电商秒杀功能
这一次总结和分享用Redis实现分布式锁来完成电商的秒杀功能.先扯点个人观点,之前我看了一篇博文说博客园的文章大部分都是分享代码,博文里强调说分享思路比分享代码更重要(貌似大概是这个意思,若有误请谅解 ...
- php 四种基础算法 ---- 插入排序法
3.插入排序法 插入排序法思路:将要排序的元素插入到已经 假定排序号的数组的指定位置. 代码: function insert_sort($arr) { //区分 哪部分是已经排序好的 / ...
- Webdriver中实现区域截图的方式以及如何截取frame中的图片
import java.awt.Rectangle;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOE ...
- POJ 1470 Closest Common Ancestors(LCA 最近公共祖先)
其实这是一个裸求LCA的题目,我使用的是离线的Tarjan算法,但是这个题的AC对于我来说却很坎坷……首先是RE,我立马想到数组开小了,然后扩大了数组,MLE了……接着把数组调整适当大小,又交了一发, ...
- PAT (Advanced Level) 1114. Family Property (25)
简单DFS. #include<cstdio> #include<cstring> #include<cmath> #include<vector> # ...
- PAT (Advanced Level) 1110. Complete Binary Tree (25)
判断一棵二叉树是否完全二叉树. #include<cstdio> #include<cstring> #include<cmath> #include<vec ...
- listview设置条目点击的时候不变色(让状态选择器不起作用)
未设置前的效果如下图: 很明显,“酷狗音乐”那个条目被点击的时候,条目背景变为蓝色,怎么去掉这个颜色呢? java代码可以这么写: listView.setSelector(new ColorDraw ...
- Android media媒体库分析之:MediaProvider
在做Android媒体应用程序时(Audio.Image.Video)需要对Android的媒体提供者(MediaProvider)做详细的分析,下面记录一下我的收获: 一.获取MediaProvid ...