package com.rehivetech.beeeon;

/**
 * @author martin
 * @author Tomas Mlynaric
 * @since 24.05.2016
 */

import android.app.Application;
import android.content.Context;

import com.google.android.gms.analytics.Tracker;
import com.rehivetech.beeeon.gcm.analytics.GoogleAnalyticsManager;
import com.rehivetech.beeeon.model.DatabaseSeed;

import io.realm.Realm;
import io.realm.RealmConfiguration;
import timber.log.Timber;

/**
 * This is a subclass of {@link Application} used to provide shared objects for this app, such as
 * the {@link Tracker}.
 */
public class BeeeOnApplication extends Application {
	private static Context sContext;

	@Override
	public void onCreate() {
		super.onCreate();
		Timber.plant(new Timber.DebugTree());

		Timber.i("BeeeOn app starting...___________________________________");
		sContext = getApplicationContext();
		GoogleAnalyticsManager.getInstance().init(sContext, getString(R.string.api_keys_google_analytics_tracking_id));
		// initialize database
		RealmConfiguration config = new RealmConfiguration.Builder(this)
//				.deleteRealmIfMigrationNeeded() // only for developing purposes
				.schemaVersion(1)
				.name("beeeon.realm")
				.initialData(new DatabaseSeed())
				.build();
		Realm.setDefaultConfiguration(config);
	}

	/**
	 * Returns application context so that it's possible to get app specifi resources/show toast etc
	 *
	 * @return Application context
	 */
	public static Context getContext() {
		return sContext;
	}
}


@@ -330,16 +330,46 @@
 eSeed;%0A%0A
+import io.realm.DynamicRealm;%0A
 import i
@@ -415,24 +415,85 @@
 figuration;%0A
+import io.realm.RealmMigration;%0Aimport io.realm.RealmSchema;%0A
 import timbe
@@ -1229,17 +1229,17 @@
 Version(
-1
+2
 )%0A%09%09%09%09.n
@@ -1295,16 +1295,366 @@
 Seed())%0A
+%09%09%09%09.migration(new RealmMigration() %7B%0A%09%09%09%09%09@Override%0A%09%09%09%09%09public void migrate(DynamicRealm realm, long oldVersion, long newVersion) %7B%0A%09%09%09%09%09%09RealmSchema schema = realm.getSchema();%0A%0A%09%09%09%09%09%09if (oldVersion == 1) %7B%0A%09%09%09%09%09%09%09schema.create(%22VentilationItem%22);%0A%09%09%09%09%09%09%09schema.create(%22VentilationItem%22);%0A%09%09%09%09%09%09%09schema.create(%22DewingItem%22);%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D)%0A
 %09%09%09%09.bui

Create Realm migration to newer version of database schema