mirror of
https://codeberg.org/Mercury-IM/Mercury-IM
synced 2024-06-18 09:34:52 +02:00
Work on app module
This commit is contained in:
parent
859ccb049e
commit
c52ff7ed25
|
@ -58,7 +58,7 @@ public class AccountsFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void observeViewModel() {
|
||||
viewModel.getConnections().observe(this, adapter::setValues);
|
||||
viewModel.getConnectionPool().observe(this, adapter::setValues);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,16 +10,11 @@ import org.mercury_im.messenger.MercuryImApplication;
|
|||
import org.mercury_im.messenger.Messenger;
|
||||
import org.mercury_im.messenger.data.repository.AccountRepository;
|
||||
import org.mercury_im.messenger.entity.Account;
|
||||
import org.mercury_im.messenger.xmpp.MercuryConnection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.mercury_im.messenger.xmpp.state.ConnectionPoolState;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import lombok.Getter;
|
||||
|
||||
public class AccountsViewModel extends AndroidViewModel {
|
||||
|
||||
|
@ -29,7 +24,7 @@ public class AccountsViewModel extends AndroidViewModel {
|
|||
@Inject
|
||||
Messenger messenger;
|
||||
|
||||
private final MutableLiveData<List<MercuryConnection>> connections = new MutableLiveData<>();
|
||||
private final MutableLiveData<ConnectionPoolState> connectionPool = new MutableLiveData<>();
|
||||
private final CompositeDisposable compositeDisposable = new CompositeDisposable();
|
||||
|
||||
@Inject
|
||||
|
@ -37,9 +32,8 @@ public class AccountsViewModel extends AndroidViewModel {
|
|||
super(application);
|
||||
MercuryImApplication.getApplication().getAppComponent().inject(this);
|
||||
compositeDisposable.add(messenger.getConnectionManager()
|
||||
.observeConnections()
|
||||
.map(Map::values)
|
||||
.subscribe(conns -> connections.postValue(new ArrayList<>(conns))));
|
||||
.observeConnectionPool()
|
||||
.subscribe(connectionPool::postValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -52,8 +46,8 @@ public class AccountsViewModel extends AndroidViewModel {
|
|||
return compositeDisposable;
|
||||
}
|
||||
|
||||
public LiveData<List<MercuryConnection>> getConnections() {
|
||||
return connections;
|
||||
public LiveData<ConnectionPoolState> getConnectionPool() {
|
||||
return connectionPool;
|
||||
}
|
||||
|
||||
public void setAccountEnabled(Account accountModel, boolean enabled) {
|
||||
|
|
|
@ -92,13 +92,7 @@ public class LoginViewModel extends AndroidViewModel {
|
|||
MercuryConnection connection = messenger.getConnectionManager().createConnection(account);
|
||||
disposable.add(Completable.fromAction(() -> {
|
||||
connection.connect().login();
|
||||
})
|
||||
.subscribeOn(Schedulers.newThread())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe()
|
||||
);
|
||||
disposable.add(messenger.addAccount()
|
||||
.execute(account)
|
||||
})
|
||||
.subscribeOn(Schedulers.newThread())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnComplete(this::signalLoginSuccessful)
|
||||
|
|
|
@ -47,9 +47,6 @@ public class MercuryConnectionManager {
|
|||
private final BehaviorSubject<ConnectionPoolState> stateObservable =
|
||||
BehaviorSubject.createDefault(new ConnectionPoolState());
|
||||
|
||||
private final BehaviorSubject<Map<UUID, MercuryConnection>> connectionsSubject =
|
||||
BehaviorSubject.createDefault(connections);
|
||||
|
||||
private final AccountRepository accountRepository;
|
||||
|
||||
private final RosterStoreBinder rosterStoreBinder;
|
||||
|
@ -84,11 +81,7 @@ public class MercuryConnectionManager {
|
|||
return new ArrayList<>(connections.values());
|
||||
}
|
||||
|
||||
public Observable<Map<UUID, MercuryConnection>> observeConnections() {
|
||||
return connectionsSubject;
|
||||
}
|
||||
|
||||
public Observable<ConnectionPoolState> observeConnectionPoolState() {
|
||||
public Observable<ConnectionPoolState> observeConnectionPool() {
|
||||
return stateObservable;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.mercury_im.messenger.xmpp.state;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import lombok.ToString;
|
||||
|
@ -11,6 +13,7 @@ import lombok.With;
|
|||
public class ConnectionState {
|
||||
|
||||
UUID id;
|
||||
XMPPConnection connection;
|
||||
@With
|
||||
ConnectivityState connectivity;
|
||||
@With
|
||||
|
@ -18,26 +21,11 @@ public class ConnectionState {
|
|||
@With
|
||||
boolean resumed;
|
||||
|
||||
public ConnectionState(UUID id, ConnectivityState connectivity, boolean authenticated, boolean resumed) {
|
||||
public ConnectionState(UUID id, XMPPConnection connection, ConnectivityState connectivity, boolean authenticated, boolean resumed) {
|
||||
this.id = id;
|
||||
this.connection = connection;
|
||||
this.connectivity = connectivity;
|
||||
this.authenticated = authenticated;
|
||||
this.resumed = resumed;
|
||||
}
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public ConnectivityState getConnectivity() {
|
||||
return connectivity;
|
||||
}
|
||||
|
||||
public boolean isAuthenticated() {
|
||||
return authenticated;
|
||||
}
|
||||
|
||||
public boolean isResumed() {
|
||||
return resumed;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit e79710840be6d6b3301e078a23688eafaa06013c
|
||||
Subproject commit e6e8547f7b29e9c961cb23020c0f0fe2ea1b0f14
|
Loading…
Reference in a new issue