package ch.pizzapp.android;

import android.app.Application;
import android.support.multidex.MultiDexApplication;

import com.crashlytics.android.Crashlytics;
import com.jakewharton.picasso.OkHttp3Downloader;
import com.onesignal.OneSignal;
import com.squareup.picasso.Picasso;

import io.fabric.sdk.android.Fabric;
import uk.co.chrisjenx.calligraphy.CalligraphyConfig;

/**
 * Created by cimenmus on 11/09/2017.
 */

public class App extends MultiDexApplication {

    @Override
    public void onCreate() {
        super.onCreate();
        initCalligraphy();
        initPicasso();
        initFabric();
        initOneSignal();
    }

    private void initCalligraphy(){
        CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
                .setDefaultFontPath("fonts/Quicksand-Regular.ttf")
                .setFontAttrId(R.attr.fontPath)
                .build()
        );
    }

    private void initPicasso(){
        // DISK CACHE
        // Disk cache of 2% storage space up to 50MB but no less than 5MB
        // 48 megabyte
        //Picasso picasso =  new Picasso.Builder(this).downloader(new OkHttp3Downloader(getCacheDir(), 48 * 1024 * 1024)).build();
        Picasso picasso =  new Picasso.Builder(this).downloader(new OkHttp3Downloader(getCacheDir())).build();
        Picasso.setSingletonInstance(picasso);
        /*
        // MEMORY CACHE
        //default cache size is %15 of available memory
        // LRU memory cache of 15% the available application RAM
        //LruCache() takes byte parameter. Here is 4 megabyte
        Picasso.Builder picassoBuilder = new Picasso.Builder(this).memoryCache(new LruCache(8 * 1024 * 1024));
        Picasso.setSingletonInstance(picassoBuilder.build());
        */
    }

    private void initFabric(){
        Fabric.with(this, new Crashlytics());
    }

    private void initOneSignal(){
        OneSignal.startInit(this)
                .inFocusDisplaying(OneSignal.OSInFocusDisplayOption.Notification)
                .unsubscribeWhenNotificationsAreDisabled(true)
                .init();
    }
}