Ejemplo n.º 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);

    if (AppUserSingleton.getInstance().getUser() != null) {
      AppUserSingleton.getInstance().logOut();
    }
    buttonSignup = (Button) findViewById(R.id.buttonSignup);
    buttonLogin = (Button) findViewById(R.id.buttonLogin);

    /** Wire up the edit texts used for signing up or logging in. */
    editTextFullName = (EditText) findViewById(R.id.editTextFullName);
    editTextUserNameSignup = (EditText) findViewById(R.id.editTextUserNameSignup);
    editTextUserNameLogin = (EditText) findViewById(R.id.editTextUserNameLogin);
    editTextEmail = (EditText) findViewById(R.id.editTextEmail);
    editTextMotto = (EditText) findViewById(R.id.editTextMotto);
    editTextUserNameLogin = (EditText) findViewById(R.id.editTextUserNameLogin);

    buttonSignup.setOnClickListener(this);
    buttonLogin.setOnClickListener(this);
  }
Ejemplo n.º 2
0
 @Override
 protected List<Thing> doInBackground(String... params) {
   List<Thing> res = ShareoData.getInstance().getGamesByField(mSearchField, mQueryText);
   List<Thing> filtered = new ArrayList<>();
   for (Thing t : res) {
     if (t.getOwner().getJestID().equals(AppUserSingleton.getInstance().getUser().getJestID())
         || t.getStatus() == Thing.Status.BORROWED) {
       continue;
     }
     filtered.add(t);
   }
   return filtered;
 }
Ejemplo n.º 3
0
  /**
   * Sign up or login user depending on button clicked. Notify user if login/create fail.
   *
   * @param v
   */
  public void onClick(View v) {
    final Intent mainIntent = new Intent(this, MainActivity.class);
    switch (v.getId()) {
        /** They clicked on button signup, so parse the signup of a new user. */
      case R.id.buttonSignup:
        Log.d(TAG, "Clicked Button Signup");
        /**
         * Store the fields userNameSignup, fullName, email, and motto based upon what the user
         * entered.
         */
        parseSignUp();
        /**
         * Only if the email is valid(i.e. they entered in [email protected]), do we parse the signup.
         */
        if (isValidEmail(email)) {
          /**
           * Create a new user by calling the relevant backend call after collecting the fields
           * inputted.
           */
          AppUserSingleton.getInstance()
              .createUser(
                  userNameSignup,
                  fullName,
                  email,
                  motto,
                  new CallbackInterface() {
                    @Override
                    public void onSuccess() {
                      startActivity(mainIntent);
                    }

                    @Override
                    public void onFailure() {
                      runOnUiThread(
                          new Runnable() {
                            @Override
                            public void run() {
                              Toast z =
                                  Toast.makeText(
                                      LoginActivity.this,
                                      "User already exists. Please choose a different username.",
                                      Toast.LENGTH_SHORT);
                              z.show();
                            }
                          });
                    }
                  });
        } else {
          Log.d(TAG, "Invalid Email");
          Toast z = Toast.makeText(this, "Invalid Email Inputted", Toast.LENGTH_SHORT);
          z.show();
        }

        break;

        /**
         * They clicked the login button, so get their username and log them in if the ID exists.
         */
      case R.id.buttonLogin:
        Log.d(TAG, "Clicked Button Login");
        /** Store the relevant field userNameLogin based upon what the user entered. */
        parseLogin();
        AppUserSingleton.getInstance()
            .logIn(
                userNameLogin,
                new CallbackInterface() {
                  @Override
                  public void onSuccess() {
                    startActivity(mainIntent);
                  }

                  @Override
                  public void onFailure() {
                    runOnUiThread(
                        new Runnable() {
                          @Override
                          public void run() {
                            Toast z =
                                Toast.makeText(
                                    LoginActivity.this,
                                    "No user exists. Please check spelling and try again.",
                                    Toast.LENGTH_SHORT);
                            z.show();
                          }
                        });
                  }
                });
        break;
    }
  }