This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class GeofenceModel(var id: String,var lat : Double, var lng: Double, var radius: Double) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity(tableName = "toll") | |
data class Toll( | |
@PrimaryKey | |
var id: Int = 0, | |
var name: String = "", | |
var lat: String = "", | |
var lng: String = "" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun setupGeofence() { | |
fusedLocationClient = LocationServices.getFusedLocationProviderClient(mContext) | |
//Get user's current location | |
fusedLocationClient.lastLocation.addOnSuccessListener { | |
val userLat = it.latitude | |
val userLong = it.longitude |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun setupGeofence() { | |
fusedLocationClient = LocationServices.getFusedLocationProviderClient(mContext) | |
//Get user's current location | |
fusedLocationClient.lastLocation.addOnSuccessListener { | |
val userLat = it.latitude | |
val userLong = it.longitude | |
//Create an instance of our GeofenceHelper Class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GeofenceHelper(context: Context) { | |
fun buildGeofencingRequest(geofences: List<Geofence>): GeofencingRequest { | |
return GeofencingRequest.Builder() | |
.setInitialTrigger(0) | |
.addGeofences(geofences) | |
.build() | |
} | |
val geofencePendingIntent: PendingIntent by lazy { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tollsList: LiveData<List<GeofenceModel>> = | |
Transformations.map(DataRepository.getAllTolls(), ::getTolls) | |
private fun getTolls(tolls: List<Toll>): List<GeofenceModel> { | |
val list = ArrayList<GeofenceModel>() | |
tolls.forEach { | |
list.add( | |
GeofenceModel( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun setupChildGeofences( | |
context: Context, | |
geofenceModelList: List<GeofenceModel>, | |
currentLat: Double, | |
currentLong: Double, | |
geofencingClient: GeofencingClient | |
) { | |
//Filter list as per user's current location |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GeofenceTransitionsJobIntentService : JobIntentService() { | |
companion object { | |
private const val JOB_ID = 101 | |
fun enqueueWork(context: Context, intent: Intent) { | |
enqueueWork( | |
context, | |
GeofenceTransitionsJobIntentService::class.java, JOB_ID, | |
intent | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GeofenceBroadcastReceiver : BroadcastReceiver() { | |
override fun onReceive(context: Context, intent: Intent) { | |
GeofenceTransitionsJobIntentService.enqueueWork(context, intent) | |
} | |
} |