All Projects → florent37 → DaggerAutoInject

florent37 / DaggerAutoInject

Licence: Apache-2.0 license
Inject automatically your Activities & Fragments, just with a simple annotation

Programming Languages

java
68154 projects - #9 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to DaggerAutoInject

UTair-MVP-Sample
Android Clean Architecture + MVP Sample written in Kotlin
Stars: ✭ 27 (-44.9%)
Mutual labels:  mvp, dagger, dagger2
android-mvp-kotlin
使用kotlin实现Android MVP模式,使用了Dagger2、Retrofit、RxJava等
Stars: ✭ 14 (-71.43%)
Mutual labels:  mvp, dagger, dagger2
Mvpframes
整合大量主流开源项目并且可高度配置化的 Android MVP 快速集成框架,支持 AndroidX
Stars: ✭ 100 (+104.08%)
Mutual labels:  mvp, dagger, dagger2
AndroidMVPArchitecture
Android MVP architecture sample project with or without RxJava and Dagger2 and Kotlin
Stars: ✭ 78 (+59.18%)
Mutual labels:  mvp, dagger, dagger2
Android Mvp Architecture
This repository contains a detailed sample app that implements MVP architecture using Dagger2, GreenDao, RxJava2, FastAndroidNetworking and PlaceholderView
Stars: ✭ 4,360 (+8797.96%)
Mutual labels:  mvp, dagger, dagger2
Bigbang
Android base project used by Xmartlabs team
Stars: ✭ 47 (-4.08%)
Mutual labels:  mvp, dagger, dagger2
Ultimateandroidtemplaterx
MVP Android App Template Ultimate Android Template MVP // Dagger 2 // Boilerplate // Bootstrap // Bottom Navigation Menu Material Design
Stars: ✭ 114 (+132.65%)
Mutual labels:  mvp, dagger, dagger2
MVPFramework
基本框架已搭建出,后续可根据需求增加
Stars: ✭ 29 (-40.82%)
Mutual labels:  mvp, dagger
mvp-sample
Demonstrates how to implement MVP (Model View Presenter) pattern using Kotlin, RXJava, Retrofit, Dagger and DataBinding
Stars: ✭ 35 (-28.57%)
Mutual labels:  mvp, dagger2
Starwars-clean
Simple project with clean architecture
Stars: ✭ 34 (-30.61%)
Mutual labels:  mvp, dagger
ContactsApp
Go-Jek Engineering Task Used MVP and Unit Testing Espresso, Mock Webserver and Activity Instrumentation Tests ,RxJava + RxAndroid + Retrofit 2 + OkHttp 3 + Dagger2 + ButterKnife+ Glide + Active Android ORM
Stars: ✭ 21 (-57.14%)
Mutual labels:  mvp, dagger2
Marvel
Marvel Characters Android Application Assigned by smava GmbH
Stars: ✭ 227 (+363.27%)
Mutual labels:  mvp, dagger
AndroidStarterAlt
A sample View-based Android app using the MVP architecture. It uses Mosby, Dagger2, RxJava, retrofit, LoganSquare, requery, EventBus, Conductor.
Stars: ✭ 27 (-44.9%)
Mutual labels:  mvp, dagger2
wikilight
A lightweight Wikipedia Client
Stars: ✭ 50 (+2.04%)
Mutual labels:  mvp, dagger2
CNeptune
CNeptune improve productivity & efficiency by urbanize .net module with meta-code to lay foundation for frameworks
Stars: ✭ 30 (-38.78%)
Mutual labels:  pattern, injection
Android-Starter-Kit
This is up-to-date android studio project for native android application, that is using modern tools and libraries.
Stars: ✭ 16 (-67.35%)
Mutual labels:  mvp, dagger2
Movieguide
Movie discovery app showcasing MVP, RxJava, Dagger 2 and Clean Architecture
Stars: ✭ 2,573 (+5151.02%)
Mutual labels:  mvp, dagger2
MVVMQuick
🚀使用MVVMQuick快速构建您的MVVM结构项目!(Quickly start projects with MVVMQuick!)
Stars: ✭ 23 (-53.06%)
Mutual labels:  dagger, dagger2
Li-MVPArms
这个项目会持续更新
Stars: ✭ 17 (-65.31%)
Mutual labels:  mvp, dagger
kotlin-mvp-starter
MVP Starter with RxJava, Dagger 2 in Kotlin
Stars: ✭ 56 (+14.29%)
Mutual labels:  dagger, dagger2

DaggerAutoInject

Inject automatically your Activities & Fragments, just with a simple annotation

Android app on Google Play
@InjectActivity
public class MainActivity extends AppCompatActivity {

    @Inject
    SharedPreferences sharedPreferences;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onStart() {
        super.onStart();
        sharedPreferences.edit()
                 .putString("androidVerions", "O")
                 .apply();
    }

}

Download

In your module Download

def dagger_version = "2.11-rc2"

dependencies {
    compile 'com.github.florent37:dagger-auto-inject:1.0.0'
    annotationProcessor 'com.github.florent37:dagger-auto-inject-compiler:1.0.0'

    //dagger2
    compile "com.google.dagger:dagger:$dagger_version"
    compile "com.google.dagger:dagger-android:$dagger_version"
    compile "com.google.dagger:dagger-android-support:$dagger_version"

    annotationProcessor "com.google.dagger:dagger-android-processor:$dagger_version"
    annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"
}

Component

Just add generated ActivityModule.class and FragmentModule.class into your Dagger's component

@Singleton
@Component(modules = {
        AppModule.class,

        AndroidInjectionModule.class,
        AndroidSupportInjectionModule.class,

        ActivityModule.class,
        FragmentModule.class,
})
public interface AppComponent {
    void inject(MainApplication application);

    @Component.Builder
    interface Builder {
        @BindsInstance
        Builder application(Application application);
        AppComponent build();
    }
}

Setup Application

Just annotate your application with @InjectApplication givin your Component, then call DaggerAutoInject.init(this);

Don't forget to implement HasActivityInjector as follow

@InjectApplication(component = AppComponent.class)
public class MainApplication extends Application implements HasActivityInjector {

    @Inject
    DispatchingAndroidInjector<Activity> activityAndroidInjector;

    @Override
    public void onCreate() {
        super.onCreate();
        
        final AppComponent appComponent = DaggerAppComponent.builder()
                        .application(this)
                        .build();
        
        DaggerAutoInject.init(this, appComponent);
    }

    @Override
    public AndroidInjector<Activity> activityInjector() {
        return activityAndroidInjector;
    }
}

Inject Fragment

Just add @InjectFragment to your fragment

@InjectFragment
public class MainFragment extends Fragment {

    @Inject
    SharedPreferences sharedPreferences;

    public static MainFragment newInstance() {
        return new MainFragment();
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_main, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        System.out.println(sharedPreferences.getAll());
    }
}

Then in your Activity / BaseActivity, implements HasSupportFragmentInjector

public class BaseActivity extends AppCompatActivity implements HasSupportFragmentInjector {

    @Inject
    DispatchingAndroidInjector<Fragment> dispatchingFragmentInjector;

    @Override
    public AndroidInjector<Fragment> supportFragmentInjector() {
        return dispatchingFragmentInjector;
    }
}

Credits

Author: Florent Champigny

Android app on Google Play Follow me on Google+ Follow me on Twitter Follow me on LinkedIn

License

Copyright 2017 florent37, Inc.

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].