mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
less db queries for avatars
This commit is contained in:
@@ -2,13 +2,15 @@ package org.thoughtcrime.securesms.contacts.avatars;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.b44t.messenger.DcChat;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
|
||||
public class GroupRecordContactPhoto extends LocalFileContactPhoto {
|
||||
|
||||
public GroupRecordContactPhoto(Context context, Address address) {
|
||||
super(context, address);
|
||||
public GroupRecordContactPhoto(Context context, Address address, DcChat dcChat) {
|
||||
super(context, address, dcChat, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -23,7 +25,7 @@ public class GroupRecordContactPhoto extends LocalFileContactPhoto {
|
||||
|
||||
@Override
|
||||
public String getPath(Context context) {
|
||||
String profileImage = DcHelper.getContext(context).getChat(getId()).getProfileImage();
|
||||
String profileImage = dcChat.getProfileImage();
|
||||
return profileImage != null ? profileImage : "";
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,9 @@ import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.b44t.messenger.DcChat;
|
||||
import com.b44t.messenger.DcContact;
|
||||
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.profiles.AvatarHelper;
|
||||
import org.thoughtcrime.securesms.util.Conversions;
|
||||
@@ -17,13 +20,17 @@ import java.security.MessageDigest;
|
||||
public abstract class LocalFileContactPhoto implements ContactPhoto {
|
||||
|
||||
final Address address;
|
||||
final DcChat dcChat;
|
||||
final DcContact dcContact;
|
||||
|
||||
private final int id;
|
||||
|
||||
private final String path;
|
||||
|
||||
LocalFileContactPhoto(Context context, Address address) {
|
||||
LocalFileContactPhoto(Context context, Address address, DcChat dcChat, DcContact dcContact) {
|
||||
this.address = address;
|
||||
this.dcChat = dcChat;
|
||||
this.dcContact = dcContact;
|
||||
id = getId();
|
||||
path = getPath(context);
|
||||
}
|
||||
|
||||
@@ -2,13 +2,15 @@ package org.thoughtcrime.securesms.contacts.avatars;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.b44t.messenger.DcContact;
|
||||
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
|
||||
public class ProfileContactPhoto extends LocalFileContactPhoto {
|
||||
|
||||
public ProfileContactPhoto(Context context, Address address) {
|
||||
super(context, address);
|
||||
public ProfileContactPhoto(Context context, Address address, DcContact dcContact) {
|
||||
super(context, address, null, dcContact);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -23,7 +25,7 @@ public class ProfileContactPhoto extends LocalFileContactPhoto {
|
||||
|
||||
@Override
|
||||
public String getPath(Context context) {
|
||||
String profileImage = DcHelper.getContext(context).getContact(getId()).getProfileImage();
|
||||
String profileImage = dcContact.getProfileImage();
|
||||
return profileImage != null ? profileImage : "";
|
||||
}
|
||||
|
||||
|
||||
@@ -215,10 +215,10 @@ public class Recipient {
|
||||
public synchronized @Nullable ContactPhoto getContactPhoto(Context context) {
|
||||
LocalFileContactPhoto contactPhoto = null;
|
||||
if (dcChat!=null) {
|
||||
contactPhoto = new GroupRecordContactPhoto(context, address);
|
||||
contactPhoto = new GroupRecordContactPhoto(context, address, dcChat);
|
||||
}
|
||||
else if (dcContact!=null) {
|
||||
contactPhoto = new ProfileContactPhoto(context, address);
|
||||
contactPhoto = new ProfileContactPhoto(context, address, dcContact);
|
||||
}
|
||||
|
||||
if (contactPhoto!=null) {
|
||||
|
||||
Reference in New Issue
Block a user