package net.squanchy;

import android.app.Application;
import android.support.annotation.MainThread;

import com.crashlytics.android.Crashlytics;
import com.ls.drupal.DrupalClient;
import com.ls.http.base.BaseRequest;
import com.ls.util.image.DrupalImageView;
import com.twitter.sdk.android.core.TwitterAuthConfig;
import com.twitter.sdk.android.core.TwitterCore;
import com.twitter.sdk.android.tweetui.TweetUi;

import net.danlew.android.joda.JodaTimeAndroid;
import net.squanchy.analytics.Analytics;
import net.squanchy.injection.ApplicationComponent;
import net.squanchy.model.AppDatabaseInfo;
import net.squanchy.model.Model;
import net.squanchy.model.database.LAPIDBRegister;
import net.squanchy.service.api.SquanchyRepository;

import io.fabric.sdk.android.Fabric;
import timber.log.Timber;

public class SquanchyApplication extends Application {

    private ApplicationComponent applicationComponent;

    @Override
    public void onCreate() {
        super.onCreate();

        JodaTimeAndroid.init(this);

        setupTracking();

        LAPIDBRegister.getInstance().register(this, new AppDatabaseInfo(this));

        SquanchyRepository repository = SquanchyRepository.newInstance(this);
        Model.createInstance(this, repository);

        DrupalClient client = new DrupalClient(
                null,
                Model.getInstance().createNewQueue(getApplicationContext()),
                BaseRequest.RequestFormat.JSON,
                null
        );

        DrupalImageView.setupSharedClient(client);
    }

    private void setupTracking() {
        setupFabric();

        Analytics analytics = Analytics.from(this);
        analytics.enableActivityLifecycleLogging();
        analytics.enableExceptionLogging();

        if (BuildConfig.DEBUG) {
            Timber.plant(new Timber.DebugTree());
        }
    }

    private void setupFabric() {
        TwitterAuthConfig authConfig = new TwitterAuthConfig(
                getString(R.string.api_value_twitter_api_key),
                getString(R.string.api_value_twitter_secret)
        );
        Fabric.with(this, new Crashlytics(), new TwitterCore(authConfig), new TweetUi());
    }

    @MainThread
    public ApplicationComponent applicationComponent() {
        if (applicationComponent == null) {
            applicationComponent = ApplicationComponent.Factory.create(this);
        }

        return applicationComponent;
    }
}

@@ -143,122 +143,8 @@
 cs;%0A
-import com.ls.drupal.DrupalClient;%0Aimport com.ls.http.base.BaseRequest;%0Aimport com.ls.util.image.DrupalImageView;%0A
 impo
@@ -194,16 +194,16 @@
 Config;%0A
+
 import c
@@ -436,187 +436,8 @@
 ent;
-%0Aimport net.squanchy.model.AppDatabaseInfo;%0Aimport net.squanchy.model.Model;%0Aimport net.squanchy.model.database.LAPIDBRegister;%0Aimport net.squanchy.service.api.SquanchyRepository;
 %0A%0Aim
@@ -713,24 +713,24 @@
 nit(this);%0A%0A
+
         setu
@@ -745,496 +745,8 @@
 g();
-%0A%0A        LAPIDBRegister.getInstance().register(this, new AppDatabaseInfo(this));%0A%0A        SquanchyRepository repository = SquanchyRepository.newInstance(this);%0A        Model.createInstance(this, repository);%0A%0A        DrupalClient client = new DrupalClient(%0A                null,%0A                Model.getInstance().createNewQueue(getApplicationContext()),%0A                BaseRequest.RequestFormat.JSON,%0A                null%0A        );%0A%0A        DrupalImageView.setupSharedClient(client);
 %0A   

Remove all drupal stuff from Application