Skip to content

Instantly share code, notes, and snippets.

@ruigoncalo
Last active September 11, 2017 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruigoncalo/3633a79b9c9b7f38a978d340c62448a4 to your computer and use it in GitHub Desktop.
Save ruigoncalo/3633a79b9c9b7f38a978d340c62448a4 to your computer and use it in GitHub Desktop.
Spek with Subjects - View
class DistancesView : FrameLayout, DistancesPresenter.View {
@Inject lateinit var presenter: DistancesPresenter
constructor(context: Context?) : super(context) {
init()
}
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
init()
}
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init()
}
private fun init() {
LayoutInflater.from(context).inflate(R.layout.layout_distances, this, true)
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
//[dagger] inject dependency declared in parent Activity's component
(context as ParentActivity).component.inject(this)
presenter.attachView(this)
presenter.start()
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
presenter.stop()
}
override fun displayDistancesToGreen(distanceToGreenBack: String,
distanceToGreenCenter: String,
distanceToGreenFront: String) {
backGreenDistanceText.text = distanceToGreenBack
centerGreenDistanceText.text = distanceToGreenCenter
frontGreenDistanceText.text = distanceToGreenFront
}
override fun displayDistanceUnit(isMetricDistanceUnit: Boolean) {
distanceUnitText.text = if (isMetricDistanceUnit) {
context.getString(R.string.round_meters_distance_unit)
} else {
context.getString(R.string.round_yards_distance_unit)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment