@@ -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