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

just rename xxxImpl

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