Public
Authored by alina diaz

Retrofit class

Edited
public class WebServiceCaller {

    private static DemoApiInterface apiInterface;

    public static DemoApiInterface getClient() {
        if (apiInterface == null) {
            HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
            logging.setLevel(HttpLoggingInterceptor.Level.BODY);
            OkHttpClient okclient = new OkHttpClient();
            Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();

            Retrofit client = new Retrofit.Builder()
                    .baseUrl(AppConstant.BASE_URL)
                    .client(okclient.newBuilder()
                            .connectTimeout(10, TimeUnit.MINUTES)
                            .readTimeout(10, TimeUnit.MINUTES)
                            .writeTimeout(10, TimeUnit.MINUTES)
                            .addInterceptor(logging).build())
                    .addConverterFactory(GsonConverterFactory.create(gson)).build();

            apiInterface = client.create(DemoApiInterface.class);
        }
        return apiInterface;
    }
}
public interface DemoApiInterface {

    @Multipart
    @POST("upload/media")
    Call<SuccessResponse> uploadImage(@Part("media_file\"; filename=\"mapall_media.png\" ") RequestBody media_file,
                                      @Part("type") RequestBody type);

   @FormUrlEncoded
    @POST("user/signup")
    Call<SuccessResponse> signup(@Field("email") String email,
                                    @Field("password") String password);
}
compile 'com.squareup.retrofit2:retrofit:2.3.0'
    compile 'com.squareup.retrofit2:converter-gson:2.3.0'
    compile 'com.squareup.okhttp3:okhttp:3.8.0'
    compile 'com.squareup.okhttp3:logging-interceptor:3.4.1'
private void callLogin() {
        if (!Utility.isNetworkAvailable(mActivity)) {
        } else {
            showProgress();
            DemoApiInterface service = WebServiceCaller.getClient();
            Call<User> call = service.signup("abc","123");

            call.enqueue(new Callback<User>() {
                @Override
                public void onResponse(Call<User> call, Response<User> response) {
                    hideProgress();
                    User result;
                    if (response.isSuccessful()) {
                        result = response.body();
                        if (result.getStatus() == 1) {

                        } else {
                        }
                    } else {
                    }
                }

                @Override
                public void onFailure(Call<User> call, Throwable t) {
                    hideProgress();
                    t.printStackTrace();
                }
            });
        }
    }
public class User {

    @SerializedName("status")
    @Expose
    private int status;

    @SerializedName("message")
    @Expose
    private String message;

    @SerializedName("data")
    @Expose
    private List<UserData> data = null;

    public class UserData implements Serializable {

        @SerializedName("user_id")
        @Expose
        private int id;
        @SerializedName("first_name")
        @Expose
        private String firstName;

        @SerializedName("profile_pic")
        @Expose
        private String profilePic;

        private boolean isSelected = false;

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getFirstName() {
            return firstName;
        }

        public void setFirstName(String firstName) {
            this.firstName = firstName;
        }

        public String getProfilePic() {
            return profilePic;
        }

        public void setProfilePic(String profilePic) {
            this.profilePic = profilePic;
        }

        public boolean isSelected() {
            return isSelected;
        }

        public void setSelected(boolean selected) {
            isSelected = selected;
        }
    }

}
29 Bytes
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment