Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Experimental LiveData support for ranging and monitoring #1025

Merged
merged 4 commits into from
Jun 7, 2021

Conversation

davidgyoung
Copy link
Member

This adds experimental LiveData support for beacon ranging and monitoring. With this change, it is possible to do the following from a Kotlin Activity instead of using RangeNotifier and MonitorNotifier:

    val monitoringObserver = Observer<Int> { state ->
        var stateString = "inside"
        if (state == MonitorNotifier.OUTSIDE) {
            stateString == "outside"
        }
        Log.d(TAG, "monitoring state changed to : $stateString")
    }

    val rangingObserver = Observer<Collection<Beacon>> { beacons ->
        Log.d(TAG, "Ranged: ${beacons.count()} beacons")
    }

        // These two lines set up a Live Data observer so this Activity can get beacon data from the Application class
        val regionViewModel = BeaconManager.getInstanceForApplication(this).getRegionViewModel(region)
        // observer will be called each time the monitored regionState changes (inside vs. outside region)
        regionViewModel.regionState.observe(this, monitoringObserver)
        // observer will be called each time a new list of beacons is ranged (typically ~1 second in the foreground)
        regionViewModel.rangedBeacons.observe(this, rangingObserver)

@davidgyoung davidgyoung changed the title Add LiveData support for ranging and monitoring Add Experimental LiveData support for ranging and monitoring Apr 28, 2021
@davidgyoung davidgyoung merged commit 6a987bc into master Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant