Search in sources :

Example 11 with NoSuchUserException

use of pinkpanthers.pinkshelters.Model.NoSuchUserException 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)

Aggregations

NoSuchUserException (pinkpanthers.pinkshelters.Model.NoSuchUserException)11 Intent (android.content.Intent)6 TextView (android.widget.TextView)6 Bundle (android.os.Bundle)5 View (android.view.View)5 Db (pinkpanthers.pinkshelters.Model.Db)5 Homeless (pinkpanthers.pinkshelters.Model.Homeless)5 ArrayAdapter (android.widget.ArrayAdapter)4 Button (android.widget.Button)4 SQLException (java.sql.SQLException)4 Editable (android.text.Editable)3 AdapterView (android.widget.AdapterView)3 Shelter (pinkpanthers.pinkshelters.Model.Shelter)3 Context (android.content.Context)2 SharedPreferences (android.content.SharedPreferences)2 TextWatcher (android.text.TextWatcher)2 Admin (pinkpanthers.pinkshelters.Model.Admin)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1