Skip to content
Snippets Groups Projects
Commit 21eee499 authored by Rinaldy Adin's avatar Rinaldy Adin
Browse files

Merge branch 'feat/open-location' into 'dev'

feat: open location in gmaps when editing a transaction

See merge request !6
parents faff0929 d723a100
Branches
Tags
1 merge request!6feat: open location in gmaps when editing a transaction
......@@ -9,6 +9,7 @@ import android.location.Address
import android.location.Geocoder
import android.location.Location
import android.location.LocationManager
import android.net.Uri
import android.os.Bundle
import android.provider.Settings
import android.util.Log
......@@ -19,6 +20,7 @@ import android.widget.AdapterView
import android.widget.ArrayAdapter
import android.widget.Toast
import androidx.activity.addCallback
import androidx.constraintlayout.widget.ConstraintSet
import androidx.core.app.ActivityCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
......@@ -81,6 +83,7 @@ class FormTransaction : Fragment() {
titleFocusListener()
amountFocusListener()
categoryFocusListener()
openInMapListener()
locationFocusListener()
saveButtonListener()
......@@ -101,15 +104,25 @@ class FormTransaction : Fragment() {
displayTrx(trxId)
} else if (args.containsKey("random_amount")) {
viewModel.setRandomAmount(args.getInt("random_amount"))
binding.btnDelete.visibility = View.GONE
useNewTrxLayout()
}
} else {
binding.btnDelete.visibility = View.GONE
useNewTrxLayout()
}
return binding.root
}
private fun useNewTrxLayout() {
binding.btnDelete.visibility = View.GONE
binding.btnOpenMap.visibility = View.GONE
ConstraintSet().apply {
clone(binding.formTransaction)
connect(R.id.formLocationContainer, ConstraintSet.TOP, R.id.formCategoryContainer, ConstraintSet.BOTTOM, 5)
applyTo(binding.formTransaction)
}
}
private fun displayTrx(idTrx: Int) {
id = idTrx
......@@ -150,6 +163,17 @@ class FormTransaction : Fragment() {
}
}
private fun openInMapListener() {
binding.btnOpenMap.setOnClickListener {
val destinationLatitude = viewModel.latitude.value.toString()
val destinationLongitude = viewModel.longitude.value.toString()
val mapUri = Uri.parse("https://maps.google.com/maps?daddr=$destinationLatitude,$destinationLongitude")
val intent = Intent(Intent.ACTION_VIEW, mapUri)
startActivity(intent)
}
}
private fun locationFocusListener() {
binding.formLocationEditText.setOnFocusChangeListener { _, focused ->
if (!focused) {
......
......@@ -75,33 +75,49 @@
android:id="@+id/categoryAutocomplete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@={viewModel.category}"
android:inputType="none"
android:labelFor="@+id/formCategoryContainer" />
android:labelFor="@+id/formCategoryContainer"
android:text="@={viewModel.category}" />
</com.google.android.material.textfield.TextInputLayout>
<Button
android:id="@+id/btnOpenMap"
android:minWidth="0dp"
android:minHeight="0dp"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:paddingTop="1dp"
android:paddingBottom="1dp"
android:layout_marginTop="8dp"
android:text="Open in Map"
android:textColor="@color/primary"
android:background="@android:color/transparent"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="@+id/formCategoryContainer"
app:layout_constraintTop_toBottomOf="@+id/formCategoryContainer" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/formLocationContainer"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="20dp"
android:layout_marginTop="5dp"
app:helperTextTextColor="@color/destructive"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/formCategoryContainer">
app:layout_constraintTop_toBottomOf="@id/btnOpenMap">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/formLocationEditText"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@={viewModel.location}"
android:hint="Location"
android:inputType="text"
android:lines="1" />
android:lines="1"
android:text="@={viewModel.location}" />
</com.google.android.material.textfield.TextInputLayout>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment