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.DynamicRealm;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import io.realm.RealmMigration;
import io.realm.RealmSchema;
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(2)
				.name("beeeon.realm")
				.initialData(new DatabaseSeed())
				.migration(new RealmMigration() {
					@Override
					public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
						RealmSchema schema = realm.getSchema();

						if (oldVersion == 1) {
							schema.create("VentilationItem");
							schema.create("VentilationItem");
							schema.create("DewingItem");
						}
					}
				})
				.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;
	}
}


@@ -334,38 +334,8 @@
 d;%0A%0A
-import io.realm.DynamicRealm;%0A
 impo
@@ -393,69 +393,8 @@
 on;%0A
-import io.realm.RealmMigration;%0Aimport io.realm.RealmSchema;%0A
 impo
@@ -1049,18 +1049,16 @@
 r(this)%0A
-//
 %09%09%09%09.del
@@ -1101,27 +1101,24 @@
 for 
-developing purposes
+this migration!!
 %0A%09%09%09
@@ -1203,358 +1203,8 @@
 ())%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

Fix Realm migration