RocketChatApplication.java 1.27 KB
Newer Older
1 2 3
package chat.rocket.android;

import android.app.Application;
4 5
import chat.rocket.android.model.ServerConfig;
import chat.rocket.android.realm_helper.RealmStore;
6 7 8 9
import com.facebook.stetho.Stetho;
import com.uphyca.stetho_realm.RealmInspectorModulesProvider;
import io.realm.Realm;
import io.realm.RealmConfiguration;
10
import java.util.List;
11 12
import timber.log.Timber;

13 14 15
/**
 * Customized Application-class for Rocket.Chat
 */
16
public class RocketChatApplication extends Application {
17 18
  @Override public void onCreate() {
    super.onCreate();
19

20
    Timber.plant(new Timber.DebugTree());
21

22 23 24
    Realm.init(this);
    Realm.setDefaultConfiguration(
        new RealmConfiguration.Builder().deleteRealmIfMigrationNeeded().build());
25

26 27 28 29 30 31
    List<ServerConfig> configs = RealmStore.getDefault().executeTransactionForReadResults(realm ->
        realm.where(ServerConfig.class).isNotNull("session").findAll());
    for (ServerConfig config : configs) {
      RealmStore.put(config.getServerConfigId());
    }

32 33 34 35
    Stetho.initialize(Stetho.newInitializerBuilder(this)
        .enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
        .enableWebKitInspector(RealmInspectorModulesProvider.builder(this).build())
        .build());
36

37 38
    //TODO: add periodic trigger for RocketChatService.keepalive(this) here!
  }
39
}