mirror of
https://codeberg.org/Mercury-IM/Mercury-IM
synced 2024-06-16 00:24:51 +02:00
Make the code compile again.
This commit is contained in:
parent
c5bf492cda
commit
c2b1d794b7
|
@ -73,6 +73,7 @@ check.configure {
|
|||
dependencies {
|
||||
|
||||
// Depend on the core project for XMPP related stuff
|
||||
implementation project(":entity")
|
||||
implementation project(":domain")
|
||||
implementation project(":data")
|
||||
|
||||
|
|
|
@ -9,7 +9,9 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
|
||||
import org.mercury_im.messenger.data.di.RepositoryModule;
|
||||
import org.mercury_im.messenger.di.component.AppComponent;
|
||||
import org.mercury_im.messenger.di.component.DaggerAppComponent;
|
||||
import org.mercury_im.messenger.di.module.AppModule;
|
||||
import org.mercury_im.messenger.service.XmppConnectionService;
|
||||
import org.mercury_im.messenger.util.AbstractActivityLifecycleCallbacks;
|
||||
|
@ -24,7 +26,7 @@ public class MercuryImApplication extends Application {
|
|||
|
||||
static {
|
||||
// Initialize Smack etc.
|
||||
new MercuryConfiguration();
|
||||
// new MercuryConfiguration();
|
||||
}
|
||||
|
||||
private static MercuryImApplication INSTANCE;
|
||||
|
@ -70,6 +72,7 @@ public class MercuryImApplication extends Application {
|
|||
public AppComponent createAppComponent() {
|
||||
AppComponent appComponent = DaggerAppComponent.builder()
|
||||
.appModule(new AppModule(this))
|
||||
.repositoryModule(new RepositoryModule())
|
||||
.build();
|
||||
|
||||
appComponent.inject(this);
|
||||
|
|
|
@ -7,7 +7,7 @@ import android.content.Intent;
|
|||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
|
||||
import org.mercury_im.messenger.entity.chat.Chat;
|
||||
import org.mercury_im.messenger.entity.chat.DirectChat;
|
||||
import org.mercury_im.messenger.ui.chat.ChatActivity;
|
||||
|
||||
public class Notifications {
|
||||
|
@ -20,13 +20,13 @@ public class Notifications {
|
|||
// Notification IDs
|
||||
public static final int FOREGROUND_SERVICE_ID = 1; // must not be 0
|
||||
|
||||
public static int chatMessageReceived(Context context, Chat chat, String contactName, String body) {
|
||||
public static int directChatMessageReceived(Context context, DirectChat chat, String contactName, String body) {
|
||||
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context);
|
||||
int id = (int) chat.getId();
|
||||
|
||||
Intent tapAction = new Intent(context, ChatActivity.class);
|
||||
tapAction.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
tapAction.putExtra(ChatActivity.EXTRA_JID, chat.getPeer().getJid().toString());
|
||||
tapAction.putExtra(ChatActivity.EXTRA_JID, chat.getPeer().getAddress());
|
||||
tapAction.putExtra(ChatActivity.EXTRA_ACCOUNT, chat.getPeer().getAccount().getId());
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, tapAction, 0);
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.mercury_im.messenger.di.component;
|
||||
|
||||
import org.mercury_im.messenger.MercuryImApplication;
|
||||
import org.mercury_im.messenger.data.di.RepositoryModule;
|
||||
import org.mercury_im.messenger.di.module.AndroidPersistenceModule;
|
||||
import org.mercury_im.messenger.di.module.AppModule;
|
||||
import org.mercury_im.messenger.service.XmppConnectionService;
|
||||
|
@ -31,6 +32,16 @@ import dagger.Component;
|
|||
})
|
||||
public interface AppComponent {
|
||||
|
||||
@Component.Builder
|
||||
interface Builder {
|
||||
|
||||
AppComponent build();
|
||||
|
||||
Builder appModule(AppModule appModule);
|
||||
|
||||
Builder repositoryModule(RepositoryModule module);
|
||||
}
|
||||
|
||||
// Application
|
||||
|
||||
void inject(MercuryImApplication mercuryImApplication);
|
||||
|
|
|
@ -2,9 +2,9 @@ package org.mercury_im.messenger.di.module;
|
|||
|
||||
import android.app.Application;
|
||||
|
||||
import org.mercury_im.messenger.data.model.Models;
|
||||
import org.mercury_im.messenger.util.ThreadUtils;
|
||||
import org.mercury_im.messenger.BuildConfig;
|
||||
import org.mercury_im.messenger.xmpp.model.Models;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
|
|
@ -16,6 +16,7 @@ import com.google.android.material.navigation.NavigationView;
|
|||
import org.mercury_im.messenger.MercuryImApplication;
|
||||
import org.mercury_im.messenger.R;
|
||||
import org.mercury_im.messenger.data.model.AccountModel;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.ui.chatlist.ChatListFragment;
|
||||
import org.mercury_im.messenger.ui.login.AccountsFragment;
|
||||
import org.mercury_im.messenger.ui.roster.RosterFragment;
|
||||
|
@ -30,9 +31,6 @@ public class MainActivity extends AppCompatActivity
|
|||
implements NavigationView.OnNavigationItemSelectedListener,
|
||||
AccountsFragment.OnAccountListItemClickListener {
|
||||
|
||||
@Inject
|
||||
ChatRepository chatRepository;
|
||||
|
||||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
|
||||
|
@ -97,12 +95,12 @@ public class MainActivity extends AppCompatActivity
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onAccountListItemClick(AccountModel item) {
|
||||
public void onAccountListItemClick(Account item) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccountListItemLongClick(AccountModel item) {
|
||||
public void onAccountListItemLongClick(Account item) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,25 +14,15 @@ import androidx.lifecycle.ViewModelProvider;
|
|||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.chat2.ChatManager;
|
||||
import org.jxmpp.jid.EntityBareJid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
|
||||
import org.mercury_im.messenger.MercuryImApplication;
|
||||
import org.mercury_im.messenger.R;
|
||||
import org.mercury_im.messenger.core.centers.ConnectionCenter;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public class ChatActivity extends AppCompatActivity
|
||||
implements ChatInputFragment.OnChatInputActionListener, SearchView.OnQueryTextListener {
|
||||
|
@ -40,18 +30,12 @@ public class ChatActivity extends AppCompatActivity
|
|||
public static final String EXTRA_JID = "JID";
|
||||
public static final String EXTRA_ACCOUNT = "ACCOUNT";
|
||||
|
||||
@Inject
|
||||
ConnectionCenter connectionCenter;
|
||||
|
||||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
|
||||
@BindView(R.id.recyclerView)
|
||||
RecyclerView recyclerView;
|
||||
|
||||
@Inject
|
||||
ChatRepository chatRepository;
|
||||
|
||||
private final MessagesRecyclerViewAdapter recyclerViewAdapter = new MessagesRecyclerViewAdapter();
|
||||
|
||||
private ChatViewModel chatViewModel;
|
||||
|
@ -186,6 +170,7 @@ public class ChatActivity extends AppCompatActivity
|
|||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
// TODO: Improve by using rx
|
||||
new Thread() {
|
||||
@Override
|
||||
|
@ -200,6 +185,8 @@ public class ChatActivity extends AppCompatActivity
|
|||
}
|
||||
}
|
||||
}.start();
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,12 +6,11 @@ import androidx.lifecycle.ViewModel;
|
|||
|
||||
import org.jxmpp.jid.EntityBareJid;
|
||||
import org.mercury_im.messenger.MercuryImApplication;
|
||||
import org.mercury_im.messenger.core.centers.ConnectionCenter;
|
||||
import org.mercury_im.messenger.xmpp.model.ChatModel;
|
||||
import org.mercury_im.messenger.xmpp.model.ContactModel;
|
||||
import org.mercury_im.messenger.xmpp.model.EntityModel;
|
||||
import org.mercury_im.messenger.xmpp.model.MessageModel;
|
||||
import org.mercury_im.messenger.data.repository.XmppPeerRepository;
|
||||
import org.mercury_im.messenger.data.repository.DirectChatRepository;
|
||||
import org.mercury_im.messenger.data.repository.PeerRepository;
|
||||
import org.mercury_im.messenger.entity.chat.DirectChat;
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
import org.mercury_im.messenger.entity.message.Message;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -26,22 +25,15 @@ public class ChatViewModel extends ViewModel {
|
|||
private final CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
@Inject
|
||||
MessageRepository messageRepository;
|
||||
PeerRepository contactRepository;
|
||||
|
||||
@Inject
|
||||
XmppPeerRepository xmppContactRepository;
|
||||
DirectChatRepository chatRepository;
|
||||
|
||||
@Inject
|
||||
ChatRepository chatRepository;
|
||||
|
||||
@Inject
|
||||
ConnectionCenter connectionCenter;
|
||||
|
||||
private MutableLiveData<EntityModel> entity = new MutableLiveData<>();
|
||||
private MutableLiveData<ContactModel> contact = new MutableLiveData<>();
|
||||
private MutableLiveData<List<MessageModel>> messages = new MutableLiveData<>();
|
||||
private MutableLiveData<Peer> contact = new MutableLiveData<>();
|
||||
private MutableLiveData<List<Message>> messages = new MutableLiveData<>();
|
||||
private MutableLiveData<String> contactDisplayName = new MutableLiveData<>();
|
||||
private MutableLiveData<ChatModel> chat = new MutableLiveData<>();
|
||||
private MutableLiveData<DirectChat> chat = new MutableLiveData<>();
|
||||
|
||||
public ChatViewModel() {
|
||||
super();
|
||||
|
@ -49,24 +41,25 @@ public class ChatViewModel extends ViewModel {
|
|||
}
|
||||
|
||||
public void init(long accountId, EntityBareJid jid) {
|
||||
disposable.add(xmppContactRepository.getOrCreateEntity(accountId, jid)
|
||||
.subscribe((Consumer<EntityModel>) this::init));
|
||||
disposable.add(contactRepository.getOrCreatePeer(accountId, jid.toString())
|
||||
.subscribe((Consumer<Peer>) this::init));
|
||||
}
|
||||
|
||||
public void init(EntityModel entityModel) {
|
||||
public void init(Peer peer) {
|
||||
disposable.add(chatRepository.getOrCreateChatWithPeer(peer)
|
||||
.subscribe((Consumer<DirectChat>) this::init));
|
||||
}
|
||||
|
||||
disposable.add(xmppContactRepository.getContact(entityModel.getAccount().getId(), entityModel.getJid())
|
||||
.subscribe(reactiveResult -> {
|
||||
ContactModel model = reactiveResult.first();
|
||||
ChatViewModel.this.contact.setValue(model);
|
||||
contactDisplayName.setValue(model.getRostername());
|
||||
}));
|
||||
public void init(DirectChat chat) {
|
||||
this.chat.setValue(chat);
|
||||
|
||||
disposable.add(messageRepository.getAllMessagesOfEntity(entityModel)
|
||||
.subscribe(reactiveResult -> {
|
||||
List<MessageModel> messages = reactiveResult.toList();
|
||||
ChatViewModel.this.messages.setValue(messages);
|
||||
}));
|
||||
// Subscribe peer
|
||||
disposable.add(contactRepository.observePeer(chat.getPeer().getId())
|
||||
.subscribe(peer -> contactDisplayName.setValue(peer.getItem().getName())));
|
||||
|
||||
// Subscribe messages
|
||||
disposable.add(chatRepository.observeMessages(chat)
|
||||
.subscribe(ChatViewModel.this.messages::setValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -75,11 +68,11 @@ public class ChatViewModel extends ViewModel {
|
|||
disposable.clear();
|
||||
}
|
||||
|
||||
public LiveData<List<MessageModel>> getMessages() {
|
||||
public LiveData<List<Message>> getMessages() {
|
||||
return messages;
|
||||
}
|
||||
|
||||
public LiveData<ContactModel> getContact() {
|
||||
public LiveData<Peer> getContact() {
|
||||
return contact;
|
||||
}
|
||||
|
||||
|
@ -107,6 +100,7 @@ public class ChatViewModel extends ViewModel {
|
|||
}
|
||||
|
||||
public Completable requestMamMessages() {
|
||||
/*
|
||||
return Completable.fromAction(() -> {
|
||||
ChatModel chatModel = ChatViewModel.this.chat.getValue();
|
||||
if (chatModel == null) {
|
||||
|
@ -115,5 +109,7 @@ public class ChatViewModel extends ViewModel {
|
|||
connectionCenter.requestMamMessagesFor(chatModel);
|
||||
});
|
||||
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@ import androidx.annotation.NonNull;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.mercury_im.messenger.R;
|
||||
import org.mercury_im.messenger.xmpp.model.MessageModel;
|
||||
import org.mercury_im.messenger.entity.message.Message;
|
||||
import org.mercury_im.messenger.entity.message.content.TextMessageContent;
|
||||
import org.mercury_im.messenger.ui.util.MessageBackgroundDrawable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -18,14 +19,14 @@ import java.util.List;
|
|||
|
||||
public class MessagesRecyclerViewAdapter extends RecyclerView.Adapter<MessagesRecyclerViewAdapter.MessageViewHolder> {
|
||||
|
||||
private List<MessageModel> messages = new ArrayList<>();
|
||||
private List<Message> messages = new ArrayList<>();
|
||||
private SparseArray<Boolean> checkedItems = new SparseArray<>();
|
||||
|
||||
public MessagesRecyclerViewAdapter() {
|
||||
|
||||
}
|
||||
|
||||
public void updateMessages(List<MessageModel> messages) {
|
||||
public void updateMessages(List<Message> messages) {
|
||||
this.messages.clear();
|
||||
this.messages.addAll(messages);
|
||||
notifyDataSetChanged();
|
||||
|
@ -47,24 +48,24 @@ public class MessagesRecyclerViewAdapter extends RecyclerView.Adapter<MessagesRe
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MessageViewHolder holder, int position) {
|
||||
MessageModel message = messages.get(position);
|
||||
Message message = messages.get(position);
|
||||
MessageBackgroundDrawable background = getBackgroundDrawable(position);
|
||||
if (message.isIncoming()) {
|
||||
// if (message.isIncoming()) {
|
||||
holder.body.setBackgroundResource(background.getIncomingDrawable());
|
||||
} else {
|
||||
holder.body.setBackgroundResource(background.getOutgoingDrawable());
|
||||
}
|
||||
holder.body.setText(message.getBody());
|
||||
// } else {
|
||||
// holder.body.setBackgroundResource(background.getOutgoingDrawable());
|
||||
// }
|
||||
holder.body.setText(((TextMessageContent) message.getMessagePayloads().get(0).getMessageContents().get(0)).getBody());
|
||||
holder.body.requestLayout();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
if (messages.get(position).isIncoming()) {
|
||||
// if (messages.get(position).isIncoming()) {
|
||||
return R.layout.view_message_text_in;
|
||||
} else {
|
||||
return R.layout.view_message_text_out;
|
||||
}
|
||||
// } else {
|
||||
// return R.layout.view_message_text_out;
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -84,26 +85,26 @@ public class MessagesRecyclerViewAdapter extends RecyclerView.Adapter<MessagesRe
|
|||
}
|
||||
|
||||
public MessageBackgroundDrawable getBackgroundDrawable(int pos) {
|
||||
MessageModel subject = messages.get(pos);
|
||||
MessageModel predecessor = pos != 0 ? messages.get(pos - 1) : null;
|
||||
MessageModel successor = pos != messages.size() - 1 ? messages.get(pos + 1) : null;
|
||||
Message subject = messages.get(pos);
|
||||
Message predecessor = pos != 0 ? messages.get(pos - 1) : null;
|
||||
Message successor = pos != messages.size() - 1 ? messages.get(pos + 1) : null;
|
||||
|
||||
if (predecessor == null || predecessor.isIncoming() != subject.isIncoming()) {
|
||||
if (successor == null || successor.isIncoming() != subject.isIncoming()) {
|
||||
// if (predecessor == null || predecessor.isIncoming() != subject.isIncoming()) {
|
||||
// if (successor == null || successor.isIncoming() != subject.isIncoming()) {
|
||||
// This is a single message
|
||||
return MessageBackgroundDrawable.SINGLE;
|
||||
} else {
|
||||
// } else {
|
||||
// This is the first message of a group
|
||||
return MessageBackgroundDrawable.FIRST;
|
||||
}
|
||||
} else {
|
||||
if (successor == null || successor.isIncoming() != subject.isIncoming()) {
|
||||
// return MessageBackgroundDrawable.FIRST;
|
||||
// }
|
||||
// } else {
|
||||
// if (successor == null || successor.isIncoming() != subject.isIncoming()) {
|
||||
// This is the last message of a group
|
||||
return MessageBackgroundDrawable.LAST;
|
||||
} else {
|
||||
// return MessageBackgroundDrawable.LAST;
|
||||
// } else {
|
||||
// This message is in the middle of a group
|
||||
return MessageBackgroundDrawable.MID;
|
||||
}
|
||||
}
|
||||
// return MessageBackgroundDrawable.MID;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import androidx.appcompat.view.ActionMode;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.mercury_im.messenger.R;
|
||||
import org.mercury_im.messenger.xmpp.model.ChatModel;
|
||||
import org.mercury_im.messenger.entity.chat.DirectChat;
|
||||
import org.mercury_im.messenger.ui.chat.ChatActivity;
|
||||
import org.mercury_im.messenger.ui.util.AbstractRecyclerViewAdapter;
|
||||
import org.mercury_im.messenger.util.ColorUtil;
|
||||
|
@ -25,7 +25,7 @@ import butterknife.BindView;
|
|||
import butterknife.ButterKnife;
|
||||
|
||||
public class ChatListRecyclerViewAdapter
|
||||
extends AbstractRecyclerViewAdapter<ChatModel, ChatListRecyclerViewAdapter.ChatHolder> {
|
||||
extends AbstractRecyclerViewAdapter<DirectChat, ChatListRecyclerViewAdapter.ChatHolder> {
|
||||
|
||||
public ChatListRecyclerViewAdapter() {
|
||||
super(new ChatMessageDiffCallback(true));
|
||||
|
@ -41,15 +41,15 @@ public class ChatListRecyclerViewAdapter
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ChatHolder holder, int position) {
|
||||
ChatModel model = getModelAt(position);
|
||||
holder.nameView.setText(model.getPeer().getJid() != null ?
|
||||
model.getPeer().getJid() : model.toString());
|
||||
holder.avatarView.setColorFilter(ColorUtil.consistentColor(model.getPeer().getJid().toString()));
|
||||
DirectChat model = getItemAt(position);
|
||||
holder.nameView.setText(model.getPeer().getAddress() != null ?
|
||||
model.getPeer().getAddress() : model.toString());
|
||||
holder.avatarView.setColorFilter(ColorUtil.consistentColor(model.getPeer().getAddress()));
|
||||
|
||||
holder.itemView.setOnClickListener(view -> {
|
||||
|
||||
Intent intent = new Intent(holder.context, ChatActivity.class);
|
||||
intent.putExtra(ChatActivity.EXTRA_JID, model.getPeer().getJid().toString());
|
||||
intent.putExtra(ChatActivity.EXTRA_JID, model.getPeer().getAddress());
|
||||
intent.putExtra(ChatActivity.EXTRA_ACCOUNT, model.getPeer().getAccount().getId());
|
||||
|
||||
holder.context.startActivity(intent);
|
||||
|
@ -84,19 +84,19 @@ public class ChatListRecyclerViewAdapter
|
|||
}
|
||||
}
|
||||
|
||||
private static class ChatMessageDiffCallback extends AbstractDiffCallback<ChatModel> {
|
||||
private static class ChatMessageDiffCallback extends AbstractDiffCallback<DirectChat> {
|
||||
|
||||
ChatMessageDiffCallback(boolean detectMoves) {
|
||||
super(detectMoves);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areItemsTheSame(ChatModel oldItem, ChatModel newItem) {
|
||||
public boolean areItemsTheSame(DirectChat oldItem, DirectChat newItem) {
|
||||
return oldItem.getId() == newItem.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areContentsTheSame(ChatModel oldItem, ChatModel newItem) {
|
||||
public boolean areContentsTheSame(DirectChat oldItem, DirectChat newItem) {
|
||||
return areItemsTheSame(oldItem, newItem);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,8 @@ import androidx.lifecycle.MutableLiveData;
|
|||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import org.mercury_im.messenger.MercuryImApplication;
|
||||
import org.mercury_im.messenger.xmpp.model.ChatModel;
|
||||
import org.mercury_im.messenger.data.repository.DirectChatRepository;
|
||||
import org.mercury_im.messenger.entity.chat.DirectChat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -16,23 +17,20 @@ import io.reactivex.disposables.CompositeDisposable;
|
|||
public class ChatListViewModel extends ViewModel {
|
||||
|
||||
@Inject
|
||||
ChatRepository chatRepository;
|
||||
|
||||
@Inject
|
||||
MessageRepository messageRepository;
|
||||
DirectChatRepository chatRepository;
|
||||
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
private final MutableLiveData<List<ChatModel>> chats = new MutableLiveData<>();
|
||||
private final MutableLiveData<List<DirectChat>> chats = new MutableLiveData<>();
|
||||
|
||||
public ChatListViewModel() {
|
||||
MercuryImApplication.getApplication().getAppComponent().inject(this);
|
||||
|
||||
disposable.add(chatRepository.getVisibleChats()
|
||||
.subscribe(result -> chats.setValue(result.toList())));
|
||||
disposable.add(chatRepository.observeAllDirectChats()
|
||||
.subscribe(chats::setValue));
|
||||
}
|
||||
|
||||
public LiveData<List<ChatModel>> getChats() {
|
||||
public LiveData<List<DirectChat>> getChats() {
|
||||
return chats;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import com.google.android.material.floatingactionbutton.ExtendedFloatingActionBu
|
|||
|
||||
import org.mercury_im.messenger.MercuryImApplication;
|
||||
import org.mercury_im.messenger.R;
|
||||
import org.mercury_im.messenger.data.model.AccountModel;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
@ -109,8 +109,8 @@ public class AccountsFragment extends Fragment {
|
|||
* >Communicating with Other Fragments</a> for more information.
|
||||
*/
|
||||
public interface OnAccountListItemClickListener {
|
||||
void onAccountListItemClick(AccountModel item);
|
||||
void onAccountListItemClick(Account item);
|
||||
|
||||
void onAccountListItemLongClick(AccountModel item);
|
||||
void onAccountListItemLongClick(Account item);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
|
||||
import org.mercury_im.messenger.MercuryImApplication;
|
||||
import org.mercury_im.messenger.R;
|
||||
import org.mercury_im.messenger.xmpp.model.AccountModel;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.ui.login.AccountsFragment.OnAccountListItemClickListener;
|
||||
import org.mercury_im.messenger.util.AbstractDiffCallback;
|
||||
import org.mercury_im.messenger.util.ColorUtil;
|
||||
|
@ -23,7 +23,7 @@ import java.util.List;
|
|||
|
||||
public class AccountsRecyclerViewAdapter extends RecyclerView.Adapter<AccountsRecyclerViewAdapter.ViewHolder> {
|
||||
|
||||
private final List<AccountModel> mValues;
|
||||
private final List<Account> mValues;
|
||||
private final OnAccountListItemClickListener mListener;
|
||||
private final AccountsViewModel viewModel;
|
||||
|
||||
|
@ -42,11 +42,11 @@ public class AccountsRecyclerViewAdapter extends RecyclerView.Adapter<AccountsRe
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(final ViewHolder holder, int position) {
|
||||
AccountModel account = mValues.get(position);
|
||||
holder.jid.setText(account.getJid());
|
||||
holder.avatar.setColorFilter(ColorUtil.consistentColor(account.getJid().toString()));
|
||||
Account account = mValues.get(position);
|
||||
holder.jid.setText(account.getAddress());
|
||||
holder.avatar.setColorFilter(ColorUtil.consistentColor(account.getAddress()));
|
||||
holder.enabled.setChecked(account.isEnabled());
|
||||
holder.accountModel = account;
|
||||
holder.account = account;
|
||||
holder.enabled.setOnCheckedChangeListener((compoundButton, b) -> {
|
||||
viewModel.toggleAccountEnabled(account);
|
||||
});
|
||||
|
@ -54,18 +54,18 @@ public class AccountsRecyclerViewAdapter extends RecyclerView.Adapter<AccountsRe
|
|||
if (null != mListener) {
|
||||
// Notify the active callbacks interface (the activity, if the
|
||||
// fragment is attached to one) that an item has been selected.
|
||||
mListener.onAccountListItemClick(holder.accountModel);
|
||||
mListener.onAccountListItemClick(holder.account);
|
||||
}
|
||||
});
|
||||
holder.mView.setOnLongClickListener(v -> {
|
||||
if (null != mListener) {
|
||||
mListener.onAccountListItemLongClick(holder.accountModel);
|
||||
mListener.onAccountListItemLongClick(holder.account);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
public void setValues(List<AccountModel> values) {
|
||||
public void setValues(List<Account> values) {
|
||||
DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new AccountsDiffCallback(values, mValues), true);
|
||||
mValues.clear();
|
||||
mValues.addAll(values);
|
||||
|
@ -79,7 +79,7 @@ public class AccountsRecyclerViewAdapter extends RecyclerView.Adapter<AccountsRe
|
|||
}
|
||||
|
||||
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||
public AccountModel accountModel;
|
||||
public Account account;
|
||||
public final View mView;
|
||||
public final ImageView avatar;
|
||||
public final TextView jid;
|
||||
|
@ -96,9 +96,9 @@ public class AccountsRecyclerViewAdapter extends RecyclerView.Adapter<AccountsRe
|
|||
}
|
||||
}
|
||||
|
||||
public class AccountsDiffCallback extends AbstractDiffCallback<AccountModel> {
|
||||
public class AccountsDiffCallback extends AbstractDiffCallback<Account> {
|
||||
|
||||
public AccountsDiffCallback(List<AccountModel> newItems, List<AccountModel> oldItems) {
|
||||
public AccountsDiffCallback(List<Account> newItems, List<Account> oldItems) {
|
||||
super(newItems, oldItems);
|
||||
}
|
||||
|
||||
|
@ -109,8 +109,8 @@ public class AccountsRecyclerViewAdapter extends RecyclerView.Adapter<AccountsRe
|
|||
|
||||
@Override
|
||||
public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
|
||||
AccountModel oldM = oldItems.get(oldItemPosition);
|
||||
AccountModel newM = newItems.get(newItemPosition);
|
||||
Account oldM = oldItems.get(oldItemPosition);
|
||||
Account newM = newItems.get(newItemPosition);
|
||||
return oldM.equals(newM);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,17 +1,14 @@
|
|||
package org.mercury_im.messenger.ui.login;
|
||||
|
||||
import android.app.Application;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import org.mercury_im.messenger.MercuryImApplication;
|
||||
import org.mercury_im.messenger.core.centers.ConnectionCenter;
|
||||
import org.mercury_im.messenger.core.connection.MercuryConnection;
|
||||
import org.mercury_im.messenger.xmpp.model.AccountModel;
|
||||
import org.mercury_im.messenger.xmpp.repository.RequeryAccountRepository;
|
||||
import org.mercury_im.messenger.data.repository.AccountRepository;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -22,20 +19,17 @@ import io.reactivex.disposables.CompositeDisposable;
|
|||
public class AccountsViewModel extends AndroidViewModel {
|
||||
|
||||
@Inject
|
||||
RequeryAccountRepository repository;
|
||||
AccountRepository repository;
|
||||
|
||||
@Inject
|
||||
ConnectionCenter connectionCenter;
|
||||
|
||||
private final MutableLiveData<List<AccountModel>> accounts = new MutableLiveData<>();
|
||||
private final MutableLiveData<List<Account>> accounts = new MutableLiveData<>();
|
||||
private final CompositeDisposable compositeDisposable = new CompositeDisposable();
|
||||
|
||||
@Inject
|
||||
public AccountsViewModel(Application application) {
|
||||
super(application);
|
||||
MercuryImApplication.getApplication().getAppComponent().inject(this);
|
||||
compositeDisposable.add(repository.getAll()
|
||||
.subscribe(accountModels -> accounts.setValue(accountModels.toList())));
|
||||
compositeDisposable.add(repository.observeAllAccounts()
|
||||
.subscribe(accounts::setValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -44,19 +38,21 @@ public class AccountsViewModel extends AndroidViewModel {
|
|||
compositeDisposable.clear();
|
||||
}
|
||||
|
||||
public LiveData<List<AccountModel>> getAccounts() {
|
||||
public LiveData<List<Account>> getAccounts() {
|
||||
return accounts;
|
||||
}
|
||||
|
||||
public void toggleAccountEnabled(AccountModel accountModel) {
|
||||
public void toggleAccountEnabled(Account accountModel) {
|
||||
/*
|
||||
MercuryConnection connection = connectionCenter.getConnection(accountModel);
|
||||
if (connection == null) {
|
||||
Toast.makeText(this.getApplication(), "MercuryConnection is null!", Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
accountModel.setEnabled(!accountModel.isEnabled());
|
||||
repository.upsert(accountModel)
|
||||
repository.upsertAccount(accountModel)
|
||||
.subscribe();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import com.google.android.material.textfield.TextInputEditText;
|
|||
|
||||
import org.mercury_im.messenger.MercuryImApplication;
|
||||
import org.mercury_im.messenger.R;
|
||||
import org.mercury_im.messenger.data.model.AccountModel;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.util.TextChangedListener;
|
||||
|
||||
import butterknife.BindView;
|
||||
|
@ -121,18 +121,18 @@ public class LoginActivity extends AppCompatActivity implements TextView.OnEdito
|
|||
});
|
||||
}
|
||||
|
||||
private void displayCredentials(LiveData<AccountModel> account) {
|
||||
account.observe(this, accountModel -> {
|
||||
if (accountModel == null) {
|
||||
private void displayCredentials(LiveData<Account> account) {
|
||||
account.observe(this, accountEvent -> {
|
||||
if (accountEvent == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (accountModel.getAddress() != null) {
|
||||
mJidView.setText(accountModel.getAddress());
|
||||
if (accountEvent.getAddress() != null) {
|
||||
mJidView.setText(accountEvent.getAddress());
|
||||
}
|
||||
|
||||
if (accountModel.getPassword() != null) {
|
||||
mPasswordView.setText(accountModel.getPassword());
|
||||
if (accountEvent.getAuthentication() != null) {
|
||||
mPasswordView.setText(accountEvent.getAuthentication().getPassword());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package org.mercury_im.messenger.ui.login;
|
||||
|
||||
import static org.mercury_im.messenger.core.connection.MercuryConnection.TAG;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
|
@ -16,9 +14,10 @@ import io.reactivex.observers.DisposableSingleObserver;
|
|||
import org.jxmpp.jid.EntityBareJid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.mercury_im.messenger.MercuryImApplication;
|
||||
import org.mercury_im.messenger.core.centers.ConnectionCenter;
|
||||
import org.mercury_im.messenger.data.model.AccountModel;
|
||||
import org.mercury_im.messenger.data.repository.AccountRepository;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.entity.IAccount;
|
||||
import org.mercury_im.messenger.entity.PasswordAuthentication;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -27,8 +26,8 @@ public class LoginViewModel extends ViewModel {
|
|||
@Inject
|
||||
AccountRepository accountRepository;
|
||||
|
||||
@Inject
|
||||
ConnectionCenter connectionCenter;
|
||||
// @Inject
|
||||
// ConnectionCenter connectionCenter;
|
||||
|
||||
private String jid;
|
||||
private String password;
|
||||
|
@ -36,14 +35,14 @@ public class LoginViewModel extends ViewModel {
|
|||
private MutableLiveData<JidError> jidError = new MutableLiveData<>();
|
||||
private MutableLiveData<PasswordError> passwordError = new MutableLiveData<>();
|
||||
|
||||
private MutableLiveData<AccountModel> account = new MutableLiveData<>();
|
||||
private MutableLiveData<Account> account = new MutableLiveData<>();
|
||||
|
||||
private MutableLiveData<Boolean> signinSuccessful = new MutableLiveData<>();
|
||||
|
||||
public LoginViewModel() {
|
||||
super();
|
||||
MercuryImApplication.getApplication().getAppComponent().inject(this);
|
||||
init(new AccountModel());
|
||||
init(new IAccount());
|
||||
}
|
||||
|
||||
public LiveData<Boolean> getSigninSuccessful() {
|
||||
|
@ -95,18 +94,18 @@ public class LoginViewModel extends ViewModel {
|
|||
return !password.isEmpty();
|
||||
}
|
||||
|
||||
public void init(@NonNull AccountModel account) {
|
||||
public void init(@NonNull Account account) {
|
||||
this.account.setValue(account);
|
||||
}
|
||||
|
||||
public MutableLiveData<AccountModel> getAccount() {
|
||||
public MutableLiveData<Account> getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public void login() {
|
||||
AccountModel account = getAccount().getValue();
|
||||
if (account != null && account.getJid() != null && !TextUtils.isEmpty(account.getPassword())) {
|
||||
accountRepository.upsert(account);
|
||||
Account account = getAccount().getValue();
|
||||
if (account != null && account.getAddress() != null && !TextUtils.isEmpty(account.getAuthentication().getPassword())) {
|
||||
accountRepository.upsertAccount(account);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,22 +128,22 @@ public class LoginViewModel extends ViewModel {
|
|||
}
|
||||
|
||||
if (loginIntact) {
|
||||
AccountModel accountModel = new AccountModel();
|
||||
accountModel.setEnabled(true);
|
||||
accountModel.setJid(bareJid);
|
||||
accountModel.setPassword(password);
|
||||
Single<AccountModel> insert = accountRepository.upsert(accountModel);
|
||||
insert.subscribe(new DisposableSingleObserver<AccountModel>() {
|
||||
Account account = new IAccount();
|
||||
account.setEnabled(true);
|
||||
account.setAddress(bareJid.toString());
|
||||
account.setAuthentication(new PasswordAuthentication(password));
|
||||
Single<Account> insert = accountRepository.upsertAccount(account);
|
||||
insert.subscribe(new DisposableSingleObserver<Account>() {
|
||||
@Override
|
||||
public void onSuccess(AccountModel inserted) {
|
||||
public void onSuccess(Account inserted) {
|
||||
Log.d(MercuryImApplication.TAG, "LoginActivity.loginDetailsEntered: Account " + inserted.getId() + " inserted.");
|
||||
connectionCenter.createConnection(accountModel);
|
||||
// connectionCenter.createConnection(account);
|
||||
signinSuccessful.setValue(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e(TAG, "Could not insert new Account data.", e);
|
||||
Log.e("Mercury", "Could not insert new Account data.", e);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ import android.widget.Toast;
|
|||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.lifecycle.ViewModelProviders;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
|
||||
|
|
|
@ -6,17 +6,17 @@ import androidx.annotation.NonNull;
|
|||
import androidx.lifecycle.AndroidViewModel;
|
||||
import androidx.lifecycle.LiveData;
|
||||
|
||||
import org.mercury_im.messenger.xmpp.model.ContactModel;
|
||||
import org.mercury_im.messenger.data.repository.XmppPeerRepository;
|
||||
import org.mercury_im.messenger.data.repository.PeerRepository;
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
public class ContactListItemViewModel extends AndroidViewModel {
|
||||
|
||||
@Inject
|
||||
XmppPeerRepository contactRepository;
|
||||
PeerRepository contactRepository;
|
||||
|
||||
private LiveData<ContactModel> contact;
|
||||
private LiveData<Peer> contact;
|
||||
|
||||
@Inject
|
||||
public ContactListItemViewModel(@NonNull Application application) {
|
||||
|
|
|
@ -11,9 +11,8 @@ import android.widget.TextView;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.jxmpp.jid.EntityBareJid;
|
||||
import org.mercury_im.messenger.R;
|
||||
import org.mercury_im.messenger.xmpp.model.ContactModel;
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
import org.mercury_im.messenger.ui.chat.ChatActivity;
|
||||
import org.mercury_im.messenger.ui.util.AbstractRecyclerViewAdapter;
|
||||
import org.mercury_im.messenger.util.ColorUtil;
|
||||
|
@ -24,7 +23,7 @@ import butterknife.BindView;
|
|||
import butterknife.ButterKnife;
|
||||
|
||||
public class ContactListRecyclerViewAdapter
|
||||
extends AbstractRecyclerViewAdapter<ContactModel, ContactListRecyclerViewAdapter.RosterItemViewHolder> {
|
||||
extends AbstractRecyclerViewAdapter<Peer, ContactListRecyclerViewAdapter.RosterItemViewHolder> {
|
||||
|
||||
public ContactListRecyclerViewAdapter() {
|
||||
super(new ContactDiffCallback());
|
||||
|
@ -39,8 +38,8 @@ public class ContactListRecyclerViewAdapter
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RosterItemViewHolder holder, int position) {
|
||||
ContactModel model = getModelAt(position);
|
||||
holder.bind(model);
|
||||
Peer peer = getItemAt(position);
|
||||
holder.bind(peer);
|
||||
}
|
||||
|
||||
public class RosterItemViewHolder extends RecyclerView.ViewHolder {
|
||||
|
@ -65,38 +64,38 @@ public class ContactListRecyclerViewAdapter
|
|||
ButterKnife.bind(this, view);
|
||||
}
|
||||
|
||||
void bind(ContactModel contactModel) {
|
||||
String name = contactModel.getRostername();
|
||||
nameView.setText(name != null ? name : contactModel.getEntity().getJid().getLocalpart().asUnescapedString());
|
||||
EntityBareJid jid = contactModel.getEntity().getJid();
|
||||
jidView.setText(jid.toString());
|
||||
avatarView.setColorFilter(ColorUtil.consistentColor(jid.toString()));
|
||||
void bind(Peer contact) {
|
||||
String name = contact.getName();
|
||||
String address = contact.getAddress();
|
||||
nameView.setText(name != null ? name : address);
|
||||
jidView.setText(address);
|
||||
avatarView.setColorFilter(ColorUtil.consistentColor(address));
|
||||
view.setOnClickListener(view -> {
|
||||
|
||||
Intent intent = new Intent(context, ChatActivity.class);
|
||||
intent.putExtra(ChatActivity.EXTRA_JID, jid.toString());
|
||||
intent.putExtra(ChatActivity.EXTRA_ACCOUNT, contactModel.getEntity().getAccount().getId());
|
||||
intent.putExtra(ChatActivity.EXTRA_JID, address);
|
||||
intent.putExtra(ChatActivity.EXTRA_ACCOUNT, contact.getAccount().getId());
|
||||
|
||||
context.startActivity(intent);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private static class ContactDiffCallback extends AbstractDiffCallback<ContactModel> {
|
||||
private static class ContactDiffCallback extends AbstractDiffCallback<Peer> {
|
||||
|
||||
ContactDiffCallback() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areItemsTheSame(ContactModel oldItem, ContactModel newItem) {
|
||||
public boolean areItemsTheSame(Peer oldItem, Peer newItem) {
|
||||
return oldItem.getId() == newItem.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean areContentsTheSame(ContactModel oldItem, ContactModel newItem) {
|
||||
public boolean areContentsTheSame(Peer oldItem, Peer newItem) {
|
||||
return areItemsTheSame(oldItem, newItem) &&
|
||||
Objects.equals(oldItem.getRostername(), newItem.getRostername());
|
||||
Objects.equals(oldItem.getName(), newItem.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,16 +7,14 @@ import androidx.lifecycle.MutableLiveData;
|
|||
import androidx.lifecycle.ViewModel;
|
||||
|
||||
import org.mercury_im.messenger.MercuryImApplication;
|
||||
import org.mercury_im.messenger.xmpp.model.ContactModel;
|
||||
import org.mercury_im.messenger.data.repository.XmppPeerRepository;
|
||||
import org.mercury_im.messenger.entity.contact.Peer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
public class ContactListViewModel extends ViewModel {
|
||||
|
@ -24,7 +22,7 @@ public class ContactListViewModel extends ViewModel {
|
|||
@Inject
|
||||
XmppPeerRepository xmppContactRepository;
|
||||
|
||||
private final MutableLiveData<List<ContactModel>> rosterEntryList = new MutableLiveData<>();
|
||||
private final MutableLiveData<List<Peer>> rosterEntryList = new MutableLiveData<>();
|
||||
private final CompositeDisposable compositeDisposable = new CompositeDisposable();
|
||||
|
||||
public ContactListViewModel() {
|
||||
|
@ -32,11 +30,8 @@ public class ContactListViewModel extends ViewModel {
|
|||
MercuryImApplication.getApplication().getAppComponent().inject(this);
|
||||
Log.d("ContactListViewModel", "Start observing database");
|
||||
// Subscribe to changes to the contacts table and update the LiveData object for the UI.
|
||||
compositeDisposable.add(xmppContactRepository.getAllContacts()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(o -> {
|
||||
List<ContactModel> list = o.toList();
|
||||
compositeDisposable.add(xmppContactRepository.observeAllPeers()
|
||||
.subscribe(list -> {
|
||||
Log.d("ContactListViewModel", "Room changed contacts: " + list.size());
|
||||
rosterEntryList.setValue(list);
|
||||
}));
|
||||
|
@ -48,7 +43,7 @@ public class ContactListViewModel extends ViewModel {
|
|||
compositeDisposable.clear();
|
||||
}
|
||||
|
||||
public LiveData<List<ContactModel>> getRosterEntryList() {
|
||||
public LiveData<List<Peer>> getRosterEntryList() {
|
||||
return rosterEntryList;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ public abstract class AbstractRecyclerViewAdapter<M, VH extends RecyclerView.Vie
|
|||
return models;
|
||||
}
|
||||
|
||||
public M getModelAt(int position) {
|
||||
public M getItemAt(int position) {
|
||||
return getModels().get(position);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ import io.reactivex.Scheduler;
|
|||
import io.requery.Persistable;
|
||||
import io.requery.reactivex.ReactiveEntityStore;
|
||||
|
||||
@Module
|
||||
@Module(includes = MappingModule.class)
|
||||
public class RepositoryModule {
|
||||
|
||||
@Provides
|
||||
|
|
|
@ -26,6 +26,9 @@ public class XmppPeerRepository
|
|||
extends RequeryRepository
|
||||
implements PeerRepository {
|
||||
|
||||
@Inject
|
||||
AccountRepository accountRepository;
|
||||
|
||||
@Inject
|
||||
PeerMapping peerMapping;
|
||||
|
||||
|
@ -75,6 +78,12 @@ public class XmppPeerRepository
|
|||
.observeOn(observerScheduler());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Single<Peer> getOrCreatePeer(long accountId, String address) {
|
||||
return accountRepository.getAccount(accountId).toSingle()
|
||||
.flatMap(account -> getOrCreatePeer(account, address));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Maybe<Peer> getPeerByAddress(long accountId, String address) {
|
||||
return data().select(PeerModel.class)
|
||||
|
|
|
@ -15,6 +15,10 @@ public interface PeerRepository {
|
|||
|
||||
Single<Peer> insertPeer(Peer Peer);
|
||||
|
||||
default Observable<Optional<Peer>> observePeer(Peer peer) {
|
||||
return observePeer(peer.getId());
|
||||
}
|
||||
|
||||
Observable<Optional<Peer>> observePeer(long PeerId);
|
||||
|
||||
Maybe<Peer> getPeer(long PeerId);
|
||||
|
@ -33,6 +37,8 @@ public interface PeerRepository {
|
|||
|
||||
Single<Peer> getOrCreatePeer(Account account, String address);
|
||||
|
||||
Single<Peer> getOrCreatePeer(long accountId, String address);
|
||||
|
||||
Observable<List<Peer>> observeAllPeers();
|
||||
|
||||
Single<Peer> updatePeer(Peer Peer);
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
package org.mercury_im.messenger.di.component;
|
||||
|
||||
import org.mercury_im.messenger.Messenger;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.Component;
|
||||
|
||||
@Singleton
|
||||
@Component
|
||||
public interface MessengerComponent {
|
||||
|
||||
void inject(Messenger messenger);
|
||||
}
|
Loading…
Reference in a new issue