diff --git a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/photo/SelectPhotoView.java b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/photo/SelectPhotoView.java index 1366224e..bd1caac1 100644 --- a/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/photo/SelectPhotoView.java +++ b/Android/chatinput/src/main/java/cn/jiguang/imui/chatinput/photo/SelectPhotoView.java @@ -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; @@ -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(); @@ -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(); diff --git a/Android/messagelist/build.gradle b/Android/messagelist/build.gradle index 5df0168f..13f1cead 100644 --- a/Android/messagelist/build.gradle +++ b/Android/messagelist/build.gradle @@ -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 { diff --git a/Android/messagelist/src/main/java/cn/jiguang/imui/commons/models/IMessage.java b/Android/messagelist/src/main/java/cn/jiguang/imui/commons/models/IMessage.java index 671ff7aa..a03ac129 100644 --- a/Android/messagelist/src/main/java/cn/jiguang/imui/commons/models/IMessage.java +++ b/Android/messagelist/src/main/java/cn/jiguang/imui/commons/models/IMessage.java @@ -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. diff --git a/Android/messagelist/src/main/java/cn/jiguang/imui/messages/BaseMessageViewHolder.java b/Android/messagelist/src/main/java/cn/jiguang/imui/messages/BaseMessageViewHolder.java index ba65f069..02e07b4e 100644 --- a/Android/messagelist/src/main/java/cn/jiguang/imui/messages/BaseMessageViewHolder.java +++ b/Android/messagelist/src/main/java/cn/jiguang/imui/messages/BaseMessageViewHolder.java @@ -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; @@ -24,16 +26,9 @@ public abstract class BaseMessageViewHolder protected MsgListAdapter.OnMsgStatusViewClickListener mMsgStatusViewClickListener; protected MediaPlayer mMediaPlayer; protected boolean mScroll; + protected List mData; public BaseMessageViewHolder(View itemView) { super(itemView); } - - public boolean isSelected() { - return mIsSelected; - } - - public ImageLoader getImageLoader() { - return mImageLoader; - } } \ No newline at end of file diff --git a/Android/messagelist/src/main/java/cn/jiguang/imui/messages/MsgListAdapter.java b/Android/messagelist/src/main/java/cn/jiguang/imui/messages/MsgListAdapter.java index fb5f400e..3ae336a7 100644 --- a/Android/messagelist/src/main/java/cn/jiguang/imui/messages/MsgListAdapter.java +++ b/Android/messagelist/src/main/java/cn/jiguang/imui/messages/MsgListAdapter.java @@ -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; @@ -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; @@ -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 class"); return TYPE_SEND_TXT; } @@ -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); } @@ -261,13 +264,29 @@ public int getItemCount() { return mItems.size(); } - private class Wrapper { + public class Wrapper { 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; + } } /** diff --git a/Android/messagelist/src/main/java/cn/jiguang/imui/messages/PhotoViewHolder.java b/Android/messagelist/src/main/java/cn/jiguang/imui/messages/PhotoViewHolder.java index 517d51db..654591e8 100644 --- a/Android/messagelist/src/main/java/cn/jiguang/imui/messages/PhotoViewHolder.java +++ b/Android/messagelist/src/main/java/cn/jiguang/imui/messages/PhotoViewHolder.java @@ -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()); } diff --git a/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/messages/MessageListActivity.java b/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/messages/MessageListActivity.java index 9bd6f2f0..497a3fd3 100644 --- a/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/messages/MessageListActivity.java +++ b/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/messages/MessageListActivity.java @@ -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); @@ -120,10 +120,10 @@ public void onSendFiles(List 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 { @@ -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); @@ -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")); @@ -379,10 +379,10 @@ private List 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())); @@ -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()); @@ -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(); @@ -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())); diff --git a/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/models/MyMessage.java b/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/models/MyMessage.java index 6507c6c8..71abd93e 100644 --- a/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/models/MyMessage.java +++ b/Android/sample/exampleui/src/main/java/imui/jiguang/cn/imuisample/models/MyMessage.java @@ -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(); @@ -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; } diff --git a/docs/Android/custom_layout.md b/docs/Android/custom_layout.md index 411bc24a..add1049f 100644 --- a/docs/Android/custom_layout.md +++ b/docs/Android/custom_layout.md @@ -85,7 +85,7 @@ public class TxtViewHolder ```java MsgListAdapter adapter = new MsgListAdapter<>("0", holdersConfig, imageLoader); -// The first parameter is ViewType,must not set number in 0-12 +// The first parameter is ViewType,must not set number between 0 // and 12, because we are already taken. // the second is resource id // the third is sender or not // the forth is the Class object of custom view holder. @@ -98,11 +98,16 @@ adapter.addCustomMsgType(13, config1); ```java public class MyMessage implements IMessage { - MessageType type = MessageType.SEND_TEXT; + private int type; // in this example the viewType is 13 public void setType(int viewType) { - this.type.setCustomType(viewType); + this.type = viewType; } + + @Override + public int getType() { + return this.type; + } } ``` diff --git a/docs/Android/custom_layout_zh.md b/docs/Android/custom_layout_zh.md index 57b716e7..a01054ac 100644 --- a/docs/Android/custom_layout_zh.md +++ b/docs/Android/custom_layout_zh.md @@ -92,11 +92,16 @@ adapter.addCustomMsgType(13, config1); ```java public class MyMessage implements IMessage { - MessageType type = MessageType.SEND_TEXT; - // 本例中 viewType 值为 13 + private int type; + // 本例中 viewType 为 13 public void setType(int viewType) { - this.type.setCustomType(viewType); + this.type = viewType; } + + @Override + public int getType() { + return this.type; + } } ``` diff --git a/docs/Android/message_list_usage.md b/docs/Android/message_list_usage.md index 906871fb..1ee68708 100644 --- a/docs/Android/message_list_usage.md +++ b/docs/Android/message_list_usage.md @@ -10,7 +10,7 @@ We have support several ways to add dependency. You can choose one of them. - Gradle: ```groovy -compile 'cn.jiguang.imui:messagelist:0.5.5' +compile 'cn.jiguang.imui:messagelist:0.5.7' ``` - Maven: @@ -18,12 +18,12 @@ compile 'cn.jiguang.imui:messagelist:0.5.5' cn.jiguang.imui messagelist - 0.5.5 + 0.5.7 pom ``` -- JitPack +- JitPack(^0.4.8 must add JitPack dependency.) ```groovy // Add in project's build.gradle allprojects { @@ -35,7 +35,7 @@ allprojects { // Add in module's build.gradle dependencies { - compile 'com.github.jpush:imui:0.6.1' + compile 'com.github.jpush:imui:0.6.5' } ``` diff --git a/docs/Android/message_list_usage_zh.md b/docs/Android/message_list_usage_zh.md index 4a22b236..dc943b22 100644 --- a/docs/Android/message_list_usage_zh.md +++ b/docs/Android/message_list_usage_zh.md @@ -9,7 +9,7 @@ - Gradle ```groovy -compile 'cn.jiguang.imui:messagelist:0.5.5' +compile 'cn.jiguang.imui:messagelist:0.5.7' ``` - Maven @@ -17,12 +17,12 @@ compile 'cn.jiguang.imui:messagelist:0.5.5' cn.jiguang.imui messagelist - 0.5.5 + 0.5.7 pom ``` -- JitPack +- JitPack(由于 0.4.8 引入了 AndroidEmoji,所以 0.4.8 以上版本需要添加 jitpack 依赖 ) ```groovy // project/build.gradle allprojects { @@ -34,7 +34,7 @@ allprojects { // module/build.gradle dependencies { - compile 'com.github.jpush:imui:0.6.1' + compile 'com.github.jpush:imui:0.6.5' } ```