Constellation | Prefix |
---|---|
GPS | 001 |
SBAS | 010 |
GLONASS | 011 |
QZSS | 100 |
Beidou | 101 |
Galileo | 110 |
IRNSS | 111 |
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
... | |
// New plugins for Room | |
apply plugin: 'kotlin-kapt' | |
apply plugin: 'dagger.hilt.android.plugin' | |
android { | |
... | |
defaultConfig { | |
... |
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
buildscript { | |
... | |
ext.hilt_version = '2.35' | |
dependencies { | |
// Hilt for dependency injection | |
classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version" | |
... | |
} |
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
@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() { | |
... |
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
@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?) { | |
... |
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
@Module | |
@InstallIn(SingletonComponent::class) | |
object DataModule { | |
@Provides | |
@Singleton | |
fun provideDatabase(@ApplicationContext context: Context): LocationDatabase = | |
LocationDatabase.create(context) | |
@Provides |
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
// Required for Hilt dependency injection | |
@HiltAndroidApp | |
class LocationApplication : Application() |
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
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") |
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
@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) | |
} | |
} |