Giter Site home page Giter Site logo

bytewelder / spork Goto Github PK

View Code? Open in Web Editor NEW
76.0 8.0 8.0 5.25 MB

Annotation processing and dependency injection for Java/Android

Home Page: http://spork.bytewelder.com

License: Apache License 2.0

Java 100.00%
dependency-injection annotation-processing android java

spork's Introduction

ARCHIVED

This project is no longer being worked on.

Spork

travis

Spork is a fast runtime annotation processing library.

Spork contains the following libraries:

  • spork is the annotation processing core
  • spork-inject for dependency injection (javax.inject compatible)
  • spork-android and spork-android-support for Android bindings

Documentation is available on the website

License

Spork is available through the Apache License Version 2.0.

spork's People

Contributors

kenvanhoeylandt avatar posytive avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spork's Issues

Activity Extra injection

Support for extra Intent extras binding for Activity.

For example:

@BindExtra
String something;

@BindExtra("something")
String mSomething;

View Not Found Exception

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import io.github.sporklibrary.Spork;
import io.github.sporklibrary.annotations.BindLayout;
import io.github.sporklibrary.annotations.BindView;

@BindLayout(R.layout.activity_test)
public class TestActivity extends AppCompatActivity {

    @BindView(R.id.textTest)
    TextView txtView;

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

        txtView.setText("Hello Test");
    }
}

Below is XML Layout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@mipmap/main_bg"
    android:orientation="vertical"
    tools:context="com.devdigital.glowmotion.view.activities.FillOutBasicDataActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:elevation="0dp">

        <include
            android:id="@+id/scanner_toolbar"
            layout="@layout/toolbar" />
    </android.support.design.widget.AppBarLayout>



    <TextView
        android:id="@+id/textTest"
        android:layout_width="@dimen/DP200"
        android:layout_height="@dimen/DP200"
        android:layout_gravity="center"
        android:layout_marginBottom="@dimen/DP5"
        />
</LinearLayout>

FATAL EXCEPTION: main
Process: com.devdigital.glowmotion.debug, PID: 19629
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.devdigital.glowmotion.debug/com.devdigital.glowmotion.TestActivity}: io.github.sporklibrary.exceptions.BindException: BindView failed for TestActivity: View not found
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: io.github.sporklibrary.exceptions.BindException: BindView failed for TestActivity: View not found

Improve internal Exception mechanisms

  • Replace BindFailedBuilder with new class ErrorMessageBuilder
  • Internal methods should declare and throw specific Exceptions that are not RuntimeExceptions

System service injection

Inject different system services.

For example:

@BindSystemService
PowerManager mPowerManager;

Observe changes on the View tree

Must re-inject Views when they have changed for all @BindView targets.

Temporary work-around: call Spork.bind() again when necessary.

spork injection 4.0

Hi! Is recommended use spork injection in android app (not spork android, spork injection product) or it decreases too much android performance???

ViewResolver throws wrong error

When BindClick fails because of an unresolved id, the error says BindView failed for [...].
This is because BindView.class is hardcoded into ViewResolver.getView().

The exception should provide the correct error message.

Suggestion: make ViewResolver.getView() throw a custom error (maybe NotFoundException or ViewNotFoundException)

Fix typo in BindClick Exception

BindClick failed for AppCompatButton at method 'startMultiplayerWithRandomPlayer': onClick failed because the method arguments must be either empty or accept a a single View type

Fix a a part of the text.

Spork on PagerAdapter

I'm trying to use Spork on PagerAdapter (to display views on a ViewPager) but I'm having problems doing so. For now, I'm creating a custom view, use Spork, and then adding it to the container.

@BindLayout(R.layout.related_item_row)
public class RelatedView extends FrameLayout {

    @BindView(R.id.textView_title)
    TextView textViewTitle;
    @BindView(R.id.imageView_play)
    View imageViewPlay;

    public RelatedView(Context context) {
        super(context);
        Spork.bind(this);
    }

    public void init(final RelatedFeed feed) {
        textViewTitle.setText(feed.getTitle());
        imageViewPlay.setVisibility(!feed.getDataType().equals("news") ? View.VISIBLE : View.GONE);

        setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }
}

So in the PagerAdapter I just have this:

public class RelatedPagerAdapter extends PagerAdapter {

    private Activity context;
    private ArrayList<RelatedFeed> items;

    public RelatedPagerAdapter(Activity context, ArrayList<RelatedFeed> items) {
        Spork.bind(this);

        this.context = context;
        this.items = items;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        final RelatedFeed feed = items.get(position);

        RelatedView view = new RelatedView(context);
        view.init(feed);

        container.addView(view);

        return view;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == ((View) object);
    }
}

It's working great for now. It would be great if Spork works the same way than in other views.

Another thing, how would be the approach if we didn't use PagerAdapter but instead a FragmentPagerAdapter (or FragmentStatePagerAdapter)?

support RecyclerView.Adapter or ViewHolder

Hi! first of all it CONGRATS on developing this great library! I'm porting my project to use this library ASAP. One thing though, I'm getting errors when trying to use it on my RecyclerView adapters or ViewHolders.

By now I've tried:
On Adapter, onCreateViewHolder method:

View view = inflater.inflate(R.layout.news_item_row, parent, false);
Spork.bind(this); //didn't work
Spork.bind(view); //didn't work
return new NewsRecyclerViewHolder(context, view);

Also using Spork.bind(this) and Spork.bind(view) in the constructors of the ViewHolder itself but unfortunately nothing works.

public NewsRecyclerViewHolder(Context context, View itemView) {
    super(itemView);
    Spork.bind(this); //didn't work
    Spork.bind(itemView); //didn't work either        
}

How can we use Spork on the adapters for RecyclerViews?
Is there a workaround?

thanks!

PS: maybe you could upload an example project to see actual code. For example for using a Fragment I didn't knew that I had to call bind inside the fragment's OnViewCreated method. I figured it out searching on the tests folders.

super.onViewCreated(view, savedInstanceState);
Spork.bind(this);

Create separate "Spork Android Support" library

This suggestion was made by Punksmurf. I'm merely writing the gist of our chat down in this ticket.

Create separate "Spork Android Support" library for all appcompat/support-v4 functionality.
This will get rid of the reflection in the code.

In effect, we should start with making Views.getRootView() more abstract. For example with a ViewProvider/RootViewProvider:

public interface RootViewProvider {
    boolean canProvideFor(Object object);
    @Nullable View getRootView(Object object);
}

There can be a DefaultRootViewResolver and a SupportRootViewResolver. The same idea goes for ContextResolver.

These resolvers will be managed in a list where more resolves can be added to.

BindException

Hi! I'm having a problem trying to bind a RecyclerAdapter

public class OrdersRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v;

    switch (viewType) {
        case HEADER:
            v = inflater.inflate(R.layout.order_header_item_row, parent, false);
            return new HeaderHolder(v);
        case ORDER:
            v = inflater.inflate(R.layout.orders_adapter_item, parent, false);
            return new OrderHolder(parent.getContext(), v);
        case TASK:
            v = inflater.inflate(R.layout.tasks_orders, parent, false);
            return new TasksHolder(parent.getContext(), v);
        case IMAGE:
            v = inflater.inflate(R.layout.progress_image_item_row, parent, false);
            return new ImageHolder(v);
        default:
            v = inflater.inflate(R.layout.order_header_item_row, parent, false);
            return new HeaderHolder(v);
        }
    }

    public class HeaderHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.order_pending_or_accepted)
        TextView orderPendingOrAccepted;

        public HeaderHolder(View itemView) {
            super(itemView);
            Spork.bind(this);      <------- HERE IS THE ERROR
        }

        public void bind(OrderHomeWrapper object) {
            String title = (String) object.getObject();
            orderPendingOrAccepted.setText(title);
        }
    }

    public class ImageHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.order_pending_or_accepted)
        TextView orderPendingOrAccepted;

        public ImageHolder(View itemView) {
            super(itemView);
            Spork.bind(this);
        }

        public void bind(OrderHomeWrapper object) {
            String title = (String) object.getObject();
            orderPendingOrAccepted.setText(title);
        }
    }

}

and so on with the other view holders

im getting the error: io.github.sporklibrary.exceptions.BindException: BindView failed for HeaderHolder: incompatible class to find views

Is there a way to have multiple view holders for the same recycler adapter?

Thanks!

Feature: Resource injection

For types:

  • strings
  • dimensions
  • animations

More types could be added, but these seem to be the most important ones.

Dependency Injection of Default Constructor

Dependency injection for an an empty or default constructor shouldn't require a module to do so since it's a simple injection. it could be use full in a DAO Service architecture when a service is only a collection of DAO required by dependency injection but a services is just an ordinary Object with no special treatment required, thus a services would be injected in presenter or view model directly by ObjectGraph

Fragment argument binding

Support for Fragment argument binding.

For example:

@BindFragmentArgument
String something;

@ BindFragmentArgument("something")
String mSomething;

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.