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

Commit 119848c

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 2cb7684 commit 119848c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ public void onCreate() {
112112
currentRealm = globalSettings.getInt(GLOBAL_SETTINGS_CURRENT, currentRealm);
113113
serverStringSet = new HashSet<String>(globalSettings.getStringSet(GLOBAL_SETTINGS_REALMS, new HashSet<String>()));
114114

115-
116-
115+
switchToRealm(currentRealm);
117116
this.api_key = settings.getString(API_KEY, null);
118117

119118
if (api_key != null) {
@@ -401,4 +400,22 @@ public void createNewRealm() {
401400
lastEventId = settings.getInt("lastEventId", -1);
402401
pointer = settings.getInt("pointer", -1);
403402
}
403+
404+
public void switchToRealm(int position) {
405+
databaseHelper = new DatabaseHelper(this, SERVER_SETTINGS + position);
406+
this.settings = getSharedPreferences(SERVER_SETTINGS + position, Context.MODE_PRIVATE);
407+
this.api_key = settings.getString("api_key", null);
408+
max_message_id = settings.getInt("max_message_id", -1);
409+
eventQueueId = settings.getString("eventQueueId", null);
410+
lastEventId = settings.getInt("lastEventId", -1);
411+
pointer = settings.getInt("pointer", -1);
412+
if (settings.contains("email"))
413+
this.you = Person.getOrUpdate(this, settings.getString("email", null), null, null);
414+
currentRealm = position;
415+
if (position != currentRealm) {
416+
SharedPreferences.Editor edit = globalSettings.edit();
417+
edit.putInt(GLOBAL_SETTINGS_CURRENT, position);
418+
edit.apply();
419+
}
420+
}
404421
}

0 commit comments

Comments
 (0)