improve chatFragment display

This commit is contained in:
Margaux Clerc 2014-08-12 15:37:52 +02:00
parent 909d351670
commit 1dc8f0f927
6 changed files with 167 additions and 231 deletions

View file

@ -7,11 +7,11 @@
android:orientation="vertical" > android:orientation="vertical" >
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="10dp" android:paddingTop="10dp"
android:paddingLeft="10dp" android:paddingLeft="10dp"
android:paddingRight="10dp" android:paddingRight="10dp"
android:gravity="center" android:gravity="center"
android:orientation="horizontal"> android:orientation="horizontal">
@ -31,23 +31,16 @@
</LinearLayout> </LinearLayout>
<org.linphone.ui.LinphoneScrollView <ListView
android:id="@+id/chatScrollView" android:id="@+id/chatMessageList"
android:paddingTop="5dp" android:layout_width="match_parent"
android:layout_weight="1" android:layout_height="0dp"
android:layout_width="match_parent" android:layout_weight="1"
android:layout_height="0dip"> android:divider="@android:color/transparent"
android:stackFromBottom="true"
<RelativeLayout android:transcriptMode="alwaysScroll"
android:id="@+id/messages" android:cacheColorHint="@color/transparent"
android:layout_width="match_parent" android:dividerHeight="1dp" />
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp">
</RelativeLayout>
</org.linphone.ui.LinphoneScrollView>
<TextView <TextView
android:id="@+id/remoteComposing" android:id="@+id/remoteComposing"

View file

@ -31,23 +31,16 @@
</LinearLayout> </LinearLayout>
<org.linphone.ui.LinphoneScrollView <ListView
android:id="@+id/chatScrollView" android:id="@+id/chatMessageList"
android:paddingTop="5dp" android:layout_width="match_parent"
android:layout_weight="1" android:layout_height="0dp"
android:layout_width="match_parent" android:layout_weight="1"
android:layout_height="0dip"> android:divider="@android:color/transparent"
android:stackFromBottom="true"
<RelativeLayout android:transcriptMode="alwaysScroll"
android:id="@+id/messages" android:cacheColorHint="@color/transparent"
android:layout_width="match_parent" android:dividerHeight="1dp" />
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp">
</RelativeLayout>
</org.linphone.ui.LinphoneScrollView>
<TextView <TextView
android:id="@+id/remoteComposing" android:id="@+id/remoteComposing"

View file

@ -6,12 +6,12 @@
android:background="@drawable/background" android:background="@drawable/background"
android:orientation="vertical" > android:orientation="vertical" >
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="10dp" android:paddingTop="10dp"
android:paddingLeft="10dp" android:paddingLeft="10dp"
android:paddingRight="10dp" android:paddingRight="10dp"
android:gravity="center" android:gravity="center"
android:orientation="horizontal"> android:orientation="horizontal">
@ -31,23 +31,16 @@
</LinearLayout> </LinearLayout>
<org.linphone.ui.LinphoneScrollView <ListView
android:id="@+id/chatScrollView" android:id="@+id/chatMessageList"
android:paddingTop="5dp" android:layout_width="match_parent"
android:layout_weight="1" android:layout_height="0dp"
android:layout_width="match_parent" android:layout_weight="1"
android:layout_height="0dip"> android:divider="@android:color/transparent"
android:stackFromBottom="true"
<RelativeLayout android:transcriptMode="alwaysScroll"
android:id="@+id/messages" android:cacheColorHint="@color/transparent"
android:layout_width="match_parent" android:dividerHeight="1dp" />
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp">
</RelativeLayout>
</org.linphone.ui.LinphoneScrollView>
<TextView <TextView
android:id="@+id/remoteComposing" android:id="@+id/remoteComposing"

View file

@ -43,8 +43,6 @@ import org.linphone.core.LinphoneCore;
import org.linphone.mediastream.Log; import org.linphone.mediastream.Log;
import org.linphone.ui.AvatarWithShadow; import org.linphone.ui.AvatarWithShadow;
import org.linphone.ui.BubbleChat; import org.linphone.ui.BubbleChat;
import org.linphone.ui.LinphoneScrollView;
import org.linphone.ui.ScrollViewListener;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity; import android.app.Activity;
@ -77,8 +75,10 @@ import android.view.View.OnClickListener;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnGlobalLayoutListener; import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.widget.BaseAdapter;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
@ -101,7 +101,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
private static final int SIZE_SMALL = 500; private static final int SIZE_SMALL = 500;
private static final int SIZE_MEDIUM = 1000; private static final int SIZE_MEDIUM = 1000;
private static final int SIZE_LARGE = 1500; private static final int SIZE_LARGE = 1500;
private static final int MESSAGES_STEP = 20;
private LinphoneChatRoom chatRoom; private LinphoneChatRoom chatRoom;
private View view; private View view;
@ -110,15 +109,13 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
private ImageView cancelUpload; private ImageView cancelUpload;
private TextView sendImage, sendMessage, contactName, remoteComposing; private TextView sendImage, sendMessage, contactName, remoteComposing;
private AvatarWithShadow contactPicture; private AvatarWithShadow contactPicture;
private RelativeLayout messagesLayout, uploadLayout, textLayout; private RelativeLayout uploadLayout, textLayout;
private LinphoneScrollView messagesScrollView;
private int previousMessageID;
private Handler mHandler = new Handler(); private Handler mHandler = new Handler();
private List<BubbleChat> lastSentMessagesBubbles; private List<BubbleChat> lastSentMessagesBubbles;
private HashMap<Integer, String> latestImageMessages; private HashMap<Integer, String> latestImageMessages;
private int messagesFilterLimit = 0;
private boolean useLinphoneMessageStorage; private boolean useLinphoneMessageStorage;
private boolean messagesArePresentButHidden = false; private List<Integer> openImagesId ;
private ListView messagesList;
private ProgressBar progressBar; private ProgressBar progressBar;
private int bytesSent; private int bytesSent;
@ -129,6 +126,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
private Thread uploadThread; private Thread uploadThread;
private TextWatcher textWatcher; private TextWatcher textWatcher;
private OnGlobalLayoutListener keyboardListener; private OnGlobalLayoutListener keyboardListener;
private ChatMessageAdapter adapter;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -149,19 +147,18 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
remoteComposing = (TextView) view.findViewById(R.id.remoteComposing); remoteComposing = (TextView) view.findViewById(R.id.remoteComposing);
remoteComposing.setVisibility(View.GONE); remoteComposing.setVisibility(View.GONE);
messagesList = (ListView) view.findViewById(R.id.chatMessageList);
openImagesId = new ArrayList<Integer>();
message = (EditText) view.findViewById(R.id.message); message = (EditText) view.findViewById(R.id.message);
if (!getActivity().getResources().getBoolean(R.bool.allow_chat_multiline)) { if (!getActivity().getResources().getBoolean(R.bool.allow_chat_multiline)) {
message.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE); message.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE);
message.setMaxLines(1); message.setMaxLines(1);
} }
uploadLayout = (RelativeLayout) view.findViewById(R.id.uploadLayout); uploadLayout = (RelativeLayout) view.findViewById(R.id.uploadLayout);
textLayout = (RelativeLayout) view.findViewById(R.id.messageLayout); textLayout = (RelativeLayout) view.findViewById(R.id.messageLayout);
messagesLayout = (RelativeLayout) view.findViewById(R.id.messages);
messagesScrollView = (LinphoneScrollView) view.findViewById(R.id.chatScrollView);
progressBar = (ProgressBar) view.findViewById(R.id.progressbar); progressBar = (ProgressBar) view.findViewById(R.id.progressbar);
sendImage = (TextView) view.findViewById(R.id.sendPicture); sendImage = (TextView) view.findViewById(R.id.sendPicture);
if (!getResources().getBoolean(R.bool.disable_chat_send_file)) { if (!getResources().getBoolean(R.bool.disable_chat_send_file)) {
registerForContextMenu(sendImage); registerForContextMenu(sendImage);
@ -193,9 +190,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
chatRoom.markAsRead(); chatRoom.markAsRead();
} }
if (savedInstanceState != null) {
messagesFilterLimit = savedInstanceState.getInt("messagesFilterLimit");
}
displayChatHeader(displayName, pictureUri); displayChatHeader(displayName, pictureUri);
uploadServerUri = LinphonePreferences.instance().getSharingPictureServerUrl(); uploadServerUri = LinphonePreferences.instance().getSharingPictureServerUrl();
@ -248,7 +242,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
public void onSaveInstanceState(Bundle outState) { public void onSaveInstanceState(Bundle outState) {
outState.putString("fileToUploadPath", fileToUploadPath); outState.putString("fileToUploadPath", fileToUploadPath);
outState.putParcelable("imageToUpload", imageToUpload); outState.putParcelable("imageToUpload", imageToUpload);
outState.putInt("messagesFilterLimit", messagesFilterLimit);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
@ -283,64 +276,70 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
public void hideKeyboardVisibleMode() { public void hideKeyboardVisibleMode() {
LinphoneActivity.instance().hideMenu(false); LinphoneActivity.instance().hideMenu(false);
contactPicture.setVisibility(View.VISIBLE); contactPicture.setVisibility(View.VISIBLE);
scrollToEnd(); //scrollToEnd();
} }
private void invalidate() { class ChatMessageAdapter extends BaseAdapter {
messagesFilterLimit += MESSAGES_STEP; LinphoneChatMessage[] history;
Context context;
if (!messagesArePresentButHidden) { public ChatMessageAdapter(Context context, LinphoneChatMessage[] history) {
LinphoneChatMessage[] history = chatRoom.getHistory(); this.history = history;
for (int i = 0; i < history.length; i++) { this.context = context;
LinphoneChatMessage msg = history[i];
boolean show = i >= history.length - messagesFilterLimit;
if (msg.getExternalBodyUrl() != null) {
displayImageMessage(msg.getStorageId(), null, msg.getTime(), !msg.isOutgoing(), msg.getStatus(), messagesLayout, msg.getExternalBodyUrl(), show);
} else {
displayMessage(msg.getStorageId(), msg.getText(), msg.getTime(), !msg.isOutgoing(), msg.getStatus(), messagesLayout, show);
}
}
messagesArePresentButHidden = true;
} }
invalidate(messagesFilterLimit); public void refreshHistory(){
this.history = chatRoom.getHistory();
}
@Override
public int getCount() {
return history.length;
}
@Override
public LinphoneChatMessage getItem(int position) {
return history[position];
}
@Override
public long getItemId(int position) {
return history[position].getStorageId();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
BubbleChat bubble;
LinphoneChatMessage msg = history[position];
View v;
Boolean showImage = false;
if (msg.getExternalBodyUrl() != null ) {
if(!openImagesId.isEmpty() && openImagesId.contains(msg.getStorageId())) showImage = true;
bubble = displayImageMessage(msg.getStorageId(), null, msg.getTime(), !msg.isOutgoing(), msg.getStatus(), context, msg.getExternalBodyUrl(),showImage);
} else {
bubble = displayMessage(msg.getStorageId(), msg.getText(), msg.getTime(), !msg.isOutgoing(), msg.getStatus(), context);
}
v = bubble.getView();
bubble.setNativeMessageObject(msg);
registerForContextMenu(v);
RelativeLayout rlayout = new RelativeLayout(context);
rlayout.addView(v);
return rlayout;
}
}
public View getBubble(int position){
return messagesList.getChildAt(position);
} }
private void invalidate(final int limit) { public void dispayMessageList(){
mHandler.post(new Runnable() { adapter = new ChatMessageAdapter(this.getActivity(), chatRoom.getHistory());
@Override messagesList.setAdapter(adapter);
public void run() {
int start = messagesLayout.getChildCount() - messagesFilterLimit;
if (start < 0)
start = 0;
for (int i = start; i < messagesLayout.getChildCount(); i++) {
messagesLayout.getChildAt(i).setVisibility(View.VISIBLE);
}
LinphoneActivity.instance().updateMissedChatCount();
if (start != 0) {
messagesScrollView.setScrollViewListener(new ScrollViewListener() {
@Override
public void OnScrollToTop(final int previousHeight) {
invalidate();
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
//Scroll to latest saw message
if (messagesScrollView != null && messagesLayout != null && messagesLayout.getChildCount() >= MESSAGES_STEP-1)
messagesScrollView.scrollTo(0, messagesLayout.getChildAt(MESSAGES_STEP-1).getBottom());
}
}, 300);
}
});
} else {
messagesScrollView.setScrollViewListener(null);
}
}
});
} }
private void displayChatHeader(String displayName, String pictureUri) { private void displayChatHeader(String displayName, String pictureUri) {
@ -359,45 +358,18 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
} }
} }
private int checkId(int id) { private BubbleChat displayMessage(int id, String message, long time, boolean isIncoming, LinphoneChatMessage.State status, Context context) {
if (id <= 0) { BubbleChat bubble = new BubbleChat(context, id, message, null, time, isIncoming, status, null);
return previousMessageID + 1;
}
return id;
}
private BubbleChat displayMessage(int id, String message, long time, boolean isIncoming, LinphoneChatMessage.State status, RelativeLayout layout) {
return displayMessage(id, message, time, isIncoming, status, layout, true);
}
private BubbleChat displayMessage(int id, String message, long time, boolean isIncoming, LinphoneChatMessage.State status, RelativeLayout layout, boolean show) {
id = checkId(id);
BubbleChat bubble = new BubbleChat(layout.getContext(), id, message, null, time, isIncoming, status, null, previousMessageID);
if (!isIncoming) { if (!isIncoming) {
if (lastSentMessagesBubbles == null) if (lastSentMessagesBubbles == null)
lastSentMessagesBubbles = new ArrayList<BubbleChat>(); lastSentMessagesBubbles = new ArrayList<BubbleChat>();
lastSentMessagesBubbles.add(bubble); lastSentMessagesBubbles.add(bubble);
} }
View v = bubble.getView();
if (!show)
v.setVisibility(View.GONE);
previousMessageID = id;
layout.addView(v);
registerForContextMenu(v);
return bubble; return bubble;
} }
private BubbleChat displayImageMessage(int id, Bitmap image, long time, boolean isIncoming, LinphoneChatMessage.State status, RelativeLayout layout, final String url) { private BubbleChat displayImageMessage(int id, Bitmap image, long time, boolean isIncoming, LinphoneChatMessage.State status, Context context, final String url, boolean show) {
return displayImageMessage(id, image, time, isIncoming, status, layout, url, true); final BubbleChat bubble = new BubbleChat(context, id, null, image, time, isIncoming, status, url);
}
private BubbleChat displayImageMessage(int id, Bitmap image, long time, boolean isIncoming, LinphoneChatMessage.State status, RelativeLayout layout, final String url, boolean show) {
id = checkId(id);
final BubbleChat bubble = new BubbleChat(layout.getContext(), id, null, image, time, isIncoming, status, url, previousMessageID);
if (!isIncoming) { if (!isIncoming) {
if (lastSentMessagesBubbles == null) if (lastSentMessagesBubbles == null)
lastSentMessagesBubbles = new ArrayList<BubbleChat>(); lastSentMessagesBubbles = new ArrayList<BubbleChat>();
@ -421,8 +393,10 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
final Bitmap bm = ChatFragment.downloadImage(url); final Bitmap bm = ChatFragment.downloadImage(url);
if (bm != null) { if (bm != null) {
if (useLinphoneMessageStorage) { if (useLinphoneMessageStorage) {
String newFileUrl = saveImage(bm, finalId, null); String newFileUrl = saveImage(bm, finalId, getMessageForId(finalId));
bubble.updateUrl(newFileUrl); bubble.updateUrl(newFileUrl);
adapter.refreshHistory();
openImagesId.add(finalId);
} else { } else {
LinphoneActivity.instance().getChatStorage().saveImage(finalId, bm); LinphoneActivity.instance().getChatStorage().saveImage(finalId, bm);
} }
@ -449,27 +423,28 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
} }
}); });
} else { // Show } else { // Show
bubble.setShowOrDownloadText(getString(R.string.show_image)); if(show){
bubble.setShowOrDownloadImageButtonListener(new OnClickListener() { Bitmap bm = BitmapFactory.decodeFile(url);
@Override ((ImageView)v.findViewById(R.id.image)).setImageBitmap(bm);
public void onClick(View view) { v.findViewById(R.id.image).setVisibility(View.VISIBLE);
Bitmap bm = BitmapFactory.decodeFile(url); v.findViewById(R.id.download).setVisibility(View.GONE);
if (bm != null) { } else {
((ImageView)v.findViewById(R.id.image)).setImageBitmap(bm); bubble.setShowOrDownloadText(getString(R.string.show_image));
v.findViewById(R.id.image).setVisibility(View.VISIBLE); bubble.setShowOrDownloadImageButtonListener(new OnClickListener() {
v.findViewById(R.id.download).setVisibility(View.GONE); @Override
public void onClick(View view) {
Bitmap bm = BitmapFactory.decodeFile(url);
if (bm != null) {
openImagesId.add(finalId);
((ImageView)v.findViewById(R.id.image)).setImageBitmap(bm);
v.findViewById(R.id.image).setVisibility(View.VISIBLE);
v.findViewById(R.id.download).setVisibility(View.GONE);
}
} }
} });
}); }
} }
if (!show)
v.setVisibility(View.GONE);
previousMessageID = id;
layout.addView(v);
registerForContextMenu(v);
return bubble; return bubble;
} }
@ -485,7 +460,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
LinphoneActivity.instance().getChatStorage().deleteDraft(sipUri); LinphoneActivity.instance().getChatStorage().deleteDraft(sipUri);
} }
messagesFilterLimit = 0;
sipUri = newSipUri; sipUri = newSipUri;
if (LinphoneActivity.isInstanciated()) { if (LinphoneActivity.isInstanciated()) {
String draft = LinphoneActivity.instance().getChatStorage().getDraft(sipUri); String draft = LinphoneActivity.instance().getChatStorage().getDraft(sipUri);
@ -618,12 +592,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
} }
private void displayMessages() { private void displayMessages() {
messagesLayout.removeAllViews(); dispayMessageList();
messagesArePresentButHidden = false;
messagesFilterLimit = 0;
previousMessageID = 0;
invalidate();
scrollToEnd();
} }
private void sendTextMessage() { private void sendTextMessage() {
@ -639,13 +608,13 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
LinphoneChatMessage chatMessage = chatRoom.createLinphoneChatMessage(messageToSend); LinphoneChatMessage chatMessage = chatRoom.createLinphoneChatMessage(messageToSend);
chatRoom.sendMessage(chatMessage, this); chatRoom.sendMessage(chatMessage, this);
int newId = -1;
if (LinphoneActivity.isInstanciated()) { if (LinphoneActivity.isInstanciated()) {
newId = LinphoneActivity.instance().onMessageSent(sipUri, messageToSend); LinphoneActivity.instance().onMessageSent(sipUri, messageToSend);
} }
BubbleChat bubble = displayMessage(newId, messageToSend, System.currentTimeMillis(), false, State.InProgress, messagesLayout); adapter.refreshHistory();
bubble.setNativeMessageObject(chatMessage); adapter.notifyDataSetChanged();
Log.i("Sent message current status: " + chatMessage.getStatus()); Log.i("Sent message current status: " + chatMessage.getStatus());
scrollToEnd(); scrollToEnd();
} else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) { } else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
@ -666,14 +635,15 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
if (LinphoneActivity.isInstanciated()) { if (LinphoneActivity.isInstanciated()) {
newId = LinphoneActivity.instance().onMessageSent(sipUri, bitmap, url); newId = LinphoneActivity.instance().onMessageSent(sipUri, bitmap, url);
} }
newId = checkId(newId); newId = chatMessage.getStorageId();
latestImageMessages.put(newId, url); latestImageMessages.put(newId, url);
if (useLinphoneMessageStorage) if (useLinphoneMessageStorage)
url = saveImage(bitmap, newId, chatMessage); url = saveImage(bitmap, newId, chatMessage);
BubbleChat bubble = displayImageMessage(newId, bitmap, System.currentTimeMillis(), false, State.InProgress, messagesLayout, url); adapter.refreshHistory();
bubble.setNativeMessageObject(chatMessage); adapter.notifyDataSetChanged();
scrollToEnd(); scrollToEnd();
} else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) { } else if (!isNetworkReachable && LinphoneActivity.isInstanciated()) {
LinphoneActivity.instance().displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG); LinphoneActivity.instance().displayCustomToast(getString(R.string.error_network_unreachable), Toast.LENGTH_LONG);
@ -698,13 +668,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
} }
private void hideMessageBubble(int id) { private void hideMessageBubble(int id) {
for (int i = 0; i < messagesLayout.getChildCount(); i++) { adapter.refreshHistory();
View v = messagesLayout.getChildAt(i); adapter.notifyDataSetChanged();
if (v.getId() == id) {
v.setVisibility(View.GONE);
break;
}
}
} }
private void resendMessage(int id) { private void resendMessage(int id) {
@ -723,15 +688,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
} }
private void scrollToEnd() { private void scrollToEnd() {
messagesScrollView.postDelayed(new Runnable() { messagesList.smoothScrollToPosition(messagesList.getBottom());
@Override chatRoom.markAsRead();
public void run() {
messagesScrollView.fullScroll(View.FOCUS_DOWN);
//Only works if using liblinphone storage
chatRoom.markAsRead();
}
}, 100);
} }
private void copyTextMessageToClipboard(int id) { private void copyTextMessageToClipboard(int id) {
@ -748,22 +706,22 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
displayMessage(id, message.getText(), message.getTime(), true, null, messagesLayout); adapter.refreshHistory();
adapter.notifyDataSetChanged();
} }
}); });
} else if (message.getExternalBodyUrl() != null) { } else if (message.getExternalBodyUrl() != null) {
Bitmap bm = null;
if (!useLinphoneMessageStorage) { if (!useLinphoneMessageStorage) {
byte[] rawImage = LinphoneActivity.instance().getChatStorage().getRawImageFromMessage(id); byte[] rawImage = LinphoneActivity.instance().getChatStorage().getRawImageFromMessage(id);
if (rawImage != null) { if (rawImage != null) {
bm = BitmapFactory.decodeByteArray(rawImage, 0, rawImage.length); Bitmap bm = BitmapFactory.decodeByteArray(rawImage, 0, rawImage.length);
} }
} }
final Bitmap fbm = bm;
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
displayImageMessage(id, fbm, message.getTime(), true, null, messagesLayout, message.getExternalBodyUrl()); adapter.refreshHistory();
adapter.notifyDataSetChanged();
} }
}); });
} }
@ -805,7 +763,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
} }
} }
} }
adapter.notifyDataSetChanged();
} }
}); });
} }
} }

View file

@ -380,7 +380,7 @@ public class ChatStorage {
if (useNativeAPI) { if (useNativeAPI) {
LinphoneChatRoom[] chats = LinphoneManager.getLc().getChatRooms(); LinphoneChatRoom[] chats = LinphoneManager.getLc().getChatRooms();
for (LinphoneChatRoom chatroom : chats) { for (LinphoneChatRoom chatroom : chats) {
if (chatroom.getHistory().length > 0) { if (chatroom.getHistory(1).length > 0) {
chatList.add(chatroom.getPeerAddress().asStringUriOnly()); chatList.add(chatroom.getPeerAddress().asStringUriOnly());
} }
} }

View file

@ -22,7 +22,6 @@ import java.util.Calendar;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.linphone.LinphoneUtils;
import org.linphone.R; import org.linphone.R;
import org.linphone.core.LinphoneChatMessage; import org.linphone.core.LinphoneChatMessage;
import org.linphone.core.LinphoneChatMessage.State; import org.linphone.core.LinphoneChatMessage.State;
@ -94,14 +93,14 @@ public class BubbleChat {
private LinphoneChatMessage nativeMessage; private LinphoneChatMessage nativeMessage;
private int id; private int id;
public BubbleChat(final Context context, int ID, String message, Bitmap image, long time, boolean isIncoming, LinphoneChatMessage.State status, String url, int previousID) { public BubbleChat(final Context context, int ID, String message, Bitmap image, long time, boolean isIncoming, LinphoneChatMessage.State status, String url) {
view = new RelativeLayout(context); view = new RelativeLayout(context);
imageUrl = url; imageUrl = url;
textMessage = message; textMessage = message;
state = status; state = status;
id = ID; id = ID;
LayoutParams layoutParams = new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
if (isIncoming) { if (isIncoming) {
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT); layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
@ -112,12 +111,9 @@ public class BubbleChat {
view.setBackgroundResource(R.drawable.chat_bubble_outgoing); view.setBackgroundResource(R.drawable.chat_bubble_outgoing);
} }
if (previousID != -1) { layoutParams.setMargins(10, 0, 10, 0);
layoutParams.addRule(RelativeLayout.BELOW, previousID);
}
view.setId(id); view.setId(id);
layoutParams.setMargins(0, LinphoneUtils.pixelsToDpi(context.getResources(), 10), 0, 0);
view.setLayoutParams(layoutParams); view.setLayoutParams(layoutParams);
Spanned text = null; Spanned text = null;
@ -218,6 +214,7 @@ public class BubbleChat {
} else { } else {
statusView.setImageResource(R.drawable.chat_message_inprogress); statusView.setImageResource(R.drawable.chat_message_inprogress);
} }
view.invalidate(); view.invalidate();
} }