@@ -83,6 +83,7 @@ public void onCreate() {
83
83
currentRealm = globalSettings .getInt (GLOBAL_SETTINGS_CURRENT , currentRealm );
84
84
serverStringSet = new ArrayList <String >(globalSettings .getStringSet (GLOBAL_SETTINGS_REALMS , new HashSet <String >()));
85
85
86
+ switchToRealm (currentRealm );
86
87
87
88
if (BuildHelper .shouldLogToCrashlytics ()) {
88
89
Crashlytics .start (this );
@@ -279,6 +280,23 @@ public void markMessageAsRead(Message message) {
279
280
unreadMessageHandler .sendEmptyMessageDelayed (0 , 2000 );
280
281
}
281
282
}
283
+ public void switchToRealm (int position ) {
284
+ databaseHelper = new DatabaseHelper (this , SERVER_SETTINGS + position );
285
+ this .settings = getSharedPreferences (SERVER_SETTINGS + position , Context .MODE_PRIVATE );
286
+ this .api_key = settings .getString ("api_key" , null );
287
+ max_message_id = settings .getInt ("max_message_id" , -1 );
288
+ eventQueueId = settings .getString ("eventQueueId" , null );
289
+ lastEventId = settings .getInt ("lastEventId" , -1 );
290
+ pointer = settings .getInt ("pointer" , -1 );
291
+ if (settings .contains ("email" ))
292
+ this .you = Person .getOrUpdate (this , settings .getString ("email" , null ), null , null );
293
+ currentRealm = position ;
294
+ if (position != currentRealm ) {
295
+ SharedPreferences .Editor edit = globalSettings .edit ();
296
+ edit .putInt (GLOBAL_SETTINGS_CURRENT , position );
297
+ edit .apply ();
298
+ }
299
+ }
282
300
public void saveServer (String server , String name ) {
283
301
SharedPreferences .Editor globalEditor = this .globalSettings .edit ();
284
302
serverStringSet .add (name );
0 commit comments