PageRenderTime 1ms CodeModel.GetById 84ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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

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