summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/utils/LocationComponentAction.kt
blob: ad80a3333ea9bd260fc466c8d75f5600832e539e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.mapbox.mapboxsdk.location.utils

import android.content.Context
import android.support.test.espresso.UiController
import android.support.test.espresso.ViewAction
import android.support.test.espresso.matcher.ViewMatchers.isDisplayed
import android.view.View
import com.mapbox.mapboxsdk.maps.MapboxMap
import com.mapbox.mapboxsdk.location.LocationComponent
import org.hamcrest.Matcher

class LocationComponentAction(private val mapboxMap: MapboxMap,
                                private val onPerformLocationComponentAction: OnPerformLocationComponentAction) : ViewAction {

  override fun getConstraints(): Matcher<View> {
    return isDisplayed()
  }

  override fun getDescription(): String {
    return javaClass.simpleName
  }

  override fun perform(uiController: UiController, view: View) {
    val component = mapboxMap.locationComponent

    while (mapboxMap.getSource("mapbox-location-source") == null) {
      uiController.loopMainThreadForAtLeast(MapboxTestingUtils.MAP_RENDER_DELAY)
    }

    onPerformLocationComponentAction.onLocationComponentAction(
      component,
      mapboxMap,
      uiController,
      view.context)
  }

  interface OnPerformLocationComponentAction {
    fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context)
  }
}