Add draft on chatFragment and opened picture in chat
This commit is contained in:
parent
43d09414ff
commit
6e05f548e9
1 changed files with 15 additions and 45 deletions
|
@ -114,7 +114,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
private List<BubbleChat> lastSentMessagesBubbles;
|
private List<BubbleChat> lastSentMessagesBubbles;
|
||||||
private HashMap<Integer, String> latestImageMessages;
|
private HashMap<Integer, String> latestImageMessages;
|
||||||
private boolean useLinphoneMessageStorage;
|
private boolean useLinphoneMessageStorage;
|
||||||
private List<Integer> openImagesId ;
|
|
||||||
private ListView messagesList;
|
private ListView messagesList;
|
||||||
|
|
||||||
private ProgressBar progressBar;
|
private ProgressBar progressBar;
|
||||||
|
@ -148,13 +147,13 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
remoteComposing.setVisibility(View.GONE);
|
remoteComposing.setVisibility(View.GONE);
|
||||||
|
|
||||||
messagesList = (ListView) view.findViewById(R.id.chatMessageList);
|
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);
|
||||||
|
|
||||||
|
@ -242,6 +241,7 @@ 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.putString("messageDraft", message.getText().toString());
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,11 +312,9 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
BubbleChat bubble;
|
BubbleChat bubble;
|
||||||
LinphoneChatMessage msg = history[position];
|
LinphoneChatMessage msg = history[position];
|
||||||
View v;
|
View v;
|
||||||
Boolean showImage = false;
|
|
||||||
|
if (msg.getExternalBodyUrl() != null ) {
|
||||||
if (msg.getExternalBodyUrl() != null ) {
|
bubble = displayImageMessage(msg.getStorageId(), null, msg.getTime(), !msg.isOutgoing(), msg.getStatus(), context, msg.getExternalBodyUrl());
|
||||||
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 {
|
} else {
|
||||||
bubble = displayMessage(msg.getStorageId(), msg.getText(), msg.getTime(), !msg.isOutgoing(), msg.getStatus(), context);
|
bubble = displayMessage(msg.getStorageId(), msg.getText(), msg.getTime(), !msg.isOutgoing(), msg.getStatus(), context);
|
||||||
|
|
||||||
|
@ -368,7 +366,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
return bubble;
|
return bubble;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BubbleChat displayImageMessage(int id, Bitmap image, long time, boolean isIncoming, LinphoneChatMessage.State status, Context context, final String url, boolean show) {
|
private BubbleChat displayImageMessage(int id, Bitmap image, long time, boolean isIncoming, LinphoneChatMessage.State status, Context context, final String url) {
|
||||||
final BubbleChat bubble = new BubbleChat(context, id, null, image, time, isIncoming, status, url);
|
final BubbleChat bubble = new BubbleChat(context, id, null, image, time, isIncoming, status, url);
|
||||||
if (!isIncoming) {
|
if (!isIncoming) {
|
||||||
if (lastSentMessagesBubbles == null)
|
if (lastSentMessagesBubbles == null)
|
||||||
|
@ -396,7 +394,6 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
String newFileUrl = saveImage(bm, finalId, getMessageForId(finalId));
|
String newFileUrl = saveImage(bm, finalId, getMessageForId(finalId));
|
||||||
bubble.updateUrl(newFileUrl);
|
bubble.updateUrl(newFileUrl);
|
||||||
adapter.refreshHistory();
|
adapter.refreshHistory();
|
||||||
openImagesId.add(finalId);
|
|
||||||
} else {
|
} else {
|
||||||
LinphoneActivity.instance().getChatStorage().saveImage(finalId, bm);
|
LinphoneActivity.instance().getChatStorage().saveImage(finalId, bm);
|
||||||
}
|
}
|
||||||
|
@ -423,26 +420,10 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else { // Show
|
} else { // Show
|
||||||
if(show){
|
Bitmap bm = BitmapFactory.decodeFile(url);
|
||||||
Bitmap bm = BitmapFactory.decodeFile(url);
|
((ImageView)v.findViewById(R.id.image)).setImageBitmap(bm);
|
||||||
((ImageView)v.findViewById(R.id.image)).setImageBitmap(bm);
|
v.findViewById(R.id.image).setVisibility(View.VISIBLE);
|
||||||
v.findViewById(R.id.image).setVisibility(View.VISIBLE);
|
v.findViewById(R.id.download).setVisibility(View.GONE);
|
||||||
v.findViewById(R.id.download).setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
bubble.setShowOrDownloadText(getString(R.string.show_image));
|
|
||||||
bubble.setShowOrDownloadImageButtonListener(new OnClickListener() {
|
|
||||||
@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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bubble;
|
return bubble;
|
||||||
|
@ -535,24 +516,15 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
latestImageMessages = null;
|
latestImageMessages = null;
|
||||||
message.removeTextChangedListener(textWatcher);
|
message.removeTextChangedListener(textWatcher);
|
||||||
removeVirtualKeyboardVisiblityListener();
|
removeVirtualKeyboardVisiblityListener();
|
||||||
|
|
||||||
LinphoneService.instance().removeMessageNotification();
|
LinphoneService.instance().removeMessageNotification();
|
||||||
|
|
||||||
if (LinphoneManager.isInstanciated())
|
if (LinphoneManager.isInstanciated())
|
||||||
LinphoneManager.getInstance().setOnComposingReceivedListener(null);
|
LinphoneManager.getInstance().setOnComposingReceivedListener(null);
|
||||||
|
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
if (!message.getText().toString().equals("") && LinphoneActivity.isInstanciated()) {
|
onSaveInstanceState(getArguments());
|
||||||
ChatStorage chatStorage = LinphoneActivity.instance().getChatStorage();
|
|
||||||
if (chatStorage.getDraft(sipUri) == null) {
|
|
||||||
chatStorage.saveDraft(sipUri, message.getText().toString());
|
|
||||||
} else {
|
|
||||||
chatStorage.updateDraft(sipUri, message.getText().toString());
|
|
||||||
}
|
|
||||||
} else if (LinphoneActivity.isInstanciated()) {
|
|
||||||
LinphoneActivity.instance().getChatStorage().deleteDraft(sipUri);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("UseSparseArrays")
|
@SuppressLint("UseSparseArrays")
|
||||||
|
@ -576,10 +548,8 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LinphoneActivity.isInstanciated()) {
|
String draft = getArguments().getString("messageDraft");
|
||||||
String draft = LinphoneActivity.instance().getChatStorage().getDraft(sipUri);
|
message.setText(draft);
|
||||||
message.setText(draft);
|
|
||||||
}
|
|
||||||
|
|
||||||
remoteComposing.setVisibility(chatRoom.isRemoteComposing() ? View.VISIBLE : View.GONE);
|
remoteComposing.setVisibility(chatRoom.isRemoteComposing() ? View.VISIBLE : View.GONE);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue