use of pinkpanthers.pinkshelters.Model.Homeless in project pink-panthers by MrTrai.
the class LoginActivity method logIn.
/**
* Check for user name, password and log the user in.
* Success: Direct User to Home Page
* Fail: Display Error
*
* @param view current view of the app
*/
public void logIn(@SuppressWarnings("unused") View view) {
txtView = findViewById(R.id.validationWarn);
try {
Editable userText = username.getText();
String user = userText.toString();
user = user.toLowerCase();
Editable passText = password.getText();
String pass = passText.toString();
account = db.getAccountByUsername(user);
txtView.setText("");
String blocked = "blocked";
String correctPass = account.getPassword();
String accountState = account.getAccountState();
if (correctPass.equals(pass) && !accountState.equals(blocked) && !accountState.equals("not_verified")) {
// correct password
Context context = getApplicationContext();
SharedPreferences preferences = context.getSharedPreferences("com.example.sp.LoginPrefs", MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
if (account instanceof Homeless) {
editor.putString("USER_TYPE", "Homeless");
} else if (account instanceof Admin) {
editor.putString("USER_TYPE", "Admin");
} else if (account instanceof Volunteer) {
editor.putString("USER_TYPE", "Volunteer");
}
editor.putString("UserID", ((Integer) account.getUserId()).toString());
editor.putString("NAME", account.getName());
// get name to use for shelter details
editor.putString("USERNAME", account.getUsername());
editor.apply();
// active account is set to this static variable when
// logged in for quick access to current user
// Db.activeAccount = account;
db.logAction(account, "Logged in");
Intent homePageIntent = new Intent(this, HomePageActivity.class);
homePageIntent.putExtra("username", user);
startActivity(homePageIntent);
} else {
// incorrect password
loginTrial++;
checkLoginTrial();
}
} catch (NoSuchUserException e) {
// User doesn't exist
loginTrial++;
checkLoginTrial();
}
}
use of pinkpanthers.pinkshelters.Model.Homeless in project pink-panthers by MrTrai.
the class HomePageActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
// Grab name and user type to show in homepage
Context context = getApplicationContext();
SharedPreferences preferences = context.getSharedPreferences(PREFS_NAME, Registration.MODE_PRIVATE);
TextView textUserType = findViewById(R.id.textView3);
TextView textName = findViewById(R.id.textView1);
TextView textWelcome = findViewById(R.id.textView2);
// Get name and user type
String prefName = preferences.getString("NAME", "");
String prefUserType = preferences.getString("USER_TYPE", "");
textName.setText("Hello " + prefName + "!");
textWelcome.setText("Welcome to Pink Shelter");
textUserType.setText(prefUserType);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
assert extras != null;
username = extras.getString("username");
db = new Db("pinkpanther", "PinkPantherReturns!");
try {
user = db.getAccountByUsername(username);
} catch (NoSuchUserException e) {
throw new RuntimeException("cannot find the account");
}
if (user instanceof Homeless) {
setShelterText();
} else {
Button infoButton = findViewById(R.id.myInfo_btn);
infoButton.setVisibility(View.INVISIBLE);
}
if (user instanceof Admin) {
Button viewAccountButton = findViewById(R.id.accountList_btn);
viewAccountButton.setVisibility(View.VISIBLE);
} else {
Button viewAccountButton = findViewById(R.id.accountList_btn);
viewAccountButton.setVisibility(View.INVISIBLE);
}
}
use of pinkpanthers.pinkshelters.Model.Homeless in project pink-panthers by MrTrai.
the class AllHomelessActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
Toolbar title = findViewById(R.id.titleBar);
title.setTitle("Current Residents");
// data to populate the RecyclerView with
ArrayList<String> accountNames = new ArrayList<>();
DBI db = new Db("pinkpanther", "PinkPantherReturns!");
accounts = db.getAllAccounts();
Intent intent = getIntent();
Bundle extras = intent.getExtras();
assert extras != null;
int shelterId = extras.getInt("shelterId");
for (Account account : accounts) {
if (account instanceof Homeless) {
if (((Homeless) account).getShelterId() == shelterId) {
accountNames.add(account.getName());
}
}
}
// set up the RecyclerView
RecyclerView recyclerView = findViewById(R.id.rvShelters);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
RecyclerAdapter adapter = new RecyclerAdapter(this, accountNames);
adapter.setClickListener(this);
recyclerView.setAdapter(adapter);
}
use of pinkpanthers.pinkshelters.Model.Homeless in project pink-panthers by MrTrai.
the class DbUnitTest method testNotHomelessUpdateAccount.
@Test
public void testNotHomelessUpdateAccount() throws SQLException, NoSuchUserException {
account = new Volunteer("test123", "test123", "test", "blocked", "test123@", 54);
db.updateAccount(account);
// correct username ad userId 54
account = db.getAccountByUsername("testcase5");
assertFalse("Account is not instance of Volunteer: ", account instanceof Volunteer);
assertTrue(account instanceof Homeless);
assertEquals(0, ((Homeless) account).getFamilyMemberNumber());
assertEquals(0, ((Homeless) account).getShelterId());
String[] expectedRestriction = { "" };
List<String> restrictionsMatch = ((Homeless) account).getRestrictionsMatch();
assertArrayEquals(expectedRestriction, restrictionsMatch.toArray());
}
Aggregations