Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CustomLifecycleOwner(private val context: Context) : LifecycleOwner {
- private val TAG = "AUDIT 2"
- private var auditHelper: AuditHelperLifecycleAware? = null
- private var lifecycle: LifecycleRegistry = LifecycleRegistry(this)
- init {
- lifecycle.markState(Lifecycle.State.INITIALIZED)
- onCreate()
- }
- private fun onStart(){
- lifecycle.markState(Lifecycle.State.STARTED)
- onResume()
- }
- private fun onCreate(){
- var action1: (String) -> Unit = {
- Log.i(TAG, String.format(context.getString(R.string.report_from_custom_lifecycle_owner) , it))
- }
- var action2: (String) -> Unit = {
- var dialog = AlertDialog.Builder(context)
- with(dialog){
- setPositiveButton(context.getString(R.string.ok_button), null)
- setMessage(String.format(context.getString(R.string.report_action) , it))
- show()
- }
- }
- auditHelper = AuditHelperLifecycleAware(lifecycle,action1, action2)
- lifecycle.addObserver(auditHelper!!)
- lifecycle.markState(Lifecycle.State.CREATED)
- onStart()
- }
- private fun onDestroy(){
- lifecycle.markState(Lifecycle.State.DESTROYED)
- }
- private fun onResume(){
- lifecycle.markState(Lifecycle.State.RESUMED)
- onDestroy()
- }
- @NonNull
- override fun getLifecycle(): Lifecycle {
- return lifecycle
- }
- }
Add Comment
Please, Sign In to add comment