Controller

abstract class Controller

A Controller manages portions of the UI. It is similar to an Activity or Fragment in that it manages its own lifecycle and controls interactions between the UI and whatever logic is required. It is, however, a much lighter weight component than either Activities or Fragments. While it offers several lifecycle methods, they are much simpler and more predictable than those of Activities and Fragments.

Types

LifecycleListener
Link copied to clipboard
abstract class LifecycleListener
Allows external classes to listen for lifecycle events in a Controller
RetainViewMode
Link copied to clipboard
enum RetainViewMode
Modes that will influence when the Controller will allow its view to be destroyed

Functions

addLifecycleListener
Link copied to clipboard
fun addLifecycleListener(@NonNull() lifecycleListener: Controller.LifecycleListener)
Adds a listener for all of this Controller's lifecycle events
getActivity
Link copied to clipboard
fun getActivity(): Activity
Returns the host Activity of this Controller's Router or {@code null} if thisController has not yet been attached to an Activity or if the Activity has been destroyed.
getApplicationContext
Link copied to clipboard
fun getApplicationContext(): Context
Returns the Application Context derived from the host Activity or {@code null} if this Controllerhas not yet been attached to an Activity or if the Activity has been destroyed.
getChildRouter
Link copied to clipboard
fun getChildRouter(@NonNull() container: ViewGroup): Router
Retrieves the child Router for the given container.
fun getChildRouter(@NonNull() container: ViewGroup, @Nullable() tag: String): Router
Retrieves the child Router for the given container/tag combination.
fun getChildRouter(@NonNull() container: ViewGroup, @Nullable() tag: String, createIfNeeded: Boolean): Router
Retrieves the child Router for the given container/tag combination.
fun getChildRouter(@NonNull() container: ViewGroup, @Nullable() tag: String, createIfNeeded: Boolean, boundToHostContainerId: Boolean): Router
Retrieves the child Router for the given container/tag combination.
getResources
Link copied to clipboard
fun getResources(): Resources
Returns the Resources from the host Activity or {@code null} if this Controller has notyet been attached to an Activity or if the Activity has been destroyed.
getTargetController
Link copied to clipboard
fun getTargetController(): Controller
Returns the target Controller that was set with the setTargetController method or {@code null} if this Controller has no target.
handleBack
Link copied to clipboard
open fun handleBack(): Boolean
Should be overridden if this Controller needs to handle the back button being pressed.
isAttached
Link copied to clipboard
fun isAttached(): Boolean
Returns whether or not this Controller is currently attached to a host View.
isDestroyed
Link copied to clipboard
fun isDestroyed(): Boolean
Returns whether or not this Controller has been destroyed.
onActivityResult
Link copied to clipboard
open fun onActivityResult(requestCode: Int, resultCode: Int, @Nullable() data: Intent)
Should be overridden if this Controller has called startActivityForResult and needs to handlethe result.
onCreateOptionsMenu
Link copied to clipboard
open fun onCreateOptionsMenu(@NonNull() menu: Menu, @NonNull() inflater: MenuInflater)
Adds option items to the host Activity's standard options menu.
onOptionsItemSelected
Link copied to clipboard
open fun onOptionsItemSelected(@NonNull() item: MenuItem): Boolean
Called when an option menu item has been selected by the user.
onPrepareOptionsMenu
Link copied to clipboard
open fun onPrepareOptionsMenu(@NonNull() menu: Menu)
Prepare the screen's options menu to be displayed.
onRequestPermissionsResult
Link copied to clipboard
open fun onRequestPermissionsResult(requestCode: Int, @NonNull() permissions: Array<String>, @NonNull() grantResults: Array<Int>)
Should be overridden if this Controller has requested runtime permissions and needs to handle the user's response.
overridePopHandler
Link copied to clipboard
open fun overridePopHandler(@Nullable() overriddenPopHandler: ControllerChangeHandler)
Overrides the ControllerChangeHandler that should be used for popping this Controller.
overridePushHandler
Link copied to clipboard
open fun overridePushHandler(@Nullable() overriddenPushHandler: ControllerChangeHandler)
Overrides the ControllerChangeHandler that should be used for pushing this Controller.
registerForActivityResult
Link copied to clipboard
fun registerForActivityResult(requestCode: Int)
Registers this Controller to handle onActivityResult responses.
removeChildRouter
Link copied to clipboard
fun removeChildRouter(@NonNull() childRouter: Router)
Removes a child Router from this Controller.
removeLifecycleListener
Link copied to clipboard
fun removeLifecycleListener(@NonNull() lifecycleListener: Controller.LifecycleListener)
Removes a previously added lifecycle listener
requestPermissions
Link copied to clipboard
fun requestPermissions(@NonNull() permissions: Array<String>, requestCode: Int)
Calls requestPermission(String[], int) from this Controller's host Activity.
setTargetController
Link copied to clipboard
open fun setTargetController(@Nullable() target: Controller)
Optional target for this Controller.
shouldShowRequestPermissionRationale
Link copied to clipboard
open fun shouldShowRequestPermissionRationale(@NonNull() permission: String): Boolean
Gets whether you should show UI with rationale for requesting a permission.
startActivity
Link copied to clipboard
fun startActivity(@NonNull() intent: Intent)
Calls startActivity(Intent) from this Controller's host Activity.
startActivityForResult
Link copied to clipboard
fun startActivityForResult(@NonNull() intent: Intent, requestCode: Int)
Calls startActivityForResult(Intent, int) from this Controller's host Activity.
fun startActivityForResult(@NonNull() intent: Intent, requestCode: Int, @Nullable() options: Bundle)
Calls startActivityForResult(Intent, int, Bundle) from this Controller's host Activity.
startIntentSenderForResult
Link copied to clipboard
fun startIntentSenderForResult(@NonNull() intent: IntentSender, requestCode: Int, @Nullable() fillInIntent: Intent, flagsMask: Int, flagsValues: Int, extraFlags: Int, @Nullable() options: Bundle)
Calls startIntentSenderForResult(IntentSender, int, Intent, int, int, int, Bundle) from this Controller's host Activity.

Properties

args
Link copied to clipboard
private val args: Bundle
hasOptionsMenu
Link copied to clipboard
private open var hasOptionsMenu: Boolean
instanceId
Link copied to clipboard
open val instanceId: String
isBeingDestroyed
Link copied to clipboard
open val isBeingDestroyed: Boolean
optionsMenuHidden
Link copied to clipboard
private open var optionsMenuHidden: Boolean
overriddenPopHandler
Link copied to clipboard
private open val overriddenPopHandler: ControllerChangeHandler
overriddenPushHandler
Link copied to clipboard
private open val overriddenPushHandler: ControllerChangeHandler
parentController
Link copied to clipboard
private open var parentController: Controller
retainViewMode
Link copied to clipboard
private open var retainViewMode: Controller.RetainViewMode
router
Link copied to clipboard
open var router: Router
view
Link copied to clipboard
open val view: View

Extensions

asTransaction
Link copied to clipboard
fun Controller.asTransaction(popChangeHandler: ControllerChangeHandler? = null, pushChangeHandler: ControllerChangeHandler? = null): RouterTransaction