2019-05-27 21:34:11 +02:00
|
|
|
package org.mercury_im.messenger.ui.chatlist;
|
|
|
|
|
2019-09-01 04:56:23 +02:00
|
|
|
import androidx.lifecycle.LiveData;
|
|
|
|
import androidx.lifecycle.MutableLiveData;
|
2019-05-27 21:34:11 +02:00
|
|
|
import androidx.lifecycle.ViewModel;
|
|
|
|
|
2019-09-01 04:56:23 +02:00
|
|
|
import org.mercury_im.messenger.MercuryImApplication;
|
2019-12-06 15:52:50 +01:00
|
|
|
import org.mercury_im.messenger.data.repository.DirectChatRepository;
|
|
|
|
import org.mercury_im.messenger.entity.chat.DirectChat;
|
2019-09-01 04:56:23 +02:00
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
2019-10-28 14:56:56 +01:00
|
|
|
import io.reactivex.disposables.CompositeDisposable;
|
|
|
|
|
2019-05-27 21:34:11 +02:00
|
|
|
public class ChatListViewModel extends ViewModel {
|
|
|
|
|
2019-09-01 04:56:23 +02:00
|
|
|
@Inject
|
2019-12-06 15:52:50 +01:00
|
|
|
DirectChatRepository chatRepository;
|
2019-09-02 01:06:17 +02:00
|
|
|
|
2019-09-01 04:56:23 +02:00
|
|
|
private CompositeDisposable disposable = new CompositeDisposable();
|
|
|
|
|
2019-12-06 15:52:50 +01:00
|
|
|
private final MutableLiveData<List<DirectChat>> chats = new MutableLiveData<>();
|
2019-09-01 04:56:23 +02:00
|
|
|
|
|
|
|
public ChatListViewModel() {
|
|
|
|
MercuryImApplication.getApplication().getAppComponent().inject(this);
|
|
|
|
|
2019-12-06 15:52:50 +01:00
|
|
|
disposable.add(chatRepository.observeAllDirectChats()
|
|
|
|
.subscribe(chats::setValue));
|
2019-09-01 04:56:23 +02:00
|
|
|
}
|
|
|
|
|
2019-12-06 15:52:50 +01:00
|
|
|
public LiveData<List<DirectChat>> getChats() {
|
2019-09-01 04:56:23 +02:00
|
|
|
return chats;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onCleared() {
|
|
|
|
super.onCleared();
|
|
|
|
disposable.dispose();
|
|
|
|
}
|
2019-05-27 21:34:11 +02:00
|
|
|
}
|