Skip to content

Base of android kotlin project. Provide app lifecycle (activity, fragment, view model), networking, utils and extension. Mission to support micro frontend.

License

Notifications You must be signed in to change notification settings

tossaro/kotlin-android-core

Repository files navigation

Kotlin Android Core License: MIT

Provide base constructor / abstract for simplify code structure. Powered by KOIN for dependency injection and using MVVM pattern with clean architecture.

Contents

Getting started

  1. Create New Personal Access Token -> Tutorial
  2. Check for read:packages role, then save your token
  3. Create github.properties in your app folder with content:
    • USER=<Your Github User ID>
    • KEY=<Generated Personal Access Token>
  4. 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))
}
  1. 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']
        }
    }
}
  1. Last, add implementation 'kotlin.android:core:1.1.0' inside tag dependencies { . . . }

Usage

  1. 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
   ....
} 
  1. 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)
            ....
        }
        ....
   }
   ....
} 
  1. On View Model :
....
import android.core.app.BaseViewModel
class SplashViewModel : BaseViewModel() {
   ....
} 

About

Base of android kotlin project. Provide app lifecycle (activity, fragment, view model), networking, utils and extension. Mission to support micro frontend.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages