-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #422 from skedgo/feature/20911-facility-marker-han…
…dling [20911] Handle Facilities from location.json
- Loading branch information
Showing
7 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
27 changes: 27 additions & 0 deletions
27
TripKitData/src/main/java/com/skedgo/tripkit/data/database/locations/facility/FacilityDao.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.skedgo.tripkit.data.database.locations.facility | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
import io.reactivex.Flowable | ||
|
||
@Dao | ||
abstract class FacilityDao { | ||
@Query("SELECT * from facilities WHERE cellId IN (:cellIds)") | ||
abstract fun getAllInCells(cellIds: List<String>): Flowable<List<FacilityLocationEntity>> | ||
|
||
@Query("SELECT * from facilities WHERE cellId IN (:cellIds) AND :southWestLat < lat AND lat < :northEastLat AND :southWestLng < lng AND lng < :northEastLng") | ||
abstract fun getAllByCellsAndLatLngBounds( | ||
cellIds: List<String>, | ||
southWestLat: Double, | ||
southWestLng: Double, | ||
northEastLat: Double, | ||
northEastLng: Double): Flowable<List<FacilityLocationEntity>> | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
abstract fun saveAll(facilities: List<FacilityLocationEntity>) | ||
|
||
@Query("SELECT * from facilities WHERE identifier == :id") | ||
abstract fun getById(id: String): FacilityLocationEntity | ||
} |
22 changes: 22 additions & 0 deletions
22
...c/main/java/com/skedgo/tripkit/data/database/locations/facility/FacilityLocationEntity.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.skedgo.tripkit.data.database.locations.facility | ||
|
||
|
||
import androidx.annotation.Keep | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
|
||
@Entity(tableName = "facilities") | ||
@Keep | ||
class FacilityLocationEntity { | ||
@PrimaryKey | ||
var identifier: String = "" | ||
var cellId: String? = null | ||
var lat: Double = 0.0 | ||
var lng: Double = 0.0 | ||
var address: String? = null | ||
var timezone: String? = null | ||
var city: String? = null | ||
var region: String? = null | ||
var name: String? = null | ||
var facilityType: String? = null | ||
} |
13 changes: 13 additions & 0 deletions
13
...a/src/main/java/com/skedgo/tripkit/data/database/locations/facility/FacilityRepository.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.skedgo.tripkit.data.database.locations.facility | ||
|
||
import io.reactivex.Completable | ||
import io.reactivex.Observable | ||
import io.reactivex.Single | ||
import com.skedgo.tripkit.location.GeoPoint | ||
|
||
interface FacilityRepository { | ||
fun saveFacilities(key: String, facilities: List<FacilityLocationEntity>): Completable | ||
fun getFacilities(cellIds: List<String>): Observable<List<FacilityLocationEntity>> | ||
fun getFacility(id: String): Single<FacilityLocationEntity> | ||
fun getFacilitiesWithinBounds(cellIds: List<String>, southwest: GeoPoint, northEast: GeoPoint): Observable<List<FacilityLocationEntity>> | ||
} |
48 changes: 48 additions & 0 deletions
48
...c/main/java/com/skedgo/tripkit/data/database/locations/facility/FacilityRepositoryImpl.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.skedgo.tripkit.data.database.locations.facility | ||
|
||
import com.skedgo.tripkit.data.database.TripKitDatabase | ||
import io.reactivex.Completable | ||
import io.reactivex.Observable | ||
import io.reactivex.Single | ||
import io.reactivex.schedulers.Schedulers | ||
import com.skedgo.tripkit.location.GeoPoint | ||
|
||
class FacilityRepositoryImpl(val tripGoDatabase2: TripKitDatabase) : FacilityRepository { | ||
override fun saveFacilities( | ||
key: String, | ||
facilities: List<FacilityLocationEntity> | ||
): Completable { | ||
return Completable | ||
.fromAction { | ||
facilities.forEach { | ||
it.cellId = key | ||
it.identifier = it.identifier | ||
} | ||
tripGoDatabase2.facilityDao().saveAll(facilities) | ||
} | ||
.subscribeOn(Schedulers.io()) | ||
} | ||
|
||
override fun getFacilities(cellIds: List<String>): Observable<List<FacilityLocationEntity>> { | ||
return tripGoDatabase2.facilityDao() | ||
.getAllInCells(cellIds) | ||
.subscribeOn(Schedulers.io()).toObservable() | ||
} | ||
|
||
override fun getFacilitiesWithinBounds( | ||
cellIds: List<String>, | ||
southwest: GeoPoint, | ||
northEast: GeoPoint | ||
): Observable<List<FacilityLocationEntity>> { | ||
return tripGoDatabase2.facilityDao().getAllInCells(cellIds) | ||
.subscribeOn(Schedulers.io()).toObservable() | ||
} | ||
|
||
override fun getFacility(id: String): Single<FacilityLocationEntity> { | ||
return Single | ||
.fromCallable { | ||
tripGoDatabase2.facilityDao().getById(id) | ||
} | ||
.subscribeOn(Schedulers.io()) | ||
} | ||
} |
This file contains 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
This file contains 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