Skip to content

Instantly share code, notes, and snippets.

@Div-e-Sepid
Created July 6, 2020 08:08
Show Gist options
  • Save Div-e-Sepid/58ecf2f10e1832629d8044b5fda8a692 to your computer and use it in GitHub Desktop.
Save Div-e-Sepid/58ecf2f10e1832629d8044b5fda8a692 to your computer and use it in GitHub Desktop.
abstract class BaseActivity(
@LayoutRes private val layoutRes: Int? = null
): AppCompatActivity(), InterfaceOne, InterfaceTwo {
@Inject // now all my children have to use dagger, YAY!
lateinit var analytics: Analytics
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (layoutRes != null) {
setContentView(layoutRes)
if (foundToolbarWithSomeSpecificId) {
init(toolbar)
}
}
// hopefully it's injected by now!
analytics.sendAnalytics(this, "onCreate")
}
override fun onStart() {
super.onStart()
analytics.sendAnalytics(this, "onStart")
}
override fun methodFromInterfaceOne() {
if (onlyHalfOfTheTimeBasedOnGodKnowsWhat) {
// do something that should have been in the child class to begin with
} else {
// do something that can be removed right now!
}
}
override fun methodFromInterfaceTwo() {
// I wished it wasn't accessible by child classes ;(
}
open fun onWeirdCallbackOne() {
// some weird logic that is irrelevant 99% of the time
}
abstract fun getSomeWeirdTypeNoOneKnowsWhy(): Int
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment