Giter Site home page Giter Site logo

locationtracker's Introduction

locationtracker

Location Tracking SDK & Sample App.

Description

The location tracker SDK is currently supporting only Android apps, and it is designed in a way to be converted to Kotlin MultiPlatform and support iOS apps easily, if need be.

The SDK exposes a very simple API to track location updates and submitting them to a backend. It contains default implementations to fetch location using native Android APIs, as well as a default mechanism to submit the location updates to a predefined backend.

However, the SDK is highly configurable, so that the user can write their own implementations for loading location and submitting it respectively.

Usage

The usage of the library is rather simple.

1. Setup Dependency

Add the dependency in the build.gradle file

implementation("io.github.mitrejcevski:locationtracker:1.0.0-SNAPSHOT")

2. Instantiation

In your main activity, instantiate the tracker by passing the desired configuration.

2.1 Without Dependency Injection Container:

class MainActivity : AppCompatActivity() {
    private val locationTracker by viewModels<LocationTracker> {
        viewModelFactory {
            initializer {
                val configuration = LocationTrackerConfig.Builder()
                    .useDefaultAndroidComponents(applicationContext)
                    .build()
                LocationTracker(configuration)
            }
        }
    }
    ...
}

2.2 With Dependency Injection Container:

class MainActivity : AppCompatActivity() {
    private val locationTracker by viewModels<LocationTracker>()
    ...
}

3. Track location

The SDK can track regular location updates, and request a location update on-demand.

3.1 Track regular location updates

locationTracker.startTrackingLocation()

3.2 Request no-demand location update

locationTracker.requestCurrentLocation()

3.3 Observe current state (Optional)

The SDK provides an observable property that you can use to check the current state of the SDK (location fetching, submitssions, failures).

3.3.1 Jetpack Compose
val state by locationTracker.locationTrackingState.collectAsStateWithLifecycle()
3.3.1 Traditional Android UI
lifecycleScope.launch {
    repeatOnLifecycle(Lifecycle.State.STARTED) {
        locationTracker.locationTrackingState.collectLatest { state ->
            //do something with the state
        }
    }
}

4. Additional customizations

You can supply your own implementations for checking permissions granted, location loading, and location submission.

val configuration = LocationTrackerConfig.Builder()
     .setLocationPermissionChecker(yourOwnImplementation)
     .setLocationFetcher(yourOwnImplementation)
     .setLocationSubmitter(yourOwnImplementation)
     .build()

That would allow to mix and match different components with the default built-in ones, and enable testability.

Design Choices

The SDK is designed with a possibility to convert it into KMP in the future, and support iOS too. It keeps the testability in mind as well. Additionally, it should be highly configurable allowing the user to use the default implementation of the components, as well as providing custom implementations of them.

The LocationTracker is getting configured by taking in LocationTrackerConfig, instead of taking the corresponding component implementations in the constructor. It would make the future development of the SDK easier as it will allow deprecations and backwards compatibility support smoother.

locationtracker's People

Contributors

mitrejcevski avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.