Introduction

Spork is a runtime annotation processing library. It comes with subprojects for Android and dependency injection.
These libraries allow you to write less boilerplate code which makes your code easier to read and maintain.

Spork is fast, open source and it aims to be different by overcoming the shortcomings of its alternatives.

Spork for Android

The spork-android dependency contains a lot of annotations to write less boilerplate code in Android:

@BindLayout(R.layout.activity_download)
public class YourActivity extends Activity {

    @BindView(R.id.your_button)
    private Button button;

    @BindFragment(R.id.your_fragment)
    private DetailsFragment fragment;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Spork.bind(this);
    }

    @BindClick(R.id.other_button)
    private void onClickButton(Button button) {
        // handle click
    }
}
If you want to see more, check out the spork-android documentation.

Spork Dependency Injection

The spork-inject library is built upon the annotations from javax.inject (JSR-330).

class CoffeeMug {
    @Inject private Coffee coffee;
    @Inject private Mug mug;

    public CoffeeMug() {
        ObjectGraphs.builder()
            .module(new BrewModule())
            .build()
            .bind(this); // same as Spork.inject(this, objectGraph)
    }
}

class BrewModule {
    @Provides
    public Coffee provideCoffee(Water water, CoffeeBeans beans) {
        return new BlackCoffee(water, beans);
    }

    @Provides
    public Mug provideMug() {
        return new MugWithPrint("Input Java, output Java.");
    }

    @Provides
    public Water provideWater() {
        return new BoilingWater();
    }

    @Provides
    public Beans provideBeans() {
        return new ArabicaBeans();
    }
}
If you like this, make sure to check out the Dependency Injection User Guide.

Libraries

All dependencies are hosted on jcenter, which is already the default repository for Android projects.

To use dependency injection:

dependencies {
    compile 'com.bytewelder.spork:spork-inject:4.0.0'
}
To use Android bindings:
dependencies {
    compile 'com.bytewelder.spork:spork-android:4.0.0@aar'
}
To use Android bindings with AppCompat/Support:
dependencies {
    compile 'com.bytewelder.spork:spork-android-support:4.0.0@aar' {
        exclude group: 'com.android.support'
    }
}

License

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.