Provide base constructor / abstract for simplify code structure. Powered by KOIN for dependency injection and using MVVM pattern with clean architecture.
- Create New Personal Access Token -> Tutorial
- Check for read:packages role, then save your token
- Create github.properties in your app folder with content:
- USER=
<Your Github User ID>
- KEY=
<Generated Personal Access Token>
- USER=
- Open build.gradle in your app folder, add this before tag android { . . . }
def githubPropsFile = file('github.properties')
Properties githubProps = new Properties()
if (githubPropsFile.canRead()) {
githubProps.load(new FileInputStream(githubPropsFile))
}
- Then add maven repository for this package before tag dependencies { . . . }
repositories {
maven {
url = uri("https://maven.pkg.github.com/tossaro/kotlin-android-core")
credentials {
username = githubProps['USER']
password = githubProps['KEY']
}
}
}
- Last, add
implementation 'kotlin.android:core:1.1.0'
inside tag dependencies { . . . }
- On Activity :
....
import android.core.app.BaseActivity
class ExampleActivity : BaseActivity() {
....
override fun navHostFragment(): FragmentContainerView = your-content-fragment-view-binding
override fun getNavGraphResource(): Int = R.navigation.navigation
....
}
- On Fragment :
....
import android.core.app.BaseFragment
class ExampleFragment: BaseFragment<ExampleFragmentBinding>(
R.layout.example_fragment
) {
....
val viewModel: ExampleViewModel by viewModel()
override fun bind() {
super.bind()
binding.viewModel = viewModel.also {
it.loadingIndicator.observe(this, ::loadingIndicator)
it.alertMessage.observe(this, ::showAlert)
....
}
....
}
....
}
- On View Model :
....
import android.core.app.BaseViewModel
class SplashViewModel : BaseViewModel() {
....
}