Skip to content

Commit

Permalink
New Map Subletting stuff for sublessee tab
Browse files Browse the repository at this point in the history
  • Loading branch information
joemacd committed Aug 30, 2024
1 parent 2df9fbb commit 7ada6b7
Show file tree
Hide file tree
Showing 5 changed files with 255 additions and 7 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 @@ -3,28 +3,26 @@ package com.pennapps.labs.pennmobile
import android.annotation.SuppressLint
import android.content.SharedPreferences
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.TextView
import android.widget.Toast
import androidx.fragment.app.Fragment
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 @@ -45,7 +43,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 @@ -54,7 +52,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 @@ -83,6 +81,7 @@ class SublesseeDetailsFragment (var dataModel: SublesseeViewModel, var position:
//AMENITIES

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

saveButton.setOnClickListener {
Expand All @@ -107,6 +106,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))
}
}
}
}
}
14 changes: 14 additions & 0 deletions PennMobile/src/main/res/layout/fragment_sublessee_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,20 @@
android:textAllCaps="false"
android:textColor="@color/white"
app:layout_constraintStart_toEndOf="@id/save_sublet_button"
app:layout_constraintEnd_toEndOf="@+id/map_sublet_button"
app:layout_constraintTop_toBottomOf="@+id/description_text" />

<Button
android:id="@+id/map_sublet_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_marginTop="6dp"
android:backgroundTint="#639AFF"
android:text="View in Map"
android:textAllCaps="false"
android:textColor="@color/white"
app:layout_constraintStart_toEndOf="@+id/interested_sublet_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/description_text" />

Expand Down
37 changes: 37 additions & 0 deletions PennMobile/src/main/res/layout/fragment_sublessee_details_map.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">>

<fragment
android:id="@+id/sublessee_map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="409dp"
android:layout_height="750dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />


<TextView
android:id="@+id/sublessee_map_proximity_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@+id/sublessee_spinner"
android:text="Proximity To:" />

<Spinner
android:id="@+id/sublessee_spinner"
android:layout_width="200dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toTopOf="@id/sublessee_map"
app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 7ada6b7

Please sign in to comment.