Commit 3da22c34 authored by Yusuke Iwaki's avatar Yusuke Iwaki

just rename xxxImpl

parent bcfb862d
......@@ -6,7 +6,7 @@ import android.content.Context;
* Connectivity Manager API Factory.
*/
public class ConnectivityManager {
private static final ConnectivityManagerImpl IMPL = new ConnectivityManagerImpl();
private static final RealmBasedConnectivityManager IMPL = new RealmBasedConnectivityManager();
public static ConnectivityManagerApi getInstance(Context appContext) {
return IMPL.setContext(appContext);
......
......@@ -21,7 +21,8 @@ import rx.subjects.PublishSubject;
/**
* Connectivity management implementation.
*/
/*package*/ class ConnectivityManagerImpl implements ConnectivityManagerApi, ConnectivityManagerInternal {
/*package*/ class RealmBasedConnectivityManager
implements ConnectivityManagerApi, ConnectivityManagerInternal {
private final HashMap<String, Integer> serverConnectivityList = new HashMap<>();
private final PublishSubject<ServerConnectivity> connectivitySubject = PublishSubject.create();
private Context appContext;
......@@ -39,7 +40,7 @@ import rx.subjects.PublishSubject;
private ConnectivityServiceInterface serviceInterface;
/*package*/ ConnectivityManagerImpl setContext(Context appContext) {
/*package*/ RealmBasedConnectivityManager setContext(Context appContext) {
this.appContext = appContext;
return this;
}
......@@ -47,7 +48,7 @@ import rx.subjects.PublishSubject;
@Override
public void resetConnectivityStateList() {
serverConnectivityList.clear();
for (ServerInfo serverInfo : ServerInfoImpl.getAllFromRealm()) {
for (ServerInfo serverInfo : RealmBasedServerInfo.getServerInfoList()) {
serverConnectivityList.put(serverInfo.hostname, ServerConnectivity.STATE_DISCONNECTED);
}
}
......@@ -72,8 +73,8 @@ import rx.subjects.PublishSubject;
@Override
public void addOrUpdateServer(String hostname, @Nullable String name, boolean insecure) {
ServerInfoImpl.addOrUpdate(hostname, name);
ServerInfoImpl.setInsecure(hostname, insecure);
RealmBasedServerInfo.addOrUpdate(hostname, name);
RealmBasedServerInfo.setInsecure(hostname, insecure);
if (!serverConnectivityList.containsKey(hostname)) {
serverConnectivityList.put(hostname, ServerConnectivity.STATE_DISCONNECTED);
}
......@@ -83,7 +84,7 @@ import rx.subjects.PublishSubject;
@Override
public void removeServer(String hostname) {
ServerInfoImpl.remove(hostname);
RealmBasedServerInfo.remove(hostname);
if (serverConnectivityList.containsKey(hostname)) {
disconnectFromServerIfNeeded(hostname)
.subscribe(_val -> { }, RCLog::e);
......@@ -97,12 +98,12 @@ import rx.subjects.PublishSubject;
@Override
public List<ServerInfo> getServerList() {
return ServerInfoImpl.getAllFromRealm();
return RealmBasedServerInfo.getServerInfoList();
}
@Override
public ServerInfo getServerInfoForHost(String hostname) {
return ServerInfoImpl.getServerInfoForHost(hostname);
return RealmBasedServerInfo.getServerInfoForHost(hostname);
}
private List<ServerConnectivity> getCurrentConnectivityList() {
......@@ -116,7 +117,7 @@ import rx.subjects.PublishSubject;
@DebugLog
@Override
public void notifyConnectionEstablished(String hostname, String session) {
ServerInfoImpl.updateSession(hostname, session);
RealmBasedServerInfo.updateSession(hostname, session);
serverConnectivityList.put(hostname, ServerConnectivity.STATE_CONNECTED);
connectivitySubject.onNext(
new ServerConnectivity(hostname, ServerConnectivity.STATE_CONNECTED));
......
......@@ -15,7 +15,7 @@ import chat.rocket.android.realm_helper.RealmStore;
/**
* Backend implementation to store ServerInfo.
*/
public class ServerInfoImpl extends RealmObject {
public class RealmBasedServerInfo extends RealmObject {
private static final String DB_NAME = "serverlist";
@PrimaryKey private String hostname;
......@@ -40,14 +40,14 @@ public class ServerInfoImpl extends RealmObject {
static void addOrUpdate(String hostname, String name) {
getRealm().executeTransaction(realm ->
realm.createOrUpdateObjectFromJson(ServerInfoImpl.class, new JSONObject()
realm.createOrUpdateObjectFromJson(RealmBasedServerInfo.class, new JSONObject()
.put(ColumnName.HOSTNAME, hostname)
.put(ColumnName.NAME, TextUtils.isEmpty(name) ? JSONObject.NULL : name)));
}
static void remove(String hostname) {
getRealm().executeTransaction(realm -> {
realm.where(ServerInfoImpl.class).equalTo(ColumnName.HOSTNAME, hostname)
realm.where(RealmBasedServerInfo.class).equalTo(ColumnName.HOSTNAME, hostname)
.findAll()
.deleteAllFromRealm();
return null;
......@@ -55,8 +55,8 @@ public class ServerInfoImpl extends RealmObject {
}
static void updateSession(String hostname, String session) {
ServerInfoImpl impl = getRealm().executeTransactionForRead(realm ->
realm.where(ServerInfoImpl.class).equalTo(ColumnName.HOSTNAME, hostname).findFirst());
RealmBasedServerInfo impl = getRealm().executeTransactionForRead(realm ->
realm.where(RealmBasedServerInfo.class).equalTo(ColumnName.HOSTNAME, hostname).findFirst());
if (impl != null) {
impl.session = session;
......@@ -68,14 +68,14 @@ public class ServerInfoImpl extends RealmObject {
}
static @Nullable ServerInfo getServerInfoForHost(String hostname) {
ServerInfoImpl impl = getRealm().executeTransactionForRead(realm ->
realm.where(ServerInfoImpl.class).equalTo(ColumnName.HOSTNAME, hostname).findFirst());
RealmBasedServerInfo impl = getRealm().executeTransactionForRead(realm ->
realm.where(RealmBasedServerInfo.class).equalTo(ColumnName.HOSTNAME, hostname).findFirst());
return impl == null ? null : impl.getServerInfo();
}
static void setInsecure(String hostname, boolean insecure) {
ServerInfoImpl impl = getRealm().executeTransactionForRead(realm ->
realm.where(ServerInfoImpl.class).equalTo(ColumnName.HOSTNAME, hostname).findFirst());
RealmBasedServerInfo impl = getRealm().executeTransactionForRead(realm ->
realm.where(RealmBasedServerInfo.class).equalTo(ColumnName.HOSTNAME, hostname).findFirst());
if (impl != null) {
impl.insecure = insecure;
......@@ -86,11 +86,11 @@ public class ServerInfoImpl extends RealmObject {
}
}
static List<ServerInfo> getAllFromRealm() {
List<ServerInfoImpl> results = getRealm().executeTransactionForReadResults(realm ->
realm.where(ServerInfoImpl.class).findAll());
static List<ServerInfo> getServerInfoList() {
List<RealmBasedServerInfo> results = getRealm().executeTransactionForReadResults(realm ->
realm.where(RealmBasedServerInfo.class).findAll());
ArrayList<ServerInfo> list = new ArrayList<>();
for (ServerInfoImpl impl : results) {
for (RealmBasedServerInfo impl : results) {
list.add(impl.getServerInfo());
}
return list;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment