diff --git a/app/src/main/java/com/example/nerbos/MapsActivity.kt b/app/src/main/java/com/example/nerbos/MapsActivity.kt index fff63b10ae1adfe69c51cede788ea6975239a7d9..00fbc24be2caa3d52bf28c22878e5414944349d8 100644 --- a/app/src/main/java/com/example/nerbos/MapsActivity.kt +++ b/app/src/main/java/com/example/nerbos/MapsActivity.kt @@ -1,12 +1,16 @@ package com.example.nerbos import android.Manifest +import android.content.Intent import android.content.pm.PackageManager import android.graphics.Camera +import android.location.Address +import android.location.Geocoder import android.location.Location import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log +import android.widget.TextView import android.widget.Toast import androidx.core.app.ActivityCompat @@ -20,13 +24,13 @@ import com.example.nerbos.databinding.ActivityMapsBinding import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationServices import com.google.android.gms.maps.model.Marker +import java.util.Locale class MapsActivity : AppCompatActivity(), OnMapReadyCallback { private lateinit var mMap: GoogleMap private lateinit var binding: ActivityMapsBinding - - private val permissionCode = 1 + private lateinit var location: Address override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -37,14 +41,31 @@ class MapsActivity : AppCompatActivity(), OnMapReadyCallback { val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as SupportMapFragment mapFragment.getMapAsync(this) + + val myIntent = intent + val locationName : String? = myIntent.getStringExtra("locationName") + val geocoder = Geocoder(this, Locale.getDefault()) + val address = geocoder.getFromLocationName(locationName!!, 1) + if (address != null) { + location = address[0] + } + + // Navigation + findViewById<TextView>(R.id.title).setOnClickListener { + val mainIntent: Intent = Intent(this, MainActivity::class.java) + startActivity(mainIntent) + finish() + } + } override fun onMapReady(googleMap: GoogleMap) { mMap = googleMap mMap.uiSettings.isZoomControlsEnabled = true - val currentLatLong : LatLng = LatLng(10.0,10.0) + val currentLatLong : LatLng = LatLng(location.latitude,location.longitude) val markerOptions = MarkerOptions().position(currentLatLong).title("Current Location") mMap.addMarker(markerOptions) + mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentLatLong, 15f)) } diff --git a/app/src/main/java/com/example/nerbos/fragments/transaction/TransactionFragment.kt b/app/src/main/java/com/example/nerbos/fragments/transaction/TransactionFragment.kt index dd151f8679a694c755d4d2cfc4ad2a8cdc4147be..3a82a2c30bcd5f0fcc1dee02f6209844a1aca870 100644 --- a/app/src/main/java/com/example/nerbos/fragments/transaction/TransactionFragment.kt +++ b/app/src/main/java/com/example/nerbos/fragments/transaction/TransactionFragment.kt @@ -103,8 +103,9 @@ class TransactionFragment : Fragment() { } private fun showLocationOnMap(location: String) { - val intent = Intent(requireActivity(), MapsActivity::class.java) - startActivity(intent) + val mapIntent = Intent(requireActivity(), MapsActivity::class.java) + mapIntent.putExtra("locationName", location) + startActivity(mapIntent) } private fun showAddTransactionDialog() { diff --git a/app/src/main/res/drawable/ic_back.xml b/app/src/main/res/drawable/ic_back.xml new file mode 100644 index 0000000000000000000000000000000000000000..15e0dcca3b0376164ca26f1b1648fe223aa976f8 --- /dev/null +++ b/app/src/main/res/drawable/ic_back.xml @@ -0,0 +1,5 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp"> + + <path android:fillColor="@android:color/white" android:pathData="M11.67,3.87L9.9,2.1 0,12l9.9,9.9 1.77,-1.77L3.54,12z"/> + +</vector> diff --git a/app/src/main/res/layout/activity_maps.xml b/app/src/main/res/layout/activity_maps.xml index ec352fc6b1aa00e0353cac5e2f4c176086cc6900..9b9619ab9889a05727a030987f8dc8dbd191eb62 100644 --- a/app/src/main/res/layout/activity_maps.xml +++ b/app/src/main/res/layout/activity_maps.xml @@ -1,9 +1,36 @@ <?xml version="1.0" encoding="utf-8"?> -<fragment xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:map="http://schemas.android.com/apk/res-auto" + +<androidx.constraintlayout.widget.ConstraintLayout + xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" - android:id="@+id/map" - android:name="com.google.android.gms.maps.SupportMapFragment" + xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".MapsActivity" /> \ No newline at end of file + tools:context=".MapsActivity" + > + + <fragment + xmlns:map="http://schemas.android.com/apk/res-auto" + android:id="@+id/map" + android:name="com.google.android.gms.maps.SupportMapFragment" + android:layout_width="match_parent" + android:layout_height="match_parent" + map:layout_constraintTop_toTopOf="parent" + /> + + <TextView + android:id="@+id/title" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:textSize="24sp" + android:textColor="@color/white" + android:background="@color/base_bg" + android:text="@string/maps" + android:padding = "10dp" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:drawableStartCompat="@drawable/ic_back" + + /> + +</androidx.constraintlayout.widget.ConstraintLayout> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 66a23ad733ac615225ad154abaaa1253ba76262d..8855b877569d402c8f2e688baca2c19afdfad4a8 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -46,5 +46,6 @@ <string name="income">Income</string> <string name="outcome">Outcome</string> <string name="title_activity_maps">MapsActivity</string> + <string name="maps">Maps</string> </resources> \ No newline at end of file