/Vinyl

:speaker:- Samples of reactive MVVM architecture for Android™

Primary LanguageKotlinApache License 2.0Apache-2.0

Vinyl for Android™

Build Status Kotlin Java Min SDK

Modular Architecture 🔧

Never heard about modular architecture? click here

For each new features please create its own component

@NewFeatureScope
@Component(
        dependencies = [CoreComponent::class],
        modules = [NewFeatureModule::class]
)
interface NewFeatureComponent {

    fun environment(): NewFeatureEnvironment

}

Its own environment

data class NewFeatureEnvironment @Inject constructor(
       // Add properties needed. Ex: api, analytics, scheduler, etc.
)

And its own module

@Module
class NewFeatureModule {

    @Provides
    @NewFeatureScope
    fun provideNewFeatureEnvironment(): NewFeatureEnvironment {
        return NewFeatureEnvironment()
    }

}

Design Pattern ⚡

MVVM facilitates a separation of development of the graphical user interface from development of the business logic or back-end logic (the data model). The view model of MVVM is a value converter, meaning the view model is responsible for exposing (converting) the data objects from the model in such a way that objects are easily managed and presented. In this respect, the view model is more model than view, and handles most if not all of the view's display logic. The view model may implement a mediator pattern, organizing access to the back-end logic around the set of use cases supported by the view.

For each new ViewModel's please follow this implementation:

class NewFeatureViewModel(
        environment: NewFeatureEnvironment,
        scopeProvider: AndroidLifecycleScopeProvider
): ActivityViewModel() {

    class Factory(
            private val environment: NewFeatureEnvironment,
            private val scopeProvider: AndroidLifecycleScopeProvider
    ) : ViewModelProvider.Factory {
        override fun <T : ViewModel?> create(modelClass: Class<T>): T {
            return NewFeatureViewModel(environment, scopeProvider) as T
        }
    }

}

To bind the ViewModel to the activity:

private val viewModelFactory by lazy {
    NewFeatureViewModel.Factory(component.environment(), scopeProvider)
}

private val viewModel by lazy {
    ViewModelProviders.of(this, viewModelFactory).get(NewFeatureViewModel::class.java)
}

Gradle 🐘

Test a unique class

./gradlew :app:testReleaseUnitTest --tests ${CLASS REFERENCE} --info

Test all

./gradlew :app:testReleaseUnitTest

Lint

./gradlew :app:lintRelease

Git 💾

Branch

  • master --> Latest code running on production
  • develop --> Stable development code before QA

Branch naming convention

$ git branch -b [developer-initial]/[issue-tag-number]_[issue-name]

Formatting commit messages

$ git commit -am "[... your message ...]"

All commit message line will be cropped at 100 characters

Formatting pull request

Please follow the template PULL_REQUEST_TEMPLATE when you create a new pull request.

Android Version Support 📱

Android fragmentation analytics --> Platform Versions

  • Min API 19 --> Kitkat : 4.4.x
  • Max API 28 --> Oreo : 8.1.x

Android Code Style Convention 🍉

Cookbooks 📚

Contributors 🍪

Guillaume Mas