|
|
@ -19,11 +19,17 @@ import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader; |
|
|
|
import com.mikepenz.materialdrawer.util.DrawerImageLoader; |
|
|
|
import com.squareup.picasso.Picasso; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
|
|
import gr.thmmy.mthmmy.R; |
|
|
|
import gr.thmmy.mthmmy.session.SessionManager; |
|
|
|
import okhttp3.HttpUrl; |
|
|
|
import okhttp3.Interceptor; |
|
|
|
import okhttp3.OkHttpClient; |
|
|
|
import okhttp3.Request; |
|
|
|
import okhttp3.Response; |
|
|
|
|
|
|
|
public class BaseApplication extends Application { |
|
|
|
|
|
|
@ -40,7 +46,7 @@ public class BaseApplication extends Application { |
|
|
|
//Display Metrics
|
|
|
|
private static float dpHeight, dpWidth; |
|
|
|
|
|
|
|
public static BaseApplication getInstance(){ |
|
|
|
public static BaseApplication getInstance() { |
|
|
|
return baseApplication; |
|
|
|
} |
|
|
|
|
|
|
@ -54,6 +60,22 @@ public class BaseApplication extends Application { |
|
|
|
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(); |
|
|
|
} |
|
|
|
} |
|
|
|
return chain.proceed(request); |
|
|
|
|
|
|
|
} |
|
|
|
}) |
|
|
|
.connectTimeout(30, TimeUnit.SECONDS) |
|
|
|
.writeTimeout(30, TimeUnit.SECONDS) |
|
|
|
.readTimeout(30, TimeUnit.SECONDS) |
|
|
@ -71,6 +93,7 @@ public class BaseApplication extends Application { |
|
|
|
public void set(ImageView imageView, Uri uri, Drawable placeholder) { |
|
|
|
Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void cancel(ImageView imageView) { |
|
|
|
Picasso.with(imageView.getContext()).cancelRequest(imageView); |
|
|
|