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