Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.unlitechsolutions.upsmobileapp.services.remittance;
- import android.app.DatePickerDialog;
- import android.content.DialogInterface;
- import android.content.Intent;
- import android.database.Cursor;
- import android.os.Bundle;
- import android.support.design.widget.TextInputLayout;
- import android.support.v4.app.Fragment;
- import android.support.v7.app.AlertDialog;
- import android.support.v7.widget.LinearLayoutManager;
- import android.support.v7.widget.RecyclerView;
- import android.text.Editable;
- import android.text.TextWatcher;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.ViewStub;
- import android.widget.Button;
- import android.widget.DatePicker;
- import android.widget.EditText;
- import android.widget.LinearLayout;
- import android.widget.RadioButton;
- import android.widget.RadioGroup;
- import android.widget.Spinner;
- import android.widget.TextView;
- import com.unlitechsolutions.upsmobileapp.Mainmenu;
- import com.unlitechsolutions.upsmobileapp.R;
- import com.unlitechsolutions.upsmobileapp.controller.remittance.SmartMoneySendController;
- import com.unlitechsolutions.upsmobileapp.data.Message;
- import com.unlitechsolutions.upsmobileapp.data.Title;
- import com.unlitechsolutions.upsmobileapp.data.User;
- import com.unlitechsolutions.upsmobileapp.model.RemittanceModel;
- import com.unlitechsolutions.upsmobileapp.model.UserModel;
- import com.unlitechsolutions.upsmobileapp.objects.ClientObjects;
- import com.unlitechsolutions.upsmobileapp.objects.adapters.SearchAdapter;
- import com.unlitechsolutions.upsmobileapp.view.RemittanceView;
- import java.util.ArrayList;
- import java.util.Calendar;
- import java.util.regex.Pattern;
- import UnlitechDevFramework.src.ud.framework.data.Response;
- import UnlitechDevFramework.src.ud.framework.utilities.ViewUtil;
- /**
- * Created by Em on 5/25/2016.
- */
- public class SmartmoneySend extends Fragment implements RemittanceView,RemittanceModel.RemittanceModelObserver {
- View view, sender_data, bene_data, inputs;
- private AlertDialog.Builder builder;
- AlertDialog mAlertDialog,searchResultDialog,registrationDialog;
- private static int SENDER_SEARCH_TYPE = 1;
- private static int BENE_SEARCH_TYPE = 2;
- private View dialogView;
- RemittanceModel mModel;
- SmartMoneySendController mController;
- private EditText smartMoneyNo;
- static final Pattern CODE_PATTERN = Pattern.compile("([0-9]{0,4})|([0-9]{4}-)+|([0-9]{4}-[0-9]{0,4})+");
- private int mYear, mMonth, mDay;
- private Calendar cal;
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- view = inflater.inflate(R.layout.remittance_ecashpadala_send, container, false);
- sender_data = view.findViewById(R.id.include_sender_data);
- bene_data = view.findViewById(R.id.include_bene_data);
- cal = Calendar.getInstance();
- mDay = cal.get(Calendar.DAY_OF_MONTH);
- mMonth = cal.get(Calendar.MONTH);
- mYear = cal.get(Calendar.YEAR);
- TextView title = (TextView) bene_data.findViewById(R.id.tv_title);
- title.setText("BENEFICIARY");
- ViewStub stub = (ViewStub) view.findViewById(R.id.layout_stub);
- stub.setLayoutResource(R.layout.remittance_inputfields_smartmoneysend);
- inputs = stub.inflate();
- LinearLayout form = (LinearLayout)view.findViewById(R.id.form);
- final EditText trackno = (EditText)view.findViewById(R.id.et_trackno);
- final TextInputLayout tl_trackno = (TextInputLayout)view.findViewById(R.id.tl_trackno);
- form.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- if(trackno.isEnabled()){
- trackno.setEnabled(false);
- }else{
- trackno.setEnabled(true);
- }
- }
- });
- view.findViewById(R.id.iv_send).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- tl_trackno.setError(null);
- if(ViewUtil.isEmpty(trackno)){
- tl_trackno.setError("Please input tracking number.");
- }else{
- mController.checkReference(trackno.getText().toString());
- }
- }
- });
- sender_data.findViewById(R.id.tv_search).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- showSearchDialog(SENDER_SEARCH_TYPE);
- }
- });
- bene_data.findViewById(R.id.tv_search).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- showSearchDialog(BENE_SEARCH_TYPE);
- }
- });
- view.findViewById(R.id.btn_submit).setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- mController.submit();
- }
- });
- view.findViewById(R.id.cv_check_status).setVisibility(View.VISIBLE);
- smartMoneyNo = (EditText)inputs.findViewById(R.id.et_smartmoneyno);
- initSmartMoneyNo();
- mModel = new RemittanceModel();
- mModel.registerObserver(this);
- mController = new SmartMoneySendController(this, mModel);
- RemittanceHolder holder = getCredentials(1);
- if(holder.sender_id.getText().toString().equals("")){
- showSearchDialog(SENDER_SEARCH_TYPE);
- }
- return view;
- }
- @Override
- public void onResume() {
- super.onResume();
- User user = new UserModel().getCurrentUser(getActivity());
- if (!user.getRemitECashSend().equals("1")) {
- showError(Title.UNIFIED, Message.MSG_UPGRADE_ACCOUNT, new DialogInterface.OnDismissListener() {
- @Override
- public void onDismiss(DialogInterface dialog) {
- Intent intent = new Intent(getActivity(), Mainmenu.class);
- startActivity(intent);
- getActivity().finish();
- }
- });
- }
- }
- public void initSmartMoneyNo() {
- smartMoneyNo.addTextChangedListener(new TextWatcher() {
- @Override
- public void afterTextChanged(Editable s) {
- Log.w("", "input" + s.toString());
- if (s.length() > 0 && !CODE_PATTERN.matcher(s).matches()) {
- String input = s.toString();
- String numbersOnly = keepNumbersOnly(input);
- String code = formatNumbersAsCode(numbersOnly);
- smartMoneyNo.removeTextChangedListener(this);
- smartMoneyNo.setText(code);
- smartMoneyNo.setSelection(code.length());
- smartMoneyNo.addTextChangedListener(this);
- }
- }
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
- private String keepNumbersOnly(CharSequence s) {
- return s.toString().replaceAll("[^0-9]", "");
- }
- private String formatNumbersAsCode(CharSequence s) {
- int groupDigits = 0;
- String tmp = "";
- for (int i = 0; i < s.length(); ++i) {
- tmp += s.charAt(i);
- ++groupDigits;
- if (groupDigits == 4) {
- tmp += "-";
- groupDigits = 0;
- }
- }
- return tmp;
- }});
- }
- private void showSearchDialog(final int searchtype) {
- builder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);
- String client;
- if(searchtype == 1){
- client = "Sender";
- }else{
- client = "Beneficiary";
- }
- builder.setTitle("Search "+client);
- LayoutInflater inflater = getActivity().getLayoutInflater();
- dialogView = inflater.inflate(R.layout.remittance_search_client, null);
- builder.setView(dialogView);
- builder.setPositiveButton("SEARCH", null);
- builder.setNegativeButton("REGISTER NEW CLIENT", null);
- mAlertDialog = builder.create();
- final EditText serachKey = (EditText)dialogView.findViewById(R.id.et_searchkey);
- final TextInputLayout tl_searchKey = (TextInputLayout)dialogView.findViewById(R.id.tl_searchkey);
- mAlertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
- @Override
- public void onShow(DialogInterface dialog) {
- Button b = mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
- b.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- tl_searchKey.setError(null);
- // TODO Do something
- if (ViewUtil.isEmpty(serachKey)) {
- tl_searchKey.setError("Please input search key.");
- } else {
- mController.searchClient(searchtype, serachKey.getText().toString());
- }
- }
- });
- Button register = mAlertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
- register.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- showRegistrationDialog(searchtype);
- }
- });
- }
- });
- mAlertDialog.show(); }
- @Override
- public void errorOnRequest(Exception exception) {
- showError(Title.UPS, Message.REQUEST_ERROR, null);
- }
- @Override
- public void responseReceived(Response response, int type) {
- if(type == 1 || type ==2){
- mController.processSearchRegReponse(response, type);
- }else{
- mController.processReponse(response, type);
- }
- }
- @Override
- public RemittanceHolder getCredentials(int type) {
- RemittanceHolder holder = new RemittanceHolder();
- holder.sender_id = (TextView)sender_data.findViewById(R.id.tv_loyaltyno);
- holder.sender_fullanme = (TextView)sender_data.findViewById(R.id.tv_fullname);
- holder.sender_address = (TextView)sender_data.findViewById(R.id.tv_address);
- holder.sender_mobile = (TextView)sender_data.findViewById(R.id.tv_mobile);
- holder.sender_email = (TextView)sender_data.findViewById(R.id.tv_email);
- holder.bene_id = (TextView)bene_data.findViewById(R.id.tv_loyaltyno);
- holder.bene_fullanme = (TextView)bene_data.findViewById(R.id.tv_fullname);
- holder.bene_address = (TextView)bene_data.findViewById(R.id.tv_address);
- holder.bene_mobile = (TextView)bene_data.findViewById(R.id.tv_mobile);
- holder.bene_email = (TextView)bene_data.findViewById(R.id.tv_email);
- holder.mAlertDialog = mAlertDialog;
- holder.idtype = (EditText) inputs.findViewById(R.id.et_idtype);
- holder.idno = (EditText) inputs.findViewById(R.id.et_idno);
- holder.amount = (EditText) inputs.findViewById(R.id.et_amount);
- holder.tpass = (EditText) inputs.findViewById(R.id.et_tpass);
- holder.smartmoneyno = (EditText) inputs.findViewById(R.id.et_smartmoneyno);
- holder.tl_idtype = (TextInputLayout) inputs.findViewById(R.id.tl_idtype);
- holder.tl_idno = (TextInputLayout) inputs.findViewById(R.id.tl_idno);
- holder.tl_amount = (TextInputLayout) inputs.findViewById(R.id.tl_amount);
- holder.tl_tpass = (TextInputLayout) inputs.findViewById(R.id.tl_tpass);
- holder.tl_smartmoneyno = (TextInputLayout) inputs.findViewById(R.id.tl_smartmoneyno);
- if(type == 2) {
- holder.registrationDialog = registrationDialog;
- holder.firstname = (EditText) dialogView.findViewById(R.id.et_firstname);
- holder.middlename = (EditText) dialogView.findViewById(R.id.et_middlename);
- holder.lastname = (EditText) dialogView.findViewById(R.id.et_lastname);
- holder.address = (EditText) dialogView.findViewById(R.id.et_address);
- holder.mobile = (EditText) dialogView.findViewById(R.id.et_mobile);
- holder.email = (EditText) dialogView.findViewById(R.id.et_email);
- holder.bday = (EditText) dialogView.findViewById(R.id.et_bday);
- holder.password = (EditText) dialogView.findViewById(R.id.et_password);
- holder.tl_firstname = (TextInputLayout) dialogView.findViewById(R.id.tl_firstname);
- holder.tl_middlename = (TextInputLayout) dialogView.findViewById(R.id.tl_middlename);
- holder.tl_lastname = (TextInputLayout) dialogView.findViewById(R.id.tl_lastname);
- holder.tl_address = (TextInputLayout) dialogView.findViewById(R.id.tl_address);
- holder.tl_mobile = (TextInputLayout) dialogView.findViewById(R.id.tl_mobile);
- holder.tl_email = (TextInputLayout) dialogView.findViewById(R.id.tl_email);
- // holder.tl_bday = (TextInputLayout) dialogView.findViewById(R.id.tl_bday);
- holder.tl_password = (TextInputLayout) dialogView.findViewById(R.id.tl_password);
- RadioGroup rg = (RadioGroup) dialogView.findViewById(R.id.gender);
- int selectedId = rg.getCheckedRadioButtonId();
- holder.gender = (RadioButton) dialogView.findViewById(selectedId);
- holder.country = (Spinner) dialogView.findViewById(R.id.sp_country);
- }
- return holder;
- }
- @Override
- public void showSearchResultDialo(ArrayList<ClientObjects> searchData, int search_type) {
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);
- LayoutInflater inflater = getActivity().getLayoutInflater();
- View view = inflater.inflate(R.layout.remittance_client_search, null);
- builder.setView(view);
- RecyclerView recList = (RecyclerView)view. findViewById(R.id.cardList);
- recList.setHasFixedSize(true);
- LinearLayoutManager llm = new LinearLayoutManager(view.getContext());
- llm.setOrientation(LinearLayoutManager.VERTICAL);
- recList.setLayoutManager(llm);
- recList.setAdapter(null);
- builder.setNegativeButton("DISMISS", null);
- searchResultDialog = builder.create();
- SearchAdapter adaper = new SearchAdapter(getActivity(), searchData,this,search_type,searchResultDialog,mAlertDialog);
- recList.setAdapter(adaper);
- searchResultDialog.show();
- }
- @Override
- public void showRegistrationDialog(final int searchType) {
- builder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);
- LayoutInflater inflater = getActivity().getLayoutInflater();
- dialogView = inflater.inflate(R.layout.remitrtance_client_registration, null);
- getCredentials(2).bday.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- DatePickerDialog dpd = new DatePickerDialog(getActivity(),
- new DatePickerDialog.OnDateSetListener() {
- @Override
- public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
- String monthPrefix = "";
- String datePrefix = "";
- if (monthOfYear + 1 <= 9) {
- monthPrefix = "0";
- } else {
- monthPrefix = "";
- }
- if (dayOfMonth <= 9) {
- datePrefix = "0";
- } else {
- datePrefix = "";
- }
- getCredentials(2).bday.setText(year + "-" + monthPrefix + (monthOfYear + 1) + "-" + (datePrefix + dayOfMonth));
- }
- }, mYear, mMonth, mDay);
- dpd.show();
- }
- });
- builder.setView(dialogView);
- builder.setPositiveButton("REGISTER", null);
- builder.setNegativeButton("CANCEL", null);
- registrationDialog = builder.create();
- registrationDialog.setOnShowListener(new DialogInterface.OnShowListener() {
- @Override
- public void onShow(DialogInterface dialog) {
- Button b = registrationDialog.getButton(AlertDialog.BUTTON_POSITIVE);
- b.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- // TODO Do something
- mController.registerUser(searchType);
- }
- });
- }
- });
- registrationDialog.show();
- }
- @Override
- public void displaySearchResult(ClientObjects clientObjects, int request_type) {
- RemittanceHolder holder = getCredentials(1);
- if(request_type ==1) {
- holder.sender_id.setText(clientObjects.CARDNO);
- holder.sender_fullanme.setText(clientObjects.FULLNAME);
- holder.sender_address.setText(clientObjects.ADDRESS);
- holder.sender_email.setText(clientObjects.EMAIL);
- holder.sender_mobile.setText(clientObjects.MOBILE);
- if( holder.bene_id.getText().toString().equals("")){
- showSearchDialog(BENE_SEARCH_TYPE);
- }
- }else{
- holder.bene_id.setText(clientObjects.CARDNO);
- holder.bene_fullanme.setText(clientObjects.FULLNAME);
- holder.bene_address.setText(clientObjects.ADDRESS);
- holder.bene_email.setText(clientObjects.EMAIL);
- holder.bene_mobile.setText(clientObjects.MOBILE);
- mAlertDialog.dismiss();
- }
- }
- @Override
- public void showError(String title, String message, DialogInterface.OnDismissListener listener) {
- AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);
- builder.setTitle(Title.SMARTMONEYSEND);
- builder.setCancelable(false);
- builder.setMessage(message);
- builder.setPositiveButton("OK", null);
- builder.setOnDismissListener(listener);
- builder.show();
- }
- @Override
- public void updateBankList(Cursor cursor) {
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement