Skip to content
This repository was archived by the owner on Jul 25, 2024. It is now read-only.

Commit 1ee50e1

Browse files
committed
Switch realm method in ZulipActivity
Abort current connections, handlers and establish new ones. Changed Database name while connecting.
1 parent ca744a0 commit 1ee50e1

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

app/src/main/java/com/zulip/android/ZulipActivity.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
import android.annotation.SuppressLint;
1010
import android.annotation.TargetApi;
11+
import android.app.Activity;
1112
import android.app.AlertDialog;
13+
import android.app.ProgressDialog;
1214
import android.app.SearchManager;
1315
import android.content.BroadcastReceiver;
1416
import android.content.Context;
@@ -51,6 +53,29 @@ public class ZulipActivity extends FragmentActivity implements
5153

5254
ZulipApp app;
5355

56+
public void switchRealm(final ProgressDialog progressDialog, final int position) {
57+
if (event_poll != null) {
58+
event_poll.abort();
59+
event_poll = null;
60+
}
61+
statusUpdateHandler.removeMessages(0);
62+
unregisterReceiver(onGcmMessage);
63+
app.clearConnectionState();
64+
notifications.logOut(new Runnable() {
65+
@Override
66+
public void run() {
67+
app.switchToRealm(position);
68+
app.resetDatabase();
69+
app.setEmail(app.you.getEmail());
70+
event_poll = new AsyncGetEvents(ZulipActivity.this);
71+
event_poll.start();
72+
IntentFilter filter = new IntentFilter(GcmBroadcastReceiver.BROADCAST);
73+
filter.setPriority(2);
74+
registerReceiver(onGcmMessage, filter);
75+
progressDialog.dismiss();
76+
}
77+
});
78+
}
5479
// Intent Extra constants
5580
public enum Flag {
5681
RESET_DATABASE,

app/src/main/java/com/zulip/android/ZulipApp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public String getUserAgent() {
166166
}
167167

168168
public void setEmail(String email) {
169-
databaseHelper = new DatabaseHelper(this, email);
169+
databaseHelper = new DatabaseHelper(this, SERVER_SETTINGS + currentRealm);
170170
this.you = Person.getOrUpdate(this, email, null, null);
171171
}
172172

0 commit comments

Comments
 (0)