Update some dependencies

This commit is contained in:
Paul Schaub 2020-01-06 01:27:11 +01:00
parent ae6d3ef9d4
commit 25011cb734
Signed by: vanitasvitae
GPG Key ID: 62BEE9264BF17311
13 changed files with 87 additions and 121 deletions

View File

@ -84,6 +84,9 @@ dependencies {
implementation "com.google.dagger:dagger:$daggerVersion" implementation "com.google.dagger:dagger:$daggerVersion"
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion" annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
compileOnly 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10'
// ViewModel and LiveData // ViewModel and LiveData
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion" implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"
annotationProcessor "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion" annotationProcessor "androidx.lifecycle:lifecycle-common-java8:$lifecycleVersion"
@ -97,11 +100,11 @@ dependencies {
// support libraries // support libraries
implementation "androidx.appcompat:appcompat:$appCompatVersion" implementation "androidx.appcompat:appcompat:$appCompatVersion"
implementation 'com.google.android.material:material:1.2.0-alpha02' implementation 'com.google.android.material:material:1.2.0-alpha03'
implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0' implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
implementation 'androidx.recyclerview:recyclerview:1.1.0' implementation 'androidx.recyclerview:recyclerview:1.1.0'
// circular image viewer for avatars // circular image viewer for avatars

View File

@ -22,6 +22,8 @@ import org.mercury_im.messenger.xmpp.MercuryConnection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import io.reactivex.android.schedulers.AndroidSchedulers;
public class AccountsRecyclerViewAdapter extends RecyclerView.Adapter<AccountsRecyclerViewAdapter.ViewHolder> { public class AccountsRecyclerViewAdapter extends RecyclerView.Adapter<AccountsRecyclerViewAdapter.ViewHolder> {
private final List<MercuryConnection> connections = new ArrayList<>(); private final List<MercuryConnection> connections = new ArrayList<>();
@ -66,7 +68,9 @@ public class AccountsRecyclerViewAdapter extends RecyclerView.Adapter<AccountsRe
holder.enabled.setOnCheckedChangeListener((compoundButton, checked) -> holder.enabled.setOnCheckedChangeListener((compoundButton, checked) ->
viewModel.setAccountEnabled(account, checked)); viewModel.setAccountEnabled(account, checked));
connection.getState().subscribe(state -> holder.status.setText(state.toString())); connection.getState()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(state -> holder.status.setText(state.toString()));
setClickListenersOnViewHolder(holder); setClickListenersOnViewHolder(holder);
} }

View File

@ -7,7 +7,7 @@ buildscript {
jcenter() jcenter()
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.5.2' classpath 'com.android.tools.build:gradle:3.5.3'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

View File

@ -30,7 +30,7 @@ dependencies {
// JUnit for testing // JUnit for testing
testImplementation "junit:junit:$junitVersion" testImplementation "junit:junit:$junitVersion"
testImplementation "org.xerial:sqlite-jdbc:3.28.0" testImplementation 'org.xerial:sqlite-jdbc:3.30.1'
} }
sourceCompatibility = "8" sourceCompatibility = "8"

View File

@ -21,6 +21,9 @@ dependencies {
implementation "com.google.dagger:dagger:$daggerVersion" implementation "com.google.dagger:dagger:$daggerVersion"
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion" annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
compileOnly 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10'
// JUnit for testing // JUnit for testing
testImplementation "junit:junit:$junitVersion" testImplementation "junit:junit:$junitVersion"
} }

View File

@ -0,0 +1,24 @@
package org.mercury_im.messenger;
import org.mercury_im.messenger.util.ThreadUtils;
import javax.inject.Inject;
import javax.inject.Named;
import io.reactivex.Scheduler;
import lombok.Getter;
public class MercurySchedulers {
@Getter
private final Scheduler subscriberScheduler;
@Getter
private final Scheduler observerScheduler;
@Inject
public MercurySchedulers(@Named(value = ThreadUtils.SCHEDULER_IO) Scheduler subscriberScheduler,
@Named(value = ThreadUtils.SCHEDULER_UI) Scheduler observerScheduler) {
this.subscriberScheduler = subscriberScheduler;
this.observerScheduler = observerScheduler;
}
}

View File

@ -4,7 +4,6 @@ import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smackx.csi.ClientStateIndicationManager; import org.jivesoftware.smackx.csi.ClientStateIndicationManager;
import org.mercury_im.messenger.data.repository.Repositories; import org.mercury_im.messenger.data.repository.Repositories;
import org.mercury_im.messenger.usecase.AddAccount; import org.mercury_im.messenger.usecase.AddAccount;
import org.mercury_im.messenger.usecase.ConnectAccountsOnStartup;
import org.mercury_im.messenger.usecase.RosterStoreBinder; import org.mercury_im.messenger.usecase.RosterStoreBinder;
import org.mercury_im.messenger.xmpp.MercuryConnection; import org.mercury_im.messenger.xmpp.MercuryConnection;
import org.mercury_im.messenger.xmpp.MercuryConnectionManager; import org.mercury_im.messenger.xmpp.MercuryConnectionManager;
@ -13,10 +12,12 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers; import io.reactivex.schedulers.Schedulers;
@Singleton
public class Messenger implements ClientStateListener { public class Messenger implements ClientStateListener {
public static final String TAG = "MercuryIM"; public static final String TAG = "MercuryIM";
@ -24,15 +25,13 @@ public class Messenger implements ClientStateListener {
private final MercuryConnectionManager connectionManager; private final MercuryConnectionManager connectionManager;
private final Repositories repositories; private final Repositories repositories;
private final RosterStoreBinder rosterStoreBinder;
private CompositeDisposable disposable = new CompositeDisposable(); private CompositeDisposable disposable = new CompositeDisposable();
@Inject @Inject
public Messenger(Repositories repositories) { public Messenger(Repositories repositories, MercuryConnectionManager connectionManager) {
this.connectionManager = new MercuryConnectionManager(this, repositories.getAccountRepository());
this.repositories = repositories; this.repositories = repositories;
this.rosterStoreBinder = new RosterStoreBinder(repositories.getAccountRepository(), repositories.getPeerRepository()); this.connectionManager = connectionManager;
performInitialLogin(); performInitialLogin();
} }
@ -41,15 +40,10 @@ public class Messenger implements ClientStateListener {
} }
public void performInitialLogin() { public void performInitialLogin() {
LOGGER.log(Level.INFO, "Perform initial login.");
disposable.add(repositories.getAccountRepository().observeAllAccounts().firstOrError() disposable.add(repositories.getAccountRepository().observeAllAccounts().firstOrError()
.subscribeOn(Schedulers.newThread()) .subscribeOn(Schedulers.newThread())
.subscribe(initialAccounts -> ConnectAccountsOnStartup .subscribe(connectionManager::registerConnections));
.with(this.connectionManager, repositories.getAccountRepository(), initialAccounts)
.execute()));
}
public void bindConnection(MercuryConnection connection) {
rosterStoreBinder.setRosterStoreOn(connection);
} }
public AddAccount addAccount() { public AddAccount addAccount() {

View File

@ -1,50 +0,0 @@
package org.mercury_im.messenger.usecase;
import org.mercury_im.messenger.data.repository.AccountRepository;
import org.mercury_im.messenger.entity.Account;
import org.mercury_im.messenger.xmpp.MercuryConnection;
import org.mercury_im.messenger.xmpp.MercuryConnectionManager;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
public class ConnectAccountsOnStartup {
private static final Logger LOGGER = Logger.getLogger(ConnectAccountsOnStartup.class.getName());
private final MercuryConnectionManager connectionManager;
private final AccountRepository accountRepository;
private final List<Account> accounts = new ArrayList<>();
private CompositeDisposable disposable = new CompositeDisposable();
private ConnectAccountsOnStartup(MercuryConnectionManager connectionManager, AccountRepository accountRepository, List<Account> initialAccounts) {
this.connectionManager = connectionManager;
this.accountRepository = accountRepository;
this.accounts.addAll(initialAccounts);
}
public static ConnectAccountsOnStartup with(MercuryConnectionManager connectionManager, AccountRepository accountRepository, List<Account> initialAccounts) {
return new ConnectAccountsOnStartup(connectionManager, accountRepository, initialAccounts);
}
public void execute() {
for (Account account : accounts) {
if (account.isEnabled()) {
MercuryConnection connection = new MercuryConnection(accountRepository, account);
disposable.add(LogIntoAccount.with(connection)
.executeAndPossiblyThrow()
.subscribeOn(Schedulers.newThread())
.doOnComplete(() -> connectionManager.registerConnection(connection))
.subscribe(
() -> LOGGER.log(Level.INFO, "Successfully logged into account " + account.getAddress()),
error -> LOGGER.log(Level.SEVERE, "Error logging into account " + account.getAddress(), error)));
}
}
}
}

View File

@ -7,11 +7,14 @@ import org.mercury_im.messenger.entity.Account;
import org.mercury_im.messenger.store.MercuryRosterStore; import org.mercury_im.messenger.store.MercuryRosterStore;
import org.mercury_im.messenger.xmpp.MercuryConnection; import org.mercury_im.messenger.xmpp.MercuryConnection;
import javax.inject.Inject;
public class RosterStoreBinder { public class RosterStoreBinder {
private final AccountRepository accountRepository; private final AccountRepository accountRepository;
private final PeerRepository peerRepository; private final PeerRepository peerRepository;
@Inject
public RosterStoreBinder(AccountRepository accountRepository, PeerRepository peerRepository) { public RosterStoreBinder(AccountRepository accountRepository, PeerRepository peerRepository) {
this.accountRepository = accountRepository; this.accountRepository = accountRepository;
this.peerRepository = peerRepository; this.peerRepository = peerRepository;

View File

@ -6,6 +6,9 @@ import org.mercury_im.messenger.data.repository.AccountRepository;
import org.mercury_im.messenger.entity.Account; import org.mercury_im.messenger.entity.Account;
import org.mercury_im.messenger.util.Optional; import org.mercury_im.messenger.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.subjects.BehaviorSubject; import io.reactivex.subjects.BehaviorSubject;
@ -60,6 +63,7 @@ public class MercuryConnection {
@Override @Override
public void connectionClosed() { public void connectionClosed() {
Logger.getLogger(MercuryConnection.class.getName()).log(Level.INFO, "connectionClosed.");
state.onNext(ConnectionState.closed); state.onNext(ConnectionState.closed);
} }

View File

@ -3,8 +3,10 @@ package org.mercury_im.messenger.xmpp;
import org.jivesoftware.smack.AbstractXMPPConnection; import org.jivesoftware.smack.AbstractXMPPConnection;
import org.mercury_im.messenger.Messenger; import org.mercury_im.messenger.Messenger;
import org.mercury_im.messenger.data.repository.AccountRepository; import org.mercury_im.messenger.data.repository.AccountRepository;
import org.mercury_im.messenger.data.repository.Repositories;
import org.mercury_im.messenger.entity.Account; import org.mercury_im.messenger.entity.Account;
import org.mercury_im.messenger.usecase.LogIntoAccount; import org.mercury_im.messenger.usecase.LogIntoAccount;
import org.mercury_im.messenger.usecase.RosterStoreBinder;
import org.mercury_im.messenger.util.Optional; import org.mercury_im.messenger.util.Optional;
import java.util.ArrayList; import java.util.ArrayList;
@ -16,11 +18,15 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton;
import io.reactivex.Observable; import io.reactivex.Observable;
import io.reactivex.Scheduler;
import io.reactivex.disposables.CompositeDisposable; import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subjects.BehaviorSubject; import io.reactivex.subjects.BehaviorSubject;
@Singleton
public class MercuryConnectionManager { public class MercuryConnectionManager {
private static final Logger LOGGER = Logger.getLogger(MercuryConnectionManager.class.getName()); private static final Logger LOGGER = Logger.getLogger(MercuryConnectionManager.class.getName());
@ -28,14 +34,14 @@ public class MercuryConnectionManager {
private final Map<UUID, MercuryConnection> connections = new ConcurrentHashMap<>(); private final Map<UUID, MercuryConnection> connections = new ConcurrentHashMap<>();
private final BehaviorSubject<Map<UUID, MercuryConnection>> connectionsSubject = BehaviorSubject.createDefault(connections); private final BehaviorSubject<Map<UUID, MercuryConnection>> connectionsSubject = BehaviorSubject.createDefault(connections);
private final AccountRepository accountRepository; private final AccountRepository accountRepository;
private final Messenger messenger; private final RosterStoreBinder rosterStoreBinder;
private final CompositeDisposable disposable = new CompositeDisposable(); private final CompositeDisposable disposable = new CompositeDisposable();
@Inject @Inject
public MercuryConnectionManager(Messenger messenger, AccountRepository accountRepository) { public MercuryConnectionManager(Repositories repositories, RosterStoreBinder rosterStoreBinder) {
this.messenger = messenger; this.accountRepository = repositories.getAccountRepository();
this.accountRepository = accountRepository; this.rosterStoreBinder = rosterStoreBinder;
} }
public List<MercuryConnection> getConnections() { public List<MercuryConnection> getConnections() {
@ -54,33 +60,32 @@ public class MercuryConnectionManager {
return connections.get(id); return connections.get(id);
} }
public void registerConnection(MercuryConnection connection) { public void registerConnections(List<Account> accounts) {
putConnection(connection); for (Account account : accounts) {
if (connection.getConnection().isAuthenticated()) { MercuryConnection connection = new MercuryConnection(accountRepository, account);
registerLiveConnection(connection); registerConnection(connection);
} else {
registerDeadConnection(connection);
} }
} }
public void registerConnection(MercuryConnection connection) {
LOGGER.log(Level.INFO, "Register Connection " + connection.getAccount().getAddress());
putConnection(connection);
disposable.add(accountRepository
.observeAccount(connection.getAccount().getId())
.subscribeOn(Schedulers.newThread())
.observeOn(Schedulers.newThread())
.subscribe(event ->
handleOptionalAccountChangedEvent(connection, event)));
}
private void putConnection(MercuryConnection connection) { private void putConnection(MercuryConnection connection) {
connections.put(connection.getAccount().getId(), connection); connections.put(connection.getAccount().getId(), connection);
connectionsSubject.onNext(connections); connectionsSubject.onNext(connections);
messenger.bindConnection(connection); bindConnection(connection);
} }
private void registerLiveConnection(MercuryConnection connection) { public void bindConnection(MercuryConnection connection) {
Observable<Optional<Account>> observableAccount = accountRepository rosterStoreBinder.setRosterStoreOn(connection);
.observeAccount(connection.getAccount().getId());
disposable.add(observableAccount.subscribe(event ->
handleOptionalAccountChangedEvent(connection, event)));
}
private void registerDeadConnection(MercuryConnection connection) {
if (connection.getAccount().isEnabled()) {
connectionLogin(connection);
}
} }
private void handleOptionalAccountChangedEvent(MercuryConnection connection, Optional<Account> event) { private void handleOptionalAccountChangedEvent(MercuryConnection connection, Optional<Account> event) {
@ -100,15 +105,18 @@ public class MercuryConnectionManager {
} }
private void handleAccountDisabled(MercuryConnection connection) { private void handleAccountDisabled(MercuryConnection connection) {
LOGGER.log(Level.INFO, "HandleAccountDisabled: " + connection.getAccount().getAddress());
shutdownConnection(connection); shutdownConnection(connection);
} }
private void handleAccountEnabled(MercuryConnection connection) { private void handleAccountEnabled(MercuryConnection connection) {
LOGGER.log(Level.INFO, "HandleAccountEnabled: " + connection.getAccount().getAddress());
connectionLogin(connection); connectionLogin(connection);
} }
private void connectionLogin(MercuryConnection connection) { private void connectionLogin(MercuryConnection connection) {
disposable.add(LogIntoAccount.with(connection).executeAndPossiblyThrow() disposable.add(LogIntoAccount.with(connection).executeAndPossiblyThrow()
.subscribeOn(Schedulers.newThread())
.subscribe(() -> LOGGER.log(Level.INFO, "Logged in."), .subscribe(() -> LOGGER.log(Level.INFO, "Logged in."),
error -> LOGGER.log(Level.SEVERE, "Connection error!", error))); error -> LOGGER.log(Level.SEVERE, "Connection error!", error)));
} }
@ -124,7 +132,7 @@ public class MercuryConnectionManager {
private void shutdownConnection(MercuryConnection connection) { private void shutdownConnection(MercuryConnection connection) {
if (connection.getConnection().isAuthenticated()) { if (connection.getConnection().isAuthenticated()) {
((AbstractXMPPConnection) connection.getConnection()).instantShutdown(); ((AbstractXMPPConnection) connection.getConnection()).disconnect();
} }
} }

View File

@ -1,27 +0,0 @@
package org.mercury_im.messenger.learning_tests.smack;
import org.junit.Test;
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.xmpp.MercuryConnection;
import org.mercury_im.messenger.xmpp.MercuryConnectionManager;
import java.util.UUID;
public class ConnectionRegistrationTest {
AccountRepository accountRepository;
@Test
public void test() {
MercuryConnectionManager manager = new MercuryConnectionManager(accountRepository);
UUID accountId = UUID.randomUUID();
Account account = new IAccount(accountId);
account.setAddress("test@add.res");
account.setPassword("monomono");
MercuryConnection connection = new MercuryConnection(account);
manager.registerConnection(connection);
}
}

View File

@ -86,16 +86,16 @@ ext {
rxAndroidVersion = "2.1.1" rxAndroidVersion = "2.1.1"
// Dagger 2 // Dagger 2
daggerVersion = '2.25.2' daggerVersion = '2.25.4'
// Android Support Library // Android Support Library
supportLibVersion = "28.0.0" supportLibVersion = "28.0.0"
// Butter Knife // Butter Knife
butterKnifeVersion = '10.2.0' butterKnifeVersion = '10.2.1'
// JUnit // JUnit
junitVersion = "4.12" junitVersion = '4.13'
andxTestJunitVersion = "1.1.1" andxTestJunitVersion = "1.1.1"
// androidx.test:runner // androidx.test:runner