Clicking on a chat image will show it in the Gallery + don't display images by default, instead add a Show button
This commit is contained in:
parent
5ed2e63ca0
commit
3ff74418e9
4 changed files with 74 additions and 37 deletions
|
@ -373,6 +373,7 @@
|
|||
|
||||
<string name="pref_background_mode">Actif en arrière plan</string>
|
||||
|
||||
<string name="show_image">Afficher</string>
|
||||
<string name="download_image">Télécharger</string>
|
||||
<string name="download_image_failed">Téléchargement échoué. Vérifiez votre connexion internet ou reéssayez plus tard.</string>
|
||||
|
||||
|
|
|
@ -421,6 +421,7 @@
|
|||
|
||||
<string name="pref_background_mode">Background mode</string>
|
||||
|
||||
<string name="show_image">Show</string>
|
||||
<string name="download_image">Download</string>
|
||||
<string name="download_image_failed">Download failed. Please check your internet access or try again later.</string>
|
||||
|
||||
|
|
|
@ -288,11 +288,11 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
LinphoneChatMessage[] history = chatRoom.getHistory();
|
||||
for (int i = 0; i < history.length; i++) {
|
||||
LinphoneChatMessage msg = history[i];
|
||||
boolean show = i >= history.length - messagesFilterLimit;
|
||||
if (msg.getExternalBodyUrl() != null) {
|
||||
Bitmap bm = BitmapFactory.decodeFile(msg.getExternalBodyUrl());
|
||||
displayImageMessage(msg.getStorageId(), bm, msg.getTime(), !msg.isOutgoing(), msg.getStatus(), messagesLayout, msg.getExternalBodyUrl(), i >= history.length - messagesFilterLimit);
|
||||
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, i >= history.length - messagesFilterLimit);
|
||||
displayMessage(msg.getStorageId(), msg.getText(), msg.getTime(), !msg.isOutgoing(), msg.getStatus(), messagesLayout, show);
|
||||
}
|
||||
}
|
||||
messagesArePresentButHidden = true;
|
||||
|
@ -375,7 +375,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
|
||||
private void 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, previousMessageID);
|
||||
BubbleChat bubble = new BubbleChat(layout.getContext(), id, message, null, time, isIncoming, status, null, previousMessageID);
|
||||
if (!isIncoming) {
|
||||
lastSentMessageBubble = bubble;
|
||||
}
|
||||
|
@ -395,14 +395,17 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
|
||||
private void displayImageMessage(int id, Bitmap image, long time, boolean isIncoming, LinphoneChatMessage.State status, RelativeLayout layout, final String url, boolean show) {
|
||||
id = checkId(id);
|
||||
BubbleChat bubble = new BubbleChat(layout.getContext(), id, null, image, time, isIncoming, status, previousMessageID);
|
||||
BubbleChat bubble = new BubbleChat(layout.getContext(), id, null, image, time, isIncoming, status, url, previousMessageID);
|
||||
if (!isIncoming) {
|
||||
lastSentMessageBubble = bubble;
|
||||
}
|
||||
|
||||
final View v = bubble.getView();
|
||||
final int finalId = id;
|
||||
bubble.setDownloadImageButtonListener(new OnClickListener() {
|
||||
|
||||
if (url.startsWith("http")) { // Download
|
||||
bubble.setShowOrDownloadText(getString(R.string.download_image));
|
||||
bubble.setShowOrDownloadImageButtonListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
new Thread(new Runnable() {
|
||||
|
@ -435,6 +438,20 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
}).start();
|
||||
}
|
||||
});
|
||||
} else { // Show
|
||||
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) {
|
||||
((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);
|
||||
|
@ -657,7 +674,7 @@ public class ChatFragment extends Fragment implements OnClickListener, LinphoneC
|
|||
mHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
displayImageMessage(id, fbm, message.getTime(), true, null, messagesLayout, fbm == null ? "" : message.getExternalBodyUrl());
|
||||
displayImageMessage(id, fbm, message.getTime(), true, null, messagesLayout, message.getExternalBodyUrl());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -28,8 +28,10 @@ import org.linphone.core.LinphoneChatMessage;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.net.Uri;
|
||||
import android.text.Html;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
|
@ -87,7 +89,7 @@ public class BubbleChat {
|
|||
private ImageView statusView;
|
||||
private Button download;
|
||||
|
||||
public BubbleChat(Context context, int id, String message, Bitmap image, long time, boolean isIncoming, LinphoneChatMessage.State status, int previousID) {
|
||||
public BubbleChat(final Context context, int id, String message, Bitmap image, long time, boolean isIncoming, LinphoneChatMessage.State status, final String url, int previousID) {
|
||||
view = new RelativeLayout(context);
|
||||
|
||||
LayoutParams layoutParams = new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
|
||||
|
@ -148,6 +150,16 @@ public class BubbleChat {
|
|||
} else if (imageView != null) {
|
||||
imageView.setVisibility(View.GONE);
|
||||
}
|
||||
if (imageView != null) {
|
||||
imageView.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setDataAndType(Uri.parse("file://" + url), "image/*");
|
||||
context.startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
download = (Button) layout.findViewById(R.id.download);
|
||||
if (download != null && image == null && message == null) {
|
||||
|
@ -272,9 +284,15 @@ public class BubbleChat {
|
|||
return Html.fromHtml(text);
|
||||
}
|
||||
|
||||
public void setDownloadImageButtonListener(OnClickListener onClickListener) {
|
||||
public void setShowOrDownloadImageButtonListener(OnClickListener onClickListener) {
|
||||
if (download != null) {
|
||||
download.setOnClickListener(onClickListener);
|
||||
}
|
||||
}
|
||||
|
||||
public void setShowOrDownloadText(String buttonName) {
|
||||
if (download != null) {
|
||||
download.setText(buttonName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue