同步操作将从 JPush/aurora-imui 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
MessageList is a message list in chatting interface, use to display all kinds of messages, and it can be fully customize. If you don't define your style, MessageList will use default style.
We have support several ways to add dependency. You can choose one of them.
compile 'cn.jiguang.imui:imui:0.1.0'
<dependency>
<groupId>cn.jiguang.imui</groupId>
<artifactId>imui</artifactId>
<version>0.1.0</version>
<type>pom</type>
</dependency>
// Add in project's build.gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
// Add in module's build.gradle
dependencies {
compile 'com.github.jpush:imui:0.1.0'
}
To use MessageList only need three simple steps, or you can check out our sample project to try it yourself.
<cn.jiguang.imui.messages.MessageList
android:id="@+id/msg_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:avatarHeight="50dp"
app:avatarWidth="50dp"
app:bubbleMaxWidth="0.70"
app:dateTextSize="14sp"
app:receiveBubblePaddingLeft="20dp"
app:receiveBubblePaddingRight="10dp"
app:receiveTextColor="#ffffff"
app:receiveTextSize="18sp"
app:sendBubblePaddingLeft="10dp"
app:sendBubblePaddingRight="20dp"
app:sendTextColor="#7587A8"
app:sendTextSize="18sp" />
We have define many kinds of attributes, to support user to adjust their layout, you can see attrs.xml in detail, and we support totally customize style either, please look down.
Adapter's constructor has three parameters. The first one is sender id
, the id of sender, the second one is HoldersConfig object
,
you can use this object to construct your custom ViewHolder and layout, the third one is implement of ImageLoader
,
use to display user's avatar, if this value is null, will not display avatar.(Click here to know more about ImageLoader)
MsgListAdapter adapter = new MsgListAdapter<MyMessage>("0", holdersConfig, imageLoader);
messageList.setAdapter(adapter);
To be add messages, you need to implement IMessage, IUser interface into your existing model and override it's methods:
public class MyMessage implements IMessage {
private long id;
private String text;
private String timeString;
private MessageType type;
private IUser user;
private String contentFile;
private long duration;
public MyMessage(String text, MessageType type) {
this.text = text;
this.type = type;
this.id = UUID.randomUUID().getLeastSignificantBits();
}
@Override
public String getMsgId() {
return String.valueOf(id);
}
@Override
public IUser getFromUser() {
if (user == null) {
return new DefaultUser("0", "user1", null);
}
return user;
}
public void setUserInfo(IUser user) {
this.user = user;
}
public void setMediaFilePath(String path) {
this.contentFile = path;
}
public void setDuration(long duration) {
this.duration = duration;
}
@Override
public long getDuration() {
return duration;
}
public void setTimeString(String timeString) {
this.timeString = timeString;
}
@Override
public String getTimeString() {
return timeString;
}
@Override
public MessageType getType() {
return type;
}
@Override
public String getText() {
return text;
}
@Override
public String getMediaFilePath() {
return contentFile;
}
}
MessageType above is an enum class in IMessage class, you need implement IUser interface, too:
public class DefaultUser implements IUser {
private String id;
private String displayName;
private String avatar;
public DefaultUser(String id, String displayName, String avatar) {
this.id = id;
this.displayName = displayName;
this.avatar = avatar;
}
@Override
public String getId() {
return id;
}
@Override
public String getDisplayName() {
return displayName;
}
@Override
public String getAvatarFilePath() {
return avatar;
}
}
That's all! Now you can use your own message model to fill into adapter without type converting of any kind!
To add new message in message list is pretty easy, we support two ways to add new messages:
addToStart(IMESSAGE message, boolean scroll)
// add a new message in the bottom of message list, the second parameter implys whether to scroll to bottom.
adapter.addToStart(message, true);
addToEnd(List<IMessage> messages)
// Add messages to the top of message list
adapter.addToEnd(messages);
OnLoadMoreListener
,when scroll to top will fire onLoadMore
event,for example:mAdapter.setOnLoadMoreListener(new MsgListAdapter.OnLoadMoreListener() {
@Override
public void onLoadMore(int page, int totalCount) {
if (totalCount < mData.size()) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mAdapter.addToEnd(mData);
}
}, 1000);
}
}
});
Here are methods to delete message:
If message updated, you can invoke these methods to notify adapter to update message:
OnMsgClickListener
Fires when click messagemAdapter.setOnMsgClickListener(new MsgListAdapter.OnMsgClickListener<MyMessage>() {
@Override
public void onMessageClick(MyMessage message) {
// do something
}
});
OnAvatarClickListener
Fires when click avatarmAdapter.setOnAvatarClickListener(new MsgListAdapter.OnAvatarClickListener<MyMessage>() {
@Override
public void onAvatarClick(MyMessage message) {
DefaultUser userInfo = (DefaultUser) message.getUserInfo();
// Do something
}
});
OnMsgLongClickListener
Fires when long click messagemAdapter.setMsgLongClickListener(new MsgListAdapter.OnMsgLongClickListener<MyMessage>() {
@Override
public void onMessageLongClick(MyMessage message) {
// do something
}
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。