use of pinkpanthers.pinkshelters.Model.Admin in project pink-panthers by MrTrai.
the class MapsActivity method onMapReady.
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// makes a new shelter when user clicks once on the map
if (user instanceof Admin) {
mMap.setOnMapLongClickListener(latLng -> {
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
// create dialog box
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Add a shelter");
// get view from xml and inflate into map activity
LinearLayout mapLayout = findViewById(R.id.linearLayout2);
LayoutInflater layoutInflater = getLayoutInflater();
View addShelter = layoutInflater.inflate(R.layout.add_new_shelter, mapLayout, false);
// get user inputs from dialog box
EditText shelterNameText = addShelter.findViewById(R.id.accountUserName);
EditText longitudeText = addShelter.findViewById(R.id.longitude);
EditText latitudeText = addShelter.findViewById(R.id.latitude);
EditText addressText = addShelter.findViewById(R.id.address);
EditText phoneNumText = addShelter.findViewById(R.id.phoneNum);
EditText restrictionsText = addShelter.findViewById(R.id.restrictions);
EditText specialNoteText = addShelter.findViewById(R.id.specialNote);
EditText capacityText = addShelter.findViewById(R.id.capacity);
// set the longitude and latitude texts to the tapped position on map
String tappedLongitude = "" + latLng.longitude;
longitudeText.setText(tappedLongitude);
String tappedLatitude = "" + latLng.latitude;
latitudeText.setText(tappedLatitude);
builder.setView(addShelter);
// calculating the address from longitude and latitude
setAddress(latLng, addressText);
// click on "Add a shelter" button
builder.setPositiveButton("add a shelter", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
Editable textName = shelterNameText.getText();
shelterName = textName.toString();
Editable textLongitude = longitudeText.getText();
String numLongitude = textLongitude.toString();
longitude = Double.parseDouble(numLongitude);
Editable textLatitude = latitudeText.getText();
String numLatitude = textLatitude.toString();
latitude = Double.parseDouble(numLatitude);
Editable textAddress = addressText.getText();
address = textAddress.toString();
Editable textPhone = phoneNumText.getText();
phoneNum = textPhone.toString();
Editable textRestrict = restrictionsText.getText();
restrictions = textRestrict.toString();
Editable textSpecial = specialNoteText.getText();
specialNote = textSpecial.toString();
Editable textCapacity = capacityText.getText();
capacity = textCapacity.toString();
Shelter newShelter = db.createShelter(shelterName, capacity, specialNote, latitude, longitude, phoneNum, restrictions, address);
newShelter.setUpdate_capacity(capacityConverter());
// details that pops up when user clicks onto the marker
markerOptions.title(newShelter.getShelterName());
markerOptions.snippet(newShelter.getAddress() + "\n Phone Number: + " + newShelter.getPhoneNumber() + "\n Restrictions: " + newShelter.getRestrictions() + "\n Vacancy: " + newShelter.getVacancy());
// add marker to map and move camera to center its screen around it
mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
Marker marker = mMap.addMarker(markerOptions);
marker.showInfoWindow();
}
});
// click on "cancel" button
builder.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
markerOptions.visible(false);
}
});
// show the builder (the dialog window)
builder.show();
});
}
}
use of pinkpanthers.pinkshelters.Model.Admin in project pink-panthers by MrTrai.
the class DbUnitTest method testZeroIdUpdateAccount.
// account with invalid id (zero)
@Test(expected = NoSuchUserException.class)
public void testZeroIdUpdateAccount() throws SQLException, NoSuchUserException {
account = new Admin("test123", "test123", "test", "blocked", "test123@", 0);
db.updateAccount(account);
}
use of pinkpanthers.pinkshelters.Model.Admin 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.Admin 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