use of pinkpanthers.pinkshelters.Model.Homeless in project pink-panthers by MrTrai.
the class HomePageActivity method setShelterText.
/**
* to set text if a user has claimed any shelter
*/
private void setShelterText() {
TextView message = findViewById(R.id.shelterMessage);
if (user instanceof Homeless) {
try {
Shelter shelter = db.getShelterById(((Homeless) user).getShelterId());
String bed = (((Homeless) user).getFamilyMemberNumber() == 1) ? " bed" : " beds";
message.setText("You have claim " + ((Homeless) user).getFamilyMemberNumber() + bed + " at shelter: " + shelter.getShelterName());
} catch (NoSuchUserException e) {
message.setText("You have not claimed any bed yet");
}
}
}
use of pinkpanthers.pinkshelters.Model.Homeless in project pink-panthers by MrTrai.
the class UserInfoActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_info_page);
// set up check box restrictions
buttonStatus = findViewById(R.id.status);
buttonStatus.setVisibility(View.INVISIBLE);
List<String> currentRestrictionList;
checkBoxList = new ArrayList<>();
checkBoxList.add((CheckBox) findViewById(R.id.checkBox1));
checkBoxList.add((CheckBox) findViewById(R.id.checkBox2));
checkBoxList.add((CheckBox) findViewById(R.id.checkBox3));
checkBoxList.add((CheckBox) findViewById(R.id.checkBox4));
checkBoxList.add((CheckBox) findViewById(R.id.checkBox5));
checkBoxList.add((CheckBox) findViewById(R.id.checkBox6));
checkBoxList.add((CheckBox) findViewById(R.id.checkBox7));
checkBoxList.add((CheckBox) findViewById(R.id.checkBox8));
checkBoxList.add((CheckBox) findViewById(R.id.checkBox9));
enums = Arrays.asList(Restrictions.values());
try {
getUserAccount();
} catch (NoSuchUserException e) {
e.printStackTrace();
}
if (account instanceof Homeless) {
homeless = (Homeless) account;
currentRestrictionList = ((Homeless) account).getRestrictionsMatch();
if (currentRestrictionList != null) {
for (int i = 0; i < currentRestrictionList.size(); i++) {
for (int j = 0; j < checkBoxList.size(); j++) {
CheckBox item = checkBoxList.get(j);
if (!item.isChecked()) {
Restrictions restrictions = enums.get(j);
boolean isCheck = checkCheckbox(currentRestrictionList.get(i), restrictions.toString());
item.setChecked(isCheck);
}
}
}
}
}
// add choices to family size
for (int i = 1; i < 16; i++) {
familySizeList.add(i);
}
family_spinner = findViewById(R.id.family_spinner);
ArrayAdapter<Integer> family_adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, familySizeList);
family_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
family_spinner.setAdapter(family_adapter);
family_spinner.setSelection(homeless.getFamilyMemberNumber() - 1);
// Spinner click listener for family size
family_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Object item = family_spinner.getSelectedItem();
familySize = Integer.valueOf(item.toString());
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
// nothing happens when nothing is selected
}
});
// Grab name and user type to show in homepage
TextView name = findViewById(R.id.accountUserName);
TextView email = findViewById(R.id.email);
// Display name and email
name.setText("Name: " + account.getName());
email.setText("Email: " + account.getEmail());
}
use of pinkpanthers.pinkshelters.Model.Homeless 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.Homeless in project pink-panthers by MrTrai.
the class DbUnitTest method testPosInvalidHomelessUpdateAccount.
@Test(expected = NullPointerException.class)
public void testPosInvalidHomelessUpdateAccount() throws SQLException, NoSuchUserException {
account = new Homeless("test123", "test123", "test", "blocked", "test123@", 1000);
// not setting shelterId, familyMemberNumber and restrictionMatch
// NullPointerException returns in the method where restrictionMatch is null by defaults
db.updateAccount(account);
}
use of pinkpanthers.pinkshelters.Model.Homeless 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();
}
Aggregations