Commit 5e018acf authored by Adrien Béraud's avatar Adrien Béraud Committed by Sébastien Blin

avatar: add method to load conversation avatar without history

Change-Id: Ieb6e776407ec56613f808e01b6efe3ec8c8aa0ba
parent a1aee92d
......@@ -101,8 +101,6 @@ public abstract class JamiApplication extends Application {
DeviceRuntimeService mDeviceRuntimeService;
@Inject
ContactService mContactService;
@Inject
ConversationFacade mConversationFacade;
private JamiInjectionComponent mJamiInjectionComponent;
private final Map<String, Boolean> mPermissionsBeingAsked = new HashMap<>();;
......@@ -343,10 +341,6 @@ public abstract class JamiApplication extends Application {
return mHardwareService;
}
public ConversationFacade getFacade() {
return mConversationFacade;
}
private void setupActivityListener() {
registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
......
......@@ -54,6 +54,7 @@ import net.jami.model.Account;
import net.jami.model.AccountConfig;
import net.jami.model.Conversation;
import net.jami.services.AccountService;
import net.jami.services.ContactService;
import net.jami.services.NotificationService;
import net.jami.smartlist.SmartListViewModel;
......@@ -72,6 +73,8 @@ import cx.ring.account.AccountEditionFragment;
import cx.ring.account.AccountWizardActivity;
import cx.ring.application.JamiApplication;
import cx.ring.contactrequests.ContactRequestsFragment;
import cx.ring.services.ContactServiceImpl;
import cx.ring.utils.BitmapUtils;
import cx.ring.views.AvatarFactory;
import cx.ring.databinding.ActivityHomeBinding;
import cx.ring.fragments.ConversationFragment;
......@@ -135,9 +138,13 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
private int mOrientation;
@Inject
ContactService mContactService;
@Inject
AccountService mAccountService;
@Inject
ConversationFacade mConversationFacade;
@Inject
NotificationService mNotificationService;
private ActivityHomeBinding mBinding;
......@@ -372,12 +379,11 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
Intent intent = getIntent();
Uri uri = intent == null ? null : intent.getData();
if ((intent == null || uri == null) && fConversation == null) {
ConversationFacade facade = ((JamiApplication) getApplication()).getFacade();
Observable<List<Observable<SmartListViewModel>>> smartlist = null;
if (fContent instanceof SmartListFragment)
smartlist = facade.getSmartList(false);
smartlist = mConversationFacade.getSmartList(false);
else if (fContent instanceof ContactRequestsFragment)
smartlist = facade.getPendingList();
smartlist = mConversationFacade.getPendingList();
if (smartlist != null) {
mDisposable.add(smartlist
......@@ -774,9 +780,10 @@ public class HomeActivity extends AppCompatActivity implements BottomNavigationV
if (maxCount == 0)
maxCount = 4;
List<Future<Bitmap>> futureIcons = new ArrayList<>(Math.min(conversations.size(),maxCount));
List<Future<Bitmap>> futureIcons = new ArrayList<>(Math.min(conversations.size(), maxCount));
for (Conversation conversation : conversations) {
futureIcons.add(AvatarFactory.getBitmapAvatar(this, conversation, targetSize, false)
futureIcons.add(((ContactServiceImpl)mContactService).loadConversationAvatar(this, conversation)
.map(d -> BitmapUtils.drawableToBitmap(d, targetSize))
.subscribeOn(Schedulers.computation())
.toFuture());
if (++i == maxCount)
......
......@@ -23,6 +23,7 @@ import android.content.ContentResolver;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.provider.ContactsContract;
import android.util.Base64;
import android.util.Log;
......@@ -30,21 +31,21 @@ import android.util.LongSparseArray;
import androidx.annotation.NonNull;
import net.jami.model.Contact;
import net.jami.model.Conversation;
import net.jami.model.Phone;
import net.jami.model.Uri;
import net.jami.services.ContactService;
import net.jami.utils.Tuple;
import net.jami.utils.VCardUtils;
import java.util.HashMap;
import java.util.Map;
import javax.inject.Inject;
import cx.ring.views.AvatarFactory;
import net.jami.model.Contact;
import net.jami.model.Uri;
import cx.ring.utils.AndroidFileUtils;
import net.jami.services.ContactService;
import net.jami.utils.Tuple;
import net.jami.utils.VCardUtils;
import cx.ring.views.AvatarFactory;
import ezvcard.VCard;
import io.reactivex.Completable;
import io.reactivex.Single;
......@@ -455,4 +456,8 @@ public class ContactServiceImpl extends ContactService {
.subscribeOn(Schedulers.io());
}
public Single<Drawable> loadConversationAvatar(@NonNull Context context, @NonNull Conversation conversation) {
return getLoadedContact(conversation.getAccountId(), conversation.getContacts(), false)
.flatMap(contacts -> AvatarFactory.getAvatar(context, conversation, false));
}
}
......@@ -167,7 +167,7 @@ public abstract class ContactService {
if (contacts.isEmpty())
return Single.just(Collections.emptyList());
return Observable.fromIterable(contacts)
.flatMapSingle(contact -> getLoadedContact(accountId, contact, withPresence))
.concatMapEager(contact -> getLoadedContact(accountId, contact, withPresence).toObservable())
.toList(contacts.size());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment