Using glide to display images in chat
This commit is contained in:
parent
a3c14faeb0
commit
25d4c1b430
3 changed files with 8 additions and 33 deletions
|
@ -144,6 +144,8 @@ dependencies {
|
||||||
implementation 'androidx.appcompat:appcompat:1.0.2'
|
implementation 'androidx.appcompat:appcompat:1.0.2'
|
||||||
implementation 'com.google.android.material:material:1.1.0-alpha02'
|
implementation 'com.google.android.material:material:1.1.0-alpha02'
|
||||||
implementation 'com.google.android:flexbox:1.1.0'
|
implementation 'com.google.android:flexbox:1.1.0'
|
||||||
|
implementation 'com.github.bumptech.glide:glide:4.9.0'
|
||||||
|
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
|
||||||
|
|
||||||
if (isLocalAarAvailable()) {
|
if (isLocalAarAvailable()) {
|
||||||
implementation project(":linphone-sdk-android")
|
implementation project(":linphone-sdk-android")
|
||||||
|
|
|
@ -25,8 +25,6 @@ import android.Manifest;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
|
@ -42,6 +40,7 @@ import android.widget.RelativeLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import androidx.core.content.FileProvider;
|
import androidx.core.content.FileProvider;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import com.bumptech.glide.Glide;
|
||||||
import com.google.android.flexbox.FlexboxLayout;
|
import com.google.android.flexbox.FlexboxLayout;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -57,8 +56,6 @@ import org.linphone.core.tools.Log;
|
||||||
import org.linphone.utils.FileUtils;
|
import org.linphone.utils.FileUtils;
|
||||||
import org.linphone.utils.ImageUtils;
|
import org.linphone.utils.ImageUtils;
|
||||||
import org.linphone.utils.LinphoneUtils;
|
import org.linphone.utils.LinphoneUtils;
|
||||||
import org.linphone.views.AsyncBitmap;
|
|
||||||
import org.linphone.views.BitmapWorkerTask;
|
|
||||||
import org.linphone.views.ContactAvatar;
|
import org.linphone.views.ContactAvatar;
|
||||||
|
|
||||||
public class ChatMessageViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
public class ChatMessageViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||||
|
@ -347,32 +344,6 @@ public class ChatMessageViewHolder extends RecyclerView.ViewHolder implements Vi
|
||||||
}
|
}
|
||||||
|
|
||||||
private void loadBitmap(String path, ImageView imageView) {
|
private void loadBitmap(String path, ImageView imageView) {
|
||||||
if (cancelPotentialWork(path, imageView)) {
|
Glide.with(mContext).load(path).into(imageView);
|
||||||
Bitmap defaultBitmap =
|
|
||||||
BitmapFactory.decodeResource(mContext.getResources(), R.drawable.chat_file);
|
|
||||||
BitmapWorkerTask task = new BitmapWorkerTask(mContext, imageView, defaultBitmap);
|
|
||||||
final AsyncBitmap asyncBitmap =
|
|
||||||
new AsyncBitmap(mContext.getResources(), defaultBitmap, task);
|
|
||||||
imageView.setImageDrawable(asyncBitmap);
|
|
||||||
task.execute(path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean cancelPotentialWork(String path, ImageView imageView) {
|
|
||||||
final BitmapWorkerTask bitmapWorkerTask = BitmapWorkerTask.getBitmapWorkerTask(imageView);
|
|
||||||
|
|
||||||
if (bitmapWorkerTask != null) {
|
|
||||||
final String bitmapData = bitmapWorkerTask.path;
|
|
||||||
// If bitmapData is not yet set or it differs from the new data
|
|
||||||
if (bitmapData == null || !bitmapData.equals(path)) {
|
|
||||||
// Cancel previous task
|
|
||||||
bitmapWorkerTask.cancel(true);
|
|
||||||
} else {
|
|
||||||
// The same work is already in progress
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// No task associated with the ImageView, or an existing task was cancelled
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/image"
|
android:id="@+id/image"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="100dp"
|
android:layout_height="wrap_content"
|
||||||
|
android:maxHeight="100dp"
|
||||||
android:layout_margin="5dp"
|
android:layout_margin="5dp"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
@ -14,7 +15,8 @@
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/bigImage"
|
android:id="@+id/bigImage"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="300dp"
|
android:layout_height="wrap_content"
|
||||||
|
android:maxHeight="300dp"
|
||||||
android:layout_margin="5dp"
|
android:layout_margin="5dp"
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
android:visibility="gone" />
|
android:visibility="gone" />
|
||||||
|
|
Loading…
Reference in a new issue