дипломная работа. Даар. Разработка службы курьерской доставки в мобильном приложении
Скачать 0.63 Mb.
|
Приложение 2.На следующем листинге представлен Presenter для активности, описанной в предыдущем блоке (View): public class ConfirmOrderPresenter { private final static String TAG = ConfirmOrderPresenter.class.getSimpleName(); private Context mContext; private OrderTempRepositorymOrderTempRepository; private SettingRepositorymSettingRepository; private FieldsValidationmValidation; private StringProcessingmStringProcessing; private OrderHistoryItemmOrderCurrent; private OnConfirmOrderDirectionmOnConfirmOrderDirection; private final static String TITLE = «Поддержка»; public ConfirmOrderPresenter(Context context){ this.mContext= context; try { init(); } catch (Exception mE) { mE.printStackTrace(); } } public void setOnConfirmOrderDirection(OnConfirmOrderDirection direction){ mOnConfirmOrderDirection= direction; } private void init() throws Exception{ mOrderCurrent= getCurrentOrder(); mOrderTempRepository= new OrderTempRepository(mContext); mSettingRepository= new SettingRepository(); mValidation= new FieldsValidation(mContext); mStringProcessing= new StringProcessing(); } public void getTitle(){ if(mOnConfirmOrderDirection!=null)mOnConfirmOrderDirection.onReceivedTitle(TITLE); } public void getScreenParamByPayMethod(){ intpayMethod = getPayMethod(); String phone = mOrderTempRepository.getOrderDataByKey(KEY_PHONE); String pay_id = mOrderTempRepository.getOrderDataByKey(KEY_PAY_METHOD); String pay_description = mSettingRepository.getData(pay_id); Log.e(TAG, phone); if(mOnConfirmOrderDirection!=null)mOnConfirmOrderDirection.onReceivedScreenParamByPayMethod(payMethod, phone, pay_description); } public void getRequestParamByPayMethod(String pin, String cvc) throws Exception{ /*set pay method*/ intpayMethod = getPayMethod(); /*set request parameters by pay method*/ String token = mSettingRepository.getData(USER_TOKEN); String idtOrder = mOrderCurrent.getIdtOrder(); Map switch (payMethod){ case CASH: String phone = mStringProcessing.convertPhoneToString(mOrderTempRepository.getOrderDataByKey(KEY_PHONE)); confirmParam.put(«phone», phone); confirmParam.put(«idt_order», idtOrder); confirmParam.put(«pin», pin); confirmParam.put(«token», token); break; case BANK_CARD: String idtPayMethod = mOrderTempRepository.getOrderDataByKey(KEY_PAY_METHOD); confirmParam.put(«token», token); confirmParam.put(«idt_order», idtOrder); confirmParam.put(«idt_pay_method», idtPayMethod); confirmParam.put(«cvc», cvc); break; default: break; } if(mOnConfirmOrderDirection!=null)mOnConfirmOrderDirection.onReceivedRequestParamByPayMethod(confirmParam, payMethod); } public booleancheckFieldValid(TextInputLayout[] fieldParents, EditText[] fields){ intpay_method = getPayMethod(); TextInputLayouttil_cvc_code = fieldParents[0]; TextInputLayouttil_sms_code = fieldParents[1]; EditTextet_cvc_code = fields[0]; EditTextet_sms_code = fields[1]; switch (pay_method){ case CASH: return mValidation.isFieldEmpty(til_sms_code, et_sms_code); case BANK_CARD: return mValidation.isFieldEmpty(til_cvc_code, et_cvc_code) &&mValidation.isValidCvc(til_cvc_code, et_cvc_code); default: return false; } } private OrderHistoryItemgetCurrentOrder() throws Exception{ intidt_order = new SettingRepository().getId(CURRENT_ORDER_ID); return new RealmHelper<>(OrderHistoryItem.class).getById(idt_order); } private intgetPayMethod(){ intpayMethod = CASH; if(mOrderTempRepository.isDataExist(KEY_PAY_METHOD)){ payMethod = BANK_CARD; } return payMethod; } public interface OnConfirmOrderDirection{ void onReceivedTitle(String title); void onReceivedScreenParamByPayMethod(intpayMethodId, String phone, String payDescription); void onReceivedRequestParamByPayMethod(Map } } |