@@ -83,6 +83,7 @@ public void onCreate() {
8383 currentRealm = globalSettings .getInt (GLOBAL_SETTINGS_CURRENT , currentRealm );
8484 serverStringSet = new ArrayList <String >(globalSettings .getStringSet (GLOBAL_SETTINGS_REALMS , new HashSet <String >()));
8585
86+ switchToRealm (currentRealm );
8687
8788 if (BuildHelper .shouldLogToCrashlytics ()) {
8889 Crashlytics .start (this );
@@ -279,6 +280,23 @@ public void markMessageAsRead(Message message) {
279280 unreadMessageHandler .sendEmptyMessageDelayed (0 , 2000 );
280281 }
281282 }
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+ }
282300 public void saveServer (String server , String name ) {
283301 SharedPreferences .Editor globalEditor = this .globalSettings .edit ();
284302 serverStringSet .add (name );
0 commit comments