|
@ -5,6 +5,7 @@ import android.content.Context; |
|
|
import android.content.SharedPreferences; |
|
|
import android.content.SharedPreferences; |
|
|
import android.graphics.drawable.Drawable; |
|
|
import android.graphics.drawable.Drawable; |
|
|
import android.net.Uri; |
|
|
import android.net.Uri; |
|
|
|
|
|
import android.os.Bundle; |
|
|
import android.support.v4.content.ContextCompat; |
|
|
import android.support.v4.content.ContextCompat; |
|
|
import android.util.DisplayMetrics; |
|
|
import android.util.DisplayMetrics; |
|
|
import android.widget.ImageView; |
|
|
import android.widget.ImageView; |
|
@ -12,6 +13,7 @@ import android.widget.ImageView; |
|
|
import com.franmontiel.persistentcookiejar.PersistentCookieJar; |
|
|
import com.franmontiel.persistentcookiejar.PersistentCookieJar; |
|
|
import com.franmontiel.persistentcookiejar.cache.SetCookieCache; |
|
|
import com.franmontiel.persistentcookiejar.cache.SetCookieCache; |
|
|
import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; |
|
|
import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; |
|
|
|
|
|
import com.google.firebase.analytics.FirebaseAnalytics; |
|
|
import com.jakewharton.picasso.OkHttp3Downloader; |
|
|
import com.jakewharton.picasso.OkHttp3Downloader; |
|
|
import com.mikepenz.fontawesome_typeface_library.FontAwesome; |
|
|
import com.mikepenz.fontawesome_typeface_library.FontAwesome; |
|
|
import com.mikepenz.iconics.IconicsDrawable; |
|
|
import com.mikepenz.iconics.IconicsDrawable; |
|
@ -22,7 +24,6 @@ import com.squareup.picasso.Picasso; |
|
|
import net.gotev.uploadservice.UploadService; |
|
|
import net.gotev.uploadservice.UploadService; |
|
|
import net.gotev.uploadservice.okhttp.OkHttpStack; |
|
|
import net.gotev.uploadservice.okhttp.OkHttpStack; |
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
import java.util.Objects; |
|
|
import java.util.Objects; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
@ -31,16 +32,17 @@ import gr.thmmy.mthmmy.R; |
|
|
import gr.thmmy.mthmmy.session.SessionManager; |
|
|
import gr.thmmy.mthmmy.session.SessionManager; |
|
|
import gr.thmmy.mthmmy.utils.CrashReportingTree; |
|
|
import gr.thmmy.mthmmy.utils.CrashReportingTree; |
|
|
import okhttp3.HttpUrl; |
|
|
import okhttp3.HttpUrl; |
|
|
import okhttp3.Interceptor; |
|
|
|
|
|
import okhttp3.OkHttpClient; |
|
|
import okhttp3.OkHttpClient; |
|
|
import okhttp3.Request; |
|
|
import okhttp3.Request; |
|
|
import okhttp3.Response; |
|
|
|
|
|
import timber.log.Timber; |
|
|
import timber.log.Timber; |
|
|
|
|
|
|
|
|
public class BaseApplication extends Application { |
|
|
public class BaseApplication extends Application { |
|
|
private static BaseApplication baseApplication; //BaseApplication singleton
|
|
|
private static BaseApplication baseApplication; //BaseApplication singleton
|
|
|
|
|
|
|
|
|
// Client & SessionManager
|
|
|
//FirebaseAnalytics
|
|
|
|
|
|
private FirebaseAnalytics firebaseAnalytics; |
|
|
|
|
|
|
|
|
|
|
|
//Client & SessionManager
|
|
|
private OkHttpClient client; |
|
|
private OkHttpClient client; |
|
|
private SessionManager sessionManager; |
|
|
private SessionManager sessionManager; |
|
|
|
|
|
|
|
@ -59,20 +61,20 @@ public class BaseApplication extends Application { |
|
|
super.onCreate(); |
|
|
super.onCreate(); |
|
|
baseApplication = this; //init singleton
|
|
|
baseApplication = this; //init singleton
|
|
|
|
|
|
|
|
|
if (BuildConfig.DEBUG) { |
|
|
if (BuildConfig.DEBUG) |
|
|
Timber.plant(new Timber.DebugTree()); |
|
|
Timber.plant(new Timber.DebugTree()); |
|
|
} else { |
|
|
else |
|
|
Timber.plant(new CrashReportingTree()); |
|
|
Timber.plant(new CrashReportingTree()); |
|
|
} |
|
|
|
|
|
|
|
|
// Analytics init
|
|
|
|
|
|
firebaseAnalytics = FirebaseAnalytics.getInstance(this); |
|
|
|
|
|
|
|
|
SharedPreferences sharedPrefs = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE); |
|
|
SharedPreferences sharedPrefs = getSharedPreferences(SHARED_PREFS_NAME, MODE_PRIVATE); |
|
|
SharedPrefsCookiePersistor sharedPrefsCookiePersistor = new SharedPrefsCookiePersistor(getApplicationContext()); |
|
|
SharedPrefsCookiePersistor sharedPrefsCookiePersistor = new SharedPrefsCookiePersistor(getApplicationContext()); |
|
|
PersistentCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), sharedPrefsCookiePersistor); |
|
|
PersistentCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), sharedPrefsCookiePersistor); |
|
|
client = new OkHttpClient.Builder() |
|
|
client = new OkHttpClient.Builder() |
|
|
.cookieJar(cookieJar) |
|
|
.cookieJar(cookieJar) |
|
|
.addInterceptor(new Interceptor() { |
|
|
.addInterceptor(chain -> { |
|
|
@Override |
|
|
|
|
|
public Response intercept(Chain chain) throws IOException { |
|
|
|
|
|
Request request = chain.request(); |
|
|
Request request = chain.request(); |
|
|
HttpUrl oldUrl = chain.request().url(); |
|
|
HttpUrl oldUrl = chain.request().url(); |
|
|
if (Objects.equals(chain.request().url().host(), "www.thmmy.gr")) { |
|
|
if (Objects.equals(chain.request().url().host(), "www.thmmy.gr")) { |
|
@ -84,7 +86,6 @@ public class BaseApplication extends Application { |
|
|
} |
|
|
} |
|
|
return chain.proceed(request); |
|
|
return chain.proceed(request); |
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
}) |
|
|
.connectTimeout(30, TimeUnit.SECONDS) |
|
|
.connectTimeout(30, TimeUnit.SECONDS) |
|
|
.writeTimeout(30, TimeUnit.SECONDS) |
|
|
.writeTimeout(30, TimeUnit.SECONDS) |
|
@ -130,6 +131,12 @@ public class BaseApplication extends Application { |
|
|
dpWidth = displayMetrics.widthPixels / displayMetrics.density; |
|
|
dpWidth = displayMetrics.widthPixels / displayMetrics.density; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void logFirebaseAnalyticsEvent(String event, Bundle params) { |
|
|
|
|
|
firebaseAnalytics.logEvent(event, params); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Getters
|
|
|
|
|
|
|
|
|
public OkHttpClient getClient() { |
|
|
public OkHttpClient getClient() { |
|
|
return client; |
|
|
return client; |
|
|
} |
|
|
} |
|
|