i'm using Retrofit, for my app, in the base interface, i'm using a base URL, like the retrofit page suggests, i want to be able to change the baseUrl from outside the interface, so to have one baseUrl for Testings, and one baseUrl for development, and that the user will be able to toggle between them. inside a java interface all variables are final and cannot be changed, and since the interface cannot take variables from outside of the enclosed interface, how do i change it in retrofit ?
here is my retrofit interface:
String baseUrl = "http://1.1.1.1:1000/";
//network calls
@GET("api/v1/alignment/measuring")
Call<AligmentDataPojo> getCallData();
@GET("api/v1/alignment/best-position")
Call<BestPositionPojo> getBestPositionCallData();
@GET("api/v1/data/resetBoxAligment")
Call<AligmentScanPojo> resetBoxAligmentCallData();
@GET("api/v1/alignment/pointer-location")
Call<CurserLocationPojo> curserLocationCallData();
@GET("api/v1/alignment/fineAlignment")
Call<FineAligmentPojo> fineAligmentCallData();
@GET("api/v1/alignment/get-bands")
Call<GetBandsPojo> getAllBandsCallData();
@POST("api/v1/alignment/set-band")
Call<PojoSetBand> postAligmentSetBand(@Body SetBandAligmentModel setBandAligmentModel);
@POST("api/v1/alignment/action/start")
Call<PojoSetBand> postAligmentAction(@Body AligmentActionPayloadModel aligmentActionPayloadModel);
@GET("api/v1/alignment/evaluation-results") //Just for mockuppurposeses we have unreal information that we send and simulate a return call
Call<EvaluationDataPojo> getEvaluationResults();
@POST("api/v1/alignment/start-evaluation") //Just for mockuppurposeses we have unreal information that we send and simulate a return call
Call<PojoSetBand> startEvaluationPost(@Body AligmentActionPayloadModel aligmentActionPayloadModel);
//testings
@POST("api/v1/data/testPost")
Call<TestPostModel> getTestPost(@Body TestPostModel testPostModel);
//factory
class Factory {
private static RetrofitInterface service;
public static RetrofitInterface getInstance() {
if (service == null) {
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.build();
service = retrofit.create(RetrofitInterface.class);
return service;
} else {
return service;
}
}
}