Commit 5f7280f6 authored by Enzo's avatar Enzo

#1 - Change Hostname on logout - fixed RC Cache Crash and RealmConfiguration access same file error

parent b83023b3
......@@ -16,7 +16,6 @@ import android.widget.TextView;
import com.jakewharton.rxbinding2.support.v7.widget.RxSearchView;
import com.jakewharton.rxbinding2.widget.RxCompoundButton;
import chat.rocket.android.LaunchUtil;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
......@@ -268,8 +267,9 @@ public class SidebarMainFragment extends AbstractFragment implements SidebarMain
rootView.findViewById(R.id.btn_logout).setOnClickListener(view -> {
presenter.onLogout();
closeUserActionContainer();
//go back to the AddServerActivity
LaunchUtil.showAddServerActivity(getContext());
// destroy Activity on logout to be able to recreate most of the environment
this.getActivity().finish();
});
}
......
......@@ -10,6 +10,9 @@ import android.support.annotation.Nullable;
import java.util.HashMap;
import java.util.concurrent.TimeUnit;
import chat.rocket.android.activity.MainActivity;
import chat.rocket.persistence.realm.RealmStore;
import hugo.weaving.DebugLog;
import rx.Observable;
import rx.Single;
......@@ -49,7 +52,6 @@ public class RocketChatService extends Service implements ConnectivityServiceInt
@Override
public void onCreate() {
super.onCreate();
connectivityManager = ConnectivityManager.getInstanceForInternal(getApplicationContext());
connectivityManager.resetConnectivityStateList();
webSocketThreads = new HashMap<>();
......@@ -81,10 +83,18 @@ public class RocketChatService extends Service implements ConnectivityServiceInt
RocketChatWebSocketThread thread = webSocketThreads.get(hostname);
if (thread != null) {
return thread.terminate()
//after disconnection from server, remove RCWebSocket key from HashMap
// after disconnection from server
.doAfterTerminate(() -> {
// remove RCWebSocket key from HashMap
webSocketThreads.remove(hostname);
stopSelf();
// remove RealmConfiguration key from HashMap
RealmStore.sStore.remove(hostname);
// clear "cache" SharedPreference
this.getSharedPreferences("cache", 0).edit().clear().apply();
// start a fresh new MainActivity
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);
});
} else {
return Observable.timer(1, TimeUnit.SECONDS).toSingle()
......
......@@ -70,4 +70,16 @@ public class Migration implements RealmMigration {
messageSchema.addField(RealmMessage.EDITED_AT, long.class);
}
}
// hack around to avoid "new different configuration cannot access the same file" error
@Override
public int hashCode() {
return 37;
}
@Override
public boolean equals(Object o) {
return (o instanceof Migration);
}
// end hack
}
......@@ -16,6 +16,8 @@ public class RealmStore {
.modules(new RocketChatLibraryModule())
.migration(new Migration())
.schemaVersion(5)
// Just in case
.deleteRealmIfMigrationNeeded()
.build();
}
......
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