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