Search in sources :

Example 1 with Admin

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();
        });
    }
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) MarkerOptions(com.google.android.gms.maps.model.MarkerOptions) DialogInterface(android.content.DialogInterface) Marker(com.google.android.gms.maps.model.Marker) Admin(pinkpanthers.pinkshelters.Model.Admin) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) LayoutInflater(android.view.LayoutInflater) Editable(android.text.Editable) Shelter(pinkpanthers.pinkshelters.Model.Shelter) LinearLayout(android.widget.LinearLayout)

Example 2 with Admin

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

Example 3 with Admin

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();
    }
}
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 4 with Admin

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

Admin (pinkpanthers.pinkshelters.Model.Admin)4 Context (android.content.Context)2 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 Editable (android.text.Editable)2 TextView (android.widget.TextView)2 Homeless (pinkpanthers.pinkshelters.Model.Homeless)2 NoSuchUserException (pinkpanthers.pinkshelters.Model.NoSuchUserException)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Bundle (android.os.Bundle)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 EditText (android.widget.EditText)1 LinearLayout (android.widget.LinearLayout)1 Marker (com.google.android.gms.maps.model.Marker)1 MarkerOptions (com.google.android.gms.maps.model.MarkerOptions)1 Test (org.junit.Test)1