Skip to content

Instantly share code, notes, and snippets.

View barbeau's full-sized avatar

Sean Barbeau barbeau

View GitHub Profile
@barbeau
barbeau / nav-message-constellation-prefixes.md
Created July 2, 2021 22:12
nav-message-constellation-prefixes.md
Constellation Prefix
GPS 001
SBAS 010
GLONASS 011
QZSS 100
Beidou 101
Galileo 110
IRNSS 111
@barbeau
barbeau / nav-message-int-to-binary-map.md
Last active July 2, 2021 22:12
Android API navigation message types
Message type Int Binary
TYPE_BDS_CNAV1 1283 00000000 00000000 00000101 00000011
TYPE_BDS_CNAV2 1284 00000000 00000000 00000101 00000100
TYPE_BDS_D1 1281 00000000 00000000 00000101 00000001
TYPE_BDS_D2 1282 00000000 00000000 00000101 00000010
TYPE_GAL_F 1538 00000000 00000000 00000110 00000010
TYPE_GAL_I 1537 00000000 00000000 00000110 00000001
TYPE_GLO_L1CA 769 00000000 00000000 00000011 00000001
TYPE_GPS_CNAV2 260 00000000 00000000 00000001 00000100
@barbeau
barbeau / build.gradle
Last active May 24, 2021 20:54
Medium article - Room + Flow for location updates - app
...
// New plugins for Room
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
android {
...
defaultConfig {
...
@barbeau
barbeau / build.gradle
Created May 24, 2021 20:02
Medium article - Room + Flow for location updates - Root
buildscript {
...
ext.hilt_version = '2.35'
dependencies {
// Hilt for dependency injection
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
...
}
@barbeau
barbeau / ForegroundOnlyLocationService.kt
Last active May 24, 2021 19:15
Medium article - Room + Flow for location updates
@AndroidEntryPoint
class ForegroundOnlyLocationService : LifecycleService() {
...
// Data store (in this case, Room database) where the service will persist the location data, injected via Hilt
@Inject
lateinit var repository: LocationRepository
override fun onCreate() {
...
@barbeau
barbeau / MainActivity.kt
Last active May 24, 2021 19:06
Medium article - Room + Flow for location updates
@AndroidEntryPoint
class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceChangeListener {
...
// Repository (in this case, Room database) from which to receive location updates via Flow, injected via Hilt
@Inject
lateinit var repository: LocationRepository
override fun onCreate(savedInstanceState: Bundle?) {
...
@barbeau
barbeau / DataModule.kt
Created May 24, 2021 18:48
Medium article - Room + Flow for location updates
@Module
@InstallIn(SingletonComponent::class)
object DataModule {
@Provides
@Singleton
fun provideDatabase(@ApplicationContext context: Context): LocationDatabase =
LocationDatabase.create(context)
@Provides
@barbeau
barbeau / LocationApplication.kt
Created May 24, 2021 18:46
Medium article - Room + Flow for location updates
// Required for Hilt dependency injection
@HiltAndroidApp
class LocationApplication : Application()
@barbeau
barbeau / LocationRepository.kt
Created May 24, 2021 18:37
Medium article - Room + Flow for location updates
class LocationRepository @Inject constructor(
private val locationDao: LocationDao
) {
fun getLocations() = locationDao.getLocations()
// By default Room runs suspend queries off the main thread, therefore, we don't need to
// implement anything else to ensure we're not doing long running database work
// off the main thread.
@Suppress("RedundantSuspendModifier")
@barbeau
barbeau / LocationDao.kt
Last active June 1, 2021 16:59
Medium article - Room + Flow for location updates
@Dao
interface LocationDao {
@Transaction
suspend fun updateLocation(location: Location) {
location.let {
deleteLocations() // This deletes previous locations to keep the database small. If you want to store a full location history, remove this line.
insertLocation(it)
}
}