Giter Site home page Giter Site logo

daggerinstantapps's Introduction

⚡ Android Instant Apps ⚡

Instant apps sample using dagger2 android support.
This sample uses Github API.
This application is flux-like architecture.

Structure

                         --------------
                        | base module  |
                         --------------
                            /       \
                           /         \
                          /           \
            ------------------   ------------------  
           | feature module 1 |  | feature module 2 |
            ------------------   ------------------ 
                      |     \                |
                      |      \____________   |
                      |                   \  |   
            ----------------------     -------------
            | Instant Apps module |    | App module |
            ----------------------     -------------

Module

Base module (app, instant apps)

  • Define models
  • API connection
  • Common utilities

Feature one module (app, instant apps)

  • Repository screen

Feature two module (app)

  • Repository List screen
  • Pull Request List screen
  • Issue List screen

Dagger scope

DaggerScope

Screen shot

RepoListActivity RepoActivity
InstallInstantApps

Setup environment

Start instant apps ⚡

  • Start github repository
    • [owner]
    • [repository name]

https://aakira.github.com/[owner]/[repository name]

  • e.g. https://aakira.github.com/aakira/DaggerInstantApps

Github access token

You should set your access token into /gradle.properties.
You don't have to set it but github api has limitations of the number of times.

# Add your github token
gitHubToken = [YOUR ACCESS TOKEN]
  1. Access this link Github settings
  2. Generate new token
  3. Input new personal access token
  4. Enter your token into gradle.properties.

Dagger injector

BaseModuleInjector

This class refers to DaggerApplication class.
You can use dagger android support even if each module is separated.

Hot to inject

  • Base/AppComponent
@Singleton
@Component(modules = [
    AndroidSupportInjectionModule::class,
    AppModule::class
])
interface AppComponent : AndroidInjector<App>, AppComponentProviders {

    override fun inject(instance: App)

    @Component.Builder
    interface Builder {
        @BindsInstance
        fun application(application: Application): Builder

        fun build(): AppComponent
    }
}
  • Feature/ModuleComponent
@PerModuleScope
@Component(
        dependencies = [AppComponent::class],
        modules = [
            AndroidSupportInjectionModule::class,
            FeatureOneUiBuilder::class,
            FeatureOneModule::class
        ]
)
interface FeatureOneComponent : AndroidInjector<FeatureOneModuleInjector>
  • Feature/ModuleInjector
@Module
abstract class FeatureOneUiBuilder {

    @PerUiScope
    @ContributesAndroidInjector(modules = [RepoModule::class])
    internal abstract fun bindRepoActivity(): RepoActivity
}
  • Feature/ModuleUiBuilder
@Module
abstract class FeatureOneUiBuilder {

    @PerUiScope
    @ContributesAndroidInjector(modules = [RepoModule::class])
    internal abstract fun bindRepoActivity(): RepoActivity
}
  • View
override fun onCreate(savedInstanceState: Bundle?) {
    FeatureOneModuleInjector.inject(this)
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_repo)
}

Author

Akira Aratani

License

Copyright (C) 2018 A.Akira

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

daggerinstantapps's People

Contributors

aakira avatar

Watchers

James Cloos avatar masaibar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.