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);
}
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());
}
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);
}
}
}
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();
}
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);
}
Aggregations