Add location permission request in the Merchants and Tellers screen, and if accepted show the icon on the map so that it can be moved to the current user's location if it is available already. Also, show the zoom UI controls on the map.

This commit is contained in:
Severiano Jaramillo 2019-01-22 15:31:24 -06:00
parent 55e57a11ad
commit 227e0224a1
4 changed files with 57 additions and 7 deletions

View file

@ -1,5 +1,8 @@
package cy.agorise.bitsybitshareswallet.fragments package cy.agorise.bitsybitshareswallet.fragments
import android.Manifest
import android.annotation.SuppressLint
import android.content.pm.PackageManager
import android.os.Bundle import android.os.Bundle
import android.util.Log import android.util.Log
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
@ -25,13 +28,22 @@ import java.io.IOException
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.drawable.Drawable import android.graphics.drawable.Drawable
import androidx.core.content.ContextCompat
import com.google.android.gms.maps.model.BitmapDescriptor import com.google.android.gms.maps.model.BitmapDescriptor
import cy.agorise.bitsybitshareswallet.database.entities.Merchant import cy.agorise.bitsybitshareswallet.database.entities.Merchant
import cy.agorise.bitsybitshareswallet.utils.Constants import cy.agorise.bitsybitshareswallet.utils.Constants
import cy.agorise.bitsybitshareswallet.utils.toast
class MerchantsFragment : Fragment(), OnMapReadyCallback, retrofit2.Callback<FeathersResponse<Merchant>> { class MerchantsFragment : Fragment(), OnMapReadyCallback, retrofit2.Callback<FeathersResponse<Merchant>> {
companion object {
private const val TAG = "MerchantsFragment"
// Camera Permission
private const val REQUEST_LOCATION_PERMISSION = 1
}
private lateinit var mMap: GoogleMap private lateinit var mMap: GoogleMap
private var merchants: List<Merchant>? = null private var merchants: List<Merchant>? = null
@ -55,6 +67,32 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, retrofit2.Callback<Fea
merchantIcon = getMarkerIconFromDrawable(resources.getDrawable(R.drawable.ic_pin_merchants, null)) merchantIcon = getMarkerIconFromDrawable(resources.getDrawable(R.drawable.ic_pin_merchants, null))
} }
private fun verifyLocationPermission() {
if (ContextCompat.checkSelfPermission(activity!!, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
// Permission is not already granted
requestPermissions(arrayOf(android.Manifest.permission.ACCESS_FINE_LOCATION), REQUEST_LOCATION_PERMISSION)
} else {
// Permission is already granted
mMap.isMyLocationEnabled = true
}
}
/** Handles the result from the location permission request */
@SuppressLint("MissingPermission")
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
if (requestCode == REQUEST_LOCATION_PERMISSION) {
if ((grantResults.isNotEmpty() && grantResults[0] == PackageManager.PERMISSION_GRANTED)) {
mMap.isMyLocationEnabled = true
} else {
context?.toast(getString(R.string.msg__location_permission_necessary))
}
return
}
}
/** /**
* Manipulates the map once available. * Manipulates the map once available.
* This callback is triggered when the map is ready to be used. * This callback is triggered when the map is ready to be used.
@ -67,6 +105,8 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, retrofit2.Callback<Fea
override fun onMapReady(googleMap: GoogleMap) { override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap mMap = googleMap
verifyLocationPermission()
val gson = GsonBuilder() val gson = GsonBuilder()
.setLenient() .setLenient()
.create() .create()

View file

@ -1,8 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android" <fragment
xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" xmlns:map="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map" android:name="com.google.android.gms.maps.SupportMapFragment"
tools:context=".fragments.MerchantsFragment" android:layout_width="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment"/> android:layout_height="match_parent"
android:id="@+id/map"
map:uiZoomControls="true"
map:uiCompass="true"
tools:context=".fragments.MerchantsFragment"/>

View file

@ -58,6 +58,9 @@
<string name="text__ignore_network_fees">Ignorar cuotas de red</string> <string name="text__ignore_network_fees">Ignorar cuotas de red</string>
<string name="button__filter">Filtrar</string> <string name="button__filter">Filtrar</string>
<!-- Merchants & Tellers -->
<string name="msg__location_permission_necessary">El permiso de localización es necesario para mostrar tu ubicación actual en el mapa.</string>
<!-- Send Transaction --> <!-- Send Transaction -->
<string name="title_info">Info</string> <string name="title_info">Info</string>
<string name="text__to">A</string> <string name="text__to">A</string>

View file

@ -58,6 +58,9 @@
<string name="text__ignore_network_fees">Ignore Network fees</string> <string name="text__ignore_network_fees">Ignore Network fees</string>
<string name="button__filter">Filter</string> <string name="button__filter">Filter</string>
<!-- Merchants & Tellers -->
<string name="msg__location_permission_necessary">Location permission is necessary to show your current location on the map.</string>
<!-- Send Transaction --> <!-- Send Transaction -->
<string name="title_info">Info</string> <string name="title_info">Info</string>
<string name="text__to">To</string> <string name="text__to">To</string>