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