Ejemplo n.º 1
0
  /**
   * Upon Save Button click, validates EditText fields If validated, edits user in singletondis and
   * displays profile view mode as Owner State
   *
   * @param view View
   */
  public void onSaveButtonClick(View view) {
    // valid input
    if (urc.validateEditedFields(etCity, etPhone, etEmail)) {
      urc.editUser(username, etCity, etPhone, etEmail);
      Toast.makeText(this, "Changes saved", Toast.LENGTH_LONG).show();
      upc.setViewMode(OWNER_STATE, etCity, etPhone, etEmail, editButton, saveButton);
    }

    // invalid input
    else Toast.makeText(this, "Form contains error", Toast.LENGTH_LONG).show();
  }
Ejemplo n.º 2
0
  /**
   * Checks for user on server
   *
   * @param user User
   */
  public void checkForUserOnServer(User user) {
    UserRegistrationController urc = new UserRegistrationController(this);
    userManager = new ESUserManager("");

    // If the user exist then we start "all activity", and he gets added to singleton, he is only
    // user in the singleton right now
    if (user != null) {
      // Toast.makeText(this, user.getUsername(), Toast.LENGTH_LONG).show();
      urc.addUser(user);
      String usernameFromServer = user.getUsername();
      Intent intent = new Intent(this, AllActivity.class);
      intent.putExtra(EXTRA_USERNAME, usernameFromServer);
      startActivity(intent);
    } else {
      Toast.makeText(this, "User not found. Register a new account.", Toast.LENGTH_LONG).show();
    }
  }
  /** Tests editing user profile (UC 2.4, 10.2) */
  public void testEditUserProfile() {
    UserProfileActivity activity = (UserProfileActivity) getActivity();
    etCity = activity.getEtCity();
    etPhone = activity.getEtPhone();
    etEmail = activity.getEtEmail();
    final String username = "******";
    final UserRegistrationController urc = new UserRegistrationController();

    // Creates user
    User user = new User();
    user.setUsername(username);
    user.setCity("Testlandia");
    user.setPhone("555-555-5555");
    user.setEmail("*****@*****.**");
    urc.getUserList().addUser(user);

    // Set up an ActivityMonitor
    Instrumentation.ActivityMonitor receiverActivityMonitor =
        getInstrumentation().addMonitor(RegisterActivity.class.getName(), null, false);

    activity.runOnUiThread(
        new Runnable() {
          public void run() {
            etCity.setText("Testopia");
            etPhone.setText("555-555-5556");
            etEmail.setText("*****@*****.**");
            if (urc.validateEditedFields(etCity, etPhone, etEmail)) {
              urc.editUser(username, etCity, etPhone, etEmail);
            }
          }
        });
    getInstrumentation().waitForIdleSync();

    assertTrue(urc.getUser(username).getCity().equals("Testopia"));
    assertTrue(urc.getUser(username).getPhone().equals("555-555-5556"));
  }
Ejemplo n.º 4
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_user_profile);

    // Get UI references
    TextView tvUsername = (TextView) findViewById(R.id.usernameTextView);
    etCity = (EditText) findViewById(R.id.cityTextView);
    etPhone = (EditText) findViewById(R.id.phoneTextView);
    etEmail = (EditText) findViewById(R.id.emailTextView);
    editButton = (Button) findViewById(R.id.editButton);
    saveButton = (Button) findViewById(R.id.saveProfileButton);

    // Retrieve data from other activities
    Intent intent = getIntent();
    username = intent.getStringExtra(EXTRA_USERNAME);
    friendUsername = intent.getStringExtra("FRIENDUSERNAME");
    profileState = (int) getIntent().getIntExtra(EXTRA_STATE, OWNER_STATE);

    // First check if showing friend's profile
    // If not, show current logged-in user's profile
    if (friendUsername != null) {
      Cache cache = new Cache(this, username);
      User cacheFriend = cache.getUser(friendUsername);

      // Set text fields
      tvUsername.setText(cacheFriend.getUsername());
      etCity.setText(cacheFriend.getCity());
      etPhone.setText(cacheFriend.getPhone());
      etEmail.setText(cacheFriend.getEmail());
    } else if (username != null) {
      User user = urc.getUser(username);

      // Set text fields
      tvUsername.setText(username);
      etCity.setText(user.getCity());
      etPhone.setText(user.getPhone());
      etEmail.setText(user.getEmail());
    }
    upc.setViewMode(profileState, etCity, etPhone, etEmail, editButton, saveButton);
  }