Skip to content

Commit

Permalink
Merge pull request #74 from jpush/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
KenChoi1992 committed Jul 10, 2017
2 parents 2b866cc + 698c1a7 commit 74dc146
Show file tree
Hide file tree
Showing 19 changed files with 200 additions and 35 deletions.
6 changes: 3 additions & 3 deletions Android/chatinput/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

- Gradle
```groovy
compile 'cn.jiguang.imui:chatinput:0.2.0'
compile 'cn.jiguang.imui:chatinput:0.4.3'
```

- Maven
```
<dependency>
<groupId>cn.jiguang.imui</groupId>
<artifactId>chatinput</artifactId>
<version>0.2.0</version>
<version>0.4.3</version>
<type>pom</type>
</dependency>
```
Expand All @@ -42,7 +42,7 @@ compile 'cn.jiguang.imui:chatinput:0.2.0'
```groovy
dependencies {
compile 'com.github.jpush:imui:0.2.0'
compile 'com.github.jpush:imui:0.4.3'
}
```

Expand Down
6 changes: 3 additions & 3 deletions Android/chatinput/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Provides several ways to add dependency, you can choose one of them:

- Via Gradle
```groovy
compile 'cn.jiguang.imui:chatinput:0.2.0'
compile 'cn.jiguang.imui:chatinput:0.4.3'
```

- Via Maven
Expand All @@ -20,7 +20,7 @@ compile 'cn.jiguang.imui:chatinput:0.2.0'
<dependency>
<groupId>cn.jiguang.imui</groupId>
<artifactId>chatinput</artifactId>
<version>0.2.0</version>
<version>0.4.3</version>
<type>pom</type>
</dependency>
```
Expand All @@ -41,7 +41,7 @@ allprojects {
```groovy
dependencies {
compile 'com.github.jpush:imui:0.2.0'
compile 'com.github.jpush:imui:0.4.3'
}
```

Expand Down
2 changes: 1 addition & 1 deletion Android/chatinput/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 = 'chatinput'
PUBLISH_VERSION = '0.3.4-beta'
PUBLISH_VERSION = '0.4.3'
}

android {
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.4.2'
PUBLISH_VERSION = '0.4.3'
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public abstract class BaseMessageViewHolder<MESSAGE extends IMessage>
protected MsgListAdapter.OnAvatarClickListener<MESSAGE> mAvatarClickListener;
protected MsgListAdapter.OnMsgResendListener<MESSAGE> mMsgResendListener;
protected MediaPlayer mMediaPlayer;
protected boolean mScroll;

public BaseMessageViewHolder(View itemView) {
super(itemView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,32 @@
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SimpleItemAnimator;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;

import cn.jiguang.imui.commons.models.IMessage;


public class MessageList extends RecyclerView {
public class MessageList extends RecyclerView implements GestureDetector.OnGestureListener {

private Context mContext;

private MessageListStyle mMsgListStyle;
private final GestureDetector mGestureDetector;
private MsgListAdapter mAdapter;

public MessageList(Context context) {
super(context);
this(context, null);
}

public MessageList(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
parseStyle(context, attrs);
this(context, attrs, 0);
}

public MessageList(Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
parseStyle(context, attrs);
mGestureDetector = new GestureDetector(context, this);
}

@SuppressWarnings("ResourceType")
Expand All @@ -44,6 +48,7 @@ private void parseStyle(Context context, AttributeSet attrs) {
* @param <MESSAGE> Message model extends IMessage.
*/
public <MESSAGE extends IMessage> void setAdapter(MsgListAdapter<MESSAGE> adapter) {
mAdapter = adapter;
SimpleItemAnimator itemAnimator = new DefaultItemAnimator();
itemAnimator.setSupportsChangeAnimations(false);
setItemAnimator(itemAnimator);
Expand Down Expand Up @@ -196,4 +201,37 @@ public void setSendingIndeterminateDrawable(String drawableName, String packageN
int resId = getResources().getIdentifier(drawableName, "drawable", packageName);
mMsgListStyle.setSendingIndeterminateDrawable(getResources().getDrawable(resId));
}

@Override
public boolean onDown(MotionEvent e) {
return false;
}

@Override
public void onShowPress(MotionEvent e) {

}

@Override
public boolean onSingleTapUp(MotionEvent e) {
return false;
}

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
return false;
}

@Override
public void onLongPress(MotionEvent e) {

}

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
if (Math.abs(velocityY) > 4000) {
mAdapter.setScrolling(true);
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public class MsgListAdapter<MESSAGE extends IMessage> extends RecyclerView.Adapt
private MediaPlayer mMediaPlayer = new MediaPlayer();

private List<Wrapper> mItems;
private boolean mScroll;

public MsgListAdapter(String senderId, ImageLoader imageLoader) {
this(senderId, new HoldersConfig(), imageLoader);
Expand All @@ -79,6 +80,14 @@ public MsgListAdapter(String senderId, HoldersConfig holders, ImageLoader imageL
mItems = new ArrayList<>();
}

public void setScrolling(boolean scroll) {
this.mScroll = scroll;
}

public boolean getScrolling() {
return this.mScroll;
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
switch (viewType) {
Expand Down Expand Up @@ -173,6 +182,7 @@ public void onBindViewHolder(ViewHolder holder, int position) {
((BaseMessageViewHolder) holder).mAvatarClickListener = this.mAvatarClickListener;
((BaseMessageViewHolder) holder).mMsgResendListener = this.mMsgResendListener;
((BaseMessageViewHolder) holder).mMediaPlayer = this.mMediaPlayer;
((BaseMessageViewHolder) holder).mScroll = this.mScroll;
}
holder.onBind(wrapper.item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ public void onBind(final MESSAGE message) {
mImageLoader.loadAvatarImage(mAvatarIv, message.getFromUser().getAvatarFilePath());
}

mImageLoader.loadImage(mPhotoIv, message.getMediaFilePath());
if (mScroll) {
mPhotoIv.setImageResource(R.drawable.aurora_picture_not_found);
} else {
mImageLoader.loadImage(mPhotoIv, message.getMediaFilePath());
}


mAvatarIv.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,22 @@
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;

import static android.support.v7.widget.RecyclerView.SCROLL_STATE_DRAGGING;
import static android.support.v7.widget.RecyclerView.SCROLL_STATE_IDLE;
import static android.support.v7.widget.RecyclerView.SCROLL_STATE_SETTLING;

public class ScrollMoreListener extends RecyclerView.OnScrollListener {

private RecyclerView.LayoutManager mLayoutManager;
private OnLoadMoreListener mListener;
private MsgListAdapter mAdapter;
private int mCurrentPage = 0;
private int mPreviousTotalItemCount = 0;
private boolean mLoading = false;
private boolean mScrolled = false;

public ScrollMoreListener(LinearLayoutManager layoutManager, OnLoadMoreListener listener) {
public ScrollMoreListener(LinearLayoutManager layoutManager, MsgListAdapter adapter) {
this.mLayoutManager = layoutManager;
this.mListener = listener;
mAdapter = adapter;
}

private int getLastVisibleItem(int[] lastVisibleItemPositions) {
Expand All @@ -33,7 +38,10 @@ private int getLastVisibleItem(int[] lastVisibleItemPositions) {

@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (mListener != null) {
if (dy != 0) {
mScrolled = true;
}
if (mAdapter != null) {
int lastVisibleItemPosition = 0;
int totalItemCount = mLayoutManager.getItemCount();
if (mLayoutManager instanceof StaggeredGridLayoutManager) {
Expand Down Expand Up @@ -62,12 +70,32 @@ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
int visibleThreshold = 5;
if (!mLoading && lastVisibleItemPosition + visibleThreshold > totalItemCount) {
mCurrentPage++;
mListener.onLoadMore(mCurrentPage, totalItemCount);
mAdapter.onLoadMore(mCurrentPage, totalItemCount);
mLoading = true;
}
}
}

@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
switch (newState) {
case SCROLL_STATE_IDLE:
if (mAdapter.getScrolling() && mScrolled) {
mAdapter.setScrolling(false);
mAdapter.notifyDataSetChanged();
}
mScrolled = false;
break;
case SCROLL_STATE_DRAGGING:
// mAdapter.setScrolling(false);
break;
case SCROLL_STATE_SETTLING:
// mAdapter.setScrolling(true);
break;
}
super.onScrollStateChanged(recyclerView, newState);
}

interface OnLoadMoreListener {
void onLoadMore(int page, int total);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import cn.jiguang.imui.R;
import cn.jiguang.imui.commons.models.IMessage;
import cn.jiguang.imui.utils.BitmapCache;
import cn.jiguang.imui.view.CircleImageView;


Expand Down Expand Up @@ -51,9 +52,12 @@ public void onBind(final Message message) {
boolean isAvatarExists = message.getFromUser().getAvatarFilePath() != null
&& !message.getFromUser().getAvatarFilePath().isEmpty();

Bitmap thumb = ThumbnailUtils.createVideoThumbnail(message.getMediaFilePath(),
MediaStore.Images.Thumbnails.MINI_KIND);
mImageCover.setImageBitmap(thumb);
if (BitmapCache.getInstance().getBitmapFromMemCache(message.getMediaFilePath()) == null) {
Bitmap thumb = ThumbnailUtils.createVideoThumbnail(message.getMediaFilePath(),
MediaStore.Images.Thumbnails.MINI_KIND);
BitmapCache.getInstance().setBitmapCache(message.getMediaFilePath(), thumb);
}
mImageCover.setImageBitmap(BitmapCache.getInstance().getBitmapFromMemCache(message.getMediaFilePath()));
mImageCover.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cn.jiguang.imui.utils;

import android.graphics.Bitmap;
import android.util.LruCache;

/**
* Created by caiyaoguan on 2017/7/6.
*/

public class BitmapCache {

private LruCache<String, Bitmap> mMemoryCache;
private static BitmapCache mInstance = new BitmapCache();

private BitmapCache() {
//获取应用程序的最大内存
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

//用最大内存的1/4来存储图片
final int cacheSize = maxMemory / 4;
mMemoryCache = new LruCache<String, Bitmap>(cacheSize) {

//获取每张图片的大小
@Override
protected int sizeOf(String key, Bitmap bitmap) {
return bitmap.getRowBytes() * bitmap.getHeight() / 1024;
}
};
}

/**
* 通过此方法来获取NativeImageLoader的实例
*
* @return NativeImageLoader
*/
public static BitmapCache getInstance() {
return mInstance;
}

public void setBitmapCache(String path, Bitmap bitmap) {
if (getBitmapFromMemCache(path) == null && bitmap != null) {
mMemoryCache.put(path, bitmap);
}
}

/**
* 根据key来获取内存中的图片
*
* @param key path
* @return bitmap
*/
public Bitmap getBitmapFromMemCache(String key) {
if (key == null) {
return null;
} else {
return mMemoryCache.get(key);
}
}


}
2 changes: 1 addition & 1 deletion Android/sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-alpha2'
classpath 'com.android.tools.build:gradle:3.0.0-alpha4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.support.v4.app.ActivityCompat;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
Expand Down Expand Up @@ -371,7 +372,8 @@ public void onMessageResend(MyMessage message) {
mAdapter.setOnLoadMoreListener(new MsgListAdapter.OnLoadMoreListener() {
@Override
public void onLoadMore(int page, int totalCount) {
if (totalCount < mData.size()) {
if (totalCount <= mData.size()) {
Log.i("MessageListActivity", "Loading next page");
loadNextPage();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,3 +365,4 @@ public void onCatalystInstanceDestroy() {
mContext.unregisterReceiver(RCTMsgListReceiver);
}
}
ra
Loading

0 comments on commit 74dc146

Please sign in to comment.