PageRenderTime 26ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/MyCampus/app/src/main/java/com/example/maheshraja/mycampus/Activity/JobportalForm.java

https://gitlab.com/swarupa/mycampus
Java | 258 lines | 195 code | 46 blank | 17 comment | 25 complexity | d07dbc31801f742b1760d2b8eda2f8d4 MD5 | raw file
  1. package com.example.maheshraja.mycampus.Activity;
  2. import android.content.Context;
  3. import android.os.Bundle;
  4. import android.view.LayoutInflater;
  5. import android.view.View;
  6. import android.view.ViewGroup;
  7. import android.widget.Button;
  8. import android.widget.EditText;
  9. import com.example.maheshraja.mycampus.R;
  10. import com.example.maheshraja.mycampus.asynctask.SearchJobAsynTask;
  11. import com.example.maheshraja.mycampus.daos.JobportalDAo;
  12. import com.example.maheshraja.mycampus.daos.UserDAO;
  13. import com.example.maheshraja.mycampus.database.DBHandler;
  14. import com.example.maheshraja.mycampus.dtos.DTO;
  15. import com.example.maheshraja.mycampus.dtos.JobPortalDTO;
  16. import com.example.maheshraja.mycampus.dtos.UserDTO;
  17. import com.example.maheshraja.mycampus.listener.AsyncTaskCompleteListener;
  18. import com.example.maheshraja.mycampus.utility.MyConstants;
  19. import com.example.maheshraja.mycampus.utility.Utility;
  20. import org.json.JSONException;
  21. import org.json.JSONObject;
  22. /**
  23. * Created by lenovo on 30-07-2016.
  24. */
  25. public class JobportalForm extends BaseFragment {
  26. private Context context;
  27. EditText userNameEdt;
  28. EditText mobileNoEdt;
  29. EditText emailIdEdt;
  30. EditText KeySkillEdt;
  31. EditText reg_resume;
  32. EditText reg_sscper;
  33. EditText reg_inter;
  34. EditText reg_btech;
  35. Button btnSubmit;
  36. EditText preferedlocation;
  37. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  38. context = mActivity;
  39. View rootView = inflater.inflate(R.layout.fragemt_jobportalform, container, false);
  40. userNameEdt = (EditText)rootView. findViewById(R.id.reg_name);
  41. mobileNoEdt = (EditText)rootView. findViewById(R.id.reg_mobile);
  42. emailIdEdt = (EditText)rootView. findViewById(R.id.reg_email);
  43. KeySkillEdt = (EditText)rootView. findViewById(R.id.reg_keyskills);
  44. reg_resume = (EditText)rootView. findViewById(R.id.reg_resume);
  45. reg_sscper = (EditText)rootView. findViewById(R.id.reg_sscper);
  46. reg_inter=(EditText)rootView. findViewById(R.id.reg_inter);
  47. reg_btech=(EditText)rootView. findViewById(R.id.reg_btech);
  48. preferedlocation=(EditText)rootView. findViewById(R.id.reg_location);
  49. btnSubmit = (Button)rootView. findViewById(R.id.reg_submit);
  50. btnSubmit.setOnClickListener(new View.OnClickListener() {
  51. @Override
  52. public void onClick(View v) {
  53. String validation = validateFields();
  54. if (validation == null) {
  55. if (Utility.networkAvailability(context)) {
  56. // showProgress();
  57. registrationProcess();
  58. // loginProcess();
  59. //saveData(getUserData());;
  60. } else {
  61. Utility.showAlert(context, null, getString(R.string.check_connection));
  62. }
  63. } else {
  64. Utility.showAlert(context, "Alert", validation);
  65. }
  66. //uploadImage();
  67. }
  68. });
  69. return rootView;
  70. }
  71. private boolean isTextEmpty(EditText editText) {
  72. if (!editText.getText().toString().trim().isEmpty())
  73. return false;
  74. else
  75. return true;
  76. }
  77. private String getText(EditText editText) {
  78. return editText.getText().toString().trim();
  79. }
  80. private String validateFields() {
  81. if (isTextEmpty(userNameEdt)) {
  82. return "Enter your name";
  83. }
  84. if (isTextEmpty(mobileNoEdt)) {
  85. return "Enter mobile number";
  86. }
  87. if (mobileNoEdt.getText().toString().trim().length() <= 9) {
  88. return "Enter valid mobile number";
  89. }
  90. if (isTextEmpty(emailIdEdt)) {
  91. return "Enter mail ID";
  92. }
  93. if(!isValidEmailAddress(getText(emailIdEdt))){
  94. return "Enter valid mail ID";
  95. }
  96. if (isTextEmpty(KeySkillEdt)) {
  97. return "Enter Keyskill";
  98. }
  99. if (isTextEmpty(reg_resume)) {
  100. return "Enter Resume Headline";
  101. }
  102. if (isTextEmpty(reg_sscper)) {
  103. return "Enter SSC Percentage";
  104. }
  105. /*if (isTextEmpty(uidEdt)) {
  106. return "Enter UID";
  107. }*/
  108. if (isTextEmpty(reg_inter)) {
  109. return "Enter Inter Percentage";
  110. }
  111. /*if (isTextEmpty(locationEdt)) {
  112. return "Enter your location";
  113. }*/
  114. if (isTextEmpty(reg_btech)) {
  115. return "Enter BTECH Percentage";
  116. }
  117. if (isTextEmpty(preferedlocation)) {
  118. return "Enter Loctaion";
  119. }
  120. return null;
  121. }
  122. public boolean isValidEmailAddress(String email) {
  123. String ePattern = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$";
  124. java.util.regex.Pattern p = java.util.regex.Pattern.compile(ePattern);
  125. java.util.regex.Matcher m = p.matcher(email);
  126. return m.matches();
  127. }
  128. private void registrationProcess() {
  129. UserDTO localObject = (UserDTO) UserDAO.getInstance().getRecords(DBHandler.getInstance(this.mActivity).getDBObject(0)).get(0);
  130. JobPortalDTO dto = (JobPortalDTO) getUserData();
  131. JSONObject reqJson = new JSONObject();
  132. try {
  133. reqJson.put("userName", dto.getUserName());
  134. System.out.println("userName" + dto.getUserName());
  135. reqJson.put("mobileNumber", dto.getMobileNumber());
  136. System.out.println("mobileNumber" + dto.getMobileNumber());
  137. reqJson.put("preferedLocation", dto.getPreferedLocation());
  138. System.out.println("preferedLocation" + dto.getPreferedLocation());
  139. reqJson.put("emailAddress", dto.getEmailAddress());
  140. System.out.println("emailAddress" + dto.getEmailAddress());
  141. reqJson.put("resumeHeadline", dto.getResumeHeadline());
  142. System.out.println("resumeHeadline" + dto.getResumeHeadline());
  143. reqJson.put("keySkills", dto.getKeySkills());
  144. System.out.println("keySkills" + dto.getKeySkills());
  145. reqJson.put("SSCPercentage", dto.getSSCPercentage());
  146. System.out.println("SSCPercentage" + dto.getSSCPercentage());
  147. reqJson.put("interPercentage", dto.getInterPercentage());
  148. System.out.println("interPercentage" + dto.getInterPercentage());
  149. reqJson.put("btechPercentage", dto.getBtechPercentage());
  150. System.out.println("btechPercentage" + dto.getBtechPercentage());
  151. reqJson.put("campus_emailid", dto.getCampus_emailid());
  152. System.out.println("campus_emailid" + localObject.getEmailId());
  153. } catch (JSONException e) {
  154. e.printStackTrace();
  155. }catch (Exception e){
  156. }
  157. SearchJobAsynTask loginAsync = new SearchJobAsynTask(reqJson.toString(), completeListener, MyConstants.CONNECTION_TIMEOUT, MyConstants.SOCKET_TIMEOUT);
  158. Utility.showProgressDialog(context);
  159. loginAsync.execute(MyConstants.JobPortal_REG_URL);
  160. }
  161. private DTO getUserData() {
  162. UserDTO localObject = (UserDTO) UserDAO.getInstance().getRecords(DBHandler.getInstance(this.mActivity).getDBObject(0)).get(0);
  163. JobPortalDTO dto = new JobPortalDTO();
  164. dto.setUserName(getText(userNameEdt));
  165. dto.setMobileNumber(getText(mobileNoEdt));
  166. dto.setEmailAddress(getText(emailIdEdt));
  167. dto.setPreferedLocation(getText(preferedlocation));
  168. dto.setResumeHeadline(getText(reg_resume));
  169. dto.setSSCPercentage(getText(reg_sscper));
  170. dto.setBtechPercentage(getText(reg_btech));
  171. dto.setInterPercentage(getText(reg_inter));
  172. dto.setKeySkills(getText(KeySkillEdt));
  173. dto.setCampus_emailid(localObject.getEmailId());
  174. return dto;
  175. }
  176. private void saveData(DTO userData) {
  177. //context.deleteDatabase("security.db");
  178. JobportalDAo.getInstance().insert(userData, DBHandler.getInstance(context).getDBObject(1));
  179. //navigateApp();
  180. }
  181. private AsyncTaskCompleteListener completeListener = new AsyncTaskCompleteListener() {
  182. @Override
  183. public void onAsynComplete(String result) {
  184. if (result != null) {
  185. if(Utility.isJSONValid(result)){
  186. try {
  187. JSONObject object = new JSONObject(result);
  188. int code = object.optInt("code");
  189. if(code == 100){
  190. // Utility.setAuthCode(object.optString("authcode"),RegistrationActivity.this);
  191. //saveData(getUserData());;
  192. mActivity.pushFragments(MyConstants.TAB_HOME, new Jobportal(), false, true);
  193. Utility.showAlert(context, null, " Your ProfileInsert Successfully");
  194. return;
  195. }else if(code == 101){
  196. Utility.showAlert(context, null, "Failed Register");
  197. }else{
  198. Utility.showAlert(context, null, "Unknown response");
  199. }
  200. } catch (JSONException e) {
  201. e.printStackTrace();
  202. }
  203. }else{
  204. Utility.showAlert(context, null, "Invalid Response contact system admin");
  205. }
  206. } else {
  207. Utility.showAlert(context, "Network problem", "Check your internet connection");
  208. }
  209. Utility.hideProgressDialog();
  210. }
  211. };
  212. }