A bit of cleanup
This commit is contained in:
parent
ff5088eaa6
commit
83fffb16d2
3 changed files with 126 additions and 144 deletions
|
@ -41,6 +41,7 @@ import android.os.ParcelFileDescriptor;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.provider.MediaStore.Images;
|
import android.provider.MediaStore.Images;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
|
import android.text.Spanned;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
@ -52,6 +53,7 @@ import android.widget.EditText;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import org.linphone.compatibility.Compatibility;
|
||||||
import org.linphone.contacts.ContactsManager;
|
import org.linphone.contacts.ContactsManager;
|
||||||
import org.linphone.core.DialPlan;
|
import org.linphone.core.DialPlan;
|
||||||
import org.linphone.core.AccountCreator;
|
import org.linphone.core.AccountCreator;
|
||||||
|
@ -87,6 +89,7 @@ import java.util.Collection;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
@ -938,5 +941,33 @@ public final class LinphoneUtils {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Spanned getTextWithHttpLinks(String text) {
|
||||||
|
if (text.contains("<")) {
|
||||||
|
text = text.replace("<", "<");
|
||||||
|
}
|
||||||
|
if (text.contains(">")) {
|
||||||
|
text = text.replace(">", ">");
|
||||||
|
}
|
||||||
|
if (text.contains("\n")) {
|
||||||
|
text = text.replace("\n", "<br>");
|
||||||
|
}
|
||||||
|
if (text.contains("http://")) {
|
||||||
|
int indexHttp = text.indexOf("http://");
|
||||||
|
int indexFinHttp = text.indexOf(" ", indexHttp) == -1 ? text.length() : text.indexOf(" ", indexHttp);
|
||||||
|
String link = text.substring(indexHttp, indexFinHttp);
|
||||||
|
String linkWithoutScheme = link.replace("http://", "");
|
||||||
|
text = text.replaceFirst(Pattern.quote(link), "<a href=\"" + link + "\">" + linkWithoutScheme + "</a>");
|
||||||
|
}
|
||||||
|
if (text.contains("https://")) {
|
||||||
|
int indexHttp = text.indexOf("https://");
|
||||||
|
int indexFinHttp = text.indexOf(" ", indexHttp) == -1 ? text.length() : text.indexOf(" ", indexHttp);
|
||||||
|
String link = text.substring(indexHttp, indexFinHttp);
|
||||||
|
String linkWithoutScheme = link.replace("https://", "");
|
||||||
|
text = text.replaceFirst(Pattern.quote(link), "<a href=\"" + link + "\">" + linkWithoutScheme + "</a>");
|
||||||
|
}
|
||||||
|
|
||||||
|
return Compatibility.fromHtml(text);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,6 @@ import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
@ -290,17 +289,16 @@ public class ChatEventsAdapter extends BaseAdapter implements ChatMessageListene
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
holder.fileTransferLayout.setVisibility(View.VISIBLE);
|
holder.fileTransferLayout.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
}
|
}
|
||||||
} else if (msg != null) {
|
} else if (msg != null) { // Text message
|
||||||
text = getTextWithHttpLinks(msg);
|
text = LinphoneUtils.getTextWithHttpLinks(msg);
|
||||||
holder.messageText.setText(text);
|
holder.messageText.setText(text);
|
||||||
holder.messageText.setMovementMethod(LinkMovementMethod.getInstance());
|
holder.messageText.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
holder.messageText.setVisibility(View.VISIBLE);
|
holder.messageText.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.bubbleLayout.setLayoutParams(layoutParams);
|
holder.bubbleLayout.setLayoutParams(layoutParams);
|
||||||
} else {
|
} else { // Event is not chat message
|
||||||
holder.eventLayout.setVisibility(View.VISIBLE);
|
holder.eventLayout.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
Log.e("Conference event type is " + event.getType().toString());
|
Log.e("Conference event type is " + event.getType().toString());
|
||||||
|
@ -338,49 +336,7 @@ public class ChatEventsAdapter extends BaseAdapter implements ChatMessageListene
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isToday(Calendar cal) {
|
private void loadBitmap(String path, ImageView imageView) {
|
||||||
return isSameDay(cal, Calendar.getInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isSameDay(Calendar cal1, Calendar cal2) {
|
|
||||||
if (cal1 == null || cal2 == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA) &&
|
|
||||||
cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
|
|
||||||
cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Spanned getTextWithHttpLinks(String text) {
|
|
||||||
if (text.contains("<")) {
|
|
||||||
text = text.replace("<", "<");
|
|
||||||
}
|
|
||||||
if (text.contains(">")) {
|
|
||||||
text = text.replace(">", ">");
|
|
||||||
}
|
|
||||||
if (text.contains("\n")) {
|
|
||||||
text = text.replace("\n", "<br>");
|
|
||||||
}
|
|
||||||
if (text.contains("http://")) {
|
|
||||||
int indexHttp = text.indexOf("http://");
|
|
||||||
int indexFinHttp = text.indexOf(" ", indexHttp) == -1 ? text.length() : text.indexOf(" ", indexHttp);
|
|
||||||
String link = text.substring(indexHttp, indexFinHttp);
|
|
||||||
String linkWithoutScheme = link.replace("http://", "");
|
|
||||||
text = text.replaceFirst(Pattern.quote(link), "<a href=\"" + link + "\">" + linkWithoutScheme + "</a>");
|
|
||||||
}
|
|
||||||
if (text.contains("https://")) {
|
|
||||||
int indexHttp = text.indexOf("https://");
|
|
||||||
int indexFinHttp = text.indexOf(" ", indexHttp) == -1 ? text.length() : text.indexOf(" ", indexHttp);
|
|
||||||
String link = text.substring(indexHttp, indexFinHttp);
|
|
||||||
String linkWithoutScheme = link.replace("https://", "");
|
|
||||||
text = text.replaceFirst(Pattern.quote(link), "<a href=\"" + link + "\">" + linkWithoutScheme + "</a>");
|
|
||||||
}
|
|
||||||
|
|
||||||
return Compatibility.fromHtml(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadBitmap(String path, ImageView imageView) {
|
|
||||||
if (cancelPotentialWork(path, imageView)) {
|
if (cancelPotentialWork(path, imageView)) {
|
||||||
if (LinphoneUtils.isExtensionImage(path)) {
|
if (LinphoneUtils.isExtensionImage(path)) {
|
||||||
mDefaultBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.chat_attachment_over);
|
mDefaultBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.chat_attachment_over);
|
||||||
|
@ -395,6 +351,90 @@ public class ChatEventsAdapter extends BaseAdapter implements ChatMessageListene
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void openFile(String path) {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||||
|
File file = null;
|
||||||
|
Uri contentUri = null;
|
||||||
|
if (path.startsWith("file://")) {
|
||||||
|
path = path.substring("file://".length());
|
||||||
|
file = new File(path);
|
||||||
|
contentUri = FileProvider.getUriForFile(mContext, "org.linphone.provider", file);
|
||||||
|
} else if (path.startsWith("content://")) {
|
||||||
|
contentUri = Uri.parse(path);
|
||||||
|
} else {
|
||||||
|
file = new File(path);
|
||||||
|
contentUri = FileProvider.getUriForFile(mContext, "org.linphone.provider", file);
|
||||||
|
}
|
||||||
|
String type = null;
|
||||||
|
String extension = MimeTypeMap.getFileExtensionFromUrl(contentUri.toString());
|
||||||
|
if (extension != null) {
|
||||||
|
type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
||||||
|
}
|
||||||
|
if (type != null) {
|
||||||
|
intent.setDataAndType(contentUri, type);
|
||||||
|
} else {
|
||||||
|
intent.setDataAndType(contentUri, "*/*");
|
||||||
|
}
|
||||||
|
intent.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
|
mContext.startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void displayDownloadedFile(ChatMessage message, ChatBubbleViewHolder holder) {
|
||||||
|
String appData = message.getAppdata();
|
||||||
|
if (LinphoneUtils.isExtensionImage(appData)) {
|
||||||
|
holder.messageImage.setVisibility(View.VISIBLE);
|
||||||
|
loadBitmap(appData, holder.messageImage);
|
||||||
|
holder.messageImage.setTag(appData);
|
||||||
|
} else {
|
||||||
|
holder.openFileButton.setVisibility(View.VISIBLE);
|
||||||
|
holder.openFileButton.setTag(appData);
|
||||||
|
holder.openFileButton.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
openFile((String)v.getTag());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chat message callbacks
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFileTransferRecv(ChatMessage message, Content content, Buffer buffer) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Buffer onFileTransferSend(ChatMessage message, Content content, int offset, int size) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFileTransferProgressIndication(ChatMessage message, Content content, int offset, int total) {
|
||||||
|
ChatBubbleViewHolder holder = (ChatBubbleViewHolder)message.getUserData();
|
||||||
|
if (holder == null) return;
|
||||||
|
|
||||||
|
if (offset == total) {
|
||||||
|
holder.fileTransferProgressBar.setVisibility(View.GONE);
|
||||||
|
holder.fileTransferLayout.setVisibility(View.GONE);
|
||||||
|
displayDownloadedFile(message, holder);
|
||||||
|
} else {
|
||||||
|
holder.fileTransferProgressBar.setVisibility(View.VISIBLE);
|
||||||
|
holder.fileTransferProgressBar.setProgress(offset * 100 / total);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onMsgStateChanged(ChatMessage msg, ChatMessage.State state) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bitmap related classes and methods
|
||||||
|
*/
|
||||||
|
|
||||||
private class BitmapWorkerTask extends AsyncTask<String, Void, Bitmap> {
|
private class BitmapWorkerTask extends AsyncTask<String, Void, Bitmap> {
|
||||||
private static final int SIZE_SMALL = 500;
|
private static final int SIZE_SMALL = 500;
|
||||||
private final WeakReference<ImageView> imageViewReference;
|
private final WeakReference<ImageView> imageViewReference;
|
||||||
|
@ -527,80 +567,4 @@ public class ChatEventsAdapter extends BaseAdapter implements ChatMessageListene
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openFile(String path) {
|
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
||||||
File file = null;
|
|
||||||
Uri contentUri = null;
|
|
||||||
if (path.startsWith("file://")) {
|
|
||||||
path = path.substring("file://".length());
|
|
||||||
file = new File(path);
|
|
||||||
contentUri = FileProvider.getUriForFile(mContext, "org.linphone.provider", file);
|
|
||||||
} else if (path.startsWith("content://")) {
|
|
||||||
contentUri = Uri.parse(path);
|
|
||||||
} else {
|
|
||||||
file = new File(path);
|
|
||||||
contentUri = FileProvider.getUriForFile(mContext, "org.linphone.provider", file);
|
|
||||||
}
|
|
||||||
String type = null;
|
|
||||||
String extension = MimeTypeMap.getFileExtensionFromUrl(contentUri.toString());
|
|
||||||
if (extension != null) {
|
|
||||||
type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
|
||||||
}
|
|
||||||
if (type != null) {
|
|
||||||
intent.setDataAndType(contentUri, type);
|
|
||||||
} else {
|
|
||||||
intent.setDataAndType(contentUri, "*/*");
|
|
||||||
}
|
|
||||||
intent.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
|
|
||||||
mContext.startActivity(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void displayDownloadedFile(ChatMessage message, ChatBubbleViewHolder holder) {
|
|
||||||
String appData = message.getAppdata();
|
|
||||||
if (LinphoneUtils.isExtensionImage(appData)) {
|
|
||||||
holder.messageImage.setVisibility(View.VISIBLE);
|
|
||||||
loadBitmap(appData, holder.messageImage);
|
|
||||||
holder.messageImage.setTag(appData);
|
|
||||||
} else {
|
|
||||||
holder.openFileButton.setVisibility(View.VISIBLE);
|
|
||||||
holder.openFileButton.setTag(appData);
|
|
||||||
holder.openFileButton.setOnClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
openFile((String)v.getTag());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFileTransferRecv(ChatMessage message, Content content, Buffer buffer) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Buffer onFileTransferSend(ChatMessage message, Content content, int offset, int size) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFileTransferProgressIndication(ChatMessage message, Content content, int offset, int total) {
|
|
||||||
ChatBubbleViewHolder holder = (ChatBubbleViewHolder)message.getUserData();
|
|
||||||
if (holder == null) return;
|
|
||||||
|
|
||||||
if (offset == total) {
|
|
||||||
holder.fileTransferProgressBar.setVisibility(View.GONE);
|
|
||||||
holder.fileTransferLayout.setVisibility(View.GONE);
|
|
||||||
displayDownloadedFile(message, holder);
|
|
||||||
} else {
|
|
||||||
holder.fileTransferProgressBar.setVisibility(View.VISIBLE);
|
|
||||||
holder.fileTransferProgressBar.setProgress(offset * 100 / total);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onMsgStateChanged(ChatMessage msg, ChatMessage.State state) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ import org.linphone.core.Address;
|
||||||
import org.linphone.core.Buffer;
|
import org.linphone.core.Buffer;
|
||||||
import org.linphone.core.ChatMessage;
|
import org.linphone.core.ChatMessage;
|
||||||
import org.linphone.core.ChatMessageListener;
|
import org.linphone.core.ChatMessageListener;
|
||||||
|
import org.linphone.core.ChatMessageListenerStub;
|
||||||
import org.linphone.core.ChatRoom;
|
import org.linphone.core.ChatRoom;
|
||||||
import org.linphone.core.ChatRoomListener;
|
import org.linphone.core.ChatRoomListener;
|
||||||
import org.linphone.core.Content;
|
import org.linphone.core.Content;
|
||||||
|
@ -464,7 +465,7 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pickImage() {
|
private void pickImage() {
|
||||||
List<Intent> cameraIntents = new ArrayList<Intent>();
|
List<Intent> cameraIntents = new ArrayList<>();
|
||||||
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
||||||
File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis())+".jpeg"));
|
File file = new File(Environment.getExternalStorageDirectory(), getString(R.string.temp_photo_name_with_date).replace("%s", String.valueOf(System.currentTimeMillis())+".jpeg"));
|
||||||
mImageToUploadUri = Uri.fromFile(file);
|
mImageToUploadUri = Uri.fromFile(file);
|
||||||
|
@ -530,25 +531,7 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
||||||
private void sendMessage() {
|
private void sendMessage() {
|
||||||
String text = mMessageTextToSend.getText().toString();
|
String text = mMessageTextToSend.getText().toString();
|
||||||
ChatMessage msg = mChatRoom.createMessage(text);
|
ChatMessage msg = mChatRoom.createMessage(text);
|
||||||
msg.setListener(new ChatMessageListener() {
|
msg.setListener(new ChatMessageListenerStub() {
|
||||||
@Override
|
|
||||||
public void onFileTransferRecv(ChatMessage message, Content content, Buffer buffer) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Buffer onFileTransferSend(ChatMessage message, Content content, int offset, int size) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFileTransferProgressIndication(ChatMessage message, Content content, int offset, int total) {
|
|
||||||
ChatBubbleViewHolder holder = (ChatBubbleViewHolder) message.getUserData();
|
|
||||||
if (holder != null && message.getMessageId().equals(holder.messageId)) {
|
|
||||||
holder.fileTransferProgressBar.setProgress(offset * 100 / total);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMsgStateChanged(ChatMessage message, ChatMessage.State state) {
|
public void onMsgStateChanged(ChatMessage message, ChatMessage.State state) {
|
||||||
ChatBubbleViewHolder holder = (ChatBubbleViewHolder) message.getUserData();
|
ChatBubbleViewHolder holder = (ChatBubbleViewHolder) message.getUserData();
|
||||||
|
@ -584,6 +567,10 @@ public class GroupChatFragment extends Fragment implements ChatRoomListener, Con
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Chat room callbacks
|
||||||
|
*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChatMessageSent(ChatRoom cr, EventLog event) {
|
public void onChatMessageSent(ChatRoom cr, EventLog event) {
|
||||||
mMessagesAdapter.addToHistory(event);
|
mMessagesAdapter.addToHistory(event);
|
||||||
|
|
Loading…
Reference in a new issue