Request merchants locations from the webservice and add them to the Merchants map.

master
Severiano Jaramillo 2018-12-18 09:27:26 -06:00
parent 89cf6f3df2
commit d5d01115f8
2 changed files with 55 additions and 18 deletions

View File

@ -23,14 +23,21 @@ import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.io.IOException
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.drawable.Drawable
import com.google.android.gms.maps.model.BitmapDescriptor
class MerchantsFragment : Fragment(), OnMapReadyCallback, retrofit2.Callback<FeathersResponse<Merchant>> {
private lateinit var mMap: GoogleMap
private var location: LatLng? = null
private var merchants: List<Merchant>? = null
private lateinit var merchantIcon: BitmapDescriptor
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
@ -42,10 +49,11 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, retrofit2.Callback<Fea
super.onViewCreated(view, savedInstanceState)
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
val mapFragment = childFragmentManager
.findFragmentById(R.id.map) as SupportMapFragment
val mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment
mapFragment.getMapAsync(this)
merchantIcon = getMarkerIconFromDrawable(resources.getDrawable(R.drawable.ic_pin_merchants, null))
// TODO https://github.com/Agorise/bitsy-wallet/blob/feat_merchants/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/MapFragment.kt
}
@ -61,17 +69,17 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, retrofit2.Callback<Fea
override fun onMapReady(googleMap: GoogleMap) {
mMap = googleMap
// val gson = GsonBuilder()
// .setLenient()
// .create()
// val retrofit = Retrofit.Builder()
// .baseUrl("https://intranet.palmpay.io/")
// .addConverterFactory(GsonConverterFactory.create(gson))
// .build()
//
// val ambassadorService = retrofit.create<AmbassadorService>(AmbassadorService::class.java)
// val call = ambassadorService.allMerchants
// call.enqueue(this)
val gson = GsonBuilder()
.setLenient()
.create()
val retrofit = Retrofit.Builder()
.baseUrl("https://intranet.palmpay.io/")
.addConverterFactory(GsonConverterFactory.create(gson))
.build()
val ambassadorService = retrofit.create<AmbassadorService>(AmbassadorService::class.java)
val call = ambassadorService.allMerchants
call.enqueue(this)
}
override fun onResponse(call: Call<FeathersResponse<Merchant>>, response: Response<FeathersResponse<Merchant>>) {
@ -79,11 +87,9 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, retrofit2.Callback<Fea
val res: FeathersResponse<Merchant>? = response.body()
merchants = res!!.data
for (mer in merchants!!) {
location = LatLng(mer.lat.toDouble(), mer.lon.toDouble())
val location = LatLng(mer.lat.toDouble(), mer.lon.toDouble())
mMap.addMarker(
MarkerOptions().position(location!!).title(mer.name).snippet(mer.address).icon(
BitmapDescriptorFactory.fromResource(R.drawable.ic_merchants)
)
MarkerOptions().position(location).title(mer.name).snippet(mer.address).icon(merchantIcon)
)
}
} else {
@ -100,4 +106,12 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback, retrofit2.Callback<Fea
}
private fun getMarkerIconFromDrawable(drawable: Drawable): BitmapDescriptor {
val canvas = Canvas()
val bitmap = Bitmap.createBitmap(drawable.intrinsicWidth, drawable.intrinsicHeight, Bitmap.Config.ARGB_8888)
canvas.setBitmap(bitmap)
drawable.setBounds(0, 0, drawable.intrinsicWidth, drawable.intrinsicHeight)
drawable.draw(canvas)
return BitmapDescriptorFactory.fromBitmap(bitmap)
}
}

View File

@ -0,0 +1,23 @@
<vector android:height="51dp"
android:viewportHeight="225.302"
android:viewportWidth="154.618"
android:width="31dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#0E9257" android:pathData="M151.705 76.396C151.705 35.31 118.397 2 77.31 2 36.219 2 2.913 35.31 2.913 76.396c0 20.073 7.961 38.277 20.889 51.66l-0.09 0.969s43.451 42.428 51.781 93.092h4.121c8.332-50.664 51.537-93.092 51.537-93.092l-0.352-0.457c12.936-13.388 20.906-32.087 20.906-52.172z" android:strokeColor="#FFFFFF" android:strokeWidth="5"/>
<path android:fillColor="#FFFFFF" android:pathData="M14.478 77.906c0-34.705 28.131-62.835 62.832-62.835 34.706 0 62.836 28.13 62.836 62.835 0 34.7-28.13 62.837-62.836 62.837-34.702 0-62.832-28.137-62.832-62.837z" android:strokeColor="#A5D5A7" android:strokeWidth="2.5162"/>
<path android:fillColor="#0E9257" android:fillType="evenOdd" android:pathData="M37.714 47.167c-0.072-2.064 0.691-3.015 2.888-3.608 5.333 0 10.67 0.003 16.006 0.002 9.134-0.003 18.271-0.014 27.403-0.014 7.197 0 14.396 0.009 21.592 0.012 2.804 0.002 5.603-0.004 8.404-0.008 1.083-0.146 1.854 0.426 2.502 1.176 0.646 0.742 0.76 1.646 0.593 2.599-0.518 1.547-1.835 2.489-3.451 2.45-0.554-0.011-1.112-0.013-1.669-0.013-23.728-0.002-47.457 0.002-71.185-0.002-1.291-0.142-2.334-0.67-2.938-1.886-0.108-0.221-0.243-0.443-0.145-0.708z"/>
<path android:fillColor="#0E9257" android:pathData="M118.797 82.431c-0.017 0.003-0.034 0.008-0.054 0.011-0.264 0.375-0.681 0.282-1.048 0.347l-1.943 0.369c-0.32 0.112-0.662-0.031-0.981 0.094-0.476-0.004-0.95-0.009-1.428-0.011-0.95 0.15-1.86-0.058-2.759-0.294v18.662H45.259V82.548c-1.265 0.451-2.589 0.714-3.988 0.751-0.155 0.005-0.305 0.034-0.451 0.077-1.104 0.032-2.187-0.046-3.236-0.265v21.727c3.944 4.054 8.478 7.523 13.471 10.257h54.286c4.983-2.732 9.518-6.2 13.457-10.251V82.431zm4.879-11.674c-0.106-0.602-0.237-1.201-0.354-1.8-0.612-2.371-1.12-4.767-1.619-7.161l-1.238-5.481c0.037-0.621-0.127-1.214-0.254-1.81-0.077-0.277-0.105-0.564-0.176-0.843-0.312-1.247-0.862-1.687-2.153-1.688-1.547-0.002-3.095-0.015-4.639 0.007-2.347-0.037-4.688-0.03-7.033-0.004-1.455-0.018-2.907-0.026-4.359 0.001-1.195 0.023-1.821 0.683-1.847 1.88-0.007 0.154-0.011 0.307 0.002 0.462 0.379 2.316 0.647 4.649 0.972 6.974 0.014 0.074 0.05 0.146 0.056 0.223 0.253 2.459 0.637 4.899 0.946 7.351 0.042 0.303 0.108 0.602 0.13 0.912 0.162 2.496 1.099 4.607 3.018 6.228 0.033 0.028 0.062 0.06 0.097 0.089 0.326 0.234 0.631 0.502 0.948 0.748 1.269 0.893 2.675 1.493 4.16 1.893 1.011 0.272 2.032 0.559 3.103 0.387l1.431 0.011c0.317-0.125 0.661 0.018 0.981-0.094l1.942-0.367c0.365-0.065 0.784 0.029 1.05-0.346l0.05-0.013c0.647-0.138 1.255-0.345 1.688-0.892 0.556-0.399 1.074-0.844 1.566-1.318 1.252-1.568 1.896-3.315 1.532-5.349zM52.445 51.958c-1.316 0.073-2.641 0.009-3.964 0.019-2.177-0.039-4.354-0.009-6.531-0.014-0.236-0.002-0.454 0.06-0.658 0.171-1.591 0.005-3.177 0.006-4.77 0.02-0.827 0.006-1.365 0.447-1.566 1.246-0.081 0.315-0.166 0.631-0.248 0.946-0.117 0.219-0.228 0.439-0.291 0.685-0.142 0.581-0.155 1.179-0.261 1.762-0.349 1.579-0.702 3.158-1.054 4.736-0.037 0.188-0.065 0.378-0.11 0.564-0.533 2.328-1.066 4.656-1.601 6.984-0.114 0.817-0.401 1.604-0.446 2.435-0.09 1.766 0.554 3.27 1.643 4.609 0.522 0.514 1.087 0.977 1.686 1.396 0.045 0.19 0.198 0.274 0.351 0.356 0.982 0.54 2.002 0.902 3.057 1.123 1.049 0.219 2.128 0.296 3.231 0.263 0.151-0.041 0.297-0.071 0.454-0.076 2.618-0.068 4.989-0.909 7.164-2.347 0.29-0.202 0.566-0.417 0.838-0.643 0.073-0.061 0.143-0.125 0.21-0.186 1.499-1.289 2.529-2.861 2.845-4.878 0.154-0.989 0.219-1.988 0.409-2.971 0.306-2.086 0.571-4.179 0.85-6.271 0.366-2.477 0.642-4.967 1.017-7.444 0.342-1.673-0.671-2.572-2.255-2.485zm46.477 9.917c-0.006-0.148-0.015-0.297-0.021-0.447 0.009-0.956-0.047-1.91-0.172-2.857-0.187-1.422-0.195-2.865-0.536-4.268 0.136-1.003-0.186-1.714-0.895-1.958-0.339-0.153-0.688-0.199-1.058-0.197-1.49 0.002-2.98-0.01-4.472-0.019-0.228-0.184-0.503-0.168-0.768-0.168-1.89-0.003-3.78-0.001-5.669-0.002-0.291 0-0.572 0.023-0.832 0.176-1.467 0.005-2.934 0.01-4.399 0.017-0.969 0.005-1.406 0.329-1.722 1.269-0.041 0.752-0.106 1.501-0.149 2.256 3.21-0.751 7.827-0.979 14.478-0.127l2.44 4.187-4.77-2.002 1.825 2.152-4.978 2.152s-3.053-3.073-4.676-3.285c0 0 2.033 4.521 1.154 4.14 0 0-1.986-1.227-5.39-1.749 0.013 0.327 0.021 0.654 0.03 0.984 1.441 0.392 2.902 1.049 4.074 2.146 0 0 6.576 5.317 9.561 14.262l-0.406 0.438c0.104-0.013 0.209-0.021 0.313-0.038 2.218-0.386 4.217-1.237 5.883-2.797 0.061-0.041 0.123-0.085 0.184-0.13 0.363-0.269 0.688-0.572 0.791-1.056 0.029-0.092 0.035-0.2 0.153-0.231 0.458-0.888 0.842-1.799 0.934-2.813 0.08-0.874-0.106-1.729-0.128-2.593-0.258-2.481-0.52-4.962-0.779-7.442z"/>
<path android:fillColor="#0E9257" android:pathData="M88.538 73.529l-1.164 1.506-2.915-4.533-0.714 0.79s-4.243-1.543-4.465-5.193l-0.941 1.673c0.004 0.35-0.002 0.699 0.004 1.048 0.031 0.65 0.156 1.295 0.132 1.95-0.054 1.713 0.56 3.189 1.646 4.48 0.226 0.265 0.406 0.583 0.714 0.757 0.075 0.042 0.157 0.08 0.251 0.102 1.066 0.893 2.252 1.587 3.527 2.13 1.947 0.673 3.93 0.955 5.951 0.831-0.218-0.426-0.63-1.06-1.412-1.969-0.001 0.001-1.663-1.567-0.614-3.572zm-17.553-11.03s-0.049-0.415 0.068-1.045l0.005-0.002c0.006-0.025 0.006-0.053 0.014-0.078 0.028-0.073 0.002-0.052 0.078-0.07 0.102-0.022 0.204 0.003 0.301-0.046-0.034 0.008-0.068 0.007-0.105 0.009-0.088 0.015-0.178 0.029-0.266 0.045 0.3-1.406 1.417-3.73 5.407-5.131 0.011-0.562 0.018-1.125 0.009-1.687-0.005-0.077 0.008-0.155 0.008-0.231 0.022-1.646-0.599-2.289-2.232-2.294-1.113-0.002-2.225 0-3.334-0.001-0.291-0.001-0.577 0.012-0.835 0.164l-7.139-0.004c-1.556 0.009-3.107 0.011-4.663 0.024-0.964 0.008-1.538 0.527-1.661 1.484-0.036 0.284-0.079 0.569-0.116 0.854-0.132 0.104-0.162 0.252-0.18 0.407-0.135 1.062-0.255 2.126-0.34 3.194-0.059 0.753-0.165 1.513-0.088 2.277-0.021 0.594-0.071 1.184-0.207 1.763l-0.708 6.7c-0.014 0.249-0.014 0.5-0.057 0.745-0.333 1.865-0.124 3.637 0.882 5.275 0.17 0.493 0.405 0.935 0.916 1.153 0.002 0 0.002 0.002 0.005 0.004 0.83 0.799 1.759 1.457 2.804 1.952 0.203 0.096 0.414 0.175 0.624 0.256 0.929-2.816 3.475-8.805 9.553-14.586 0 0 1.345 1.415-0.254 2.75 0 0-5.172 6.826-6.514 12.597l0.146 0.028c2.385 0.261 4.715 0.019 6.983-0.798 1.242-0.536 2.395-1.217 3.441-2.083 0.08-0.037 0.158-0.075 0.235-0.117 0.123-0.068 0.241-0.147 0.337-0.258 1.016-1.145 1.766-2.415 2.024-3.955-0.724-1.412-1.596-2.757-2.408-4.107 0 0-0.448 0.115-1.048-0.318-0.78-0.425-1.106-1.189-1.416-2.02l-1.133-2.192c2.329-0.202 3.687 0.845 4.917 1.969 0.165 0.151 0.326 0.321 0.48 0.502 0.268 0.286 0.523 0.606 0.761 0.962 0.01-0.383 0.024-0.768 0.037-1.153-1.129-1.099-2.838-2.281-5.331-2.938zm-3.712 2.199l-4.204-0.359s2.349-3.566 6.402-1.527l-2.198 1.886zm2.638-2.36c-2.869-0.969-2.47-2.525-1.874-3.466 0.021-0.035 0.037-0.072 0.061-0.104 0.017-0.021 0.035-0.037 0.047-0.059 0.168-0.235 0.335-0.421 0.441-0.53 0.011-0.009 0.019-0.02 0.03-0.029 0.052-0.053 0.087-0.083 0.087-0.083 0.072-0.066 0.15-0.125 0.228-0.186 0.381-0.315 0.801-0.563 1.254-0.756l0.174-0.075c0.06-0.021 0.119-0.047 0.176-0.069 1.554-0.594 3.046-0.558 3.046-0.558-1.56 0.978-2.454 2.153-2.969 3.2-0.325 0.801-0.543 1.706-0.701 2.715z"/>
<path android:fillColor="#0E9257" android:pathData="M76.377 60.942c-1.377-0.076-2.92-0.022-4.609 0.255-0.121 0.02-0.231 0.039-0.344 0.056 0.005 0.002 0.022 0.002 0.026 0.005l0.004-0.001c-0.051 0.021-0.061 0.057-0.078 0.098-0.015 0.029-0.019 0.044-0.023 0.055l0.031-0.004 1.106 0.234s1.727-0.195 3.889 0.092c-0.002-0.032 0-0.063 0-0.094-0.004-0.232 0-0.464-0.002-0.696z"/>
<path android:fillColor="#F7F8F9" android:pathData="M77.698 76.82c0.63-1.794 0.581-4.177 0.058-6.393 0.302 1.703 0.332 3.802-0.058 6.393zm-1.554-5.131c-0.005 0.038-0.013 0.072-0.02 0.106 0.798 1.559 1.417 3.201 1.573 5.025 0 0-0.055-2.078-1.549-5.174 0.001 0.016 0.001 0.029-0.004 0.043zm-4.891-6.338c0.31 0.83 0.636 1.594 1.416 2.019-0.43-0.309-0.937-0.897-1.416-2.019zm4.265 0.278c-0.154-0.181-0.316-0.351-0.48-0.502-1.231-1.125-2.588-2.171-4.917-1.969-0.001 0 3.09-0.006 5.397 2.471z"/>
<path android:fillColor="#F7F8F9" android:pathData="M76.149 71.646c-0.573-1.189-1.35-2.525-2.432-3.958 0.812 1.35 1.684 2.695 2.408 4.107 0.006-0.034 0.014-0.068 0.02-0.106 0.004-0.014 0.004-0.027 0.004-0.043zm-7.563-13.467l0.03-0.029c-0.011 0.01-0.018 0.02-0.03 0.029zm-0.488 0.589c-0.024 0.032-0.041 0.069-0.061 0.104 0.036-0.057 0.073-0.112 0.108-0.163-0.012 0.021-0.03 0.037-0.047 0.059zm2.262-1.718l0.176-0.069c-0.057 0.022-0.116 0.048-0.176 0.069zm-0.449 5.288c0.158-1.009 0.376-1.914 0.704-2.715-0.737 1.49-0.704 2.715-0.704 2.715zm-0.979-4.457c0.395-0.314 0.824-0.562 1.254-0.756-0.454 0.192-0.873 0.44-1.254 0.756zM59.7 79.872l2.96 2.071c-0.062-0.923 0.059-1.927 0.297-2.964-0.948-0.188-1.884-0.411-2.785-0.761-0.344 1.041-0.472 1.654-0.472 1.654zm10.837-22.891c0.928-0.327 1.968-0.467 3.046-0.558 0 0-1.493-0.036-3.046 0.558z"/>
<path android:fillColor="#F7F8F9" android:pathData="M73.583 56.423c-1.503 0.733-2.402 1.807-2.969 3.2 0.515-1.047 1.409-2.222 2.969-3.2zm-5.437 2.286c0.138-0.191 0.287-0.37 0.441-0.53-0.106 0.109-0.274 0.295-0.441 0.53zm2.04-1.584c0.061-0.024 0.114-0.052 0.174-0.075l-0.174 0.075zm-1.482 0.942s-0.035 0.03-0.087 0.083c0.1-0.099 0.208-0.181 0.315-0.269-0.078 0.061-0.157 0.12-0.228 0.186z"/>
<path android:fillAlpha="0.3" android:fillColor="#F7F8F9" android:pathData="M77.756 70.428c-0.288-1.609-0.822-2.86-1.477-3.837-0.002 0.031-0.002 0.063-0.002 0.094 0.646 1.064 1.155 2.37 1.479 3.743z" android:strokeAlpha="0.3"/>
<path android:fillColor="#0E9257" android:pathData="M73.717 67.688c-0.428-0.049-0.765-0.163-1.048-0.318 0.6 0.433 1.048 0.318 1.048 0.318z"/>
<path android:fillAlpha="0.3" android:fillColor="#F7F8F9" android:pathData="M73.717 67.688c-0.428-0.049-0.765-0.163-1.048-0.318 0.6 0.433 1.048 0.318 1.048 0.318z" android:strokeAlpha="0.3"/>
<path android:fillColor="#0E9257" android:pathData="M71.253 65.35c-0.279-0.751-0.545-1.553-1.133-2.192l1.133 2.192z"/>
<path android:fillAlpha="0.3" android:fillColor="#F7F8F9" android:pathData="M71.253 65.35c-0.279-0.751-0.545-1.553-1.133-2.192l1.133 2.192z" android:strokeAlpha="0.3"/>
<path android:fillColor="#0E9257" android:pathData="M76.276 66.685c0-0.031 0-0.062 0.002-0.094-0.238-0.355-0.493-0.676-0.761-0.962 0.271 0.312 0.524 0.669 0.759 1.056z"/>
<path android:fillAlpha="0.3" android:fillColor="#F7F8F9" android:pathData="M76.276 66.685c0-0.031 0-0.062 0.002-0.094-0.238-0.355-0.493-0.676-0.761-0.962 0.271 0.312 0.524 0.669 0.759 1.056z" android:strokeAlpha="0.3"/>
<path android:fillColor="#F7F8F9" android:pathData="M76.267 68.808c-0.055 0.945 0.021 1.893-0.118 2.839 1.494 3.096 1.549 5.174 1.549 5.174 0.391-2.592 0.36-4.69 0.058-6.393-0.324-1.373-0.833-2.679-1.479-3.743-0.02 0.707-0.032 1.415-0.01 2.123zm0.11-7.866c0.689 0.038 1.335 0.106 1.938 0.2-0.06-1.619-0.151-3.238-0.119-4.858 0.002-0.203 0.023-0.406 0.034-0.609-0.636 0.149-1.215 0.32-1.745 0.506-0.033 1.586-0.113 3.173-0.108 4.761zm1.968 1.184c-0.671-0.185-1.336-0.31-1.966-0.394 0.032 1.237-0.017 2.473-0.064 3.706 1.377 1.342 1.896 2.564 1.896 2.564l0.127-0.229c-0.003-1.042-0.011-2.085 0-3.127 0.034-0.841 0.028-1.681 0.007-2.52zm12.449 17.688l0.779-0.841c-0.337 0.044-0.676 0.076-1.01 0.098 0.274 0.54 0.231 0.743 0.231 0.743z"/>
</vector>