Skip to content

Commit 2587121

Browse files
guangyaoguangyao
authored andcommitted
2 parents 2e1a7e8 + 0ba0b38 commit 2587121

File tree

27 files changed

+255
-114
lines changed

27 files changed

+255
-114
lines changed

android/chatinput/src/main/java/cn/jiguang/imui/chatinput/ChatInputView.java

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ protected void onDetachedFromWindow() {
225225
if (mWindow != null) {
226226
getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayoutListener);
227227
mWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
228-
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
228+
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
229229
}
230+
hideInputMethod();
230231
super.onDetachedFromWindow();
231232

232233

@@ -277,7 +278,7 @@ public void onClick(View view) {
277278
dismissSoftInputAndShowMenu();
278279
} else if (view.getId() == mLastClickId) {
279280
dismissMenuAndResetSoftMode();
280-
showType = 0;
281+
showType = -1;
281282
if (mListener != null) {
282283
mListener.onFeatureView(inputHeight, showType);
283284
}
@@ -304,13 +305,20 @@ public void onClick(View view) {
304305
emoticonPickerView.show(emoticonSelectedListener);
305306
actionLayout.setVisibility(INVISIBLE);
306307
}
308+
307309
if (mListener != null) {
308-
mListener.onFeatureView(inputHeight, showType);
310+
postDelayed(new Runnable() {
311+
@Override
312+
public void run() {
313+
mListener.onFeatureView(inputHeight, showType);
314+
}
315+
}, 100);
316+
309317
}
310318
mLastClickId = view.getId();
311319
// mMenuContainer.requestLayout();
312320
}
313-
Log.w(TAG, "viewId: " + view.getId() + "-showType:" + showType);
321+
// Log.w(TAG, "viewId: " + view.getId() + "-showType:" + showType);
314322
}
315323
};
316324
private IEmoticonSelectedListener emoticonSelectedListener = new IEmoticonSelectedListener() {
@@ -444,36 +452,41 @@ public void setSoftInput(boolean resize) {
444452

445453
public void dismissMenuAndResetSoftMode() {
446454
mWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
447-
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
448-
try {
449-
Thread.sleep(140);
450-
} catch (InterruptedException e) {
451-
e.printStackTrace();
452-
}
455+
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
456+
// try {
457+
// Thread.sleep(140);
458+
// } catch (InterruptedException e) {
459+
// e.printStackTrace();
460+
// }
461+
postDelayed(new Runnable() {
462+
@Override
463+
public void run() {
464+
dismissMenuLayout();
465+
}
466+
}, 100);
453467
showInputMethod();
454-
dismissMenuLayout();
455-
// setMenuContainerHeight(1);
468+
456469
mChatInput.requestFocus();
457470
}
458471

459472
public void dismissSoftInputAndShowMenu() {
460473
mWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN
461474
| WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
462-
try {
463-
Thread.sleep(140);
464-
} catch (InterruptedException e) {
465-
e.printStackTrace();
466-
}
475+
// try {
476+
// Thread.sleep(140);
477+
// } catch (InterruptedException e) {
478+
// e.printStackTrace();
479+
// }
480+
481+
hideInputMethod();
467482
showMenuLayout();
468-
if (inputMethodManager != null) {
469-
inputMethodManager.hideSoftInputFromWindow(mChatInput.getWindowToken(), 0);
470-
}
471483
setMenuContainerHeight(sMenuHeight);
484+
472485
mShowSoftInput = false;
473486
}
474487

475488
public void dismissMenuLayout() {
476-
mMenuContainer.setVisibility(GONE);
489+
mMenuContainer.setVisibility(INVISIBLE);
477490
if (showType == 1) {
478491
showType = 0;
479492
mEmojiBtn.setImageResource(R.drawable.nim_message_button_bottom_emoji_selector);
@@ -498,7 +511,7 @@ public void setMenuContainerHeight(int height) {
498511
if (height > 0) {
499512
sMenuHeight = height;
500513
mMenuContainer.setLayoutParams(
501-
new LinearLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, height));
514+
new LinearLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, dip2px(height)));
502515
}
503516
}
504517

@@ -625,7 +638,7 @@ public void onGlobalLayout() {
625638
mWindow.getDecorView().getWindowVisibleDisplayFrame(r);
626639
int screenHeight = mWindow.getDecorView().getRootView().getHeight();
627640
int height = screenHeight - r.bottom + mChatInputContainer.getHeight();
628-
Log.d(TAG, "Keyboard Size: " + px2dip(height) + "-showType:" + showType);
641+
// Log.d(TAG, "Keyboard Size: " + px2dip(height) + "-showType:" + showType);
629642
if (inputHeight == height) {
630643
return;
631644
}

android/chatinput/src/main/java/cn/jiguang/imui/chatinput/record/RecordHelper.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ public void onError(MediaRecorder mediaRecorder, int i, int i2) {
9090
if (currentAudioFile != null) {
9191
currentAudioFile.delete();
9292
}
93-
recorder.release();
94-
recorder = null;
93+
if(recorder!=null) {
94+
recorder.release();
95+
recorder = null;
96+
}
9597
}
9698

9799
}

android/chatinput/src/main/java/cn/jiguang/imui/chatinput/utils/ViewUtil.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package cn.jiguang.imui.chatinput.utils;
22

3+
import android.animation.Animator;
4+
import android.animation.AnimatorListenerAdapter;
5+
import android.animation.ValueAnimator;
36
import android.content.res.Resources;
7+
import android.util.Log;
8+
import android.view.View;
9+
import android.view.ViewGroup;
410

511

612
public final class ViewUtil {
@@ -16,4 +22,55 @@ public static int dpToPx(int dp) {
1622
}
1723

1824

25+
// 高度渐变的动画;
26+
private static void animHeightToView(final View v, final int start, final int end, final boolean isToShow,
27+
long duration) {
28+
Log.w(v.getClass().getName(), "start:" + start + "-end:" + end);
29+
ValueAnimator va = ValueAnimator.ofInt(start, end);
30+
final ViewGroup.LayoutParams layoutParams = v.getLayoutParams();
31+
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
32+
@Override
33+
public void onAnimationUpdate(ValueAnimator animation) {
34+
int h = (int) animation.getAnimatedValue();
35+
layoutParams.height = h;
36+
v.setLayoutParams(layoutParams);
37+
v.requestLayout();
38+
}
39+
});
40+
41+
va.addListener(new AnimatorListenerAdapter() {
42+
@Override
43+
public void onAnimationStart(Animator animation) {
44+
45+
Log.w(v.getClass().getName(), "Start:" + (v.getVisibility() == View.VISIBLE));
46+
if (isToShow) {
47+
v.setVisibility(View.VISIBLE);
48+
v.requestLayout();
49+
}
50+
super.onAnimationStart(animation);
51+
}
52+
53+
@Override
54+
public void onAnimationEnd(Animator animation) {
55+
56+
Log.w(v.getClass().getName(), "End:" + (v.getVisibility() == View.VISIBLE));
57+
super.onAnimationEnd(animation);
58+
if (!isToShow) {
59+
v.setVisibility(View.GONE);
60+
}
61+
}
62+
});
63+
va.setDuration(duration);
64+
va.start();
65+
}
66+
67+
public static void animHeightToView(int height, final View v, final boolean isToShow, final long duration) {
68+
69+
if (isToShow) {
70+
animHeightToView(v, 0, height, isToShow, duration);
71+
} else {
72+
// 隐藏:从当前高度变化到0,最后设置不可见;
73+
animHeightToView(v, v.getLayoutParams().height, 0, isToShow, duration);
74+
}
75+
}
1976
}

android/emoji/src/main/java/dowin/com/emoji/media/ScreenUtil.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ public static void init(Context context) {
6262
Log.d(TAG, "screenWidth=" + screenWidth + " screenHeight=" + screenHeight + " density=" + density);
6363
}
6464

65-
public static int getDisplayWidth() {
65+
public static int getDisplayWidth(Context context) {
6666
if (screenWidth == 0) {
67-
// GetInfo(NimUIKit.getContext());
67+
GetInfo(context);
6868
}
6969
return screenWidth;
7070
}
7171

72-
public static int getDisplayHeight() {
72+
public static int getDisplayHeight(Context context) {
7373
if (screenHeight == 0) {
74-
// GetInfo(NimUIKit.getContext());
74+
GetInfo(context);
7575
}
7676
return screenHeight;
7777
}

android/messagelist/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ dependencies {
2727
compile project(':react-native-imui:emoji')
2828
compile project(':react-native-imui:photoViewPagerview')
2929

30-
compile 'com.facebook.fresco:fresco:1.0.1'
3130
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
3231
exclude group: 'com.android.support', module: 'support-annotations'
3332
})

android/messagelist/src/main/java/cn/jiguang/imui/messages/MsgListAdapter.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public boolean needShowTime(MESSAGE message) {
131131
}
132132

133133
private void setShowTime(MESSAGE message, boolean show) {
134-
Log.w("MsgListAdatper", message.getTimeString() + "-" + show);
134+
//Log.w("MsgListAdatper", message.getTimeString() + "-" + show);
135135
if (show) {
136136
mTimedItems.add(message.getMsgId());
137137
} else {
@@ -377,19 +377,19 @@ private class Wrapper<DATA> {
377377
public void addToStart(List<MESSAGE> messages, boolean scrollToBottom) {
378378
boolean first = mItems.isEmpty();
379379
updateShowTimeItem(messages, first, true);
380-
for (int i = 0; i < messages.size(); i++) {
380+
for (int i = 0; i < messages.size(); i++) {//3 2 1
381381
MESSAGE message = messages.get(i);
382+
382383
mItems.add(0, new Wrapper<>(message));
383384
notifyItemRangeInserted(0, 1);
384385
addImage(message, false);
385386
}
386387

387388
// notifyItemRangeInserted(0, messages.size());
388-
if (mLayoutManager != null && scrollToBottom) {
389-
mLayoutManager.scrollToPosition(0);
390-
mLayoutManager.requestLayout();
391-
}
392389
if (mLayoutManager != null) {
390+
if (scrollToBottom) {
391+
mLayoutManager.scrollToPosition(0);
392+
}
393393
mLayoutManager.requestLayout();
394394
}
395395
}
@@ -436,8 +436,9 @@ void deleteImage(MESSAGE message) {
436436
void updateImage(MESSAGE message) {
437437
if (message.getType() == IMessage.MessageType.RECEIVE_IMAGE || message.getType() == IMessage.MessageType.SEND_IMAGE) {
438438
IMediaFile extend = (IMediaFile) message.getExtend();
439+
extend.setId(message.getMsgId());
439440
for (int i = 0; i < imageList.size(); i++) {
440-
if (TextUtils.equals(message.getMsgId(),imageList.get(i).getId())) {
441+
if (TextUtils.equals(message.getMsgId(), imageList.get(i).getId())) {
441442
imageList.set(i, extend);
442443
break;
443444
}
@@ -1278,6 +1279,7 @@ public void pausePlayVoice() {
12781279
mMediaPlayer.pause();
12791280
}
12801281
}
1282+
12811283
public void stopPlayVoice() {
12821284
if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
12831285
mMediaPlayer.stop();

android/messagelist/src/main/java/cn/jiguang/imui/messages/ScrollMoreListener.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class ScrollMoreListener extends RecyclerView.OnScrollListener {
1313
private int mCurrentPage = 0;
1414
private int mPreviousTotalItemCount = 0;
1515
private boolean mLoading = false;
16-
private int visibleThreshold = 20;
16+
private int visibleThreshold = 5;
1717
private int scrollThreshold = 3;
1818
private boolean autoScroll = true;
1919

@@ -39,6 +39,26 @@ private int getLastVisibleItem(int[] lastVisibleItemPositions) {
3939

4040
@Override
4141
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
42+
if (mLayoutManager instanceof LinearLayoutManager) {
43+
LinearLayoutManager ll = (LinearLayoutManager) mLayoutManager;
44+
if (ll.getStackFromEnd()) {
45+
if (ll.getChildCount() < mLayoutManager.getItemCount()) {
46+
try {
47+
ll.setStackFromEnd(false);
48+
} catch (Exception e) {
49+
e.printStackTrace();
50+
}
51+
}
52+
}else {
53+
if (ll.getChildCount() >= mLayoutManager.getItemCount()) {
54+
try {
55+
ll.setStackFromEnd(true);
56+
} catch (Exception e) {
57+
e.printStackTrace();
58+
}
59+
}
60+
}
61+
}
4262
if (mListener != null) {
4363
int lastVisibleItemPosition = 0;
4464
int firstVisibleItemPosition = 0;

android/messagelist/src/main/java/cn/jiguang/imui/messages/viewholder/PhotoViewHolder.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ public boolean onLongClick(View view) {
5959
@Override
6060
public void applyStyle(MessageListStyle style) {
6161
super.applyStyle(style);
62-
if (mIsSender) {
63-
mPhotoIv.setBackground(style.getSendPhotoMsgBg());
64-
} else {
65-
mPhotoIv.setBackground(style.getReceivePhotoMsgBg());
66-
}
62+
63+
mPhotoIv.setScaleType(ImageView.ScaleType.FIT_END);
64+
// if (mIsSender) {
65+
// mPhotoIv.setBackground(style.getSendPhotoMsgBg());
66+
// } else {
67+
// mPhotoIv.setBackground(style.getReceivePhotoMsgBg());
68+
// }
6769
}
6870

6971
}

android/messagelist/src/main/java/cn/jiguang/imui/messages/viewholder/TipViewHoler.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ public void onBind(MESSAGE message) {
3232

3333
@Override
3434
public void applyStyle(MessageListStyle style) {
35+
3536
mEvent.setTextColor(Color.WHITE);
36-
mEvent.setTextSize(style.getEventTextSize());
37+
mEvent.setTextSize(12);
3738
mEvent.setPadding(style.getEventPadding(), style.getEventPadding(), style.getEventPadding(), style.getEventPadding());
3839
}
3940
}

android/messagelist/src/main/java/cn/jiguang/imui/messages/viewholder/TxtViewHolder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public boolean onLongClick(View view) {
7777
public void applyStyle(MessageListStyle style) {
7878
super.applyStyle(style);
7979
mMsgTv.setMaxWidth((int) (style.getWindowWidth() * style.getBubbleMaxWidth()));
80-
mMsgTv.setTextSize(17);
80+
mMsgTv.setTextSize(22);
8181
mMsgTv.setTextColor(mIsSender ? Color.WHITE : Color.BLACK);
8282
mMsgTv.setLinkTextColor(mIsSender ? Color.parseColor("#bbdcff") : Color.parseColor("#238dfa"));
8383

0 commit comments

Comments
 (0)