Cleanup
This commit is contained in:
parent
0b27a66dcd
commit
e150bb7631
|
@ -72,7 +72,10 @@ check.configure {
|
|||
// Dependency versions are located in version.gradle
|
||||
dependencies {
|
||||
|
||||
// Depend on the core project for XMPP related stuff
|
||||
implementation(project(':xmpp_core'))
|
||||
|
||||
// Plug a Room based implementation into the persistence api
|
||||
implementation(project(':persistence-room')) {
|
||||
transitive = true
|
||||
}
|
||||
|
@ -81,10 +84,6 @@ dependencies {
|
|||
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"
|
||||
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycleVersion"
|
||||
|
||||
// Dagger 2 for dependency injection
|
||||
implementation "com.google.dagger:dagger:$daggerVersion"
|
||||
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
|
||||
|
||||
// ButterKnife for View Binding
|
||||
implementation "com.jakewharton:butterknife:$butterKnifeVersion"
|
||||
annotationProcessor "com.jakewharton:butterknife-compiler:$butterKnifeVersion"
|
||||
|
@ -98,12 +97,14 @@ dependencies {
|
|||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.0.0'
|
||||
|
||||
// circular image viewer for avatars
|
||||
implementation 'de.hdodenhof:circleimageview:3.0.0'
|
||||
|
||||
// Android specific classes of Smacks API
|
||||
implementation "org.igniterealtime.smack:smack-android-extensions:$smackAndroidExtensionsVersion"
|
||||
|
||||
// Testing - as if...
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test:runner:1.2.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
|
||||
// circular image viewer for avatars
|
||||
implementation 'de.hdodenhof:circleimageview:2.2.0'
|
||||
|
||||
implementation "org.igniterealtime.smack:smack-android-extensions:$smackAndroidExtensionsVersion"
|
||||
}
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
package org.mercury_im.messenger;
|
||||
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||
import org.mercury_im.messenger.xmpp_core.ConnectionState;
|
||||
import org.mercury_im.messenger.xmpp_core.MercuryConnection;
|
||||
|
||||
public class AndroidMercuryConnection extends MercuryConnection {
|
||||
|
||||
private MutableLiveData<ConnectionState> connectionState = new MutableLiveData<>();
|
||||
|
||||
public AndroidMercuryConnection(XMPPTCPConnection connection, long accountId) {
|
||||
super(connection, accountId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connected(XMPPConnection connection) {
|
||||
super.connected(connection);
|
||||
connectionState.postValue(ConnectionState.CONNECTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void authenticated(XMPPConnection connection, boolean resumed) {
|
||||
super.authenticated(connection, resumed);
|
||||
connectionState.postValue(ConnectionState.CONNECTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionClosed() {
|
||||
super.connectionClosed();
|
||||
connectionState.postValue(ConnectionState.DISCONNECTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionClosedOnError(Exception e) {
|
||||
super.connectionClosedOnError(e);
|
||||
connectionState.postValue(ConnectionState.WAIRING_FOR_RETRY);
|
||||
}
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
package org.mercury_im.messenger.service;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.jxmpp.jid.EntityBareJid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
|
||||
public class XmppConnectionCredentials implements Parcelable {
|
||||
|
||||
public static final Creator<XmppConnectionCredentials> CREATOR = new Creator<XmppConnectionCredentials>() {
|
||||
@Override
|
||||
public XmppConnectionCredentials createFromParcel(Parcel in) {
|
||||
return new XmppConnectionCredentials(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public XmppConnectionCredentials[] newArray(int size) {
|
||||
return new XmppConnectionCredentials[size];
|
||||
}
|
||||
};
|
||||
|
||||
private long accountId;
|
||||
private EntityBareJid jid;
|
||||
private String password;
|
||||
|
||||
public XmppConnectionCredentials(Parcel in) {
|
||||
this.accountId = in.readLong();
|
||||
this.jid = JidCreate.entityBareFromOrNull(in.readString());
|
||||
this.password = in.readString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel parcel, int i) {
|
||||
parcel.writeLong(accountId);
|
||||
parcel.writeString(jid.asEntityBareJidString());
|
||||
parcel.writeString(password);
|
||||
}
|
||||
}
|
|
@ -5,50 +5,24 @@ import android.app.PendingIntent;
|
|||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
import android.util.LongSparseArray;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import org.jivesoftware.smack.SmackException;
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
import org.jivesoftware.smack.XMPPException;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
|
||||
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
|
||||
import org.jivesoftware.smackx.ping.android.ServerPingWithAlarmManager;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
import org.mercury_im.messenger.AndroidMercuryConnection;
|
||||
import org.mercury_im.messenger.MercuryImApplication;
|
||||
import org.mercury_im.messenger.Notifications;
|
||||
import org.mercury_im.messenger.R;
|
||||
import org.mercury_im.messenger.handler.RoomPlainMessageHandler;
|
||||
import org.mercury_im.messenger.handler.RoomRosterHandler;
|
||||
import org.mercury_im.messenger.persistence.model.AccountModel;
|
||||
import org.mercury_im.messenger.persistence.repository.AccountRepository;
|
||||
import org.mercury_im.messenger.persistence.repository.ContactRepository;
|
||||
import org.mercury_im.messenger.persistence.repository.EntityRepository;
|
||||
import org.mercury_im.messenger.persistence.room.dao.ContactDao;
|
||||
import org.mercury_im.messenger.persistence.room.dao.EntityDao;
|
||||
import org.mercury_im.messenger.ui.MainActivity;
|
||||
import org.mercury_im.messenger.xmpp_core.ConnectionHolder;
|
||||
import org.mercury_im.messenger.xmpp_core.ConnectionState;
|
||||
import org.mercury_im.messenger.xmpp_core.MercuryConnection;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
/**
|
||||
* Started, Bound Service, which is responsible for managing {@link XMPPConnection XMPPConnections}
|
||||
* affiliated with registered accounts.
|
||||
*/
|
||||
public class XmppConnectionService extends Service implements ConnectionHolder, MercuryConnection.ConnectionStateListener {
|
||||
public class XmppConnectionService extends Service {
|
||||
|
||||
private static final String TAG = MercuryImApplication.TAG;
|
||||
|
||||
|
@ -79,24 +53,6 @@ public class XmppConnectionService extends Service implements ConnectionHolder,
|
|||
public static final String STATUS_SUCCESS = STATUS + ".SUCCESS";
|
||||
public static final String STATUS_FAILURE = STATUS + ".FAILURE";
|
||||
|
||||
@Inject
|
||||
ContactRepository contactRepository;
|
||||
|
||||
@Inject
|
||||
AccountRepository accountRepository;
|
||||
|
||||
@Inject
|
||||
EntityRepository entityRepository;
|
||||
|
||||
@Inject
|
||||
EntityDao entityDao;
|
||||
|
||||
@Inject
|
||||
ContactDao contactDao;
|
||||
|
||||
private final LongSparseArray<MercuryConnection> connections = new LongSparseArray<>();
|
||||
|
||||
private Handler uiHandler;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
|
@ -110,18 +66,6 @@ public class XmppConnectionService extends Service implements ConnectionHolder,
|
|||
Log.d(TAG, "onCreate()");
|
||||
MercuryImApplication.getApplication().getAppComponent().inject(this);
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
List<AccountModel> accounts = accountRepository.getAllAccounts();
|
||||
|
||||
for(AccountModel accountModel : accounts) {
|
||||
startConnection(accountModel);
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
|
||||
|
||||
// Begin life cycle of Ping Manager.
|
||||
// The Manager will automatically detect newly created connections and ping the server
|
||||
// every half hour if necessary.
|
||||
|
@ -137,17 +81,6 @@ public class XmppConnectionService extends Service implements ConnectionHolder,
|
|||
ServerPingWithAlarmManager.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MercuryConnection getConnection(long accountId) {
|
||||
return connections.get(accountId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putConnection(long accountId, MercuryConnection connection) {
|
||||
connections.put(accountId, connection);
|
||||
connection.setConnectionStateListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.d(TAG, "onStartCommand(" + intent + ")");
|
||||
|
@ -175,70 +108,22 @@ public class XmppConnectionService extends Service implements ConnectionHolder,
|
|||
|
||||
public void startAndDisplayForegroundNotification() {
|
||||
Log.d(TAG, "startAndDisplayForegroundNotification()");
|
||||
Notification notification = getForegroundNotification(getApplicationContext(), connections.size());
|
||||
Notification notification = getForegroundNotification(getApplicationContext());
|
||||
|
||||
startForeground(Notifications.FOREGROUND_SERVICE_ID, notification);
|
||||
}
|
||||
|
||||
static Notification getForegroundNotification(Context context, int numConnections) {
|
||||
static Notification getForegroundNotification(Context context) {
|
||||
Intent startMainActivityIntent = new Intent(context, MainActivity.class);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
|
||||
startMainActivityIntent, 0);
|
||||
return new NotificationCompat.Builder(context, Notifications.NOTIFICATION_CHANNEL__FOREGROUND_SERVICE)
|
||||
.setContentTitle("Mercury")
|
||||
.setContentText(numConnections + " connections.")
|
||||
.setSmallIcon(R.drawable.ic_send_black_24dp)
|
||||
.setContentIntent(pendingIntent)
|
||||
.build();
|
||||
}
|
||||
|
||||
public void startConnection(AccountModel accountModel) {
|
||||
MercuryConnection connection = connections.get(accountModel.getId());
|
||||
|
||||
if (connection != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
XMPPTCPConnectionConfiguration configuration = XMPPTCPConnectionConfiguration.builder()
|
||||
.setHost(accountModel.getJid().getDomain().toString())
|
||||
.setXmppAddressAndPassword(accountModel.getJid(), accountModel.getPassword())
|
||||
.setConnectTimeout(2 * 60 * 1000)
|
||||
.build();
|
||||
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
XMPPTCPConnection connection = new XMPPTCPConnection(configuration);
|
||||
connection.setUseStreamManagement(true);
|
||||
connection.setUseStreamManagementResumption(true);
|
||||
MercuryConnection mercuryConnection = new AndroidMercuryConnection(connection, accountModel.getId());
|
||||
putConnection(accountModel.getId(), mercuryConnection);
|
||||
mercuryConnection.setRosterHandler(new RoomRosterHandler(mercuryConnection));
|
||||
mercuryConnection.setPlainMessageHandler(new RoomPlainMessageHandler(accountModel.getId()));
|
||||
|
||||
connection.connect().login();
|
||||
Log.d(MercuryImApplication.TAG, "Logged in for " + accountModel.getJid().toString());
|
||||
} catch (XmppStringprepException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SmackException e) {
|
||||
e.printStackTrace();
|
||||
} catch (XMPPException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stateChanged(MercuryConnection connection, ConnectionState state) {
|
||||
accountRepository.updateState(connection.getAccountId(), state.toString());
|
||||
}
|
||||
|
||||
public class Binder extends android.os.Binder {
|
||||
|
||||
private final XmppConnectionService service;
|
||||
|
|
|
@ -29,7 +29,6 @@ import org.mercury_im.messenger.persistence.model.AccountModel;
|
|||
import org.mercury_im.messenger.persistence.repository.AccountRepository;
|
||||
import org.mercury_im.messenger.persistence.room.model.RoomAccountModel;
|
||||
import org.mercury_im.messenger.ui.BindingActivity;
|
||||
import org.mercury_im.messenger.AndroidMercuryConnection;
|
||||
import org.mercury_im.messenger.xmpp_core.MercuryConnection;
|
||||
|
||||
import java.io.IOException;
|
||||
|
@ -158,8 +157,7 @@ public class LoginActivity extends BindingActivity implements TextView.OnEditorA
|
|||
XMPPTCPConnection connection = new XMPPTCPConnection(configuration);
|
||||
connection.setUseStreamManagementResumption(true);
|
||||
connection.setUseStreamManagement(true);
|
||||
MercuryConnection mercuryConnection = new AndroidMercuryConnection(connection, accountModel.getId());
|
||||
connectionService.putConnection(accountModel.getId(), mercuryConnection);
|
||||
MercuryConnection mercuryConnection = new MercuryConnection(connection, accountModel.getId());
|
||||
mercuryConnection.setRosterHandler(new RoomRosterHandler(mercuryConnection));
|
||||
mercuryConnection.setPlainMessageHandler(new RoomPlainMessageHandler(accountModel.getId()));
|
||||
|
||||
|
|
11
build.gradle
11
build.gradle
|
@ -25,10 +25,21 @@ allprojects {
|
|||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
mavenLocal()
|
||||
|
||||
// Smack nightly unique snapshots repo
|
||||
maven {
|
||||
url 'https://igniterealtime.org/repo/'
|
||||
}
|
||||
}
|
||||
|
||||
configurations {
|
||||
// Exclude XmlPullParser from Smack dependencies, as its now provided by Android
|
||||
// https://stackoverflow.com/questions/48488563/gradle-xpp3-error/48746294#48746294
|
||||
all {
|
||||
exclude group: 'xpp3', module: 'xpp3'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
|
|
|
@ -6,10 +6,8 @@ import androidx.room.Query;
|
|||
import androidx.room.TypeConverters;
|
||||
|
||||
import org.jxmpp.jid.EntityBareJid;
|
||||
import org.jxmpp.jid.EntityFullJid;
|
||||
import org.mercury_im.messenger.persistence.room.model.RoomMessageModel;
|
||||
import org.mercury_im.messenger.persistence.room.type_converter.EntityBareJidConverter;
|
||||
import org.mercury_im.messenger.persistence.room.type_converter.EntityFullJidConverter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
package org.mercury_im.messenger.persistence.room.type_converter;
|
||||
|
||||
import androidx.room.TypeConverter;
|
||||
|
||||
import org.jxmpp.jid.BareJid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
public class BareJidConverter {
|
||||
|
||||
@TypeConverter
|
||||
public static String bareJidToString(BareJid jid) {
|
||||
return jid != null ? jid.toString() : null;
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static BareJid stringToBareJid(String string) {
|
||||
try {
|
||||
return string != null ? JidCreate.bareFrom(string) : null;
|
||||
} catch (XmppStringprepException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package org.mercury_im.messenger.persistence.room.type_converter;
|
||||
|
||||
import androidx.room.TypeConverter;
|
||||
|
||||
import org.jxmpp.jid.EntityFullJid;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.jxmpp.stringprep.XmppStringprepException;
|
||||
|
||||
public class EntityFullJidConverter {
|
||||
|
||||
@TypeConverter
|
||||
public static String toString(EntityFullJid jid) {
|
||||
return jid != null ? jid.toString() : null;
|
||||
}
|
||||
|
||||
@TypeConverter
|
||||
public static EntityFullJid toEntityFullJid(String string) {
|
||||
try {
|
||||
return string != null ? JidCreate.entityFullFrom(string) : null;
|
||||
} catch (XmppStringprepException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -2,24 +2,71 @@ package org.mercury_im.messenger.persistence.model;
|
|||
|
||||
import org.jxmpp.jid.EntityBareJid;
|
||||
|
||||
/**
|
||||
* Interface representing an account database entity.
|
||||
*/
|
||||
public interface AccountModel {
|
||||
|
||||
/**
|
||||
* Primary key.
|
||||
*
|
||||
* @return account id
|
||||
*/
|
||||
long getId();
|
||||
|
||||
/**
|
||||
* Set the primary key.
|
||||
*
|
||||
* @param id account id
|
||||
*/
|
||||
void setId(long id);
|
||||
|
||||
/**
|
||||
* Return the password of the XMPP account.
|
||||
*
|
||||
* @return password
|
||||
*/
|
||||
String getPassword();
|
||||
|
||||
/**
|
||||
* Set the password of the XMPP account.
|
||||
*
|
||||
* @param password password
|
||||
*/
|
||||
void setPassword(String password);
|
||||
|
||||
/**
|
||||
* Return the JID of the XMPP account.
|
||||
*
|
||||
* @return XMPP address
|
||||
*/
|
||||
EntityBareJid getJid();
|
||||
|
||||
/**
|
||||
* Set the JID of the XMPP account.
|
||||
*
|
||||
* @param jid XMPP address
|
||||
*/
|
||||
void setJid(EntityBareJid jid);
|
||||
|
||||
/**
|
||||
* Is the account enabled (should it be online).
|
||||
*
|
||||
* @return account enabled?
|
||||
*/
|
||||
boolean getEnabled();
|
||||
|
||||
/**
|
||||
* Set whether or not the account is enabled and active.
|
||||
*
|
||||
* @param enabled enabled
|
||||
*/
|
||||
void setEnabled(boolean enabled);
|
||||
|
||||
/**
|
||||
* Return the
|
||||
* @return
|
||||
*/
|
||||
String getState();
|
||||
|
||||
void setState(String state);
|
||||
|
|
|
@ -8,14 +8,29 @@ ext {
|
|||
|
||||
smackAndroidVersion = smackVersion
|
||||
smackAndroidExtensionsVersion = smackVersion
|
||||
smackBoshVersion = smackVersion
|
||||
smackCompressionJzlibVersion = smackVersion
|
||||
smackCoreVersion = smackVersion
|
||||
smackDebugVersion = smackVersion
|
||||
smackDebugSlf4jVersion = smackVersion
|
||||
smackExperimentalVersion = smackVersion
|
||||
smackExtensionsVersion = smackVersion
|
||||
smackImVersion = smackVersion
|
||||
smackIntegrationTestVersion = smackVersion
|
||||
smackJava7Version = smackVersion
|
||||
smackJingleOldVersion = smackVersion
|
||||
smackLegacyVersion = smackVersion
|
||||
smackOmemoVersion = smackVersion
|
||||
smackOmemoSignalVersion = smackVersion
|
||||
smackOmemoSignalIntegrationTestVersion = smackVersion
|
||||
smackOpenpgpVersion = smackVersion
|
||||
smackResolverMiniDnsVersion = smackVersion
|
||||
smackReplVersion = smackVersion
|
||||
smackResolverDnsjavaVersion = smackVersion
|
||||
smackResolverJavaxVersion = smackVersion
|
||||
smackResolverMinidnsVersion = smackVersion
|
||||
smackResolverMinidnsDoxVersion = smackVersion
|
||||
smackSaslJavaxVersion = smackVersion
|
||||
smackSaslProvidedVersion = smackVersion
|
||||
smackTcpVersion = smackVersion
|
||||
|
||||
/*/
|
||||
|
@ -23,32 +38,33 @@ ext {
|
|||
// https://github.com/igniterealtime/Smack/wiki/How-to-use-Smack-snapshots
|
||||
// These can be determined using utils/smack-unique-snapshots.sh
|
||||
|
||||
smackAndroidVersion = "4.4.0-alpha2-20190429.010406-55"
|
||||
smackAndroidExtensionsVersion = "4.4.0-alpha2-20190429.010406-55"
|
||||
smackBoshVersion = "4.4.0-alpha2-20190429.010407-55"
|
||||
smackCompressionJzlibVersion = "4.4.0-alpha2-20190429.010407-55"
|
||||
smackCoreVersion = "4.4.0-alpha2-20190429.010407-55"
|
||||
smackDebugVersion = "4.4.0-alpha2-20190429.010407-55"
|
||||
smackDebugSlf4jVersion = "4.4.0-alpha2-20190429.010407-55"
|
||||
smackExperimentalVersion = "4.4.0-alpha2-20190429.010407-55"
|
||||
smackExtensionsVersion = "4.4.0-alpha2-20190429.010408-54"
|
||||
smackImVersion = "4.4.0-alpha2-20190429.010408-54"
|
||||
smackIntegrationTestVersion = "4.4.0-alpha2-20190429.010408-51"
|
||||
smackJava7Version = "4.4.0-alpha2-20190429.010409-54"
|
||||
smackJingleOldVersion = "4.4.0-alpha2-20190429.010409-54"
|
||||
smackLegacyVersion = "4.4.0-alpha2-20190429.010409-54"
|
||||
smackOmemoVersion = "4.4.0-alpha2-20190429.010409-54"
|
||||
smackOmemoSignalVersion = "4.4.0-alpha2-20190429.010409-54"
|
||||
smackOmemoSignalIntegrationTestVersion = "4.4.0-alpha2-20190429.010409-51"
|
||||
smackOpenpgpVersion = "4.4.0-alpha2-20190429.010410-50"
|
||||
smackReplVersion = "4.4.0-alpha2-20190429.010410-54"
|
||||
smackResolverDnsjavaVersion = "4.4.0-alpha2-20190429.010410-54"
|
||||
smackResolverJavaxVersion = "4.4.0-alpha2-20190429.010410-54"
|
||||
smackResolverMinidnsVersion = "4.4.0-alpha2-20190429.010410-54"
|
||||
smackResolverMinidnsDoxVersion = "4.4.0-alpha2-20190429.010410-2"
|
||||
smackSaslJavaxVersion = "4.4.0-alpha2-20190429.010410-54"
|
||||
smackSaslProvidedVersion = "4.4.0-alpha2-20190429.010410-54"
|
||||
smackTcpVersion = "4.4.0-alpha2-20190429.010411-54"
|
||||
smackAndroidVersion = "4.4.0-alpha2-20190721.010510-56"
|
||||
smackAndroidExtensionsVersion = "4.4.0-alpha2-20190721.010510-56"
|
||||
smackBoshVersion = "4.4.0-alpha2-20190721.010510-56"
|
||||
smackCompressionJzlibVersion = "4.4.0-alpha2-20190721.010510-56"
|
||||
smackCoreVersion = "4.4.0-alpha2-20190721.010511-56"
|
||||
smackDebugVersion = "4.4.0-alpha2-20190721.010511-56"
|
||||
smackDebugSlf4jVersion = "4.4.0-alpha2-20190721.010511-56"
|
||||
smackExperimentalVersion = "4.4.0-alpha2-20190721.010511-56"
|
||||
smackExtensionsVersion = "4.4.0-alpha2-20190721.010511-55"
|
||||
smackImVersion = "4.4.0-alpha2-20190721.010511-55"
|
||||
smackIntegrationTestVersion = "4.4.0-alpha2-20190721.010512-52"
|
||||
smackJava7Version = "4.4.0-alpha2-20190721.010512-55"
|
||||
smackJingleOldVersion = "4.4.0-alpha2-20190721.010513-55"
|
||||
smackLegacyVersion = "4.4.0-alpha2-20190721.010513-55"
|
||||
smackOmemoVersion = "4.4.0-alpha2-20190721.010513-55"
|
||||
smackOmemoSignalVersion = "4.4.0-alpha2-20190721.010513-55"
|
||||
smackOmemoSignalIntegrationTestVersion = "4.4.0-alpha2-20190721.010513-52"
|
||||
smackOpenpgpVersion = "4.4.0-alpha2-20190721.010514-51"
|
||||
smackReplVersion = "4.4.0-alpha2-20190721.010514-55"
|
||||
smackResolverDnsjavaVersion = "4.4.0-alpha2-20190721.010514-55"
|
||||
smackResolverJavaxVersion = "4.4.0-alpha2-20190721.010514-55"
|
||||
smackResolverMinidnsVersion = "4.4.0-alpha2-20190721.010514-55"
|
||||
smackResolverMinidnsDoxVersion = "4.4.0-alpha2-20190721.010514-3"
|
||||
smackSaslJavaxVersion = "4.4.0-alpha2-20190721.010515-55"
|
||||
smackSaslProvidedVersion = "4.4.0-alpha2-20190721.010515-55"
|
||||
smackTcpVersion = "4.4.0-alpha2-20190721.010515-55"
|
||||
|
||||
//*/
|
||||
|
||||
// Other libraries
|
||||
|
|
|
@ -8,17 +8,16 @@ dependencies {
|
|||
api "org.igniterealtime.smack:smack-experimental:$smackExperimentalVersion"
|
||||
api "org.igniterealtime.smack:smack-extensions:$smackExtensionsVersion"
|
||||
api "org.igniterealtime.smack:smack-im:$smackImVersion"
|
||||
//api "org.igniterealtime.smack:smack-omemo:$smackOmemoVersion"
|
||||
//api "org.igniterealtime.smack:smack-omemo-signal:$smackOmemoSignalVersion"
|
||||
//api "org.igniterealtime.smack:smack-openpgp:$smackOpenpgpVersion"
|
||||
// api "org.igniterealtime.smack:smack-resolver-minidns:$smackResolverMiniDnsVersion"
|
||||
api "org.igniterealtime.smack:smack-tcp:$smackTcpVersion"
|
||||
|
||||
// Exclude XmlPullParser from Smack dependencies, as its now provided by Android
|
||||
// https://stackoverflow.com/questions/48488563/gradle-xpp3-error/48746294#48746294
|
||||
configurations {
|
||||
all*.exclude group: 'xpp3', module: 'xpp3'
|
||||
}
|
||||
// api "org.igniterealtime.smack:smack-omemo:$smackOmemoVersion"
|
||||
// api "org.igniterealtime.smack:smack-omemo-signal:$smackOmemoSignalVersion"
|
||||
// api "org.igniterealtime.smack:smack-openpgp:$smackOpenpgpVersion"
|
||||
// api "org.igniterealtime.smack:smack-resolver-minidns:$smackResolverMiniDnsVersion"
|
||||
|
||||
// Dagger 2 for dependency injection
|
||||
api "com.google.dagger:dagger:$daggerVersion"
|
||||
annotationProcessor "com.google.dagger:dagger-compiler:$daggerVersion"
|
||||
}
|
||||
|
||||
sourceCompatibility = "8"
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package org.mercury_im.messenger.xmpp_core;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ConnectionCenter {
|
||||
|
||||
private static ConnectionCenter INSTANCE;
|
||||
|
||||
private final Map<Long, MercuryConnection> connectionMap = new HashMap<>();
|
||||
|
||||
private ConnectionCenter() {
|
||||
|
||||
}
|
||||
|
||||
public static ConnectionCenter get() {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new ConnectionCenter();
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public MercuryConnection getConnection(long accountId) {
|
||||
return connectionMap.get(accountId);
|
||||
}
|
||||
|
||||
public void putConnection(MercuryConnection connection) {
|
||||
connectionMap.put(connection.getAccountId(), connection);
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package org.mercury_im.messenger.xmpp_core;
|
||||
|
||||
public interface ConnectionHolder {
|
||||
|
||||
MercuryConnection getConnection(long accountId);
|
||||
|
||||
void putConnection(long accountId, MercuryConnection connection);
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
package org.mercury_im.messenger.xmpp_core;
|
||||
|
||||
public interface ConnectionStateHolder {
|
||||
|
||||
void updateConnectionState(ConnectionState state);
|
||||
}
|
|
@ -24,7 +24,7 @@ import org.jivesoftware.smackx.sid.StableUniqueStanzaIdManager;
|
|||
import java.io.IOException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public abstract class MercuryConnection implements ConnectionListener {
|
||||
public class MercuryConnection implements ConnectionListener {
|
||||
|
||||
public static final String TAG = "Mercury";
|
||||
|
||||
|
@ -40,10 +40,6 @@ public abstract class MercuryConnection implements ConnectionListener {
|
|||
protected final StableUniqueStanzaIdManager stanzaIdManager;
|
||||
protected final ServiceDiscoveryManager serviceDiscoveryManager;
|
||||
|
||||
protected ConnectionStateHolder stateHolder;
|
||||
|
||||
protected ConnectionStateListener stateListener = null;
|
||||
|
||||
public MercuryConnection(XMPPConnection connection, long accountId) {
|
||||
this.connection = connection;
|
||||
connection.addConnectionListener(this);
|
||||
|
@ -74,10 +70,6 @@ public abstract class MercuryConnection implements ConnectionListener {
|
|||
return connection;
|
||||
}
|
||||
|
||||
public void setConnectionStateListener(ConnectionStateListener stateListener) {
|
||||
this.stateListener = stateListener;
|
||||
}
|
||||
|
||||
public void setRosterHandler(RosterHandler handler) {
|
||||
roster.addRosterListener(handler);
|
||||
roster.addRosterLoadedListener(handler);
|
||||
|
@ -100,7 +92,6 @@ public abstract class MercuryConnection implements ConnectionListener {
|
|||
@Override
|
||||
public void connected(XMPPConnection connection) {
|
||||
LOGGER.info("Connection " + getAccountId() + " connected.");
|
||||
notifyStateListener(ConnectionState.CONNECTING);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -113,28 +104,16 @@ public abstract class MercuryConnection implements ConnectionListener {
|
|||
exception.printStackTrace();
|
||||
});
|
||||
}
|
||||
notifyStateListener(ConnectionState.CONNECTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionClosed() {
|
||||
LOGGER.fine("Connection " + accountId + " closed.");
|
||||
notifyStateListener(ConnectionState.DISCONNECTED);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void connectionClosedOnError(Exception e) {
|
||||
LOGGER.severe("Connection " + accountId + " closed on error: " + e.getMessage());
|
||||
notifyStateListener(ConnectionState.WAIRING_FOR_RETRY);
|
||||
}
|
||||
|
||||
private void notifyStateListener(ConnectionState newState) {
|
||||
if (stateListener != null) {
|
||||
stateListener.stateChanged(this, newState);
|
||||
}
|
||||
}
|
||||
|
||||
public interface ConnectionStateListener {
|
||||
void stateChanged(MercuryConnection connection, ConnectionState state);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue