Giter Site home page Giter Site logo

savepopulation / piri Goto Github PK

View Code? Open in Web Editor NEW
55.0 3.0 11.0 111 KB

Piri is a lightweight annotation processing library that generates static factory methods for your Activities and Fragments.

Java 100.00%
android java-library annotation-processing annotation-processor android-navigation

piri's Introduction

piri

Piri is a lightweight annotation processing library that generates static factory methods for your Activities and Fragments.

How to use?

Add PiriActivity annotation to your Activity.

@PiriActivity
public class YourActivity extends AppCompatActivity {
...
}

And start YourActivity from another Activity.

public class MainActivity extends AppCompatActivity {
...
 navButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final Intent intent = PiriIntentFactory.newIntentForYourActivity(MainActivity.this);
                startActivity(intent);
            }
        });
...
}

If you want to pass data to YourActivity with Piri add PiriParam annotation to your fields in your Activity and receive data from bundle.

@PiriActivity
public class YourActivity extends AppCompatActivity {
    
    @PiriParam(key = "extra_id")
    private Long id;

    @PiriParam(key = "extra_name")
    private String name;
    
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_your);

        final Bundle bundle = getIntent().getExtras();
        if (bundle != null) {
            id = bundle.getLong("extra_id");
            name = bundle.getString("extra_name");
        }

        // INIT UI
        ...
    }
}

And start YourActivity like the following:

public class MainActivity extends AppCompatActivity {
...

 final Long id = 1234567890L;
 final String name = "PiriExample";
 navButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final Intent intent = PiriIntentFactory.newIntentForYourActivity(MainActivity.this,id,name);
                startActivity(intent);
            }
        });
...
}

Now you can generate your fragment instances with Piri.

Add PiriFragment annotation to your Fragments.

@PiriFragment
public class SampleFragment extends Fragment{
    
    private static final String EXTRA_ID = "extra_id";
    private static final String EXTRA_USER = "extra_user";
    private static final String EXTRA_BOOK = "extra_book";

    @PiriParam(key = EXTRA_ID)
    private Long id;

    @PiriParam(key = EXTRA_USER)
    private User user;

    @PiriParam(key = EXTRA_BOOK)
    private Book book;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final Bundle args = getArguments();
        if (args != null) {
            id = args.getLong(EXTRA_ID, 0);
            user = args.getParcelable(EXTRA_USER);
            book = (Book) args.getSerializable(EXTRA_BOOK);
        }
    }
}

Where Piri comes from?

https://en.wikipedia.org/wiki/P%C3%AEr%C3%AE_Reis

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.