Displaying pictures (todo: add back async loading)
This commit is contained in:
parent
6d9339b463
commit
b9e424a2de
6 changed files with 103 additions and 28 deletions
|
@ -113,6 +113,8 @@ dependencies {
|
|||
implementation 'androidx.recyclerview:recyclerview:1.0.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.0.2'
|
||||
implementation 'com.google.android.material:material:1.1.0-alpha01'
|
||||
implementation 'com.google.android:flexbox:1.1.0'
|
||||
|
||||
if (isLocalAarAvailable()) {
|
||||
implementation project(":linphone-sdk-android")
|
||||
} else {
|
||||
|
|
|
@ -20,10 +20,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|||
package org.linphone.chat;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.core.content.FileProvider;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.text.Spanned;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.webkit.MimeTypeMap;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
|
@ -31,20 +38,27 @@ import android.widget.ProgressBar;
|
|||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.flexbox.FlexboxLayout;
|
||||
|
||||
import org.linphone.R;
|
||||
import org.linphone.contacts.ContactsManager;
|
||||
import org.linphone.contacts.LinphoneContact;
|
||||
import org.linphone.core.Address;
|
||||
import org.linphone.core.ChatMessage;
|
||||
import org.linphone.core.Content;
|
||||
import org.linphone.utils.FileUtils;
|
||||
import org.linphone.utils.LinphoneUtils;
|
||||
import org.linphone.views.ContactAvatar;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION;
|
||||
|
||||
public class ChatMessageViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||
public Context mContext;
|
||||
private Context mContext;
|
||||
|
||||
public ChatMessage message;
|
||||
|
||||
public LinearLayout eventLayout;
|
||||
|
@ -63,6 +77,8 @@ public class ChatMessageViewHolder extends RecyclerView.ViewHolder implements Vi
|
|||
public ImageView outgoingImdn;
|
||||
public TextView messageText;
|
||||
|
||||
public FlexboxLayout pictures;
|
||||
|
||||
public CheckBox delete;
|
||||
private ClickListener mListener;
|
||||
|
||||
|
@ -91,6 +107,8 @@ public class ChatMessageViewHolder extends RecyclerView.ViewHolder implements Vi
|
|||
outgoingImdn = view.findViewById(R.id.imdn);
|
||||
messageText = view.findViewById(R.id.message);
|
||||
|
||||
pictures = view.findViewById(R.id.pictures);
|
||||
|
||||
delete = view.findViewById(R.id.delete_message);
|
||||
}
|
||||
|
||||
|
@ -115,6 +133,8 @@ public class ChatMessageViewHolder extends RecyclerView.ViewHolder implements Vi
|
|||
outgoingImdn.setVisibility(View.GONE);
|
||||
avatarLayout.setVisibility(View.GONE);
|
||||
sendInProgress.setVisibility(View.GONE);
|
||||
pictures.setVisibility(View.GONE);
|
||||
pictures.removeAllViews();
|
||||
|
||||
ChatMessage.State status = message.getState();
|
||||
Address remoteSender = message.getFromAddress();
|
||||
|
@ -183,5 +203,65 @@ public class ChatMessageViewHolder extends RecyclerView.ViewHolder implements Vi
|
|||
fileContents.add(c);
|
||||
}
|
||||
}
|
||||
|
||||
if (fileContents.size() > 0) {
|
||||
pictures.setVisibility(View.VISIBLE);
|
||||
for (Content c : fileContents) {
|
||||
if (c.isFile()) {
|
||||
String filePath = c.getFilePath();
|
||||
View content = LayoutInflater.from(mContext).inflate(R.layout.chat_bubble_content, null, false);
|
||||
|
||||
if (FileUtils.isExtensionImage(filePath)) {
|
||||
ImageView iv = content.findViewById(R.id.image);
|
||||
iv.setImageURI(Uri.parse(c.getFilePath()));
|
||||
iv.setTag(c.getFilePath());
|
||||
iv.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
openFile((String) v.getTag());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
//TODO: display file name and extension ?
|
||||
}
|
||||
pictures.addView(content);
|
||||
} else {
|
||||
//TODO: download button if incoming
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void openFile(String path) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
File file;
|
||||
Uri contentUri;
|
||||
if (path.startsWith("file://")) {
|
||||
path = path.substring("file://".length());
|
||||
file = new File(path);
|
||||
contentUri = FileProvider.getUriForFile(mContext, mContext.getResources().getString(R.string.file_provider), file);
|
||||
} else if (path.startsWith("content://")) {
|
||||
contentUri = Uri.parse(path);
|
||||
} else {
|
||||
file = new File(path);
|
||||
try {
|
||||
contentUri = FileProvider.getUriForFile(mContext, mContext.getResources().getString(R.string.file_provider), file);
|
||||
} catch (Exception e) {
|
||||
contentUri = Uri.parse(path);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -207,6 +207,7 @@ public class ChatMessagesAdapter extends SelectableAdapter<ChatMessageViewHolder
|
|||
public void addToHistory(EventLog log) {
|
||||
mHistory.add(0, log);
|
||||
notifyItemInserted(0);
|
||||
notifyItemChanged(1); // Update second to last item just in case for grouping purposes
|
||||
}
|
||||
|
||||
public void addAllToHistory(ArrayList<EventLog> logs) {
|
||||
|
|
|
@ -107,8 +107,17 @@
|
|||
android:background="@drawable/chat_bubble_outgoing_full"
|
||||
android:layout_below="@+id/time"
|
||||
android:layout_toLeftOf="@+id/imdn"
|
||||
android:paddingBottom="10dp"
|
||||
android:paddingTop="10dp">
|
||||
android:paddingBottom="5dp"
|
||||
android:paddingTop="5dp">
|
||||
|
||||
<com.google.android.flexbox.FlexboxLayout
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/pictures"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginRight="5dp"
|
||||
app:flexWrap="wrap"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/message"
|
||||
|
@ -116,7 +125,10 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:textAppearance="@style/chat_bubble_message_font"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"/>
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_below="@id/pictures"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
|
|
@ -2,34 +2,12 @@
|
|||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/file"
|
||||
android:textAlignment="center"
|
||||
android:gravity="center"
|
||||
style="@style/chat_bubble_file_name_font"
|
||||
android:background="@color/colorN"
|
||||
android:ellipsize="end"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="75dp"/>
|
||||
android:padding="5dp">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:adjustViewBounds="true"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="75dp"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/download"
|
||||
android:text="Download"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/fileTransferInProgress"
|
||||
android:layout_width="75dp"
|
||||
android:layout_height="75dp"
|
||||
android:indeterminate="true"/>
|
||||
android:layout_height="100dp"/>
|
||||
|
||||
</RelativeLayout>
|
|
@ -5,3 +5,5 @@ RELEASE_KEY_ALIAS=
|
|||
RELEASE_KEY_PASSWORD=
|
||||
#source:https://docs.gradle.org/current/userguide/build_environment.html#sec:configuring_jvm_memory
|
||||
org.gradle.jvmargs=-Xmx2g -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
||||
android.useAndroidX=true
|
||||
android.enableJetifier=true
|
||||
|
|
Loading…
Reference in a new issue