Example #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    initialize();
    onClick();

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle("Sign in");
    setSupportActionBar(toolbar);

    if (preferenceClass.getLastUserEmail() != null) {

      email.setText(preferenceClass.getLastUserEmail());
      email.setFocusable(false);
      email.setFocusableInTouchMode(true);
    }
  }
Example #2
0
  public void parseJsonData(JsonObject jsonObject) {
    if (jsonObject == null) {
      return;
    }
    if (jsonObject.has(KEY_LOGGED_IN_USER)) {
      JsonObject loggedInUserObject = jsonObject.getAsJsonObject(KEY_LOGGED_IN_USER);
      firstName = loggedInUserObject.get(KEY_FIRST_NAME).getAsString();
      preferenceClass.saveFirstName(firstName);
      lastName = loggedInUserObject.get(KEY_LAST_NAME).getAsString();
      preferenceClass.saveLastName(lastName);
      gender = loggedInUserObject.get(KEY_GENDER).getAsString();
      userEmail = loggedInUserObject.get(KEY_EMAIL).getAsString();
      preferenceClass.saveLastUserEmail(userEmail);
      preferenceClass.saveUserEmail(userEmail);
      phoneNo = loggedInUserObject.get(KEY_PHONE_NO).getAsString();
      preferenceClass.saveUserPhoneNo(phoneNo);
      userType = loggedInUserObject.get(KEY_USER_TYPE).getAsString();
      if (loggedInUserObject.get(KEY_PROFILE_PIC).getAsString() != null) {
        imageURL = loggedInUserObject.get(KEY_PROFILE_PIC).getAsString();
      }

      preferenceClass.saveProfileImageUrl(KEY_UAT_BASE_URL + imageURL);

      if (loggedInUserObject.has(KEY_USER_TYPE_OBJECT)) {
        JsonObject userTypeObject = loggedInUserObject.getAsJsonObject(KEY_USER_TYPE_OBJECT);
        userId = userTypeObject.get(KEY_ID).getAsString();
        preferenceClass.saveCustomerId(userId);
      }
    }
    if (jsonObject.has(KEY_LOGIN_STATUS)) {
      if (jsonObject.get(KEY_LOGIN_STATUS).getAsBoolean() && userType.contentEquals("packrboy")) {
        Intent intent = new Intent(LoginActivity.this, TaskActivity.class);
        startActivity(intent);
        finish();

      } else {
        Log.e("error2", "Invalid credentials");
        hideKeyboard();
        Snackbar.make(
                loginLayout,
                "Sorry you do not have an account with us. Go ahead create one and make life easy :)",
                Snackbar.LENGTH_LONG)
            .show();
      }
    }
  }
Example #3
0
  public void sendLoginJsonRequest() {
    if (!Connectivity.isConnected(getApplicationContext())) {
      Snackbar.make(
              loginLayout,
              "Something is wrong with your internet connection. Please check your settings",
              Snackbar.LENGTH_LONG)
          .show();
    } else {
      progressWheel.setVisibility(View.VISIBLE);
      final JsonObject loginObject = new JsonObject();
      final JsonObject jsonObject1 = new JsonObject();
      final JsonObject deviceObject = new JsonObject();
      try {
        jsonObject1.addProperty("email", email.getText().toString());
        jsonObject1.addProperty("password", password.getText().toString());
        loginObject.add("payload", jsonObject1);
        loginObject.addProperty("token", preferenceClass.getAccessToken());
        deviceObject.addProperty("device_name", deviceInfo.getDeviceName());
        deviceObject.addProperty("device_type", "ANDROID");
        deviceObject.addProperty("device_os_ver", deviceInfo.getDeviceOSVersion());
        deviceObject.addProperty(
            "device_resolution",
            getResources().getDisplayMetrics().widthPixels
                + "*"
                + getResources().getDisplayMetrics().heightPixels);
        deviceObject.addProperty("device_token", preferenceClass.getDeviceToken());
        deviceObject.addProperty("app_ver", BuildConfig.VERSION_NAME);
        deviceObject.addProperty("lon", "");
        deviceObject.addProperty("lat", "");
        deviceObject.addProperty("user_id", "");
        jsonObject1.add("device", deviceObject);

      } catch (JsonIOException e) {
        e.printStackTrace();
      }

      Ion.with(getApplicationContext())
          .load(getLoginRequestUrl())
          .setJsonObjectBody(loginObject)
          .asJsonObject()
          .withResponse()
          .setCallback(
              new FutureCallback<com.koushikdutta.ion.Response<JsonObject>>() {
                @Override
                public void onCompleted(
                    Exception e, com.koushikdutta.ion.Response<JsonObject> result) {
                  progressWheel.setVisibility(View.GONE);
                  if (e != null) {
                    Log.e("exception", e.getLocalizedMessage() + " " + e.getLocalizedMessage());
                    hideKeyboard();
                    Snackbar.make(
                            loginLayout,
                            "We are facing problems in connecting to our servers. Just chill and try after some time :)",
                            Snackbar.LENGTH_LONG)
                        .show();
                  } else if (result != null) {
                    xxx = result.getHeaders().getHeaders().getAll("Set-Cookie");
                    //
                    xxx = result.getHeaders().getHeaders().getAll("Set-Cookie");
                    if (xxx.size() != 0) {
                      size = xxx.size();
                      splitCookie = xxx.get(size - 1).split(";");
                      splitSessionId = splitCookie[0].split("=");

                      preferenceClass.saveCookie("laravel_session=" + splitSessionId[1]);
                    }
                    parseJsonData(result.getResult());
                  } else {
                    Log.e("Exception", "There is a problem");
                    hideKeyboard();
                    Snackbar.make(
                            loginLayout,
                            "Something is wrong with the internet connection",
                            Snackbar.LENGTH_LONG)
                        .show();
                  }
                }
              });
    }
  }