Commit d4683f4a authored by Yusuke Iwaki's avatar Yusuke Iwaki

fix issue realm#close() is called dupplicately

parent 68e85070
......@@ -123,13 +123,6 @@ public class MainActivity extends AbstractAuthedActivity {
}
}
@Override protected void onResume() {
super.onResume();
if (sessionObserver != null) {
sessionObserver.keepalive();
}
}
@Override protected void onDestroy() {
if (sessionObserver != null) {
sessionObserver.unsub();
......
......@@ -49,7 +49,6 @@ public class InputHostnameFragment extends AbstractServerConfigFragment {
@Override public void onResume() {
super.onResume();
serverConfigObserver.keepalive();
}
@Override public void onDestroyView() {
......
......@@ -9,11 +9,6 @@ public interface Registerable {
*/
void register();
/**
* keepalive.
*/
void keepalive();
/**
* unregister.
*/
......
......@@ -88,7 +88,7 @@ public class RocketChatService extends Service {
}
return null;
}).onSuccessTask(task -> {
connectionRequiredServerConfigObserver.keepalive();
connectionRequiredServerConfigObserver.sub();
return null;
});
return START_STICKY;
......@@ -133,6 +133,13 @@ public class RocketChatService extends Service {
}
}
@Override public void onDestroy() {
if (connectionRequiredServerConfigObserver != null) {
connectionRequiredServerConfigObserver.unsub();
}
super.onDestroy();
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
......
......@@ -134,8 +134,6 @@ public class RocketChatWebSocketThread extends HandlerThread {
}
return null;
});
} else {
new Handler(getLooper()).post(this::keepaliveListeners);
}
}
......@@ -227,17 +225,6 @@ public class RocketChatWebSocketThread extends HandlerThread {
}
}
//@DebugLog
private void keepaliveListeners() {
if (!listenersRegistered) {
return;
}
for (Registerable registerable : listeners) {
registerable.keepalive();
}
}
@DebugLog
private void unregisterListeners() {
if (!listenersRegistered) {
......
......@@ -139,10 +139,6 @@ abstract class AbstractDDPDocEventSubscriber implements Registerable {
}
}
@Override public void keepalive() {
}
@Override public void unregister() {
if (rxSubscription != null) {
rxSubscription.unsubscribe();
......
......@@ -27,10 +27,6 @@ abstract class AbstractModelObserver<T extends RealmObject>
observer.sub();
}
@Override public void keepalive() {
observer.keepalive();
}
@Override public void unregister() {
observer.unsub();
}
......
......@@ -4,7 +4,6 @@ import io.realm.Realm;
import io.realm.RealmChangeListener;
import io.realm.RealmObject;
import io.realm.RealmResults;
import timber.log.Timber;
abstract class AbstractRealmResultsObserver<T extends RealmObject> {
protected Realm realm;
......@@ -31,26 +30,16 @@ abstract class AbstractRealmResultsObserver<T extends RealmObject> {
results.addChangeListener(listener);
}
public void keepalive() {
if (realm == null || realm.isClosed() || !results.isValid()) {
unsub();
sub();
}
}
public void unsub() {
try {
if (realm != null) {
if (results != null) {
if (results.isValid()) {
results.removeChangeListener(listener);
}
results = null;
}
if (realm != null && !realm.isClosed()) {
realm.close();
}
} catch (IllegalStateException exception) {
Timber.w(exception, "failed to unsub. ignore.");
realm = null;
}
}
......
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