Skip to content

Commit

Permalink
Merge branch 'subletting' of https://github.com/pennlabs/penn-mobile-…
Browse files Browse the repository at this point in the history
…android into subletting

# Conflicts:
#	PennMobile/src/main/java/com/pennapps/labs/pennmobile/SublesseeDetailsFragment.kt
  • Loading branch information
trinif committed Sep 29, 2024
2 parents ba8b878 + b33b56e commit 1422d47
Show file tree
Hide file tree
Showing 12 changed files with 398 additions and 35 deletions.
3 changes: 3 additions & 0 deletions PennMobile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
android:name="preloaded_fonts"
android:resource="@array/preloaded_fonts"
/>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyDFOB7fgIQubKyOjjrmsgNoDt-xRvlBDrk"/>

<receiver
android:name=".LaundryBroadcastReceiver"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ import androidx.fragment.app.FragmentTransaction
import androidx.preference.PreferenceManager
import com.pennapps.labs.pennmobile.classes.SublesseeViewModel
import com.pennapps.labs.pennmobile.databinding.FragmentSublesseeDetailsBinding
import com.pennapps.labs.pennmobile.databinding.FragmentSubletteeMarketplaceBinding
import kotlinx.android.synthetic.main.fragment_sublessee_details.interested_sublet_button
import org.joda.time.format.DateTimeFormatter

class SublesseeDetailsFragment (var dataModel: SublesseeViewModel, var position: Int): Fragment() {
class SublesseeDetailsFragment (var dataModel: SublesseeViewModel, var position: Int): Fragment(){

private var _binding : FragmentSublesseeDetailsBinding? = null
private val binding get() = _binding!!
private lateinit var mActivity: MainActivity

private lateinit var saveButton: Button
private lateinit var mapButton: Button
private lateinit var interestedButton: Button

private lateinit var titleText: TextView
Expand All @@ -46,7 +44,7 @@ class SublesseeDetailsFragment (var dataModel: SublesseeViewModel, var position:
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
savedInstanceState: Bundle?): View {
//container?.removeAllViews()
// Inflate the layout for this fragment
_binding = FragmentSublesseeDetailsBinding.inflate(inflater, container, false)
Expand All @@ -55,7 +53,7 @@ class SublesseeDetailsFragment (var dataModel: SublesseeViewModel, var position:

@SuppressLint("MutatingSharedPrefs")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
var sublet = dataModel.getSublet(position)
val sublet = dataModel.getSublet(position)

titleText = binding.titleText
titleText.text = sublet.title
Expand Down Expand Up @@ -84,6 +82,7 @@ class SublesseeDetailsFragment (var dataModel: SublesseeViewModel, var position:
//AMENITIES

saveButton = binding.saveSubletButton
mapButton = binding.mapSubletButton
interestedButton = binding.interestedSubletButton

saveButton.setOnClickListener {
Expand Down Expand Up @@ -117,6 +116,14 @@ class SublesseeDetailsFragment (var dataModel: SublesseeViewModel, var position:
.commit()
}

mapButton.setOnClickListener{
mActivity.supportFragmentManager.beginTransaction()
.replace(((view as ViewGroup).parent as View).id, SublesseeDetailsMapFragment(sublet.address!!))
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.commit()
}

interestedButton.setOnClickListener {
mActivity.supportFragmentManager.beginTransaction()
.replace(((view as ViewGroup).parent as View).id, SublesseeInterestForm())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
package com.pennapps.labs.pennmobile

import android.location.Geocoder
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import com.google.android.gms.location.FusedLocationProviderClient
import com.google.android.gms.location.LocationServices
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions
import android.widget.AdapterView
import android.widget.ArrayAdapter
import com.google.android.gms.maps.model.BitmapDescriptorFactory
import com.pennapps.labs.pennmobile.databinding.FragmentSublesseeDetailsMapBinding
import java.util.Locale



class SublesseeDetailsMapFragment(var address: String): Fragment(), OnMapReadyCallback {

data class LocationInfo(val address: String, val name: String)

private var _binding : FragmentSublesseeDetailsMapBinding? = null
private val binding get() = _binding!!

private lateinit var myMap: GoogleMap
private lateinit var mActivity: MainActivity
private lateinit var fusedLocationProviderClient: FusedLocationProviderClient


override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mActivity = activity as MainActivity
mActivity.closeKeyboard()

//Google maps API client
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(mActivity)

//Retrieve map fragment
val mapFragment = childFragmentManager.findFragmentById(R.id.sublessee_map) as? SupportMapFragment
mapFragment?.getMapAsync(this)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View {
_binding = FragmentSublesseeDetailsMapBinding.inflate(inflater, container, false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val mapFragment = childFragmentManager.findFragmentById(R.id.sublessee_map) as? SupportMapFragment
val spinner = binding.sublesseeSpinner

val typesOfBuildings = listOf("Dining", "Libraries")

val adapter = ArrayAdapter(requireContext(), android.R.layout.simple_spinner_item, typesOfBuildings.map { it })
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)

spinner.adapter = adapter

spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
// Retrieve selected LocationInfo object
val selectedLocation = typesOfBuildings[position]

// Add marker and move camera to selected location
loadBuildingData(selectedLocation)
}

override fun onNothingSelected(parent: AdapterView<*>?) {
// Do nothing if nothing is selected
}
}

mapFragment?.getMapAsync(this)
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

override fun onMapReady(googleMap: GoogleMap) {
myMap = googleMap
//address string to lat/long
//place marker
//zoom camera to marker
// Convert address to LatLng
val addressCord = getCoordinates(address)
if (addressCord!=null) {
// Place marker on map
myMap.addMarker(MarkerOptions().position(addressCord).title("Sublet Location"))

// Zoom camera to marker
myMap.moveCamera(CameraUpdateFactory.newLatLngZoom(addressCord, 16.0f))
}
}

fun reset() {
myMap.clear()
val addressCord = getCoordinates(address)
if (addressCord!=null) {
// Place marker on map
myMap.addMarker(MarkerOptions().position(addressCord).title("Sublet Location"))
}
}

fun getCoordinates(address : String) : LatLng? {
val geocoder = Geocoder(requireContext(), Locale.getDefault())
val addressList = geocoder.getFromLocationName(address, 1)
if (!addressList.isNullOrEmpty()) {
val location = addressList[0]
return LatLng(location.latitude, location.longitude)
}
else {
val addressListPhilly = geocoder.getFromLocationName(address.plus(" Philadelphia, PA 19104"), 1)
if (!addressListPhilly.isNullOrEmpty()) {
val location = addressListPhilly[0]
return LatLng(location.latitude, location.longitude)
}
return null
}
}

fun loadBuildingData(locationCategory : String) {
reset()


val diningLocations = listOf(
LocationInfo("3800 Locust Walk", "1920 Commons"),
LocationInfo("3465 Sansom Street, English House", "English House"),
LocationInfo("215 S 39th Street, Falk at Penn Hillel", "Falk at Penn Hillel"),
LocationInfo("3333 Walnut Street, Hill House", "Hill House"),
LocationInfo("3335 Woodland Walk, Lauder College House", "Lauder College House"),
LocationInfo("201 S 40th St, Quaker Kitchen", "Quaker Kitchen"),
LocationInfo("220 South 33rd Street", "Accenture Café"),
LocationInfo("201 S 40th St", "Café West"),
LocationInfo("3800 Locust Walk", "Gourmet Grocer"),
LocationInfo("3417 Spruce Street","Houston Hall"),
LocationInfo("3620 Locust Walk", "Joe's Café"),
LocationInfo("3650 Spruce Street", "McClelland Sushi & Market"),
LocationInfo("3730 Walnut Street", "Pret a Manger"),
LocationInfo("3800 Locust Walk", "Starbucks")
)
val libraryLocations = listOf(
LocationInfo("3620 Walnut Street Philadelphia, PA 19104", "Annenberg School Library"),
LocationInfo("3443 Sansom Street Philadelphia, PA 19104", "Biddle Law Library"),
LocationInfo("231 South 34th Street Philadelphia, PA 19104", "Chemistry Library"),
LocationInfo("240 South 40th Street Philadelphia, PA 19104", "Dental Medicine Library"),
LocationInfo("233 South 33rd Street Philadelphia, PA 19104", "Education Commons"),
LocationInfo("220 South 34th Street Philadelphia, PA 19104", "Fisher Fine Arts Library"),
LocationInfo("3610 Hamilton Walk Philadelphia, PA 19104", "Holman Biotech Commons"),
LocationInfo("209 South 33rd Street Philadelphia, PA 19104","Math/Physics/Astronomy LibraryL"),
LocationInfo("3260 South Street Philadelphia, PA 19104", "Museum Library"),
LocationInfo("3420 Walnut Street Philadelphia, PA 19104","Van Pelt")
)

val locations = when (locationCategory){
"Dining" -> diningLocations
"Libraries" -> libraryLocations
else -> null
}

val icon = when (locationCategory){
"Dining" -> BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)
"Libraries" -> BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)
else -> null
}


if (locations != null) {
for (location in locations) {
val tempCoords = getCoordinates(location.address)
if(tempCoords!=null) {
myMap.addMarker(MarkerOptions().position(tempCoords).title(location.name).icon(icon))
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ class NewListingsFragment(private val dataModel: SublettingViewModel) : Fragment
internal lateinit var descriptionEt : EditText
internal lateinit var bathroomCheck : CheckBox
internal lateinit var laundryCheck : CheckBox
internal lateinit var gymCheck : CheckBox
internal lateinit var fitnessCheck : CheckBox
internal lateinit var wifiCheck : CheckBox
internal lateinit var furnishedCheck : CheckBox
internal lateinit var furnitureCheck : CheckBox
internal lateinit var closetCheck : CheckBox
internal lateinit var utilitiesCheck : CheckBox
internal lateinit var poolCheck : CheckBox
Expand All @@ -57,6 +57,13 @@ class NewListingsFragment(private val dataModel: SublettingViewModel) : Fragment
internal lateinit var kitchenCheck : CheckBox
internal lateinit var dogCheck : CheckBox
internal lateinit var catCheck : CheckBox
internal lateinit var kitchenAppliancesCheck : CheckBox
internal lateinit var maintenanceCheck : CheckBox
internal lateinit var securityCheck : CheckBox
internal lateinit var acCheck : CheckBox
internal lateinit var accessibilityCheck : CheckBox
internal lateinit var heatingCheck : CheckBox

internal lateinit var imageView: ImageView
internal lateinit var imageIcon: ImageView
internal lateinit var imageText: TextView
Expand Down Expand Up @@ -115,9 +122,9 @@ class NewListingsFragment(private val dataModel: SublettingViewModel) : Fragment
descriptionEt = binding.descriptionInput
bathroomCheck = binding.bathroomCheck
laundryCheck = binding.laundryCheck
gymCheck = binding.gymCheck
fitnessCheck = binding.fitnessCheck
wifiCheck = binding.wifiCheck
furnishedCheck = binding.furnishedCheck
furnitureCheck = binding.furnitureCheck
closetCheck = binding.closetCheck
utilitiesCheck = binding.utilitiesCheck
poolCheck = binding.poolCheck
Expand All @@ -127,6 +134,12 @@ class NewListingsFragment(private val dataModel: SublettingViewModel) : Fragment
kitchenCheck = binding.kitchenCheck
dogCheck = binding.dogCheck
catCheck = binding.catCheck
kitchenAppliancesCheck = binding.kitchenAppliancesCheck
maintenanceCheck = binding.maintenanceCheck
securityCheck = binding.securityCheck
acCheck = binding.acCheck
accessibilityCheck = binding.accessibilityCheck
heatingCheck = binding.heatingCheck
imageView = binding.mainImage
imageIcon = binding.mainImageIcon
imageText = binding.addPhotosText
Expand Down Expand Up @@ -193,9 +206,9 @@ class NewListingsFragment(private val dataModel: SublettingViewModel) : Fragment
val amenitiesList = mutableListOf<String>()
if(bathroomCheck.isChecked) { amenitiesList.add("Private Bathroom") }
if(laundryCheck.isChecked) { amenitiesList.add("In-Unit Laundry") }
if(gymCheck.isChecked) { amenitiesList.add("Gym") }
if(fitnessCheck.isChecked) { amenitiesList.add("Fitness Facilities") }
if(wifiCheck.isChecked) { amenitiesList.add("Wifi") }
if(furnishedCheck.isChecked) { amenitiesList.add("Furnished") }
if(furnitureCheck.isChecked) { amenitiesList.add("Furniture") }
if(closetCheck.isChecked) { amenitiesList.add("Walk-in Closet") }
if(utilitiesCheck.isChecked) { amenitiesList.add("Utilities Included") }
if(poolCheck.isChecked) { amenitiesList.add("Swimming Pool") }
Expand All @@ -205,6 +218,14 @@ class NewListingsFragment(private val dataModel: SublettingViewModel) : Fragment
if(kitchenCheck.isChecked) { amenitiesList.add("Kitchen") }
if(dogCheck.isChecked) { amenitiesList.add("Dog-Friendly") }
if(catCheck.isChecked) { amenitiesList.add("Cat-Friendly") }
if(kitchenAppliancesCheck.isChecked) { amenitiesList.add("Kitchen Appliances") }
if(maintenanceCheck.isChecked) { amenitiesList.add("Maintenance Services") }
if(securityCheck.isChecked) { amenitiesList.add("Security Features") }
if(acCheck.isChecked) { amenitiesList.add("Air Conditioning") }
if(accessibilityCheck.isChecked) { amenitiesList.add("Accessibility Features") }
if(heatingCheck.isChecked) { amenitiesList.add("Heating") }



description = descriptionEt.text.toString()
if (description.equals("")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ class SubletDetailsFragment(private val dataModel: SublettingViewModel, private
dataModel.deleteSublet(mActivity, subletNumber)
}

binding.editText.setOnClickListener(){
binding.editText.setOnClickListener{
navigateEditListing()
}

binding.deleteText.setOnClickListener{
dataModel.deleteSublet(mActivity, subletNumber)

}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import com.pennapps.labs.pennmobile.Subletting.SubletDetailsHolderFragment
import com.pennapps.labs.pennmobile.classes.Sublet
import com.pennapps.labs.pennmobile.classes.SublettingModel
import com.pennapps.labs.pennmobile.classes.SublettingViewModel
import kotlinx.android.synthetic.main.include_main.expandable_bottom_bar
import kotlinx.android.synthetic.main.include_main.toolbar

class PostedSubletsListAdapter(private val dataModel: SublettingViewModel):
RecyclerView.Adapter<PostedSubletsListAdapter.SublettingCardViewHolder>() {
Expand Down Expand Up @@ -62,6 +64,7 @@ class PostedSubletsListAdapter(private val dataModel: SublettingViewModel):
holder.listingRooms.text = rooms

holder.itemView.setOnClickListener {
mActivity.hideBottomBar()
mActivity.supportFragmentManager.beginTransaction()
.replace(R.id.content_frame, SubletDetailsHolderFragment(dataModel, position))
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class SublettingListAdapter(var sublettingList: ArrayList<SublettingModel>, var
}

holder.itemView.setOnClickListener {
mActivity.hideBottomBar()
mActivity.supportFragmentManager.beginTransaction()
.replace(R.id.content_frame, SublesseeDetailsFragment(dataModel, position))
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
Expand Down
Loading

0 comments on commit 1422d47

Please sign in to comment.