|
@ -1,7 +1,5 @@ |
|
|
package awais.instagrabber.webservices; |
|
|
package awais.instagrabber.webservices; |
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
|
|
|
|
|
|
|
|
import com.google.gson.FieldNamingPolicy; |
|
|
import com.google.gson.FieldNamingPolicy; |
|
|
import com.google.gson.Gson; |
|
|
import com.google.gson.Gson; |
|
|
import com.google.gson.GsonBuilder; |
|
|
import com.google.gson.GsonBuilder; |
|
@ -9,7 +7,6 @@ import com.google.gson.GsonBuilder; |
|
|
import java.io.File; |
|
|
import java.io.File; |
|
|
|
|
|
|
|
|
import awais.instagrabber.BuildConfig; |
|
|
import awais.instagrabber.BuildConfig; |
|
|
import awais.instagrabber.activities.MainActivity; |
|
|
|
|
|
import awais.instagrabber.repositories.responses.Caption; |
|
|
import awais.instagrabber.repositories.responses.Caption; |
|
|
import awais.instagrabber.utils.Utils; |
|
|
import awais.instagrabber.utils.Utils; |
|
|
import awais.instagrabber.webservices.interceptors.AddCookiesInterceptor; |
|
|
import awais.instagrabber.webservices.interceptors.AddCookiesInterceptor; |
|
@ -29,35 +26,24 @@ public final class RetrofitFactory { |
|
|
private final Cache cache = new Cache(new File(Utils.cacheDir), cacheSize); |
|
|
private final Cache cache = new Cache(new File(Utils.cacheDir), cacheSize); |
|
|
|
|
|
|
|
|
private IgErrorsInterceptor igErrorsInterceptor; |
|
|
private IgErrorsInterceptor igErrorsInterceptor; |
|
|
private MainActivity mainActivity; |
|
|
|
|
|
private Retrofit.Builder builder; |
|
|
private Retrofit.Builder builder; |
|
|
private Retrofit retrofit; |
|
|
private Retrofit retrofit; |
|
|
private Retrofit retrofitWeb; |
|
|
private Retrofit retrofitWeb; |
|
|
|
|
|
|
|
|
public static void setup(@NonNull final MainActivity mainActivity) { |
|
|
|
|
|
|
|
|
public static RetrofitFactory getInstance() { |
|
|
if (instance == null) { |
|
|
if (instance == null) { |
|
|
synchronized (LOCK) { |
|
|
synchronized (LOCK) { |
|
|
if (instance == null) { |
|
|
if (instance == null) { |
|
|
instance = new RetrofitFactory(mainActivity); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
instance = new RetrofitFactory(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public static RetrofitFactory getInstance() { |
|
|
|
|
|
if (instance == null) { |
|
|
|
|
|
throw new RuntimeException("Setup not done!"); |
|
|
|
|
|
} |
|
|
|
|
|
return instance; |
|
|
return instance; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private RetrofitFactory(@NonNull final MainActivity mainActivity) { |
|
|
|
|
|
this.mainActivity = mainActivity; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Retrofit.Builder getRetrofitBuilder() { |
|
|
private Retrofit.Builder getRetrofitBuilder() { |
|
|
if (builder == null) { |
|
|
if (builder == null) { |
|
|
igErrorsInterceptor = new IgErrorsInterceptor(mainActivity); |
|
|
|
|
|
|
|
|
igErrorsInterceptor = new IgErrorsInterceptor(); |
|
|
final OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder() |
|
|
final OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder() |
|
|
.followRedirects(false) |
|
|
.followRedirects(false) |
|
|
.followSslRedirects(false) |
|
|
.followSslRedirects(false) |
|
@ -103,7 +89,6 @@ public final class RetrofitFactory { |
|
|
igErrorsInterceptor.destroy(); |
|
|
igErrorsInterceptor.destroy(); |
|
|
} |
|
|
} |
|
|
igErrorsInterceptor = null; |
|
|
igErrorsInterceptor = null; |
|
|
mainActivity = null; |
|
|
|
|
|
retrofit = null; |
|
|
retrofit = null; |
|
|
retrofitWeb = null; |
|
|
retrofitWeb = null; |
|
|
builder = null; |
|
|
builder = null; |
|
|