-
-
Save pvnvk/32e647ac2db6e4aac02c315f681d8594 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity(), StateLogger by StateLoggerImpl(), ActionBarHandler by ActionbarHandlerImpl() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
registerLifecycleOwner(this) | |
setActionbar(actionBar) | |
setContentView(R.layout.activity_main) | |
} | |
} | |
interface StateLogger { | |
fun registerLifecycleOwner(lifecycleOwner: LifecycleOwner) | |
} | |
interface ActionBarHandler { | |
fun setActionbar(toolbar: ActionBar?) | |
} | |
class StateLoggerImpl: StateLogger, LifecycleEventObserver { | |
override fun registerLifecycleOwner(lifecycleOwner: LifecycleOwner) { | |
lifecycleOwner.lifecycle.addObserver(this) | |
} | |
override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) { | |
Log.d(TAG, "State is : ${event.name}") | |
} | |
fun sendStateEvent(state: String) { | |
Log.d(TAG, "State is : $state") | |
} | |
} | |
class ActionbarHandlerImpl: ActionBarHandler { | |
private var mActionbar: ActionBar? = null | |
override fun setActionbar(actionBar: ActionBar?) { | |
mActionbar = actionBar | |
initToolbar() | |
} | |
private fun initToolbar() { | |
mActionbar?.setLogo(R.drawable.ic_launcher_background) | |
mActionbar?.title = "SampleTitle" | |
} | |
fun setTitle(title: String) { | |
mActionbar?.title = title | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment