@@ -102,7 +102,7 @@ public void onCreate() {
102
102
currentRealm = globalSettings .getInt (GLOBAL_SETTINGS_CURRENT , currentRealm );
103
103
serverStringSet = new ArrayList <String >(globalSettings .getStringSet (GLOBAL_SETTINGS_REALMS , new HashSet <String >()));
104
104
105
-
105
+ switchToRealm ( currentRealm );
106
106
if (BuildHelper .shouldLogToCrashlytics ()) {
107
107
// TODO(lfaraone): figure out what to do about crash reporting
108
108
}
@@ -389,4 +389,22 @@ public void createNewRealm() {
389
389
lastEventId = settings .getInt ("lastEventId" , -1 );
390
390
pointer = settings .getInt ("pointer" , -1 );
391
391
}
392
+
393
+ public void switchToRealm (int position ) {
394
+ databaseHelper = new DatabaseHelper (this , SERVER_SETTINGS + position );
395
+ this .settings = getSharedPreferences (SERVER_SETTINGS + position , Context .MODE_PRIVATE );
396
+ this .api_key = settings .getString ("api_key" , null );
397
+ max_message_id = settings .getInt ("max_message_id" , -1 );
398
+ eventQueueId = settings .getString ("eventQueueId" , null );
399
+ lastEventId = settings .getInt ("lastEventId" , -1 );
400
+ pointer = settings .getInt ("pointer" , -1 );
401
+ if (settings .contains ("email" ))
402
+ this .you = Person .getOrUpdate (this , settings .getString ("email" , null ), null , null );
403
+ currentRealm = position ;
404
+ if (position != currentRealm ) {
405
+ SharedPreferences .Editor edit = globalSettings .edit ();
406
+ edit .putInt (GLOBAL_SETTINGS_CURRENT , position );
407
+ edit .apply ();
408
+ }
409
+ }
392
410
}
0 commit comments