use of pinkpanthers.pinkshelters.Model.Shelter in project pink-panthers by MrTrai.
the class ListOfSheltersActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout);
// data to populate the RecyclerView with
ArrayList<String> shelterNames = new ArrayList<>();
DBI db = new Db("pinkpanther", "PinkPantherReturns!");
shelters = db.getAllShelters();
for (int i = 0; i < shelters.size(); i++) {
Shelter s = shelters.get(i);
shelterNames.add(s.getShelterName());
}
// set up the RecyclerView
RecyclerView recyclerView = findViewById(R.id.rvShelters);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
RecyclerAdapter adapter = new RecyclerAdapter(this, shelterNames);
adapter.setClickListener(this);
recyclerView.setAdapter(adapter);
// set up search button
Button search_button = findViewById(R.id.search_button);
search_button.setVisibility(View.VISIBLE);
search_button.setOnClickListener(this);
Button map_search = findViewById(R.id.button2);
map_search.setVisibility(View.VISIBLE);
Intent intent = getIntent();
Bundle extras = intent.getExtras();
assert extras != null;
username = extras.getString("username");
}
use of pinkpanthers.pinkshelters.Model.Shelter in project pink-panthers by MrTrai.
the class ListOfSheltersActivity method onItemClick.
@Override
public void onItemClick(View view, int position) {
// clicked on one shelter
Intent detail = new Intent(this, ShelterDetails.class);
Shelter s = shelters.get(position);
detail.putExtra("shelterId", s.getId());
detail.putExtra("username", username);
startActivity(detail);
}
use of pinkpanthers.pinkshelters.Model.Shelter 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.Shelter in project pink-panthers by MrTrai.
the class HomePageActivity method setShelterText.
/**
* to set text if a user has claimed any shelter
*/
private void setShelterText() {
TextView message = findViewById(R.id.shelterMessage);
if (user instanceof Homeless) {
try {
Shelter shelter = db.getShelterById(((Homeless) user).getShelterId());
String bed = (((Homeless) user).getFamilyMemberNumber() == 1) ? " bed" : " beds";
message.setText("You have claim " + ((Homeless) user).getFamilyMemberNumber() + bed + " at shelter: " + shelter.getShelterName());
} catch (NoSuchUserException e) {
message.setText("You have not claimed any bed yet");
}
}
}
use of pinkpanthers.pinkshelters.Model.Shelter in project pink-panthers by MrTrai.
the class SearchActivity method onItemClick.
@Override
public void onItemClick(View view, int position) {
Intent detail = new Intent(this, ShelterDetails.class);
Shelter s = myShelters.get(position);
detail.putExtra("shelterId", s.getId());
detail.putExtra("username", username);
startActivity(detail);
}
Aggregations