Skip to content

Commit

Permalink
Be more Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
colinanderson committed Dec 11, 2024
1 parent 8aacd89 commit 108e401
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ class PlayKmlTourViewModel(application: Application) : AndroidViewModel(applicat
)
}
kmlLayer.load().onSuccess {
kmlTour = findFirstKMLTour(kmlDataSet.rootNodes)
kmlTourController.tour = kmlTour

if (kmlTour != null) {
collectKmlTourStatus(kmlTour!!)
findFirstKMLTour(kmlDataSet.rootNodes)?.let {
kmlTour = it
collectKmlTourStatus(it)
kmlTourController.tour = it
collectProgress(kmlTourController)
}
}.onFailure { error ->
Expand All @@ -107,10 +106,12 @@ class PlayKmlTourViewModel(application: Application) : AndroidViewModel(applicat
* Plays or pauses the KML tour
*/
fun playOrPause() {
if (kmlTour!!.status.value == KmlTourStatus.Playing) {
kmlTourController.pause()
} else {
kmlTourController.play()
kmlTour?.let {
when (it.status.value) {
KmlTourStatus.Playing -> kmlTourController.pause()
KmlTourStatus.Paused, KmlTourStatus.Initialized, KmlTourStatus.Completed -> kmlTourController.play()
else -> throw IllegalStateException("KML tour is not initialized")
}
}
}

Expand Down

0 comments on commit 108e401

Please sign in to comment.