All Projects → Jintin → FancyLocationProvider

Jintin / FancyLocationProvider

Licence: MIT license
Wrapper of FusedLocationProviderClient for Android to support modern usage like LiveData and Flow

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to FancyLocationProvider

Jetpack Mvvm Scaffold
人生苦短,让脚手架为你节省时间。(目前作为《最佳实践》项目的 Dev 版来优先更新)
Stars: ✭ 239 (+262.12%)
Mutual labels:  livedata
NSE-Stock-Scanner
National Stock Exchange (NSE), India based Stock screener program. Supports Live Data, Swing / Momentum Trading, Intraday Trading, Connect to online brokers as Zerodha Kite, Risk Management, Emotion Control, Screening, Strategies, Backtesting, Automatic Stock Downloading after closing, live free day trading data and much more
Stars: ✭ 78 (+18.18%)
Mutual labels:  livedata
gps-permission-checks-livedata
Sample project to demonstrate how GPS and Runtime Location Permission checks can be done on UI and Background Service using LiveData
Stars: ✭ 37 (-43.94%)
Mutual labels:  livedata
Nytimes App
🗽 A Simple Demonstration of the New York Times App 📱 using Jsoup web crawler with MVVM Architecture 🔥
Stars: ✭ 246 (+272.73%)
Mutual labels:  livedata
RestaurantsExplorer
Android application build with MVVM Pattern, using Zomato API to enable search cities arround the world and display the city restaurants on a map.
Stars: ✭ 32 (-51.52%)
Mutual labels:  livedata
LifecycleMvp
No description or website provided.
Stars: ✭ 20 (-69.7%)
Mutual labels:  livedata
Newandroidarchitecture Component Github
Sample project based on the new Android Component Architecture
Stars: ✭ 229 (+246.97%)
Mutual labels:  livedata
ReactiveLiveData
An RxJava Extension for the LiveData observer introduced by Google.
Stars: ✭ 17 (-74.24%)
Mutual labels:  livedata
LiveData
Android Architecture Component - LiveData example
Stars: ✭ 18 (-72.73%)
Mutual labels:  livedata
Dagger-Hilt-MVVM
Sample app that demonstrates the usage of Dagger Hilt with Kotlin & MVVM
Stars: ✭ 62 (-6.06%)
Mutual labels:  livedata
Relax
☘☘Relax 基于Kotlin语言编写的一套组件化框架,不紧整体组件化、内部也高度组件化🎋你可配置MVP、MVVM的开发模式、也可以配置所需要的业务组件🍁🍁
Stars: ✭ 253 (+283.33%)
Mutual labels:  livedata
StateFlow-MVVM-MVI-demo
Using StateFlow as LiveData | StateFlow instead of LiveData | LiveData to StateFlow | StateFlow MVVM | StateFlow sample | StateFlow demo
Stars: ✭ 144 (+118.18%)
Mutual labels:  livedata
Restaurants
Restaurants sample app built with the new architecture components (LiveData, Room, ViewModel) and Dagger 2
Stars: ✭ 47 (-28.79%)
Mutual labels:  livedata
Liveeventbus
📬EventBus for Android,消息总线,基于LiveData,具有生命周期感知能力,支持Sticky,支持AndroidX,支持跨进程,支持跨APP
Stars: ✭ 3,192 (+4736.36%)
Mutual labels:  livedata
LiveAdapter
Auto updating RecyclerView Adapter for LiveData
Stars: ✭ 50 (-24.24%)
Mutual labels:  livedata
Geeknews
An MVVM practice app that uses Kotlin, DataBinding, LiveData, ViewModel and Room. The app's data source is from https://gank.io/api
Stars: ✭ 239 (+262.12%)
Mutual labels:  livedata
livedata-recyclerview-sample
No description or website provided.
Stars: ✭ 76 (+15.15%)
Mutual labels:  livedata
Pursuit-Core-Android
Pursuit Core Android
Stars: ✭ 45 (-31.82%)
Mutual labels:  livedata
StatefulLiveData
StatefulLiveData is a lean, yet powerful tool that harnesses the capabilities of LiveData and enhances them, enabling the observer to distinguish between different states the data can be in, such as Success, Loading and Error.
Stars: ✭ 18 (-72.73%)
Mutual labels:  livedata
TeamManagerApp
A sample app structure using the MVVM architecture LiveData, RxJava, ViewModel, Room and the Navigation Arch Components.
Stars: ✭ 36 (-45.45%)
Mutual labels:  livedata

FancyLocationProvider

CircleCI jitpack

Wrapper of FusedLocationProviderClient for Android to support modern usage like LiveData or Flow.

Install

Add Jitpack repository to your root build.grable:

allprojects {
  repositories {
    ...
    maven { url 'https://jitpack.io' }
  }
}

Then add dependency in your module build.gradle:

dependencies {
  implementation 'com.github.jintin:FancyLocationProvider:2.0.0'
}

Usage

LiveData

Here is an example of how you can create a LocationLiveData in ViewModel layer, just provide Context and the LocationRequest with your own config.

class MainViewModel(application: Application) : AndroidViewModel(application) {
    private val locationRequest =
        LocationRequest.create()
            .setInterval(3000)
            .setFastestInterval(3000)
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)

    val locationLiveData = LocationLiveData(application, locationRequest)
}

And here is how you observe the update on View layer.

// check for the location permission first
locationLiveData.observe(this) {
    when (it) {
        is LocationData.Success -> // get location by "it.location"
        is LocationData.Fail -> // Fail to get location
    }
}

Flow

val locationFlow = LocationFlow(application, locationRequest)

// check for the location permission first
// should inside coroutine
locationFlow.get().collect {
    when (it) {
        is LocationData.Success -> // get location by "it.location"
        is LocationData.Fail -> // Fail to get location
    }
}

You can go to ./app module for more information.

Custom Location Provider

FancyLocationProvider using GMS as the default location provider as it serve the most use case. But you can also used it with any other provider you want like Huawei HMS. Just create the custom provider implement the ILocationProvider interface like this:

class LocationProvider(
    private val context: Context,
    private val locationRequest: LocationRequest
) : ILocationProvider {

    private val locationProviderClient by lazy {
        LocationServices.getFusedLocationProviderClient(context)
    }
    private val locationListener by lazy {
        LocationListener()
    }

    @RequiresPermission(anyOf = [Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION])
    override fun requestLocationUpdates(locationObserver: ILocationObserver) {
        locationListener.locationObserver = locationObserver
        locationProviderClient.requestLocationUpdates(
            locationRequest,
            locationListener,
            Looper.getMainLooper()
        )
    }

    override fun removeLocationUpdates() {
        locationProviderClient.removeLocationUpdates(locationListener)
    }

    private class LocationListener : LocationCallback() {
        var locationObserver: ILocationObserver? = null

        override fun onLocationResult(result: LocationResult?) {
            result?.lastLocation?.let {
                locationObserver?.onLocationResult(it)
            }
        }

        override fun onLocationAvailability(availability: LocationAvailability?) {
            if (availability?.isLocationAvailable == false) {
                locationObserver?.onLocationFailed()
            }
        }
    }
}

Then you can create the custom provider and transform it into LiveData or Flow.

private val locationProvider: ILocationProvider = LocationProvider(context, locationRequest)

@ExperimentalCoroutinesApi
val locationFlow: LocationFlow = locationProvider.asFlow()
val locationLiveData: LocationLiveData = locationProvider.asLiveData()

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/Jintin/FancyLocationProvider.

License

The package is available as open source under the terms of the MIT License.

Buy Me A Coffee

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].