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

Commit 2ef8fc8

Browse files
committed
Method to switch the current realm
Saves current server position, changes the databaseHelper and get's the saved data for this server
1 parent 2dde2e0 commit 2ef8fc8

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public void onCreate() {
100100
currentRealm = globalSettings.getInt(GLOBAL_SETTINGS_CURRENT, currentRealm);
101101
serverStringSet = new HashSet<String>(globalSettings.getStringSet(GLOBAL_SETTINGS_REALMS, new HashSet<String>()));
102102

103-
103+
switchToRealm(currentRealm);
104104
if (BuildHelper.shouldLogToCrashlytics()) {
105105
// TODO(lfaraone): figure out what to do about crash reporting
106106
}
@@ -387,4 +387,22 @@ public void createNewRealm() {
387387
lastEventId = settings.getInt("lastEventId", -1);
388388
pointer = settings.getInt("pointer", -1);
389389
}
390+
391+
public void switchToRealm(int position) {
392+
databaseHelper = new DatabaseHelper(this, SERVER_SETTINGS + position);
393+
this.settings = getSharedPreferences(SERVER_SETTINGS + position, Context.MODE_PRIVATE);
394+
this.api_key = settings.getString("api_key", null);
395+
max_message_id = settings.getInt("max_message_id", -1);
396+
eventQueueId = settings.getString("eventQueueId", null);
397+
lastEventId = settings.getInt("lastEventId", -1);
398+
pointer = settings.getInt("pointer", -1);
399+
if (settings.contains("email"))
400+
this.you = Person.getOrUpdate(this, settings.getString("email", null), null, null);
401+
currentRealm = position;
402+
if (position != currentRealm) {
403+
SharedPreferences.Editor edit = globalSettings.edit();
404+
edit.putInt(GLOBAL_SETTINGS_CURRENT, position);
405+
edit.apply();
406+
}
407+
}
390408
}

0 commit comments

Comments
 (0)