Advertisement
Guest User

Untitled

a guest
May 24th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.94 KB | None | 0 0
  1. package com.unlitechsolutions.upsmobileapp.services.remittance;
  2.  
  3. import android.app.DatePickerDialog;
  4. import android.content.DialogInterface;
  5. import android.content.Intent;
  6. import android.database.Cursor;
  7. import android.os.Bundle;
  8. import android.support.design.widget.TextInputLayout;
  9. import android.support.v4.app.Fragment;
  10. import android.support.v7.app.AlertDialog;
  11. import android.support.v7.widget.LinearLayoutManager;
  12. import android.support.v7.widget.RecyclerView;
  13. import android.text.Editable;
  14. import android.text.TextWatcher;
  15. import android.util.Log;
  16. import android.view.LayoutInflater;
  17. import android.view.View;
  18. import android.view.ViewGroup;
  19. import android.view.ViewStub;
  20. import android.widget.Button;
  21. import android.widget.DatePicker;
  22. import android.widget.EditText;
  23. import android.widget.LinearLayout;
  24. import android.widget.RadioButton;
  25. import android.widget.RadioGroup;
  26. import android.widget.Spinner;
  27. import android.widget.TextView;
  28.  
  29. import com.unlitechsolutions.upsmobileapp.Mainmenu;
  30. import com.unlitechsolutions.upsmobileapp.R;
  31. import com.unlitechsolutions.upsmobileapp.controller.remittance.SmartMoneySendController;
  32. import com.unlitechsolutions.upsmobileapp.data.Message;
  33. import com.unlitechsolutions.upsmobileapp.data.Title;
  34. import com.unlitechsolutions.upsmobileapp.data.User;
  35. import com.unlitechsolutions.upsmobileapp.model.RemittanceModel;
  36. import com.unlitechsolutions.upsmobileapp.model.UserModel;
  37. import com.unlitechsolutions.upsmobileapp.objects.ClientObjects;
  38. import com.unlitechsolutions.upsmobileapp.objects.adapters.SearchAdapter;
  39. import com.unlitechsolutions.upsmobileapp.view.RemittanceView;
  40.  
  41. import java.util.ArrayList;
  42. import java.util.Calendar;
  43. import java.util.regex.Pattern;
  44.  
  45. import UnlitechDevFramework.src.ud.framework.data.Response;
  46. import UnlitechDevFramework.src.ud.framework.utilities.ViewUtil;
  47.  
  48. /**
  49. * Created by Em on 5/25/2016.
  50. */
  51. public class SmartmoneySend extends Fragment implements RemittanceView,RemittanceModel.RemittanceModelObserver {
  52. View view, sender_data, bene_data, inputs;
  53. private AlertDialog.Builder builder;
  54. AlertDialog mAlertDialog,searchResultDialog,registrationDialog;
  55. private static int SENDER_SEARCH_TYPE = 1;
  56. private static int BENE_SEARCH_TYPE = 2;
  57. private View dialogView;
  58. RemittanceModel mModel;
  59. SmartMoneySendController mController;
  60. private EditText smartMoneyNo;
  61. static final Pattern CODE_PATTERN = Pattern.compile("([0-9]{0,4})|([0-9]{4}-)+|([0-9]{4}-[0-9]{0,4})+");
  62. private int mYear, mMonth, mDay;
  63. private Calendar cal;
  64. @Override
  65. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  66. view = inflater.inflate(R.layout.remittance_ecashpadala_send, container, false);
  67. sender_data = view.findViewById(R.id.include_sender_data);
  68. bene_data = view.findViewById(R.id.include_bene_data);
  69. cal = Calendar.getInstance();
  70. mDay = cal.get(Calendar.DAY_OF_MONTH);
  71. mMonth = cal.get(Calendar.MONTH);
  72. mYear = cal.get(Calendar.YEAR);
  73. TextView title = (TextView) bene_data.findViewById(R.id.tv_title);
  74. title.setText("BENEFICIARY");
  75. ViewStub stub = (ViewStub) view.findViewById(R.id.layout_stub);
  76. stub.setLayoutResource(R.layout.remittance_inputfields_smartmoneysend);
  77. inputs = stub.inflate();
  78. LinearLayout form = (LinearLayout)view.findViewById(R.id.form);
  79. final EditText trackno = (EditText)view.findViewById(R.id.et_trackno);
  80. final TextInputLayout tl_trackno = (TextInputLayout)view.findViewById(R.id.tl_trackno);
  81. form.setOnClickListener(new View.OnClickListener() {
  82. @Override
  83. public void onClick(View v) {
  84. if(trackno.isEnabled()){
  85. trackno.setEnabled(false);
  86. }else{
  87. trackno.setEnabled(true);
  88. }
  89. }
  90. });
  91. view.findViewById(R.id.iv_send).setOnClickListener(new View.OnClickListener() {
  92. @Override
  93. public void onClick(View v) {
  94. tl_trackno.setError(null);
  95. if(ViewUtil.isEmpty(trackno)){
  96. tl_trackno.setError("Please input tracking number.");
  97. }else{
  98. mController.checkReference(trackno.getText().toString());
  99. }
  100. }
  101. });
  102. sender_data.findViewById(R.id.tv_search).setOnClickListener(new View.OnClickListener() {
  103. @Override
  104. public void onClick(View v) {
  105. showSearchDialog(SENDER_SEARCH_TYPE);
  106. }
  107. });
  108. bene_data.findViewById(R.id.tv_search).setOnClickListener(new View.OnClickListener() {
  109. @Override
  110. public void onClick(View v) {
  111. showSearchDialog(BENE_SEARCH_TYPE);
  112. }
  113. });
  114. view.findViewById(R.id.btn_submit).setOnClickListener(new View.OnClickListener() {
  115. @Override
  116. public void onClick(View v) {
  117. mController.submit();
  118. }
  119. });
  120. view.findViewById(R.id.cv_check_status).setVisibility(View.VISIBLE);
  121. smartMoneyNo = (EditText)inputs.findViewById(R.id.et_smartmoneyno);
  122. initSmartMoneyNo();
  123. mModel = new RemittanceModel();
  124. mModel.registerObserver(this);
  125. mController = new SmartMoneySendController(this, mModel);
  126. RemittanceHolder holder = getCredentials(1);
  127. if(holder.sender_id.getText().toString().equals("")){
  128. showSearchDialog(SENDER_SEARCH_TYPE);
  129. }
  130. return view;
  131. }
  132. @Override
  133. public void onResume() {
  134. super.onResume();
  135. User user = new UserModel().getCurrentUser(getActivity());
  136. if (!user.getRemitECashSend().equals("1")) {
  137. showError(Title.UNIFIED, Message.MSG_UPGRADE_ACCOUNT, new DialogInterface.OnDismissListener() {
  138. @Override
  139. public void onDismiss(DialogInterface dialog) {
  140. Intent intent = new Intent(getActivity(), Mainmenu.class);
  141. startActivity(intent);
  142. getActivity().finish();
  143. }
  144. });
  145. }
  146. }
  147.  
  148. public void initSmartMoneyNo() {
  149.  
  150. smartMoneyNo.addTextChangedListener(new TextWatcher() {
  151. @Override
  152. public void afterTextChanged(Editable s) {
  153. Log.w("", "input" + s.toString());
  154.  
  155. if (s.length() > 0 && !CODE_PATTERN.matcher(s).matches()) {
  156. String input = s.toString();
  157. String numbersOnly = keepNumbersOnly(input);
  158. String code = formatNumbersAsCode(numbersOnly);
  159.  
  160. smartMoneyNo.removeTextChangedListener(this);
  161. smartMoneyNo.setText(code);
  162. smartMoneyNo.setSelection(code.length());
  163. smartMoneyNo.addTextChangedListener(this);
  164. }
  165. }
  166. @Override
  167. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  168. }
  169.  
  170. @Override
  171. public void onTextChanged(CharSequence s, int start, int before, int count) {
  172. }
  173.  
  174. private String keepNumbersOnly(CharSequence s) {
  175. return s.toString().replaceAll("[^0-9]", "");
  176. }
  177.  
  178. private String formatNumbersAsCode(CharSequence s) {
  179. int groupDigits = 0;
  180. String tmp = "";
  181. for (int i = 0; i < s.length(); ++i) {
  182. tmp += s.charAt(i);
  183. ++groupDigits;
  184. if (groupDigits == 4) {
  185. tmp += "-";
  186. groupDigits = 0;
  187. }
  188. }
  189. return tmp;
  190. }});
  191. }
  192. private void showSearchDialog(final int searchtype) {
  193. builder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);
  194. String client;
  195. if(searchtype == 1){
  196. client = "Sender";
  197. }else{
  198. client = "Beneficiary";
  199. }
  200. builder.setTitle("Search "+client);
  201. LayoutInflater inflater = getActivity().getLayoutInflater();
  202. dialogView = inflater.inflate(R.layout.remittance_search_client, null);
  203. builder.setView(dialogView);
  204. builder.setPositiveButton("SEARCH", null);
  205. builder.setNegativeButton("REGISTER NEW CLIENT", null);
  206. mAlertDialog = builder.create();
  207. final EditText serachKey = (EditText)dialogView.findViewById(R.id.et_searchkey);
  208. final TextInputLayout tl_searchKey = (TextInputLayout)dialogView.findViewById(R.id.tl_searchkey);
  209. mAlertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
  210.  
  211. @Override
  212. public void onShow(DialogInterface dialog) {
  213.  
  214. Button b = mAlertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
  215. b.setOnClickListener(new View.OnClickListener() {
  216.  
  217. @Override
  218. public void onClick(View view) {
  219. tl_searchKey.setError(null);
  220. // TODO Do something
  221. if (ViewUtil.isEmpty(serachKey)) {
  222. tl_searchKey.setError("Please input search key.");
  223. } else {
  224. mController.searchClient(searchtype, serachKey.getText().toString());
  225. }
  226. }
  227. });
  228. Button register = mAlertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
  229. register.setOnClickListener(new View.OnClickListener() {
  230.  
  231. @Override
  232. public void onClick(View view) {
  233. showRegistrationDialog(searchtype);
  234. }
  235. });
  236. }
  237. });
  238. mAlertDialog.show(); }
  239. @Override
  240. public void errorOnRequest(Exception exception) {
  241. showError(Title.UPS, Message.REQUEST_ERROR, null);
  242. }
  243.  
  244. @Override
  245. public void responseReceived(Response response, int type) {
  246. if(type == 1 || type ==2){
  247. mController.processSearchRegReponse(response, type);
  248. }else{
  249. mController.processReponse(response, type);
  250. }
  251.  
  252. }
  253.  
  254. @Override
  255. public RemittanceHolder getCredentials(int type) {
  256.  
  257. RemittanceHolder holder = new RemittanceHolder();
  258. holder.sender_id = (TextView)sender_data.findViewById(R.id.tv_loyaltyno);
  259. holder.sender_fullanme = (TextView)sender_data.findViewById(R.id.tv_fullname);
  260. holder.sender_address = (TextView)sender_data.findViewById(R.id.tv_address);
  261. holder.sender_mobile = (TextView)sender_data.findViewById(R.id.tv_mobile);
  262. holder.sender_email = (TextView)sender_data.findViewById(R.id.tv_email);
  263.  
  264. holder.bene_id = (TextView)bene_data.findViewById(R.id.tv_loyaltyno);
  265. holder.bene_fullanme = (TextView)bene_data.findViewById(R.id.tv_fullname);
  266. holder.bene_address = (TextView)bene_data.findViewById(R.id.tv_address);
  267. holder.bene_mobile = (TextView)bene_data.findViewById(R.id.tv_mobile);
  268. holder.bene_email = (TextView)bene_data.findViewById(R.id.tv_email);
  269.  
  270. holder.mAlertDialog = mAlertDialog;
  271.  
  272. holder.idtype = (EditText) inputs.findViewById(R.id.et_idtype);
  273. holder.idno = (EditText) inputs.findViewById(R.id.et_idno);
  274. holder.amount = (EditText) inputs.findViewById(R.id.et_amount);
  275. holder.tpass = (EditText) inputs.findViewById(R.id.et_tpass);
  276. holder.smartmoneyno = (EditText) inputs.findViewById(R.id.et_smartmoneyno);
  277. holder.tl_idtype = (TextInputLayout) inputs.findViewById(R.id.tl_idtype);
  278. holder.tl_idno = (TextInputLayout) inputs.findViewById(R.id.tl_idno);
  279. holder.tl_amount = (TextInputLayout) inputs.findViewById(R.id.tl_amount);
  280. holder.tl_tpass = (TextInputLayout) inputs.findViewById(R.id.tl_tpass);
  281. holder.tl_smartmoneyno = (TextInputLayout) inputs.findViewById(R.id.tl_smartmoneyno);
  282. if(type == 2) {
  283. holder.registrationDialog = registrationDialog;
  284. holder.firstname = (EditText) dialogView.findViewById(R.id.et_firstname);
  285. holder.middlename = (EditText) dialogView.findViewById(R.id.et_middlename);
  286. holder.lastname = (EditText) dialogView.findViewById(R.id.et_lastname);
  287. holder.address = (EditText) dialogView.findViewById(R.id.et_address);
  288. holder.mobile = (EditText) dialogView.findViewById(R.id.et_mobile);
  289. holder.email = (EditText) dialogView.findViewById(R.id.et_email);
  290. holder.bday = (EditText) dialogView.findViewById(R.id.et_bday);
  291. holder.password = (EditText) dialogView.findViewById(R.id.et_password);
  292.  
  293. holder.tl_firstname = (TextInputLayout) dialogView.findViewById(R.id.tl_firstname);
  294. holder.tl_middlename = (TextInputLayout) dialogView.findViewById(R.id.tl_middlename);
  295. holder.tl_lastname = (TextInputLayout) dialogView.findViewById(R.id.tl_lastname);
  296. holder.tl_address = (TextInputLayout) dialogView.findViewById(R.id.tl_address);
  297. holder.tl_mobile = (TextInputLayout) dialogView.findViewById(R.id.tl_mobile);
  298. holder.tl_email = (TextInputLayout) dialogView.findViewById(R.id.tl_email);
  299. // holder.tl_bday = (TextInputLayout) dialogView.findViewById(R.id.tl_bday);
  300. holder.tl_password = (TextInputLayout) dialogView.findViewById(R.id.tl_password);
  301. RadioGroup rg = (RadioGroup) dialogView.findViewById(R.id.gender);
  302. int selectedId = rg.getCheckedRadioButtonId();
  303. holder.gender = (RadioButton) dialogView.findViewById(selectedId);
  304. holder.country = (Spinner) dialogView.findViewById(R.id.sp_country);
  305. }
  306. return holder;
  307. }
  308.  
  309. @Override
  310. public void showSearchResultDialo(ArrayList<ClientObjects> searchData, int search_type) {
  311. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);
  312. LayoutInflater inflater = getActivity().getLayoutInflater();
  313. View view = inflater.inflate(R.layout.remittance_client_search, null);
  314. builder.setView(view);
  315. RecyclerView recList = (RecyclerView)view. findViewById(R.id.cardList);
  316. recList.setHasFixedSize(true);
  317. LinearLayoutManager llm = new LinearLayoutManager(view.getContext());
  318. llm.setOrientation(LinearLayoutManager.VERTICAL);
  319. recList.setLayoutManager(llm);
  320. recList.setAdapter(null);
  321. builder.setNegativeButton("DISMISS", null);
  322. searchResultDialog = builder.create();
  323. SearchAdapter adaper = new SearchAdapter(getActivity(), searchData,this,search_type,searchResultDialog,mAlertDialog);
  324. recList.setAdapter(adaper);
  325. searchResultDialog.show();
  326. }
  327.  
  328. @Override
  329. public void showRegistrationDialog(final int searchType) {
  330. builder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);
  331. LayoutInflater inflater = getActivity().getLayoutInflater();
  332. dialogView = inflater.inflate(R.layout.remitrtance_client_registration, null);
  333. getCredentials(2).bday.setOnClickListener(new View.OnClickListener() {
  334. @Override
  335. public void onClick(View v) {
  336. DatePickerDialog dpd = new DatePickerDialog(getActivity(),
  337. new DatePickerDialog.OnDateSetListener() {
  338.  
  339. @Override
  340. public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
  341. String monthPrefix = "";
  342. String datePrefix = "";
  343. if (monthOfYear + 1 <= 9) {
  344. monthPrefix = "0";
  345. } else {
  346. monthPrefix = "";
  347. }
  348. if (dayOfMonth <= 9) {
  349. datePrefix = "0";
  350. } else {
  351. datePrefix = "";
  352. }
  353. getCredentials(2).bday.setText(year + "-" + monthPrefix + (monthOfYear + 1) + "-" + (datePrefix + dayOfMonth));
  354. }
  355. }, mYear, mMonth, mDay);
  356. dpd.show();
  357.  
  358. }
  359. });
  360. builder.setView(dialogView);
  361. builder.setPositiveButton("REGISTER", null);
  362. builder.setNegativeButton("CANCEL", null);
  363. registrationDialog = builder.create();
  364. registrationDialog.setOnShowListener(new DialogInterface.OnShowListener() {
  365.  
  366. @Override
  367. public void onShow(DialogInterface dialog) {
  368.  
  369. Button b = registrationDialog.getButton(AlertDialog.BUTTON_POSITIVE);
  370. b.setOnClickListener(new View.OnClickListener() {
  371.  
  372. @Override
  373. public void onClick(View view) {
  374. // TODO Do something
  375. mController.registerUser(searchType);
  376. }
  377. });
  378. }
  379. });
  380. registrationDialog.show();
  381. }
  382.  
  383. @Override
  384. public void displaySearchResult(ClientObjects clientObjects, int request_type) {
  385. RemittanceHolder holder = getCredentials(1);
  386. if(request_type ==1) {
  387. holder.sender_id.setText(clientObjects.CARDNO);
  388. holder.sender_fullanme.setText(clientObjects.FULLNAME);
  389. holder.sender_address.setText(clientObjects.ADDRESS);
  390. holder.sender_email.setText(clientObjects.EMAIL);
  391. holder.sender_mobile.setText(clientObjects.MOBILE);
  392. if( holder.bene_id.getText().toString().equals("")){
  393. showSearchDialog(BENE_SEARCH_TYPE);
  394. }
  395. }else{
  396. holder.bene_id.setText(clientObjects.CARDNO);
  397. holder.bene_fullanme.setText(clientObjects.FULLNAME);
  398. holder.bene_address.setText(clientObjects.ADDRESS);
  399. holder.bene_email.setText(clientObjects.EMAIL);
  400. holder.bene_mobile.setText(clientObjects.MOBILE);
  401. mAlertDialog.dismiss();
  402. }
  403. }
  404.  
  405. @Override
  406. public void showError(String title, String message, DialogInterface.OnDismissListener listener) {
  407. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppCompatAlertDialogStyle);
  408. builder.setTitle(Title.SMARTMONEYSEND);
  409. builder.setCancelable(false);
  410. builder.setMessage(message);
  411. builder.setPositiveButton("OK", null);
  412. builder.setOnDismissListener(listener);
  413. builder.show();
  414. }
  415.  
  416. @Override
  417. public void updateBankList(Cursor cursor) {
  418.  
  419. }
  420. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement