Search in sources :

Example 1 with Account

use of pinkpanthers.pinkshelters.Model.Account in project pink-panthers by MrTrai.

the class AccountListActivity method onItemClick.

@Override
public void onItemClick(View view, int position) {
    Intent detailAccount = new Intent(this, AccountDetailsActivity.class);
    Account acc = allAccountList.get(position);
    detailAccount.putExtra("accUserName", acc.getUsername());
    Log.d("this is the account", acc.getUsername().toString());
    startActivity(detailAccount);
}
Also used : Account(pinkpanthers.pinkshelters.Model.Account) Intent(android.content.Intent)

Example 2 with Account

use of pinkpanthers.pinkshelters.Model.Account in project pink-panthers by MrTrai.

the class DbUnitTest method testValidIdUpdateAccount.

@Test
public void testValidIdUpdateAccount() throws SQLException, NoSuchUserException {
    account = db.getAccountByUsername("asdfasdf");
    ((Homeless) account).setFamilyMemberNumber(20);
    ((Homeless) account).setRestrictionsMatch(Arrays.asList("test_gender", "test_age"));
    ((Homeless) account).setShelterId(-1);
    db.updateAccount(account);
    Account updatedAccount = db.getAccountByUsername("asdfasdf");
    assertEquals(20, ((Homeless) updatedAccount).getFamilyMemberNumber());
    String[] expectedRestrictions = { "test_gender", "test_age" };
    List<String> restrictionsMatch = ((Homeless) updatedAccount).getRestrictionsMatch();
    assertArrayEquals(expectedRestrictions, restrictionsMatch.toArray());
    assertEquals(-1, ((Homeless) updatedAccount).getShelterId());
}
Also used : Account(pinkpanthers.pinkshelters.Model.Account) Homeless(pinkpanthers.pinkshelters.Model.Homeless) Test(org.junit.Test)

Example 3 with Account

use of pinkpanthers.pinkshelters.Model.Account in project pink-panthers by MrTrai.

the class Registration method registerButton.

/**
 * Register user with:
 * Name
 * Password
 * Email
 * User Types
 *
 * @param view the current view that the register button is on
 */
public void registerButton(@SuppressWarnings("unused") View view) {
    Boolean noName;
    Boolean noUsername;
    Boolean noPass;
    Boolean noEmail;
    Boolean noType;
    String empty = "";
    Editable nameText = name.getText();
    String isValidName = nameText.toString();
    TextView missingName = findViewById(R.id.missingName);
    if (isValidName.equals(empty)) {
        // missing name
        missingName.setVisibility(View.VISIBLE);
        noName = false;
    } else {
        missingName.setVisibility(View.INVISIBLE);
        noName = true;
    }
    Editable emailText = email.getText();
    String isValidEmail = emailText.toString();
    isValidEmail = isValidEmail.toLowerCase();
    TextView missingEmail = findViewById(R.id.missingEmail);
    if (isValidEmail.equals(empty) || !isValidEmail.contains("@")) {
        // missing email or "@" sign
        missingEmail.setVisibility(View.VISIBLE);
        noEmail = false;
    } else {
        missingEmail.setVisibility(View.INVISIBLE);
        noEmail = true;
    }
    Editable usernameText = username.getText();
    String isValidUsername = usernameText.toString();
    isValidUsername = isValidUsername.toLowerCase();
    TextView missingUsername = findViewById(R.id.missingUsername);
    if (isValidUsername.length() < 6) {
        // username cannot be less than 6 characters
        missingUsername.setVisibility(View.VISIBLE);
        noUsername = false;
    } else {
        missingUsername.setVisibility(View.INVISIBLE);
        noUsername = true;
    }
    Editable passwordText = password.getText();
    String isValidPassword = passwordText.toString();
    TextView missingPassword = findViewById(R.id.missingPassword);
    if (isValidPassword.length() < 6) {
        // password cannot be less than 6 characters
        missingPassword.setVisibility(View.VISIBLE);
        noPass = false;
    } else {
        missingPassword.setVisibility(View.INVISIBLE);
        noPass = true;
    }
    String isValidType = (String) userTypes.getSelectedItem();
    TextView missingUserType = findViewById(R.id.missingUserType);
    if (isValidType.equals(empty)) {
        // missing user type
        missingUserType.setVisibility(View.VISIBLE);
        noType = false;
    } else {
        missingUserType.setVisibility(View.INVISIBLE);
        noType = true;
    }
    Boolean missingAnything = noName && noEmail && noPass && noUsername && noType;
    if (missingAnything) {
        try {
            Account newAccount = db.createAccount(isValidType, isValidUsername, isValidPassword, isValidName, isValidEmail);
            sendEmail(isValidEmail);
            db.logAction(newAccount, "account_created");
            Intent loginPageIntent = new Intent(this, LoginActivity.class);
            startActivity(loginPageIntent);
        } catch (UniqueKeyError e) {
            TextView duplicate = findViewById(R.id.duplicate);
            duplicate.setVisibility(View.VISIBLE);
        }
    }
}
Also used : UniqueKeyError(pinkpanthers.pinkshelters.Model.UniqueKeyError) Account(pinkpanthers.pinkshelters.Model.Account) Editable(android.text.Editable) TextView(android.widget.TextView) Intent(android.content.Intent)

Example 4 with Account

use of pinkpanthers.pinkshelters.Model.Account in project pink-panthers by MrTrai.

the class ShelterDetails method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_shelter_details);
    db = new Db("pinkpanther", "PinkPantherReturns!");
    errorMessage = findViewById(R.id.errorMessage);
    vacancy = findViewById(R.id.vacancy);
    Button claimBedButton = findViewById(R.id.claimBed);
    updateInfoButton = findViewById(R.id.updateAccountButton);
    Button cancelBedButton = findViewById(R.id.cancelReservation);
    checkIn = findViewById(R.id.check_in_btn);
    viewResident = findViewById(R.id.view_all_homeless);
    peopleNumber = findViewById(R.id.people_number);
    List<Integer> number = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    ArrayAdapter<Integer> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, number);
    peopleNumber.setAdapter(adapter);
    try {
        Intent intent = getIntent();
        Bundle extra = intent.getExtras();
        assert extra != null;
        int shelterId = extra.getInt("shelterId");
        s = db.getShelterById(shelterId);
        updateView(s);
    } catch (NoSuchUserException e) {
        throw new RuntimeException("This is not how it works " + e.toString());
    } catch (NullPointerException e) {
        throw new RuntimeException("NullPointerException is raised: " + "getExtras() returns null in ListOfShelter");
    }
    try {
        Intent intent = getIntent();
        Bundle extra = intent.getExtras();
        assert extra != null;
        username = extra.getString("username");
        Account user = db.getAccountByUsername(username);
        if (user instanceof Homeless) {
            // user is a homeless person
            a = (Homeless) user;
            claimBedButton.setVisibility(View.VISIBLE);
            try {
                reservedShelter = db.getShelterById(a.getShelterId());
                if (reservedShelter.getId() == s.getId()) {
                    cancelBedButton.setVisibility(View.VISIBLE);
                    message = "You have claimed " + a.getFamilyMemberNumber() + " bed(s) at this shelter";
                    errorMessage.setText(message);
                    errorMessage.setTextColor(Color.GREEN);
                    errorMessage.setVisibility(View.VISIBLE);
                }
            } catch (NoSuchUserException e) {
            // this shelter is not the one that the user reserved to
            // so nothing happens (cancel reservation button remains invisible)
            }
        } else {
            // user is not a homeless person
            claimBedButton.setVisibility(View.INVISIBLE);
            checkIn.setVisibility(View.VISIBLE);
            peopleNumber.setVisibility(View.VISIBLE);
            viewResident.setVisibility(View.VISIBLE);
        }
    } catch (NoSuchUserException e) {
        throw new RuntimeException("There is no user with that " + "username or shelter with that ID");
    } catch (NullPointerException e) {
        throw new RuntimeException("getExtras() returns null username");
    }
    addListenerOnRatingBar();
    addListenerOnButton();
    checkInButton();
}
Also used : Account(pinkpanthers.pinkshelters.Model.Account) Bundle(android.os.Bundle) NoSuchUserException(pinkpanthers.pinkshelters.Model.NoSuchUserException) Intent(android.content.Intent) Homeless(pinkpanthers.pinkshelters.Model.Homeless) Button(android.widget.Button) Db(pinkpanthers.pinkshelters.Model.Db) ArrayAdapter(android.widget.ArrayAdapter)

Example 5 with Account

use of pinkpanthers.pinkshelters.Model.Account in project pink-panthers by MrTrai.

the class AccountListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout);
    Toolbar title = findViewById(R.id.titleBar);
    title.setTitle("Account List");
    // data to populate the RecyclerView with
    ArrayList<String> allAccountName = new ArrayList<>();
    DBI db = new Db("pinkpanther", "PinkPantherReturns!");
    allAccountList = db.getAllAccounts();
    for (int i = 0; i < allAccountList.size(); i++) {
        Account a = allAccountList.get(i);
        allAccountName.add(a.getUsername());
    // allAccountName.add(a.getAccountState());
    }
    // set up the RecyclerView
    RecyclerView recyclerView = findViewById(R.id.rvShelters);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    RecyclerAdapter adapter = new RecyclerAdapter(this, allAccountName);
    adapter.setClickListener(this);
    recyclerView.setAdapter(adapter);
}
Also used : Account(pinkpanthers.pinkshelters.Model.Account) ArrayList(java.util.ArrayList) DBI(pinkpanthers.pinkshelters.Model.DBI) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Db(pinkpanthers.pinkshelters.Model.Db) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Account (pinkpanthers.pinkshelters.Model.Account)6 Intent (android.content.Intent)4 Db (pinkpanthers.pinkshelters.Model.Db)3 Homeless (pinkpanthers.pinkshelters.Model.Homeless)3 Bundle (android.os.Bundle)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 Toolbar (android.support.v7.widget.Toolbar)2 ArrayList (java.util.ArrayList)2 DBI (pinkpanthers.pinkshelters.Model.DBI)2 Editable (android.text.Editable)1 ArrayAdapter (android.widget.ArrayAdapter)1 Button (android.widget.Button)1 TextView (android.widget.TextView)1 Test (org.junit.Test)1 NoSuchUserException (pinkpanthers.pinkshelters.Model.NoSuchUserException)1 UniqueKeyError (pinkpanthers.pinkshelters.Model.UniqueKeyError)1