Search in sources :

Example 6 with Homeless

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();
    }
}
Also used : Context(android.content.Context) Homeless(pinkpanthers.pinkshelters.Model.Homeless) SharedPreferences(android.content.SharedPreferences) Volunteer(pinkpanthers.pinkshelters.Model.Volunteer) NoSuchUserException(pinkpanthers.pinkshelters.Model.NoSuchUserException) Editable(android.text.Editable) Intent(android.content.Intent) Admin(pinkpanthers.pinkshelters.Model.Admin)

Example 7 with Homeless

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);
    }
}
Also used : Context(android.content.Context) Homeless(pinkpanthers.pinkshelters.Model.Homeless) SharedPreferences(android.content.SharedPreferences) Button(android.widget.Button) Bundle(android.os.Bundle) NoSuchUserException(pinkpanthers.pinkshelters.Model.NoSuchUserException) TextView(android.widget.TextView) Intent(android.content.Intent) Admin(pinkpanthers.pinkshelters.Model.Admin) Db(pinkpanthers.pinkshelters.Model.Db)

Example 8 with Homeless

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);
}
Also used : Account(pinkpanthers.pinkshelters.Model.Account) Bundle(android.os.Bundle) ArrayList(java.util.ArrayList) DBI(pinkpanthers.pinkshelters.Model.DBI) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Homeless(pinkpanthers.pinkshelters.Model.Homeless) RecyclerView(android.support.v7.widget.RecyclerView) Db(pinkpanthers.pinkshelters.Model.Db) Toolbar(android.support.v7.widget.Toolbar)

Example 9 with Homeless

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());
}
Also used : Homeless(pinkpanthers.pinkshelters.Model.Homeless) Volunteer(pinkpanthers.pinkshelters.Model.Volunteer) Test(org.junit.Test)

Aggregations

Homeless (pinkpanthers.pinkshelters.Model.Homeless)9 NoSuchUserException (pinkpanthers.pinkshelters.Model.NoSuchUserException)5 Intent (android.content.Intent)4 Bundle (android.os.Bundle)3 TextView (android.widget.TextView)3 Test (org.junit.Test)3 Account (pinkpanthers.pinkshelters.Model.Account)3 Db (pinkpanthers.pinkshelters.Model.Db)3 Context (android.content.Context)2 SharedPreferences (android.content.SharedPreferences)2 ArrayAdapter (android.widget.ArrayAdapter)2 Button (android.widget.Button)2 Admin (pinkpanthers.pinkshelters.Model.Admin)2 Volunteer (pinkpanthers.pinkshelters.Model.Volunteer)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 Editable (android.text.Editable)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1