This document summarizes how to use the Conductor library to manage view stacks and transitions in Android apps. It discusses how Conductor handles activities, controllers, transitions, lifecycles, dependency injection, and testing. Key points include using Conductor to push and pop controllers to manage the view stack, creating custom transition animations, surviving configuration changes, integrating with architectures like MVVM, and testing controllers with Espresso. The presenter provides code examples and recommends Conductor for building view-based Android apps.
21. override fun getAnimator(…): Animator {
val animator = AnimatorSet()
to?.let {
animator.play(…)
// The "to" View has a child with id "image"
animator.play(
ObjectAnimator
.ofFloat(to.image, View.ROTATION, -360f, 1f)
)
}
return animator
}
@Miqubel
30. class MyController(val parameter: String) : Controller() {
override fun onCreateView(…): View {
val view = inflater.inflate(…)
view.textView.text = "My favorite city is $parameter"
return view
}
}
❌
DON’T!
@Miqubel
31. class MyController(bundle: Bundle) : Controller(bundle) {
constructor(parameter: String) : this(Bundle().apply {
putString(EXTRA_PARAMETER, parameter)
})
// Access arguments like class properties
private val parameter by lazy {
args.getString(EXTRA_PARAMETER)
}
//…
view.textView.text = "My favorite city is $parameter"
👍
@Miqubel
34. class MyController : Controller() {
// Warning! this will leak on onDestroyView
lateinit var textView: TextView
override fun onCreateView(…): View {
val view = inflater.inflate(…)
// Store a reference to the textView for later
textView = view.textView
return view
}
❌
DON’T!
@Miqubel
36. model = ViewModelProviders
.of(activity as AppCompatActivity)
.get(MyViewModel::class.java)
model.getLiveData()
.observe(
activity as AppCompatActivity,
Observer<String> {
// Use the LiveData values
}
)
❌
DON’T!
@Miqubel
37. abstract class BaseViewModelController
: LifecycleController() {
private val viewModelStore = ViewModelStore()
fun viewModelProvider(factory): ViewModelProvider {
return ViewModelProvider(viewModelStore, factory)
}
}
@Miqubel
Ref: https://github.com/bluelinelabs/Conductor/pull/405
48. Recap
@Miqubel
View based apps on Android
Manage your view stack
Nice transition animations
Surviving configuration changes
49. Recap
@Miqubel
View based apps on Android
Manage your view stack
Nice transition animations
Surviving configuration changes
Compatible with pres. patterns
50. Recap
@Miqubel
View based apps on Android
Manage your view stack
Nice transition animations
Surviving configuration changes
Compatible with pres. patterns
Easy to test with Espresso