Added code to fetch the merchants locations from the palmapay intranet web service.
This commit is contained in:
parent
5659a1dd8c
commit
41f7541918
7 changed files with 166 additions and 6 deletions
|
@ -9,6 +9,7 @@
|
|||
location permissions for the 'MyLocation' functionality.
|
||||
-->
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
|
||||
<application
|
||||
|
|
|
@ -1,23 +1,36 @@
|
|||
package cy.agorise.bitsybitshareswallet.fragments
|
||||
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
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.BitmapDescriptorFactory
|
||||
import com.google.android.gms.maps.model.LatLng
|
||||
import com.google.android.gms.maps.model.MarkerOptions
|
||||
import com.google.gson.GsonBuilder
|
||||
|
||||
import cy.agorise.bitsybitshareswallet.R
|
||||
import cy.agorise.bitsybitshareswallet.models.Merchant
|
||||
import cy.agorise.bitsybitshareswallet.network.AmbassadorService
|
||||
import cy.agorise.bitsybitshareswallet.network.FeathersResponse
|
||||
import retrofit2.Call
|
||||
import retrofit2.Response
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.gson.GsonConverterFactory
|
||||
import java.io.IOException
|
||||
|
||||
class MerchantsFragment : Fragment(), OnMapReadyCallback {
|
||||
class MerchantsFragment : Fragment(), OnMapReadyCallback, retrofit2.Callback<FeathersResponse<Merchant>> {
|
||||
|
||||
private lateinit var mMap: GoogleMap
|
||||
|
||||
private var location: LatLng? = null
|
||||
private var merchants: List<Merchant>? = null
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
|
@ -32,6 +45,8 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback {
|
|||
val mapFragment = childFragmentManager
|
||||
.findFragmentById(R.id.map) as SupportMapFragment
|
||||
mapFragment.getMapAsync(this)
|
||||
|
||||
// TODO https://github.com/Agorise/bitsy-wallet/blob/feat_merchants/app/src/main/java/cy/agorise/bitsybitshareswallet/fragments/MapFragment.kt
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,10 +61,43 @@ class MerchantsFragment : Fragment(), OnMapReadyCallback {
|
|||
override fun onMapReady(googleMap: GoogleMap) {
|
||||
mMap = googleMap
|
||||
|
||||
// Add a marker in Sydney and move the camera
|
||||
val sydney = LatLng(-34.0, 151.0)
|
||||
mMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
|
||||
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))
|
||||
// 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>>) {
|
||||
if (response.isSuccessful) {
|
||||
val res: FeathersResponse<Merchant>? = response.body()
|
||||
merchants = res!!.data
|
||||
for (mer in merchants!!) {
|
||||
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)
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
Log.e("error_bitsy", response.errorBody()?.string())
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(call: Call<FeathersResponse<Merchant>>, t: Throwable) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package cy.agorise.bitsybitshareswallet.models
|
||||
|
||||
class Ambassador(var id: String?, var account: String?, var country: String?, var city: String?) {
|
||||
var cityId: String? = null
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package cy.agorise.bitsybitshareswallet.models
|
||||
|
||||
import androidx.annotation.NonNull
|
||||
|
||||
class AmbassadorLocation(
|
||||
var id: String?,
|
||||
var name: String?,
|
||||
var country: String?
|
||||
) : Comparable<AmbassadorLocation> {
|
||||
|
||||
override fun toString(): String {
|
||||
return this.name!!
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
return other is AmbassadorLocation && id == other.id
|
||||
}
|
||||
|
||||
override fun compareTo(@NonNull other: AmbassadorLocation): Int {
|
||||
return name!!.compareTo(other.name!!)
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = id?.hashCode() ?: 0
|
||||
result = 31 * result + (name?.hashCode() ?: 0)
|
||||
result = 31 * result + (country?.hashCode() ?: 0)
|
||||
return result
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package cy.agorise.bitsybitshareswallet.models
|
||||
|
||||
import java.util.*
|
||||
|
||||
class Merchant {
|
||||
|
||||
var id: String? = null
|
||||
var address: String? = null
|
||||
var phone: String? = null
|
||||
var name: String? = null
|
||||
var lat: Float = 0F
|
||||
var lon: Float = 0F
|
||||
var city: String? = null
|
||||
var country: String? = null
|
||||
var createdAt: Date? = null
|
||||
var updatedAt: Date? = null
|
||||
var __v: Int = 0
|
||||
|
||||
constructor() {}
|
||||
constructor(id: String) {
|
||||
this.id = id
|
||||
}
|
||||
|
||||
constructor(_id: String, address: String, phone: String, name: String, lat: Float, lon: Float, city: String, country: String, createdAt: Date, updatedAt: Date, __v: Int) {
|
||||
this.id = _id
|
||||
this.address = address
|
||||
this.phone = phone
|
||||
this.name = name
|
||||
this.lat = lat
|
||||
this.lon = lon
|
||||
this.city = city
|
||||
this.country = country
|
||||
this.createdAt = createdAt
|
||||
this.updatedAt = updatedAt
|
||||
this.__v = __v
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package cy.agorise.bitsybitshareswallet.network
|
||||
|
||||
import cy.agorise.bitsybitshareswallet.models.Ambassador
|
||||
import cy.agorise.bitsybitshareswallet.models.AmbassadorLocation
|
||||
import cy.agorise.bitsybitshareswallet.models.Merchant
|
||||
import retrofit2.Call
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Query
|
||||
|
||||
interface AmbassadorService {
|
||||
|
||||
//https://ambpay.palmpay.io/api/v1/merchants?%24sort%5Baccount%5D=1&%24limit=50&%24skip=0
|
||||
@get:GET("/api/v1/merchants?%24sort%5Baccount%5D=1&%24limit=50&%24skip=0")
|
||||
val allMerchants: Call<FeathersResponse<Merchant>>
|
||||
|
||||
@GET("/api/v1/ambassadors")
|
||||
fun getAmbassadors(@Query("cityId") cityId: String): Call<FeathersResponse<Ambassador>>
|
||||
|
||||
@GET("/api/v1/cities")
|
||||
fun getAllCitiesSync(@Query("\$skip") skip: Long): Call<FeathersResponse<AmbassadorLocation>>
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cy.agorise.bitsybitshareswallet.network
|
||||
|
||||
class FeathersResponse<T>(private val error: Throwable?) {
|
||||
var total: Long = 0
|
||||
var limit: Long = 0
|
||||
var skip: Long = 0
|
||||
var data: List<T>? = null
|
||||
|
||||
val isSuccessful: Boolean
|
||||
get() = error == null && data != null
|
||||
|
||||
fun message(): String {
|
||||
return if (error != null) {
|
||||
error.message!!
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue