Retrofit Complete Depenedencies
// Retrofit Complete Depenedencies
// Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.facebook.shimmer:shimmer:0.4.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.10.0'
implementation 'com.google.code.gson:gson:2.8.6'
Retrofit Client
package com.example.ukagentapp.Retrofit;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
public class RetrofitClient {
public static Retrofit retrofit = null;
public static Retrofit getClient(String baseUrl) {
HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(httpLoggingInterceptor).build();
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.client(okHttpClient)
.build();
}
return retrofit;
}
}
Progress Bar Class
public class MyProgress{
private static ProgressDialog progressDialog;
public static void showProgress(Context context, String message) {
progressDialog = new ProgressDialog(context);
progressDialog.setMessage(message);
progressDialog.setCancelable(false);
progressDialog.show();
}
public static void dismissProgress() {
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
}
}
Common Class
public class Common {
private Common(){}
public static final String BASE_URL = "http://cane.caneuk.com/GrowerEnqueryServices.asmx/";
// public static final String BASE_URL2 = "http://cane.caneuk.com/GrowerEnqueryServices.asmx";
public static ApiService getAPIService() {
return RetrofitClient.getClient(BASE_URL).create(ApiService.class);
}
/*public static ApiService getAPIService2() {
return RetrofitClient.getClient(BASE_URL2).create(ApiService.class);
}*/
}
Api Service Interface
public interface ApiService {
@GET("GETOVERLAPPLOTOVERLAPLIST")
Call -ResponseBody- GETOVERLAPPLOTOVERLAPLIST(
@Query("villagecode") String villagecode,
@Query("Overlappercent") String Overlappercent,
@Query("society") String society );
@GET("GETOVERLAPPLOTCOORDINATE")
Call -ResponseBody- GETOVERLAPPLOTCOORDINATE (
@Query("Plot1Villagecode") String Plot1Villagecode,
@Query("Plot1SrNo") String Plot1SrNo,
@Query("Plot1Soccode") String Plot1Soccode ,
@Query("PLOT2VILLAGECODE") String PLOT2VILLAGECODE ,
@Query("Plot2SrNo") String Plot2SrNo ,
@Query("Plot2Soccode") String Plot2Soccode ,
@Query("OverlaopPercent") String OverlaopPercent);
}
For Extraction Of SopaObject
public class MyJsonExtractor {
// Private constructor to prevent instantiation
private MyJsonExtractor() {
}
public static String extractJsonObjectFromXml(String xmlResponse) {
try {
int startIndex = xmlResponse.indexOf("{");
int endIndex = xmlResponse.lastIndexOf("}") + 1;
if (startIndex != -1 && endIndex != -1) {
return xmlResponse.substring(startIndex, endIndex);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
public static String extractJsonArrayFromXml(String xmlResponse) {
try {
int startIndex = xmlResponse.indexOf("[");
int endIndex = xmlResponse.lastIndexOf("]") + 1;
if (startIndex != -1 && endIndex != -1) {
return xmlResponse.substring(startIndex, endIndex);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}