Added Android code
[wl-app.git] / Android / app / src / main / java / com / moiseum / wolnelektury / base / WLApplication.java
1 package com.moiseum.wolnelektury.base;
2
3 import android.support.multidex.MultiDexApplication;
4
5 import com.crashlytics.android.Crashlytics;
6 import com.crashlytics.android.core.CrashlyticsCore;
7 import com.moiseum.wolnelektury.BuildConfig;
8 import com.moiseum.wolnelektury.connection.RestClient;
9 import com.moiseum.wolnelektury.storage.BookStorage;
10 import com.moiseum.wolnelektury.utils.SharedPreferencesUtils;
11 import com.moiseum.wolnelektury.utils.TrackerUtils;
12
13 import org.piwik.sdk.Tracker;
14
15 import io.fabric.sdk.android.Fabric;
16
17 public class WLApplication extends MultiDexApplication {
18
19         private static WLApplication instance;
20         private RestClient restClient;
21         private BookStorage bookStorage;
22         private Tracker tracker;
23         private SharedPreferencesUtils preferences;
24
25         @Override
26         public void onCreate() {
27                 super.onCreate();
28                 instance = this;
29                 bookStorage = new BookStorage(this);
30
31                 Crashlytics crashlytics = new Crashlytics.Builder()
32                                 .core(new CrashlyticsCore.Builder().disabled(BuildConfig.DEBUG).build())
33                                 .build();
34                 Fabric.with(this, new Crashlytics());
35         }
36
37         public static WLApplication getInstance() {
38                 return instance;
39         }
40
41         public RestClient getRestClient() {
42                 if (restClient == null) {
43                         restClient = new RestClient(getApplicationContext());
44                 }
45                 return restClient;
46         }
47
48         public BookStorage getBookStorage() {
49                 return bookStorage;
50         }
51
52         public synchronized Tracker getTracker() {
53                 if (tracker == null) {
54                         tracker = TrackerUtils.create(this);
55                 }
56                 return tracker;
57         }
58
59         public SharedPreferencesUtils getPreferences() {
60                 if (preferences == null) {
61                         preferences = new SharedPreferencesUtils(this);
62                 }
63                 return preferences;
64         }
65 }