Skip to content

Commit

Permalink
Merge pull request #196 from jpush/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
KenChoi1992 authored Dec 22, 2017
2 parents 2d88b6a + 9a52980 commit 678bf3b
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.widget.ProgressBar;
import android.widget.Toast;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -111,14 +112,17 @@ private boolean getPhotos() {
if (cursor.getCount() != 0) {
while (cursor.moveToNext()) {
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA));
String fileName =
cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME));
String size = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.SIZE));
String date = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATE_ADDED));

FileItem item = new FileItem(path, fileName, size, date);
item.setType(FileItem.Type.Image);
mMedias.add(item);
File file = new File(path);
if (file.exists()) {
String fileName =
cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DISPLAY_NAME));
String size = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.SIZE));
String date = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media.DATE_ADDED));

FileItem item = new FileItem(path, fileName, size, date);
item.setType(FileItem.Type.Image);
mMedias.add(item);
}
}
}
cursor.close();
Expand All @@ -140,13 +144,16 @@ private boolean getVideos() {
if (cursor.getCount() != 0) {
while (cursor.moveToNext()) {
String path = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA));
String name = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DISPLAY_NAME));
String date = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATE_ADDED));
long duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media.DURATION));

VideoItem item = new VideoItem(path, name, null, date, duration);
item.setType(FileItem.Type.Video);
mMedias.add(item);
File file = new File(path);
if (file.exists()) {
String name = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DISPLAY_NAME));
String date = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATE_ADDED));
long duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Video.Media.DURATION));

VideoItem item = new VideoItem(path, name, null, date, duration);
item.setType(FileItem.Type.Video);
mMedias.add(item);
}
}
}
cursor.close();
Expand Down
2 changes: 1 addition & 1 deletion Android/messagelist/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'com.android.library'
ext {
PUBLISH_GROUP_ID = 'cn.jiguang.imui'
PUBLISH_ARTIFACT_ID = 'messagelist'
PUBLISH_VERSION = '0.5.5'
PUBLISH_VERSION = '0.5.7'
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,15 @@ enum MessageType {
SEND_CUSTOM,
RECEIVE_CUSTOM;

private int type;

MessageType() {
}

public void setCustomType(int type) {
if (type > 12 || type < 0) {
this.type = type;
} else {
throw new IllegalArgumentException("Custom message type should not set 0-12");
}
}

public int getCustomType() {
return this.type;
}
}

/**
* Type of message, enum.
* @return Message Type
* Type of message
* @return integer
*/
MessageType getType();
int getType();

/**
* Status of message, enum.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import android.media.MediaPlayer;
import android.view.View;

import java.util.List;

import cn.jiguang.imui.commons.ImageLoader;
import cn.jiguang.imui.commons.ViewHolder;
import cn.jiguang.imui.commons.models.IMessage;
Expand All @@ -24,16 +26,9 @@ public abstract class BaseMessageViewHolder<MESSAGE extends IMessage>
protected MsgListAdapter.OnMsgStatusViewClickListener<MESSAGE> mMsgStatusViewClickListener;
protected MediaPlayer mMediaPlayer;
protected boolean mScroll;
protected List<MsgListAdapter.Wrapper> mData;

public BaseMessageViewHolder(View itemView) {
super(itemView);
}

public boolean isSelected() {
return mIsSelected;
}

public ImageLoader getImageLoader() {
return mImageLoader;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
Expand Down Expand Up @@ -178,31 +179,30 @@ public int getItemViewType(int position) {
Wrapper wrapper = mItems.get(position);
if (wrapper.item instanceof IMessage) {
IMessage message = (IMessage) wrapper.item;
switch (message.getType()) {
case SEND_TEXT:
return TYPE_SEND_TXT;
case RECEIVE_TEXT:
return TYPE_RECEIVE_TXT;
case SEND_LOCATION:
return TYPE_SEND_LOCATION;
case RECEIVE_LOCATION:
return TYPE_RECEIVER_LOCATION;
case SEND_VOICE:
return TYPE_SEND_VOICE;
case RECEIVE_VOICE:
return TYPE_RECEIVER_VOICE;
case SEND_IMAGE:
return TYPE_SEND_IMAGE;
case RECEIVE_IMAGE:
return TYPE_RECEIVER_IMAGE;
case SEND_VIDEO:
return TYPE_SEND_VIDEO;
case RECEIVE_VIDEO:
return TYPE_RECEIVE_VIDEO;
case EVENT:
return TYPE_EVENT;
default:
return getCustomType(message);
if (message.getType() == IMessage.MessageType.EVENT.ordinal()) {
return TYPE_EVENT;
} else if (message.getType() == IMessage.MessageType.SEND_TEXT.ordinal()) {
return TYPE_SEND_TXT;
} else if (message.getType() == IMessage.MessageType.RECEIVE_TEXT.ordinal()) {
return TYPE_RECEIVE_TXT;
} else if (message.getType() == IMessage.MessageType.SEND_IMAGE.ordinal()) {
return TYPE_SEND_IMAGE;
} else if (message.getType() == IMessage.MessageType.RECEIVE_IMAGE.ordinal()) {
return TYPE_RECEIVER_IMAGE;
} else if (message.getType() == IMessage.MessageType.SEND_VOICE.ordinal()) {
return TYPE_SEND_VOICE;
} else if (message.getType() == IMessage.MessageType.RECEIVE_VOICE.ordinal()) {
return TYPE_RECEIVER_VOICE;
} else if (message.getType() == IMessage.MessageType.SEND_VIDEO.ordinal()) {
return TYPE_SEND_VIDEO;
} else if (message.getType() == IMessage.MessageType.RECEIVE_VIDEO.ordinal()) {
return TYPE_RECEIVE_VIDEO;
} else if (message.getType() == IMessage.MessageType.SEND_LOCATION.ordinal()) {
return TYPE_SEND_LOCATION;
} else if (message.getType() == IMessage.MessageType.RECEIVE_LOCATION.ordinal()) {
return TYPE_RECEIVER_LOCATION;
} else {
return getCustomType(message);
}
}
return TYPE_SEND_TXT;
Expand All @@ -211,10 +211,12 @@ public int getItemViewType(int position) {
private int getCustomType(IMessage message) {
for (int i=0; i < mCustomMsgList.size(); i++) {
CustomMsgConfig config = mCustomMsgList.valueAt(i);
if (message.getType().getCustomType() == config.getViewType()) {
if (message.getType() == config.getViewType()) {
return config.getViewType();
}
}
Log.d("MsgListAdapter", "Can not find custom type, maybe you are forget to call " +
"setType() in your <? extends IMessage> class");
return TYPE_SEND_TXT;
}

Expand Down Expand Up @@ -252,6 +254,7 @@ public void onBindViewHolder(ViewHolder holder, int position) {
((BaseMessageViewHolder) holder).mMsgStatusViewClickListener = this.mMsgStatusViewClickListener;
((BaseMessageViewHolder) holder).mMediaPlayer = this.mMediaPlayer;
((BaseMessageViewHolder) holder).mScroll = this.mScroll;
((BaseMessageViewHolder) holder).mData = this.mItems;
}
holder.onBind(wrapper.item);
}
Expand All @@ -261,13 +264,29 @@ public int getItemCount() {
return mItems.size();
}

private class Wrapper<DATA> {
public class Wrapper<DATA> {
private DATA item;
boolean isSelected;

Wrapper(DATA item) {
this.item = item;
}

public DATA getItem() {
return this.item;
}

public boolean getIsSelected() {
return this.isSelected;
}

public void setItem(DATA item) {
this.item = item;
}

public void setSelected(boolean isSelected) {
this.isSelected = isSelected;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,14 @@ public void applyStyle(MessageListStyle style) {
}
if (style.getShowSenderDisplayName() == 1) {
mDisplayNameTv.setVisibility(View.VISIBLE);
} else {
mDisplayNameTv.setVisibility(View.GONE);
}
} else {
if (style.getShowReceiverDisplayName() == 1) {
mDisplayNameTv.setVisibility(View.VISIBLE);
} else {
mDisplayNameTv.setVisibility(View.GONE);
}
mPhotoIv.setBackground(style.getReceivePhotoMsgBg());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public boolean onSendTextMessage(CharSequence input) {
if (input.length() == 0) {
return false;
}
MyMessage message = new MyMessage(input.toString(), IMessage.MessageType.SEND_TEXT);
MyMessage message = new MyMessage(input.toString(), IMessage.MessageType.SEND_TEXT.ordinal());
message.setUserInfo(new DefaultUser("1", "Ironman", "R.drawable.ironman"));
message.setTimeString(new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date()));
mAdapter.addToStart(message, true);
Expand All @@ -120,10 +120,10 @@ public void onSendFiles(List<FileItem> list) {
MyMessage message;
for (FileItem item : list) {
if (item.getType() == FileItem.Type.Image) {
message = new MyMessage(null, IMessage.MessageType.SEND_IMAGE);
message = new MyMessage(null, IMessage.MessageType.SEND_IMAGE.ordinal());

} else if (item.getType() == FileItem.Type.Video) {
message = new MyMessage(null, IMessage.MessageType.SEND_VIDEO);
message = new MyMessage(null, IMessage.MessageType.SEND_VIDEO.ordinal());
message.setDuration(((VideoItem) item).getDuration());

} else {
Expand Down Expand Up @@ -219,7 +219,7 @@ public void onStartRecord() {

@Override
public void onFinishRecord(File voiceFile, int duration) {
MyMessage message = new MyMessage(null, IMessage.MessageType.SEND_VOICE);
MyMessage message = new MyMessage(null, IMessage.MessageType.SEND_VOICE.ordinal());
message.setUserInfo(new DefaultUser("1", "Ironman", "R.drawable.ironman"));
message.setMediaFilePath(voiceFile.getPath());
message.setDuration(duration);
Expand All @@ -236,7 +236,7 @@ public void onCancelRecord() {
mChatView.setOnCameraCallbackListener(new OnCameraCallbackListener() {
@Override
public void onTakePictureCompleted(String photoPath) {
final MyMessage message = new MyMessage(null, IMessage.MessageType.SEND_IMAGE);
final MyMessage message = new MyMessage(null, IMessage.MessageType.SEND_IMAGE.ordinal());
message.setTimeString(new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date()));
message.setMediaFilePath(photoPath);
message.setUserInfo(new DefaultUser("1", "Ironman", "R.drawable.ironman"));
Expand Down Expand Up @@ -379,10 +379,10 @@ private List<MyMessage> getMessages() {
for (int i = 0; i < messages.length; i++) {
MyMessage message;
if (i % 2 == 0) {
message = new MyMessage(messages[i], IMessage.MessageType.RECEIVE_TEXT);
message = new MyMessage(messages[i], IMessage.MessageType.RECEIVE_TEXT.ordinal());
message.setUserInfo(new DefaultUser("0", "DeadPool", "R.drawable.deadpool"));
} else {
message = new MyMessage(messages[i], IMessage.MessageType.SEND_TEXT);
message = new MyMessage(messages[i], IMessage.MessageType.SEND_TEXT.ordinal());
message.setUserInfo(new DefaultUser("1", "IronMan", "R.drawable.ironman"));
}
message.setTimeString(new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date()));
Expand Down Expand Up @@ -435,8 +435,8 @@ public void loadImage(ImageView imageView, String string) {
@Override
public void onMessageClick(MyMessage message) {
// do something
if (message.getType() == IMessage.MessageType.RECEIVE_VIDEO
|| message.getType() == IMessage.MessageType.SEND_VIDEO) {
if (message.getType() == IMessage.MessageType.RECEIVE_VIDEO.ordinal()
|| message.getType() == IMessage.MessageType.SEND_VIDEO.ordinal()) {
if (!TextUtils.isEmpty(message.getMediaFilePath())) {
Intent intent = new Intent(MessageListActivity.this, VideoActivity.class);
intent.putExtra(VideoActivity.VIDEO_PATH, message.getMediaFilePath());
Expand Down Expand Up @@ -478,10 +478,10 @@ public void onStatusViewClick(MyMessage message) {
}
});

MyMessage message = new MyMessage("Hello World", IMessage.MessageType.RECEIVE_TEXT);
MyMessage message = new MyMessage("Hello World", IMessage.MessageType.RECEIVE_TEXT.ordinal());
message.setUserInfo(new DefaultUser("0", "Deadpool", "R.drawable.deadpool"));
mAdapter.addToStart(message, true);
MyMessage eventMsg = new MyMessage("haha", IMessage.MessageType.EVENT);
MyMessage eventMsg = new MyMessage("haha", IMessage.MessageType.EVENT.ordinal());
mAdapter.addToStart(eventMsg, true);
mAdapter.addToEnd(mData);
PullToRefreshLayout layout = mChatView.getPtrLayout();
Expand Down Expand Up @@ -515,10 +515,10 @@ public void run() {
for (int i = 0; i < messages.length; i++) {
MyMessage message;
if (i % 2 == 0) {
message = new MyMessage(messages[i], IMessage.MessageType.RECEIVE_TEXT);
message = new MyMessage(messages[i], IMessage.MessageType.RECEIVE_TEXT.ordinal());
message.setUserInfo(new DefaultUser("0", "DeadPool", "R.drawable.deadpool"));
} else {
message = new MyMessage(messages[i], IMessage.MessageType.SEND_TEXT);
message = new MyMessage(messages[i], IMessage.MessageType.SEND_TEXT.ordinal());
message.setUserInfo(new DefaultUser("1", "IronMan", "R.drawable.ironman"));
}
message.setTimeString(new SimpleDateFormat("HH:mm", Locale.getDefault()).format(new Date()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public class MyMessage implements IMessage {
private long id;
private String text;
private String timeString;
private MessageType type;
private int type;
private IUser user;
private String mediaFilePath;
private long duration;
private String progress;

public MyMessage(String text, MessageType type) {
public MyMessage(String text, int type) {
this.text = text;
this.type = type;
this.id = UUID.randomUUID().getLeastSignificantBits();
Expand Down Expand Up @@ -78,11 +78,14 @@ public String getTimeString() {
}

public void setType(int type) {
this.type.setCustomType(type);
if (type >= 0 && type <= 12) {
throw new IllegalArgumentException("Message type should not take the value between 0 and 12");
}
this.type = type;
}

@Override
public MessageType getType() {
public int getType() {
return type;
}

Expand Down
Loading

0 comments on commit 678bf3b

Please sign in to comment.