모델 생성
public class DeliveryModel {
@SerializedName("MSG_ID")
@Expose
private String mSGID;
}
ApiService
public interface ApiService {
@FormUrlEncoded
@POST("lst/101")
Call<ProductModel> getProduct(@Field("REQUEST") String request);
@FormUrlEncoded
@POST("lst/102")
Call<DeliveryModel> getDelivery(@Field("REQUEST") String request);
@FormUrlEncoded
@POST("ins/103")
Call<SetOrderModel> setOrder(@Field("REQUEST") String request);
@FormUrlEncoded
@POST("lst/104")
Call<DiscountRateModel> getDCRate(@Field("REQUEST") String request);
}
ApiUtils
public class ApiUtils {
public static final String BASE_URL = ""; //개발용
public static final String BASE_URL_RELEASE = ""; //배포용
public static ApiService getApiService() {
return RetrofitClient.getClient(BASE_URL_RELEASE).create(ApiService.class);
}
}
RetrofitClient
public class RetrofitClient {
private static final String TAG = RetrofitClient.class.getSimpleName();
private static Retrofit retrofit = null;
public static Retrofit getClient(String baseUrl) {
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
apiService.setOrder(stringBuilder.toString()).enqueue(new Callback<SetOrderModel>() {
@Override
public void onResponse(Call<SetOrderModel> call, Response<SetOrderModel> response) {
if (response.body().getODS0() == null) {
// FirebaseCrash.log("주문등록 실패 (입력오류)\n" + insert);
showToast("주문등록 실패(입력오류)");
System.out.println(stringBuilder.toString());
binding.btnRegiOrder.setEnabled(true);
return;
}
}
@Override
public void onFailure(Call<SetOrderModel> call, Throwable t) {
binding.btnRegiOrder.setEnabled(true);
runOnUiThread(() -> showToast("통신오류 (와이파이 연결을 확인 해주세요)"));
}
});
'Android' 카테고리의 다른 글
RecyclerView SwipeToDelete (0) | 2019.04.19 |
---|---|
ScrollView PullToRefreshLayout (0) | 2019.04.19 |
RecyclerView 하단 합계 ( FooterView) (0) | 2019.04.19 |
리스트 선택 : DialogFragment + ViewPager + 리스너연결 (0) | 2019.04.19 |
BottomNavigationView 아이콘 사이즈 수정법 (태블릿 대응) (0) | 2018.10.19 |